#include<stdio.h>
#include<math.h>

#define abs(x) (x > 0 ? x : -(x))
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
#define PI 3.1415926
#define GRIDDIM 32
#define BLOCKDIM 1024 //32*32

extern "C" void TOF_dist_backprojection(float *image_bp, const float *proj_value, const float *tof_value,
                            const float *x1l, const float *y1l, const float *x1r, const float *y1r,
                            const float *x2l, const float *y2l, const float *x2r, const float *y2r,
                            const float time_resolution, const float dx, const float dy,
                            const int nx, const int ny, const int event_num);

// define TOF-dist-bp
__device__ void TOF_dist_bp(float *image_bp, const float proj_value, const float tof_value,
                            const float x1l, const float y1l, const float x1r, const float y1r,
                            const float x2l, const float y2l, const float x2r, const float y2r,
                            const float time_resolution, const float dx, const float dy,
                            const int nx, const int ny)
{
    const float nx2 = nx/2;
    const float ny2 = ny/2;
    const float tof_sigma = time_resolution * 0.3 / 2.355 / 2;
    const float tof_sigma_2 = tof_sigma * tof_sigma;
    const float x1c = (x1l + x1r) / 2;
    const float y1c = (y1l + y1r) / 2;
    const float x2c = (x2l + x2r) / 2;
    const float y2c = (y2l + y2r) / 2;
    const float L = sqrtf((x1c - x2c) * (x1c - x2c) + (y1c - y2c) * (y1c - y2c));
    const float ratio1 = (1 - (tof_value / L)) / 2;

    
    
    if (abs(x1c - x2c) > abs(y1c - y2c))
    {
        for (int ix = 0; ix < nx; ix++)
        {
            float xc = (ix - nx2 + 0.5) * dx;
            float tof_bin = dx;
            float d2_tof, w_tof;
            
            if (tof_sigma > 0)
            {
                d2_tof = ((xc-x1c) / (x2c-x1c) - ratio1)*L;
                if (d2_tof <= 3 * tof_sigma)
                {
                    w_tof = expf(-0.5 * d2_tof * d2_tof / tof_sigma_2) / sqrtf(2.0 * PI * tof_sigma_2) * tof_bin;
                }
                else
                {
                    w_tof = 0.0;
                }
            }
            else
            {
                w_tof = 1.0;
            }
            //d1l-d2r
            float kylr = (y1l-y2r)/(x1l-x2r);
            float ylr = kylr * (xc - x1l) + y1l + ny2 * dy;
            //d1r-d2l
            float kyrl = (y1r - y2l) / (x1r - x2l);
            float yrl = kyrl * (xc - x1r) + y1r + ny2 * dy;

            float yy1 = MIN(ylr,yrl); // 横坐标为xc时，detector边缘与x轴的交点中y较小值
            float yy2 = MAX(ylr,yrl);
            int cy1 = (int)floorf(yy1/dy);
            int cy2 = (int)floorf(yy2/dy);

            for (int iy=(int)MAX(0, cy1); iy < (int)MIN(ny, cy2+1); iy++)
            {
                float dist_w = (MIN((iy+1) * dy,yy2) - MAX(iy * dy,yy1)) / dy;
                atomicAdd(image_bp + (ix + iy * nx), proj_value * dist_w * w_tof);
            }

        }
        
    }
    else
    {
        for (int iy=0; iy < ny; iy++)
        {
            float yc = (iy - ny2 + 0.5) * dy;
            float tof_bin = dy;
            float d2_tof, w_tof;

            if (tof_sigma > 0)
            {
                d2_tof = (((yc-y1c) / (y2c-y1c)) - ratio1) * L;
                if (d2_tof <= 3 * tof_sigma)
                {
                    w_tof = expf(-0.5 * d2_tof * d2_tof / tof_sigma_2) / sqrtf(2.0 * PI * tof_sigma_2) * tof_bin;
                }
                else
                {
                    w_tof = 0.0;
                }
            }
            else
            {
                w_tof = 1.0;
            }
            //d1l-d2r:
            float kxlr = (x1l-x2r)/(y1l-y2r);
            float xlr = kxlr * (yc-y1l)+x1l+nx2 * dx;
            //d1r-d2l:
            float kxrl = (x1r-x2l)/(y1r-y2l);
            float xrl = kxrl * (yc-y1r)+x1r+nx2 * dx;
            
            float xx1 = MIN(xlr,xrl);
            float xx2 = MAX(xlr,xrl);
            float cx1 = (int)floorf(xx1/dx);
            float cx2 = (int)floorf(xx2/dx);

            
            for (int ix=(int)MAX(0, cx1); ix < (int)MIN(nx, cx2+1); ix++)
            {
                float dist_w = (MIN((ix+1) * dx,xx2) - MAX(ix * dx,xx1))/dx;
                atomicAdd(image_bp + (ix + iy * nx), proj_value * dist_w * w_tof);
            }

        }
    }

}

__global__ void TOF_dist_bp_kernel(float *image_bp, const float *proj_value, const float *tof_value,
                                   const float *x1l, const float *y1l, const float *x1r, const float *y1r,
                                   const float *x2l, const float *y2l, const float *x2r, const float *y2r,
                                   const float time_resolution, const float dx, const float dy,
                                   const int nx, const int ny, const int event_num)
{
    int step = blockDim.x * gridDim.x;
    for (int idx = threadIdx.x + blockIdx.x * blockDim.x; idx < event_num; idx += step)
    {
        TOF_dist_bp(image_bp, proj_value[idx], tof_value[idx],
                    x1l[idx], y1l[idx], x1r[idx], y1r[idx],
                    x2l[idx], y2l[idx], x2r[idx], y2r[idx],
                    time_resolution, dx, dy,
                    nx, ny);
    }

}



void TOF_dist_backprojection(float *image_bp, const float *proj_value, const float *tof_value,
                            const float *x1l, const float *y1l, const float *x1r, const float *y1r,
                            const float *x2l, const float *y2l, const float *x2r, const float *y2r,
                            const float time_resolution, const float dx, const float dy,
                            const int nx, const int ny, const int event_num)
{
    float *image_bp_d, *proj_value_d, *tof_value_d, *x1l_d, *y1l_d, *x1r_d, *y1r_d, *x2l_d, *y2l_d, *x2r_d, *y2r_d;
    // 申请device内存
    cudaMalloc(&image_bp_d, nx * ny * sizeof(float));
    cudaMalloc(&proj_value_d, event_num * sizeof(float));
    cudaMalloc(&tof_value_d, event_num * sizeof(float));
    cudaMalloc(&x1l_d, event_num * sizeof(float));
    cudaMalloc(&y1l_d, event_num * sizeof(float));
    cudaMalloc(&x1r_d, event_num * sizeof(float));
    cudaMalloc(&y1r_d, event_num * sizeof(float));
    cudaMalloc(&x2l_d, event_num * sizeof(float));
    cudaMalloc(&y2l_d, event_num * sizeof(float));
    cudaMalloc(&x2r_d, event_num * sizeof(float));
    cudaMalloc(&y2r_d, event_num * sizeof(float));
    // 将host上的数据拷贝到device上
    cudaMemcpy(proj_value_d, proj_value, event_num * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(tof_value_d, tof_value, event_num * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(x1l_d, x1l, event_num * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(y1l_d, y1l, event_num * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(x1r_d, x1r, event_num * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(y1r_d, y1r, event_num * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(x2l_d, x2l, event_num * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(y2l_d, y2l, event_num * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(x2r_d, x2r, event_num * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(y2r_d, y2r, event_num * sizeof(float), cudaMemcpyHostToDevice);
    // 执行kernel
    TOF_dist_bp_kernel<<<GRIDDIM, BLOCKDIM>>>(image_bp_d, proj_value_d, tof_value_d, x1l_d, y1l_d, x1r_d, y1r_d,
                                            x2l_d, y2l_d, x2r_d, y2r_d, time_resolution, dx, dy, nx, ny, event_num);
    // 同步device，保证结果正常访问
    cudaDeviceSynchronize();
    // 将device结果cpy到host
    cudaMemcpy(image_bp, image_bp_d, nx * ny * sizeof(float), cudaMemcpyDeviceToHost);
    // 释放内存
    //cudaFree(image_bp_d);
    cudaFree(proj_value_d);
    cudaFree(tof_value_d);
    cudaFree(x1l_d);
    cudaFree(y1l_d);
    cudaFree(x1r_d);
    cudaFree(y1r_d);
    cudaFree(x2l_d);
    cudaFree(y2l_d);
    cudaFree(x2r_d);
    cudaFree(y2r_d);
}

//nvcc -Xcompiler -fPIC -shared -lcudart -o proj.so proj.cu

	.file	"tmpxft_002cf4fc_00000000-6_bproj.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0, @function
_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0:
.LFB2173:
	.cfi_startproc
	jmp	cudaMalloc@PLT
	.cfi_endproc
.LFE2173:
	.size	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0, .-_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	.globl	_Z11TOF_dist_bpPffffffffffffffii
	.type	_Z11TOF_dist_bpPffffffffffffffii, @function
_Z11TOF_dist_bpPffffffffffffffii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z11TOF_dist_bpPffffffffffffffii, .-_Z11TOF_dist_bpPffffffffffffffii
	.globl	_Z74__device_stub__Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiiiPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.type	_Z74__device_stub__Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiiiPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii, @function
_Z74__device_stub__Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiiiPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$328, %rsp
	.cfi_def_cfa_offset 336
	movq	336(%rsp), %rax
	movq	%rdi, 104(%rsp)
	leaq	128(%rsp), %rdi
	movq	%rsi, 96(%rsp)
	leaq	140(%rsp), %rsi
	movq	%rax, 56(%rsp)
	movq	344(%rsp), %rax
	movq	%rdx, 88(%rsp)
	leaq	112(%rsp), %rdx
	movq	%rax, 48(%rsp)
	movq	352(%rsp), %rax
	movq	%rcx, 80(%rsp)
	leaq	120(%rsp), %rcx
	movq	%rax, 40(%rsp)
	movq	360(%rsp), %rax
	movq	%r8, 72(%rsp)
	movq	%rax, 32(%rsp)
	movq	368(%rsp), %rax
	movq	%r9, 64(%rsp)
	movq	%rax, 24(%rsp)
	movss	%xmm0, 20(%rsp)
	movss	%xmm1, 16(%rsp)
	movss	%xmm2, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 312(%rsp)
	xorl	%eax, %eax
	leaq	104(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	96(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	88(%rsp), %rax
	movq	%rax, 192(%rsp)
	leaq	80(%rsp), %rax
	movq	%rax, 200(%rsp)
	leaq	72(%rsp), %rax
	movq	%rax, 208(%rsp)
	leaq	64(%rsp), %rax
	movq	%rax, 216(%rsp)
	leaq	56(%rsp), %rax
	movq	%rax, 224(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 232(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 240(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 248(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 256(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 264(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 272(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 280(%rsp)
	leaq	376(%rsp), %rax
	movq	%rax, 288(%rsp)
	leaq	384(%rsp), %rax
	movq	%rax, 296(%rsp)
	leaq	392(%rsp), %rax
	movq	%rax, 304(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 128(%rsp)
	movl	$1, 136(%rsp)
	movq	%rax, 140(%rsp)
	movl	$1, 148(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L5
	pushq	120(%rsp)
	.cfi_def_cfa_offset 344
	leaq	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii(%rip), %rdi
	pushq	120(%rsp)
	.cfi_def_cfa_offset 352
	movq	156(%rsp), %rcx
	movl	164(%rsp), %r8d
	movq	144(%rsp), %rsi
	movl	152(%rsp), %edx
	leaq	192(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 344
	popq	%rdx
	.cfi_def_cfa_offset 336
.L5:
	movq	312(%rsp), %rax
	subq	%fs:40, %rax
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	addq	$328, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z74__device_stub__Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiiiPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii, .-_Z74__device_stub__Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiiiPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.globl	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.type	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii, @function
_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z74__device_stub__Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiiiPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.cfi_endproc
.LFE2054:
	.size	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii, .-_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.globl	TOF_dist_backprojection
	.type	TOF_dist_backprojection, @function
TOF_dist_backprojection:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r8, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%r9, %rbx
	subq	$216, %rsp
	.cfi_def_cfa_offset 272
	movq	280(%rsp), %rax
	movq	%rdi, 24(%rsp)
	leaq	88(%rsp), %rdi
	movss	%xmm0, 76(%rsp)
	movq	272(%rsp), %r15
	movq	%rax, 32(%rsp)
	movq	288(%rsp), %rax
	movss	%xmm1, 72(%rsp)
	movq	%rax, 40(%rsp)
	movq	296(%rsp), %rax
	movss	%xmm2, 68(%rsp)
	movq	%rax, 48(%rsp)
	movq	304(%rsp), %rax
	movq	%rax, 56(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	movl	312(%rsp), %eax
	imull	320(%rsp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 16(%rsp)
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movslq	328(%rsp), %rax
	leaq	96(%rsp), %rdi
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movq	8(%rsp), %rsi
	leaq	104(%rsp), %rdi
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movq	8(%rsp), %rsi
	leaq	112(%rsp), %rdi
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movq	8(%rsp), %rsi
	leaq	120(%rsp), %rdi
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movq	8(%rsp), %rsi
	leaq	128(%rsp), %rdi
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movq	8(%rsp), %rsi
	leaq	136(%rsp), %rdi
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movq	8(%rsp), %rsi
	leaq	144(%rsp), %rdi
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movq	8(%rsp), %rsi
	leaq	152(%rsp), %rdi
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movq	8(%rsp), %rsi
	leaq	160(%rsp), %rdi
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movq	8(%rsp), %rsi
	leaq	168(%rsp), %rdi
	call	_Z10cudaMallocIfE9cudaErrorPPT_m.isra.0
	movq	8(%rsp), %rdx
	movq	96(%rsp), %rdi
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	104(%rsp), %rdi
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	112(%rsp), %rdi
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	120(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movl	$1, %ecx
	movq	%rbx, %rsi
	movq	128(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movl	$1, %ecx
	movq	%r15, %rsi
	movq	136(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$1, %ecx
	movq	144(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	40(%rsp), %rsi
	movl	$1, %ecx
	movq	152(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	48(%rsp), %rsi
	movl	$1, %ecx
	movq	160(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	56(%rsp), %rsi
	movl	$1, %ecx
	movq	168(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$134217729, %edi
	salq	$10, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	salq	$5, %rdi
	call	__cudaPushCallConfiguration@PLT
	movss	68(%rsp), %xmm2
	movss	72(%rsp), %xmm1
	testl	%eax, %eax
	movss	76(%rsp), %xmm0
	jne	.L12
	movl	328(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 280
	movl	328(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 288
	movl	328(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 296
	pushq	192(%rsp)
	.cfi_def_cfa_offset 304
	pushq	192(%rsp)
	.cfi_def_cfa_offset 312
	pushq	192(%rsp)
	.cfi_def_cfa_offset 320
	pushq	192(%rsp)
	.cfi_def_cfa_offset 328
	pushq	192(%rsp)
	.cfi_def_cfa_offset 336
	movq	192(%rsp), %r9
	movq	184(%rsp), %r8
	movq	176(%rsp), %rcx
	movq	168(%rsp), %rdx
	movq	160(%rsp), %rsi
	movq	152(%rsp), %rdi
	call	_Z74__device_stub__Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiiiPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	addq	$64, %rsp
	.cfi_def_cfa_offset 272
.L12:
	call	cudaDeviceSynchronize@PLT
	movq	16(%rsp), %rdx
	movq	88(%rsp), %rsi
	movl	$2, %ecx
	movq	24(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	96(%rsp), %rdi
	call	cudaFree@PLT
	movq	104(%rsp), %rdi
	call	cudaFree@PLT
	movq	112(%rsp), %rdi
	call	cudaFree@PLT
	movq	120(%rsp), %rdi
	call	cudaFree@PLT
	movq	128(%rsp), %rdi
	call	cudaFree@PLT
	movq	136(%rsp), %rdi
	call	cudaFree@PLT
	movq	144(%rsp), %rdi
	call	cudaFree@PLT
	movq	152(%rsp), %rdi
	call	cudaFree@PLT
	movq	160(%rsp), %rdi
	call	cudaFree@PLT
	movq	168(%rsp), %rdi
	call	cudaFree@PLT
	movq	200(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$216, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	TOF_dist_backprojection, .-TOF_dist_backprojection
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC0(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2056:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include<stdio.h>
#include<math.h>

#define abs(x) (x > 0 ? x : -(x))
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
#define PI 3.1415926
#define GRIDDIM 32
#define BLOCKDIM 1024 //32*32

extern "C" void TOF_dist_backprojection(float *image_bp, const float *proj_value, const float *tof_value,
                            const float *x1l, const float *y1l, const float *x1r, const float *y1r,
                            const float *x2l, const float *y2l, const float *x2r, const float *y2r,
                            const float time_resolution, const float dx, const float dy,
                            const int nx, const int ny, const int event_num);

// define TOF-dist-bp
__device__ void TOF_dist_bp(float *image_bp, const float proj_value, const float tof_value,
                            const float x1l, const float y1l, const float x1r, const float y1r,
                            const float x2l, const float y2l, const float x2r, const float y2r,
                            const float time_resolution, const float dx, const float dy,
                            const int nx, const int ny)
{
    const float nx2 = nx/2;
    const float ny2 = ny/2;
    const float tof_sigma = time_resolution * 0.3 / 2.355 / 2;
    const float tof_sigma_2 = tof_sigma * tof_sigma;
    const float x1c = (x1l + x1r) / 2;
    const float y1c = (y1l + y1r) / 2;
    const float x2c = (x2l + x2r) / 2;
    const float y2c = (y2l + y2r) / 2;
    const float L = sqrtf((x1c - x2c) * (x1c - x2c) + (y1c - y2c) * (y1c - y2c));
    const float ratio1 = (1 - (tof_value / L)) / 2;

    
    
    if (abs(x1c - x2c) > abs(y1c - y2c))
    {
        for (int ix = 0; ix < nx; ix++)
        {
            float xc = (ix - nx2 + 0.5) * dx;
            float tof_bin = dx;
            float d2_tof, w_tof;
            
            if (tof_sigma > 0)
            {
                d2_tof = ((xc-x1c) / (x2c-x1c) - ratio1)*L;
                if (d2_tof <= 3 * tof_sigma)
                {
                    w_tof = expf(-0.5 * d2_tof * d2_tof / tof_sigma_2) / sqrtf(2.0 * PI * tof_sigma_2) * tof_bin;
                }
                else
                {
                    w_tof = 0.0;
                }
            }
            else
            {
                w_tof = 1.0;
            }
            //d1l-d2r
            float kylr = (y1l-y2r)/(x1l-x2r);
            float ylr = kylr * (xc - x1l) + y1l + ny2 * dy;
            //d1r-d2l
            float kyrl = (y1r - y2l) / (x1r - x2l);
            float yrl = kyrl * (xc - x1r) + y1r + ny2 * dy;

            float yy1 = MIN(ylr,yrl); // 横坐标为xc时，detector边缘与x轴的交点中y较小值
            float yy2 = MAX(ylr,yrl);
            int cy1 = (int)floorf(yy1/dy);
            int cy2 = (int)floorf(yy2/dy);

            for (int iy=(int)MAX(0, cy1); iy < (int)MIN(ny, cy2+1); iy++)
            {
                float dist_w = (MIN((iy+1) * dy,yy2) - MAX(iy * dy,yy1)) / dy;
                atomicAdd(image_bp + (ix + iy * nx), proj_value * dist_w * w_tof);
            }

        }
        
    }
    else
    {
        for (int iy=0; iy < ny; iy++)
        {
            float yc = (iy - ny2 + 0.5) * dy;
            float tof_bin = dy;
            float d2_tof, w_tof;

            if (tof_sigma > 0)
            {
                d2_tof = (((yc-y1c) / (y2c-y1c)) - ratio1) * L;
                if (d2_tof <= 3 * tof_sigma)
                {
                    w_tof = expf(-0.5 * d2_tof * d2_tof / tof_sigma_2) / sqrtf(2.0 * PI * tof_sigma_2) * tof_bin;
                }
                else
                {
                    w_tof = 0.0;
                }
            }
            else
            {
                w_tof = 1.0;
            }
            //d1l-d2r:
            float kxlr = (x1l-x2r)/(y1l-y2r);
            float xlr = kxlr * (yc-y1l)+x1l+nx2 * dx;
            //d1r-d2l:
            float kxrl = (x1r-x2l)/(y1r-y2l);
            float xrl = kxrl * (yc-y1r)+x1r+nx2 * dx;
            
            float xx1 = MIN(xlr,xrl);
            float xx2 = MAX(xlr,xrl);
            float cx1 = (int)floorf(xx1/dx);
            float cx2 = (int)floorf(xx2/dx);

            
            for (int ix=(int)MAX(0, cx1); ix < (int)MIN(nx, cx2+1); ix++)
            {
                float dist_w = (MIN((ix+1) * dx,xx2) - MAX(ix * dx,xx1))/dx;
                atomicAdd(image_bp + (ix + iy * nx), proj_value * dist_w * w_tof);
            }

        }
    }

}

__global__ void TOF_dist_bp_kernel(float *image_bp, const float *proj_value, const float *tof_value,
                                   const float *x1l, const float *y1l, const float *x1r, const float *y1r,
                                   const float *x2l, const float *y2l, const float *x2r, const float *y2r,
                                   const float time_resolution, const float dx, const float dy,
                                   const int nx, const int ny, const int event_num)
{
    int step = blockDim.x * gridDim.x;
    for (int idx = threadIdx.x + blockIdx.x * blockDim.x; idx < event_num; idx += step)
    {
        TOF_dist_bp(image_bp, proj_value[idx], tof_value[idx],
                    x1l[idx], y1l[idx], x1r[idx], y1r[idx],
                    x2l[idx], y2l[idx], x2r[idx], y2r[idx],
                    time_resolution, dx, dy,
                    nx, ny);
    }

}



void TOF_dist_backprojection(float *image_bp, const float *proj_value, const float *tof_value,
                            const float *x1l, const float *y1l, const float *x1r, const float *y1r,
                            const float *x2l, const float *y2l, const float *x2r, const float *y2r,
                            const float time_resolution, const float dx, const float dy,
                            const int nx, const int ny, const int event_num)
{
    float *image_bp_d, *proj_value_d, *tof_value_d, *x1l_d, *y1l_d, *x1r_d, *y1r_d, *x2l_d, *y2l_d, *x2r_d, *y2r_d;
    // 申请device内存
    hipMalloc(&image_bp_d, nx * ny * sizeof(float));
    hipMalloc(&proj_value_d, event_num * sizeof(float));
    hipMalloc(&tof_value_d, event_num * sizeof(float));
    hipMalloc(&x1l_d, event_num * sizeof(float));
    hipMalloc(&y1l_d, event_num * sizeof(float));
    hipMalloc(&x1r_d, event_num * sizeof(float));
    hipMalloc(&y1r_d, event_num * sizeof(float));
    hipMalloc(&x2l_d, event_num * sizeof(float));
    hipMalloc(&y2l_d, event_num * sizeof(float));
    hipMalloc(&x2r_d, event_num * sizeof(float));
    hipMalloc(&y2r_d, event_num * sizeof(float));
    // 将host上的数据拷贝到device上
    hipMemcpy(proj_value_d, proj_value, event_num * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(tof_value_d, tof_value, event_num * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(x1l_d, x1l, event_num * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(y1l_d, y1l, event_num * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(x1r_d, x1r, event_num * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(y1r_d, y1r, event_num * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(x2l_d, x2l, event_num * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(y2l_d, y2l, event_num * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(x2r_d, x2r, event_num * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(y2r_d, y2r, event_num * sizeof(float), hipMemcpyHostToDevice);
    // 执行kernel
    TOF_dist_bp_kernel<<<GRIDDIM, BLOCKDIM>>>(image_bp_d, proj_value_d, tof_value_d, x1l_d, y1l_d, x1r_d, y1r_d,
                                            x2l_d, y2l_d, x2r_d, y2r_d, time_resolution, dx, dy, nx, ny, event_num);
    // 同步device，保证结果正常访问
    hipDeviceSynchronize();
    // 将device结果cpy到host
    hipMemcpy(image_bp, image_bp_d, nx * ny * sizeof(float), hipMemcpyDeviceToHost);
    // 释放内存
    //cudaFree(image_bp_d);
    hipFree(proj_value_d);
    hipFree(tof_value_d);
    hipFree(x1l_d);
    hipFree(y1l_d);
    hipFree(x1r_d);
    hipFree(y1r_d);
    hipFree(x2l_d);
    hipFree(y2l_d);
    hipFree(x2r_d);
    hipFree(y2r_d);
}

//nvcc -Xcompiler -fPIC -shared -lcudart -o proj.so proj.cu

	.text
	.file	"bproj.hip"
	.globl	_Z33__device_stub__TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii # -- Begin function _Z33__device_stub__TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.type	_Z33__device_stub__TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii,@function
_Z33__device_stub__TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii: # @_Z33__device_stub__TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$256, %rsp                      # imm = 0x100
	.cfi_def_cfa_offset 304
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	72(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	64(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	56(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	48(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	32(%rsp), %r8
	movq	%r9, (%r8)
	leaq	12(%rsp), %r9
	movss	%xmm0, (%r9)
	leaq	8(%rsp), %r10
	movss	%xmm1, (%r10)
	leaq	4(%rsp), %r11
	movss	%xmm2, (%r11)
	leaq	112(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	304(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	312(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	320(%rsp), %rax
	movq	%rax, 64(%rbx)
	leaq	328(%rsp), %rax
	movq	%rax, 72(%rbx)
	leaq	336(%rsp), %rax
	movq	%rax, 80(%rbx)
	movq	%r9, 88(%rbx)
	movq	%r10, 96(%rbx)
	movq	%r11, 104(%rbx)
	leaq	344(%rsp), %rax
	movq	%rax, 112(%rbx)
	leaq	352(%rsp), %rax
	movq	%rax, 120(%rbx)
	leaq	360(%rsp), %rax
	movq	%rax, 128(%rbx)
	leaq	96(%rsp), %r14
	leaq	80(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$272, %rsp                      # imm = 0x110
	.cfi_adjust_cfa_offset -272
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z33__device_stub__TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii, .Lfunc_end0-_Z33__device_stub__TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.cfi_endproc
                                        # -- End function
	.globl	TOF_dist_backprojection         # -- Begin function TOF_dist_backprojection
	.type	TOF_dist_backprojection,@function
TOF_dist_backprojection:                # @TOF_dist_backprojection
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movss	%xmm2, 68(%rsp)                 # 4-byte Spill
	movss	%xmm1, 64(%rsp)                 # 4-byte Spill
	movss	%xmm0, 60(%rsp)                 # 4-byte Spill
	movq	%r9, 136(%rsp)                  # 8-byte Spill
	movq	%r8, 128(%rsp)                  # 8-byte Spill
	movq	%rcx, 120(%rsp)                 # 8-byte Spill
	movq	%rdx, 112(%rsp)                 # 8-byte Spill
	movq	%rsi, %r12
	movq	%rdi, 144(%rsp)                 # 8-byte Spill
	movslq	264(%rsp), %rbx
	movl	256(%rsp), %eax
	movl	248(%rsp), %ecx
                                        # kill: def $eax killed $eax killed $rax
	imull	%ecx, %eax
	movslq	%eax, %r14
	shlq	$2, %r14
	leaq	96(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	%rbx, 104(%rsp)                 # 8-byte Spill
	leaq	(,%rbx,4), %r13
	leaq	88(%rsp), %rbx
	movq	%rbx, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	80(%rsp), %r15
	movq	%r15, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	72(%rsp), %rbp
	movq	%rbp, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	48(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	40(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	%rsp, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movq	%r12, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r15), %rdi
	movq	112(%rsp), %rsi                 # 8-byte Reload
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbp), %rdi
	movq	120(%rsp), %rsi                 # 8-byte Reload
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	48(%rsp), %rax
	movq	(%rax), %rdi
	movq	128(%rsp), %rsi                 # 8-byte Reload
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	40(%rsp), %rax
	movq	(%rax), %rdi
	movq	136(%rsp), %rsi                 # 8-byte Reload
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	32(%rsp), %rax
	movq	(%rax), %rdi
	movq	208(%rsp), %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	24(%rsp), %rax
	movq	(%rax), %rdi
	movq	216(%rsp), %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	16(%rsp), %rax
	movq	(%rax), %rdi
	movq	224(%rsp), %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	8(%rsp), %rax
	movq	(%rax), %rdi
	movq	232(%rsp), %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%rsp, %rax
	movq	(%rax), %rdi
	movq	240(%rsp), %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$4294967328, %rdi               # imm = 0x100000020
	leaq	992(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_2
# %bb.1:
	movq	96(%rsp), %rdi
	movq	88(%rsp), %rsi
	movq	80(%rsp), %rdx
	movq	72(%rsp), %rcx
	movq	48(%rsp), %r8
	movq	40(%rsp), %r9
	movss	60(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movss	64(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movss	68(%rsp), %xmm2                 # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	pushq	104(%rsp)                       # 8-byte Folded Reload
	.cfi_adjust_cfa_offset 8
	movl	264(%rsp), %eax
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	movl	264(%rsp), %eax
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	24(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	40(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	56(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	72(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	88(%rsp)
	.cfi_adjust_cfa_offset 8
	callq	_Z33__device_stub__TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	addq	$64, %rsp
	.cfi_adjust_cfa_offset -64
.LBB1_2:
	callq	hipDeviceSynchronize
	movq	96(%rsp), %rsi
	movq	144(%rsp), %rdi                 # 8-byte Reload
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	88(%rsp), %rdi
	callq	hipFree
	movq	80(%rsp), %rdi
	callq	hipFree
	movq	72(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	addq	$152, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	TOF_dist_backprojection, .Lfunc_end1-TOF_dist_backprojection
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB3_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii,@object # @_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.section	.rodata,"a",@progbits
	.globl	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.p2align	3, 0x0
_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii:
	.quad	_Z33__device_stub__TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.size	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii, 8

	.type	.L__unnamed_1,@object           # @0
	.section	.rodata.str1.1,"aMS",@progbits,1
.L__unnamed_1:
	.asciz	"_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii"
	.size	.L__unnamed_1, 61

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z33__device_stub__TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii ; -- Begin function _Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.globl	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
	.p2align	8
	.type	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii,@function
_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii: ; @_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
; %bb.0:
	s_clause 0x1
	s_load_b32 s6, s[0:1], 0x7c
	s_load_b64 s[2:3], s[0:1], 0x68
	s_add_u32 s4, s0, 0x70
	s_addc_u32 s5, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s30, s6, 0xffff
	s_mov_b32 s6, exec_lo
	v_mad_u64_u32 v[1:2], null, s15, s30, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB0_29
; %bb.1:                                ; %.lr.ph
	s_load_b128 s[20:23], s[0:1], 0x58
	s_mov_b32 s6, 0x33333333
	s_mov_b32 s7, 0x3fd33333
	s_lshr_b32 s24, s2, 31
	s_mov_b32 s33, 0
	s_add_i32 s31, s2, s24
	v_mov_b32_e32 v19, 0
	s_waitcnt lgkmcnt(0)
	v_cvt_f64_f32_e32 v[2:3], s20
	s_load_b32 s20, s[4:5], 0x0
	s_clause 0x1
	s_load_b64 s[28:29], s[0:1], 0x50
	s_load_b128 s[24:27], s[0:1], 0x40
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s30, s20, s30
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f64 v[2:3], v[2:3], s[6:7]
	s_mov_b32 s6, 0x3d70a3d7
	s_mov_b32 s7, 0x4002d70a
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_div_scale_f64 v[4:5], null, s[6:7], s[6:7], v[2:3]
	v_div_scale_f64 v[10:11], vcc_lo, v[2:3], s[6:7], v[2:3]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[6:7], v[4:5]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[8:9], v[10:11], v[6:7]
	v_fma_f64 v[4:5], -v[4:5], v[8:9], v[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_fmas_f64 v[4:5], v[4:5], v[6:7], v[8:9]
	v_cvt_f64_f32_e32 v[7:8], s21
	v_div_fixup_f64 v[2:3], v[4:5], s[6:7], v[2:3]
	s_mov_b32 s6, 0x4d12d84a
	s_mov_b32 s7, 0x401921fb
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[2:3], v[2:3], 0.5
	v_cvt_f32_f64_e32 v2, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v0, v2, v2
	v_mul_f32_e32 v17, 0x40400000, v2
	v_cvt_f64_f32_e32 v[3:4], v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mul_f64 v[5:6], v[3:4], s[6:7]
	s_load_b512 s[4:19], s[0:1], 0x0
	s_ashr_i32 s1, s31, 1
	v_cvt_f32_f64_e32 v0, v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v0
	v_mul_f32_e32 v5, 0x4f800000, v0
	v_cndmask_b32_e32 v9, v0, v5, vcc_lo
	v_cvt_f64_f32_e32 v[5:6], s22
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_sqrt_f32_e32 v0, v9
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v10, -1, v0
	v_add_nc_u32_e32 v11, 1, v0
	v_fma_f32 v12, -v10, v0, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v13, -v11, v0, v9
	v_cmp_ge_f32_e64 s0, 0, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v10, v0, v10, s0
	v_cmp_lt_f32_e64 s0, 0, v13
	v_cvt_f32_i32_e32 v0, s1
	s_lshr_b32 s1, s23, 31
	v_cvt_f32_i32_e32 v13, s23
	s_delay_alu instid0(VALU_DEP_3)
	v_cndmask_b32_e64 v10, v10, v11, s0
	s_add_i32 s0, s23, s1
	v_mul_f32_e32 v15, s22, v0
	s_ashr_i32 s0, s0, 1
	s_cmp_gt_i32 s2, 0
	v_mul_f32_e32 v11, 0x37800000, v10
	v_cvt_f32_i32_e32 v14, s0
	v_cmp_lt_f32_e64 s0, 0, v2
	s_cselect_b32 s31, -1, 0
	s_cmp_gt_i32 s23, 0
	v_cndmask_b32_e32 v10, v10, v11, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v9, 0x260
	v_mul_f32_e32 v16, s21, v14
	s_cselect_b32 s34, -1, 0
	s_delay_alu instid0(VALU_DEP_3)
	v_cndmask_b32_e32 v18, v10, v9, vcc_lo
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_5 Depth 2
                                        ;       Child Loop BB0_11 Depth 3
                                        ;         Child Loop BB0_12 Depth 4
                                        ;     Child Loop BB0_18 Depth 2
                                        ;       Child Loop BB0_24 Depth 3
                                        ;         Child Loop BB0_25 Depth 4
	v_ashrrev_i32_e32 v2, 31, v1
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[23:24], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v21, vcc_lo, s10, v23
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v22, vcc_lo, s11, v24, vcc_lo
	v_add_co_u32 v9, vcc_lo, s12, v23
	v_add_co_ci_u32_e32 v10, vcc_lo, s13, v24, vcc_lo
	v_add_co_u32 v25, vcc_lo, s16, v23
	v_add_co_ci_u32_e32 v26, vcc_lo, s17, v24, vcc_lo
	global_load_b32 v2, v[9:10], off
	v_add_co_u32 v9, vcc_lo, s24, v23
	v_add_co_ci_u32_e32 v10, vcc_lo, s25, v24, vcc_lo
	v_add_co_u32 v27, vcc_lo, s18, v23
	v_add_co_ci_u32_e32 v28, vcc_lo, s19, v24, vcc_lo
	global_load_b32 v9, v[9:10], off
	v_add_co_u32 v10, vcc_lo, s28, v23
	v_add_co_ci_u32_e32 v11, vcc_lo, s29, v24, vcc_lo
	v_add_co_u32 v29, vcc_lo, s26, v23
	v_add_co_ci_u32_e32 v30, vcc_lo, s27, v24, vcc_lo
	global_load_b32 v12, v[10:11], off
	v_add_co_u32 v31, vcc_lo, s14, v23
	v_add_co_ci_u32_e32 v32, vcc_lo, s15, v24, vcc_lo
	global_load_b32 v20, v[25:26], off
	global_load_b32 v10, v[27:28], off
	global_load_b32 v30, v[29:30], off
	global_load_b32 v21, v[21:22], off
	global_load_b32 v22, v[31:32], off
	v_add_co_u32 v25, vcc_lo, s8, v23
	v_add_co_ci_u32_e32 v26, vcc_lo, s9, v24, vcc_lo
	v_add_co_u32 v23, vcc_lo, s6, v23
	v_add_co_ci_u32_e32 v24, vcc_lo, s7, v24, vcc_lo
	global_load_b32 v25, v[25:26], off
	global_load_b32 v23, v[23:24], off
	s_waitcnt vmcnt(4)
	v_dual_add_f32 v11, v9, v12 :: v_dual_add_f32 v24, v10, v30
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_dual_add_f32 v26, v2, v20 :: v_dual_mul_f32 v27, 0.5, v11
	v_mul_f32_e32 v11, 0.5, v24
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fma_f32 v28, v26, 0.5, -v27
	s_waitcnt vmcnt(2)
	v_dual_add_f32 v31, v21, v22 :: v_dual_mul_f32 v24, v28, v28
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v29, v31, 0.5, -v11
	v_fmac_f32_e32 v24, v29, v29
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v32, 0x4f800000, v24
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v24
	v_cndmask_b32_e32 v24, v24, v32, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_sqrt_f32_e32 v32, v24
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v33, -1, v32
	v_add_nc_u32_e32 v34, 1, v32
	v_fma_f32 v35, -v33, v32, v24
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v36, -v34, v32, v24
	v_cmp_ge_f32_e64 s1, 0, v35
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v32, v32, v33, s1
	v_cmp_lt_f32_e64 s1, 0, v36
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v32, v32, v34, s1
	s_mov_b32 s1, exec_lo
	v_mul_f32_e32 v33, 0x37800000, v32
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v32, v32, v33, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v24, 0x260
	v_cndmask_b32_e32 v24, v32, v24, vcc_lo
	s_waitcnt vmcnt(1)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_scale_f32 v32, null, v24, v24, v25
	v_div_scale_f32 v35, vcc_lo, v25, v24, v25
	v_rcp_f32_e32 v33, v32
	s_waitcnt_depctr 0xfff
	v_fma_f32 v34, -v32, v33, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v33, v34, v33
	v_mul_f32_e32 v34, v35, v33
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v36, -v32, v34, v35
	v_fmac_f32_e32 v34, v36, v33
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v32, -v32, v34, v35
	v_div_fmas_f32 v32, v32, v33, v34
	v_cmp_lt_f32_e32 vcc_lo, 0, v29
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_div_fixup_f32 v25, v32, v24, v25
	v_cndmask_b32_e64 v29, -v29, v29, vcc_lo
	v_cmp_lt_f32_e32 vcc_lo, 0, v28
	v_sub_f32_e32 v25, 1.0, v25
	v_cndmask_b32_e64 v28, -v28, v28, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v25, 0.5, v25
	v_cmpx_ngt_f32_e32 v29, v28
	s_xor_b32 s20, exec_lo, s1
	s_cbranch_execz .LBB0_15
; %bb.3:                                ; %.preheader218.i
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_and_not1_b32 vcc_lo, exec_lo, s31
                                        ; implicit-def: $vgpr11
                                        ; implicit-def: $vgpr31
	s_cbranch_vccnz .LBB0_15
; %bb.4:                                ; %.lr.ph222.i
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_dual_sub_f32 v11, v21, v30 :: v_dual_sub_f32 v12, v2, v12
	v_dual_sub_f32 v10, v22, v10 :: v_dual_sub_f32 v9, v20, v9
	s_mov_b32 s35, 0
	v_mul_f32_e32 v26, 0.5, v26
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_div_scale_f32 v28, null, v12, v12, v11
	v_div_scale_f32 v29, null, v9, v9, v10
	v_div_scale_f32 v34, vcc_lo, v11, v12, v11
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_rcp_f32_e32 v30, v28
	v_rcp_f32_e32 v31, v29
	v_sub_f32_e32 v27, v27, v26
	s_waitcnt_depctr 0xfff
	v_fma_f32 v32, -v28, v30, 1.0
	v_fma_f32 v33, -v29, v31, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_dual_fmac_f32 v30, v32, v30 :: v_dual_fmac_f32 v31, v33, v31
	v_div_scale_f32 v32, s1, v10, v9, v10
	v_mul_f32_e32 v33, v34, v30
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v35, v32, v31
	v_fma_f32 v36, -v28, v33, v34
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v37, -v29, v35, v32
	v_fmac_f32_e32 v33, v36, v30
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v35, v37, v31
	v_fma_f32 v28, -v28, v33, v34
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v29, -v29, v35, v32
	v_div_fmas_f32 v28, v28, v30, v33
	s_mov_b32 vcc_lo, s1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fmas_f32 v29, v29, v31, v35
	v_div_fixup_f32 v28, v28, v12, v11
	s_delay_alu instid0(VALU_DEP_2)
	v_div_fixup_f32 v29, v29, v9, v10
.LBB0_5:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_11 Depth 3
                                        ;         Child Loop BB0_12 Depth 4
	v_cvt_f32_i32_e32 v9, s35
	s_and_not1_b32 vcc_lo, exec_lo, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v30, 1.0 :: v_dual_sub_f32 v9, v9, v0
	v_cvt_f64_f32_e32 v[9:10], v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[9:10], v[9:10], 0.5
	v_mul_f64 v[9:10], v[9:10], v[5:6]
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_f32_f64_e32 v9, v[9:10]
	s_cbranch_vccnz .LBB0_9
; %bb.6:                                ;   in Loop: Header=BB0_5 Depth=2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_sub_f32_e32 v10, v9, v26
	s_mov_b32 s1, exec_lo
	v_div_scale_f32 v11, null, v27, v27, v10
	v_div_scale_f32 v31, vcc_lo, v10, v27, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v12, v11
	s_waitcnt_depctr 0xfff
	v_fma_f32 v30, -v11, v12, 1.0
	v_fmac_f32_e32 v12, v30, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v30, v31, v12
	v_fma_f32 v32, -v11, v30, v31
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v30, v32, v12
	v_fma_f32 v11, -v11, v30, v31
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_fmas_f32 v11, v11, v12, v30
	v_mov_b32_e32 v30, 0
	v_div_fixup_f32 v10, v11, v27, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_f32_e32 v10, v10, v25
	v_mul_f32_e32 v10, v24, v10
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_le_f32_e32 v10, v17
	s_cbranch_execz .LBB0_8
; %bb.7:                                ;   in Loop: Header=BB0_5 Depth=2
	v_cvt_f64_f32_e32 v[10:11], v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[30:31], v[10:11], -0.5
	v_mul_f64 v[10:11], v[30:31], v[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_scale_f64 v[30:31], null, v[3:4], v[3:4], v[10:11]
	v_div_scale_f64 v[36:37], vcc_lo, v[10:11], v[3:4], v[10:11]
	v_rcp_f64_e32 v[32:33], v[30:31]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[34:35], -v[30:31], v[32:33], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[32:33], v[32:33], v[34:35], v[32:33]
	v_fma_f64 v[34:35], -v[30:31], v[32:33], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[32:33], v[32:33], v[34:35], v[32:33]
	v_mul_f64 v[34:35], v[36:37], v[32:33]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[30:31], -v[30:31], v[34:35], v[36:37]
	v_div_fmas_f64 v[30:31], v[30:31], v[32:33], v[34:35]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fixup_f64 v[10:11], v[30:31], v[3:4], v[10:11]
	v_cvt_f32_f64_e32 v10, v[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v11, 0x3fb8aa3b, v10
	v_cmp_ngt_f32_e32 vcc_lo, 0xc2ce8ed0, v10
	v_fma_f32 v12, 0x3fb8aa3b, v10, -v11
	v_rndne_f32_e32 v30, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v12, 0x32a5705f, v10
	v_sub_f32_e32 v11, v11, v30
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_f32_e32 v11, v11, v12
	v_cvt_i32_f32_e32 v12, v30
	v_exp_f32_e32 v11, v11
	s_waitcnt_depctr 0xfff
	v_ldexp_f32 v11, v11, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v11, 0, v11, vcc_lo
	v_cmp_nlt_f32_e32 vcc_lo, 0x42b17218, v10
	v_cndmask_b32_e32 v10, 0x7f800000, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f32 v11, null, v18, v18, v10
	v_rcp_f32_e32 v12, v11
	s_waitcnt_depctr 0xfff
	v_fma_f32 v30, -v11, v12, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v12, v30, v12
	v_div_scale_f32 v30, vcc_lo, v10, v18, v10
	v_mul_f32_e32 v31, v30, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v32, -v11, v31, v30
	v_fmac_f32_e32 v31, v32, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v11, -v11, v31, v30
	v_div_fmas_f32 v11, v11, v12, v31
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fixup_f32 v10, v11, v18, v10
	v_mul_f32_e32 v30, s22, v10
.LBB0_8:                                ; %Flow103
                                        ;   in Loop: Header=BB0_5 Depth=2
	s_or_b32 exec_lo, exec_lo, s1
.LBB0_9:                                ;   in Loop: Header=BB0_5 Depth=2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_sub_f32_e32 v10, v9, v2
	v_sub_f32_e32 v9, v9, v20
	v_fma_f32 v9, v29, v9, v22
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_f32_e32 v9, v16, v9
	v_fma_f32 v10, v28, v10, v21
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v10, v16, v10
	v_cmp_lt_f32_e32 vcc_lo, v10, v9
	v_cndmask_b32_e32 v31, v9, v10, vcc_lo
	v_cmp_gt_f32_e32 vcc_lo, v10, v9
	v_cndmask_b32_e32 v32, v9, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f32 v10, null, s21, s21, v32
	v_rcp_f32_e32 v12, v10
	s_waitcnt_depctr 0xfff
	v_fma_f32 v34, -v10, v12, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v12, v34, v12
	v_div_scale_f32 v9, null, s21, s21, v31
	v_div_scale_f32 v35, vcc_lo, v31, s21, v31
	v_rcp_f32_e32 v11, v9
	s_waitcnt_depctr 0xfff
	v_fma_f32 v33, -v9, v11, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v11, v33, v11
	v_div_scale_f32 v33, s1, v32, s21, v32
	v_mul_f32_e32 v36, v33, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v38, -v10, v36, v33
	v_fmac_f32_e32 v36, v38, v12
	v_mul_f32_e32 v34, v35, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v10, -v10, v36, v33
	v_fma_f32 v37, -v9, v34, v35
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v34, v37, v11
	v_fma_f32 v9, -v9, v34, v35
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_div_fmas_f32 v9, v9, v11, v34
	s_mov_b32 vcc_lo, s1
	s_mov_b32 s1, exec_lo
	v_div_fmas_f32 v10, v10, v12, v36
	v_div_fixup_f32 v9, v9, s21, v31
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_floor_f32_e32 v9, v9
	v_cvt_i32_f32_e32 v9, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f32_i32_e32 v9, v9
	v_cmp_ngt_f32_e32 vcc_lo, 0, v9
	v_cndmask_b32_e32 v9, 0, v9, vcc_lo
	v_div_fixup_f32 v10, v10, s21, v32
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_i32_f32_e32 v34, v9
	v_floor_f32_e32 v10, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_i32_f32_e32 v10, v10
	v_cvt_f32_i32_e32 v10, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v10, 1.0, v10
	v_cmp_gt_f32_e32 vcc_lo, v10, v13
	v_cndmask_b32_e32 v10, v10, v13, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_i32_f32_e32 v33, v10
	v_cmpx_lt_i32_e64 v34, v33
	s_cbranch_execz .LBB0_14
; %bb.10:                               ; %.lr.ph.i
                                        ;   in Loop: Header=BB0_5 Depth=2
	s_mul_i32 s36, s35, s23
	s_mov_b32 s37, 0
.LBB0_11:                               ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_5 Depth=2
                                        ; =>    This Loop Header: Depth=3
                                        ;         Child Loop BB0_12 Depth 4
	v_mov_b32_e32 v11, v34
	s_mov_b32 s38, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v9, s36, v11
	v_add_nc_u32_e32 v34, 1, v11
	v_cvt_f32_i32_e32 v11, v11
	v_ashrrev_i32_e32 v10, 31, v9
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_f32_i32_e32 v35, v34
	v_mul_f32_e32 v11, s21, v11
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	v_mul_f32_e32 v35, s21, v35
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v9, vcc_lo, s4, v9
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e32 vcc_lo, v35, v32
	global_load_b32 v12, v[9:10], off
	v_cndmask_b32_e32 v35, v32, v35, vcc_lo
	v_cmp_gt_f32_e32 vcc_lo, v11, v31
	v_cndmask_b32_e32 v11, v31, v11, vcc_lo
	v_sub_f32_e32 v11, v35, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f32 v35, null, s21, s21, v11
	v_rcp_f32_e32 v36, v35
	s_waitcnt_depctr 0xfff
	v_fma_f32 v37, -v35, v36, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v36, v37, v36
	v_div_scale_f32 v37, vcc_lo, v11, s21, v11
	v_mul_f32_e32 v38, v37, v36
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v39, -v35, v38, v37
	v_fmac_f32_e32 v38, v39, v36
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v35, -v35, v38, v37
	v_div_fmas_f32 v35, v35, v36, v38
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_div_fixup_f32 v11, v35, s21, v11
	s_waitcnt vmcnt(1)
	v_mul_f32_e32 v11, v23, v11
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f32_e32 v35, v30, v11
.LBB0_12:                               ; %atomicrmw.start46
                                        ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_5 Depth=2
                                        ;       Parent Loop BB0_11 Depth=3
                                        ; =>      This Inner Loop Header: Depth=4
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v11, v12, v35
	global_atomic_cmpswap_b32 v11, v[9:10], v[11:12], off glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, v11, v12
	v_mov_b32_e32 v12, v11
	s_or_b32 s38, vcc_lo, s38
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s38
	s_cbranch_execnz .LBB0_12
; %bb.13:                               ; %atomicrmw.end45
                                        ;   in Loop: Header=BB0_11 Depth=3
	s_or_b32 exec_lo, exec_lo, s38
	v_cmp_ge_i32_e32 vcc_lo, v34, v33
	s_or_b32 s37, vcc_lo, s37
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s37
	s_cbranch_execnz .LBB0_11
.LBB0_14:                               ; %Flow102
                                        ;   in Loop: Header=BB0_5 Depth=2
	s_or_b32 exec_lo, exec_lo, s1
	s_add_i32 s35, s35, 1
                                        ; implicit-def: $vgpr10
                                        ; implicit-def: $vgpr9
                                        ; implicit-def: $vgpr30
                                        ; implicit-def: $vgpr12
                                        ; implicit-def: $vgpr11
                                        ; implicit-def: $vgpr31
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s35, s2
	s_cbranch_scc0 .LBB0_5
.LBB0_15:                               ; %Flow111
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_and_not1_saveexec_b32 s35, s20
	s_cbranch_execz .LBB0_28
; %bb.16:                               ; %.preheader.i
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_and_not1_b32 vcc_lo, exec_lo, s34
	s_cbranch_vccnz .LBB0_28
; %bb.17:                               ; %.lr.ph228.i
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_dual_sub_f32 v12, v2, v12 :: v_dual_sub_f32 v9, v20, v9
	v_sub_f32_e32 v28, v21, v30
	s_mov_b32 s20, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f32 v26, null, v28, v28, v12
	v_rcp_f32_e32 v29, v26
	s_waitcnt_depctr 0xfff
	v_fma_f32 v32, -v26, v29, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_dual_fmac_f32 v29, v32, v29 :: v_dual_sub_f32 v10, v22, v10
	v_div_scale_f32 v34, vcc_lo, v12, v28, v12
	v_div_scale_f32 v27, null, v10, v10, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v30, v27
	s_waitcnt_depctr 0xfff
	v_fma_f32 v33, -v27, v30, 1.0
	v_dual_fmac_f32 v30, v33, v30 :: v_dual_mul_f32 v33, v34, v29
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v36, -v26, v33, v34
	v_fmac_f32_e32 v33, v36, v29
	v_div_scale_f32 v32, s1, v9, v10, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v34, -v26, v33, v34
	v_dual_mul_f32 v35, v32, v30 :: v_dual_mul_f32 v26, 0.5, v31
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fmas_f32 v29, v34, v29, v33
	v_fma_f32 v37, -v27, v35, v32
	s_mov_b32 vcc_lo, s1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f32 v28, v29, v28, v12
	v_fmac_f32_e32 v35, v37, v30
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v27, -v27, v35, v32
	v_div_fmas_f32 v30, v27, v30, v35
	v_sub_f32_e32 v27, v11, v26
	s_delay_alu instid0(VALU_DEP_2)
	v_div_fixup_f32 v29, v30, v10, v9
.LBB0_18:                               ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_24 Depth 3
                                        ;         Child Loop BB0_25 Depth 4
	v_cvt_f32_i32_e32 v9, s20
	s_and_not1_b32 vcc_lo, exec_lo, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v30, 1.0 :: v_dual_sub_f32 v9, v9, v14
	v_cvt_f64_f32_e32 v[9:10], v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[9:10], v[9:10], 0.5
	v_mul_f64 v[9:10], v[9:10], v[7:8]
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_f32_f64_e32 v9, v[9:10]
	s_cbranch_vccnz .LBB0_22
; %bb.19:                               ;   in Loop: Header=BB0_18 Depth=2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_sub_f32_e32 v10, v9, v26
	s_mov_b32 s1, exec_lo
	v_div_scale_f32 v11, null, v27, v27, v10
	v_div_scale_f32 v31, vcc_lo, v10, v27, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v12, v11
	s_waitcnt_depctr 0xfff
	v_fma_f32 v30, -v11, v12, 1.0
	v_fmac_f32_e32 v12, v30, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v30, v31, v12
	v_fma_f32 v32, -v11, v30, v31
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v30, v32, v12
	v_fma_f32 v11, -v11, v30, v31
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_fmas_f32 v11, v11, v12, v30
	v_mov_b32_e32 v30, 0
	v_div_fixup_f32 v10, v11, v27, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_f32_e32 v10, v10, v25
	v_mul_f32_e32 v10, v24, v10
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_le_f32_e32 v10, v17
	s_cbranch_execz .LBB0_21
; %bb.20:                               ;   in Loop: Header=BB0_18 Depth=2
	v_cvt_f64_f32_e32 v[10:11], v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[30:31], v[10:11], -0.5
	v_mul_f64 v[10:11], v[30:31], v[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_scale_f64 v[30:31], null, v[3:4], v[3:4], v[10:11]
	v_div_scale_f64 v[36:37], vcc_lo, v[10:11], v[3:4], v[10:11]
	v_rcp_f64_e32 v[32:33], v[30:31]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[34:35], -v[30:31], v[32:33], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[32:33], v[32:33], v[34:35], v[32:33]
	v_fma_f64 v[34:35], -v[30:31], v[32:33], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[32:33], v[32:33], v[34:35], v[32:33]
	v_mul_f64 v[34:35], v[36:37], v[32:33]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[30:31], -v[30:31], v[34:35], v[36:37]
	v_div_fmas_f64 v[30:31], v[30:31], v[32:33], v[34:35]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fixup_f64 v[10:11], v[30:31], v[3:4], v[10:11]
	v_cvt_f32_f64_e32 v10, v[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v11, 0x3fb8aa3b, v10
	v_cmp_ngt_f32_e32 vcc_lo, 0xc2ce8ed0, v10
	v_fma_f32 v12, 0x3fb8aa3b, v10, -v11
	v_rndne_f32_e32 v30, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v12, 0x32a5705f, v10
	v_sub_f32_e32 v11, v11, v30
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_f32_e32 v11, v11, v12
	v_cvt_i32_f32_e32 v12, v30
	v_exp_f32_e32 v11, v11
	s_waitcnt_depctr 0xfff
	v_ldexp_f32 v11, v11, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v11, 0, v11, vcc_lo
	v_cmp_nlt_f32_e32 vcc_lo, 0x42b17218, v10
	v_cndmask_b32_e32 v10, 0x7f800000, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f32 v11, null, v18, v18, v10
	v_rcp_f32_e32 v12, v11
	s_waitcnt_depctr 0xfff
	v_fma_f32 v30, -v11, v12, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v12, v30, v12
	v_div_scale_f32 v30, vcc_lo, v10, v18, v10
	v_mul_f32_e32 v31, v30, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v32, -v11, v31, v30
	v_fmac_f32_e32 v31, v32, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v11, -v11, v31, v30
	v_div_fmas_f32 v11, v11, v12, v31
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fixup_f32 v10, v11, v18, v10
	v_mul_f32_e32 v30, s21, v10
.LBB0_21:                               ; %Flow108
                                        ;   in Loop: Header=BB0_18 Depth=2
	s_or_b32 exec_lo, exec_lo, s1
.LBB0_22:                               ;   in Loop: Header=BB0_18 Depth=2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_sub_f32_e32 v10, v9, v21
	v_sub_f32_e32 v9, v9, v22
	v_fma_f32 v10, v28, v10, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v9, v29, v9, v20
	v_add_f32_e32 v10, v15, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v9, v15, v9
	v_cmp_lt_f32_e32 vcc_lo, v10, v9
	v_cndmask_b32_e32 v31, v9, v10, vcc_lo
	v_cmp_gt_f32_e32 vcc_lo, v10, v9
	v_cndmask_b32_e32 v32, v9, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_div_scale_f32 v9, null, s22, s22, v31
	v_div_scale_f32 v35, vcc_lo, v31, s22, v31
	v_div_scale_f32 v10, null, s22, s22, v32
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v11, v9
	v_rcp_f32_e32 v12, v10
	s_waitcnt_depctr 0xfff
	v_fma_f32 v33, -v9, v11, 1.0
	v_fma_f32 v34, -v10, v12, 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v11, v33, v11
	v_div_scale_f32 v33, s1, v32, s22, v32
	v_fmac_f32_e32 v12, v34, v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v34, v35, v11
	v_mul_f32_e32 v36, v33, v12
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v37, -v9, v34, v35
	v_fma_f32 v38, -v10, v36, v33
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v34, v37, v11
	v_fmac_f32_e32 v36, v38, v12
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v9, -v9, v34, v35
	v_fma_f32 v10, -v10, v36, v33
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_div_fmas_f32 v9, v9, v11, v34
	s_mov_b32 vcc_lo, s1
	s_mov_b32 s1, exec_lo
	v_div_fmas_f32 v10, v10, v12, v36
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f32 v9, v9, s22, v31
	v_div_fixup_f32 v10, v10, s22, v32
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_floor_f32_e32 v9, v9
	v_floor_f32_e32 v10, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_i32_f32_e32 v9, v9
	v_cvt_i32_f32_e32 v10, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_max_i32_e32 v34, 0, v9
	v_add_nc_u32_e32 v10, 1, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_min_i32_e32 v33, s2, v10
	v_cmpx_lt_i32_e64 v34, v33
	s_cbranch_execz .LBB0_27
; %bb.23:                               ; %.lr.ph225.i.preheader
                                        ;   in Loop: Header=BB0_18 Depth=2
	s_mov_b32 s36, 0
.LBB0_24:                               ; %.lr.ph225.i
                                        ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_18 Depth=2
                                        ; =>    This Loop Header: Depth=3
                                        ;         Child Loop BB0_25 Depth 4
	v_mov_b32_e32 v11, v34
	s_mov_b32 s37, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[9:10], null, v11, s23, s[20:21]
	v_mov_b32_e32 v10, v19
	v_add_nc_u32_e32 v34, 1, v11
	v_cvt_f32_i32_e32 v11, v11
	v_cvt_f32_i32_e32 v35, v34
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	v_mul_f32_e32 v11, s22, v11
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_mul_f32_e32 v35, s22, v35
	v_add_co_u32 v9, vcc_lo, s4, v9
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v10, vcc_lo
	v_cmp_lt_f32_e32 vcc_lo, v35, v32
	global_load_b32 v12, v[9:10], off
	v_cndmask_b32_e32 v35, v32, v35, vcc_lo
	v_cmp_gt_f32_e32 vcc_lo, v11, v31
	v_cndmask_b32_e32 v11, v31, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_f32_e32 v11, v35, v11
	v_div_scale_f32 v35, null, s22, s22, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v36, v35
	s_waitcnt_depctr 0xfff
	v_fma_f32 v37, -v35, v36, 1.0
	v_fmac_f32_e32 v36, v37, v36
	v_div_scale_f32 v37, vcc_lo, v11, s22, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v38, v37, v36
	v_fma_f32 v39, -v35, v38, v37
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v38, v39, v36
	v_fma_f32 v35, -v35, v38, v37
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f32 v35, v35, v36, v38
	v_div_fixup_f32 v11, v35, s22, v11
	s_waitcnt vmcnt(1)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v11, v23, v11
	v_mul_f32_e32 v35, v30, v11
.LBB0_25:                               ; %atomicrmw.start
                                        ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_18 Depth=2
                                        ;       Parent Loop BB0_24 Depth=3
                                        ; =>      This Inner Loop Header: Depth=4
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v11, v12, v35
	global_atomic_cmpswap_b32 v11, v[9:10], v[11:12], off glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, v11, v12
	v_mov_b32_e32 v12, v11
	s_or_b32 s37, vcc_lo, s37
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s37
	s_cbranch_execnz .LBB0_25
; %bb.26:                               ; %atomicrmw.end
                                        ;   in Loop: Header=BB0_24 Depth=3
	s_or_b32 exec_lo, exec_lo, s37
	v_cmp_ge_i32_e32 vcc_lo, v34, v33
	s_or_b32 s36, vcc_lo, s36
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s36
	s_cbranch_execnz .LBB0_24
.LBB0_27:                               ; %Flow107
                                        ;   in Loop: Header=BB0_18 Depth=2
	s_or_b32 exec_lo, exec_lo, s1
	s_add_i32 s20, s20, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s20, s23
	s_cbranch_scc0 .LBB0_18
.LBB0_28:                               ; %_Z11TOF_dist_bpPffffffffffffffii.exit
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s35
	v_add_nc_u32_e32 v1, s30, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_le_i32_e32 vcc_lo, s3, v1
	s_or_b32 s33, vcc_lo, s33
	s_and_not1_b32 exec_lo, exec_lo, s33
	s_cbranch_execnz .LBB0_2
.LBB0_29:                               ; %Flow113
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 368
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 40
		.amdhsa_next_free_sgpr 39
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii, .Lfunc_end0-_Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 3984
; NumSgprs: 41
; NumVgprs: 40
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 5
; VGPRBlocks: 4
; NumSGPRsForWavesPerEU: 41
; NumVGPRsForWavesPerEU: 40
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         48
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         56
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         64
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         72
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         80
        .size:           8
        .value_kind:     global_buffer
      - .offset:         88
        .size:           4
        .value_kind:     by_value
      - .offset:         92
        .size:           4
        .value_kind:     by_value
      - .offset:         96
        .size:           4
        .value_kind:     by_value
      - .offset:         100
        .size:           4
        .value_kind:     by_value
      - .offset:         104
        .size:           4
        .value_kind:     by_value
      - .offset:         108
        .size:           4
        .value_kind:     by_value
      - .offset:         112
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         116
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         120
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         124
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         126
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         128
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         130
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         132
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         134
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         152
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         160
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         168
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         176
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 368
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii
    .private_segment_fixed_size: 0
    .sgpr_count:     41
    .sgpr_spill_count: 0
    .symbol:         _Z18TOF_dist_bp_kernelPfPKfS1_S1_S1_S1_S1_S1_S1_S1_S1_fffiii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     40
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
