#include "math.h"
#include "float.h"

__device__ void normalize_vector(float *a, float *b, float *c)
{
    float len;
    float ta, tb, tc;

    ta = *a;
    tb = *b;
    tc = *c;
    len = ta*ta + tb*tb + tc*tc;

    if(len == 0.0)
        return;
    len = sqrt(len);
    *a = ta/len;
    *b = tb/len;
    *c = tc/len;
}

__device__ void intersectGPU(float *ray_array, float *scene, float *output, int *hit_obj_index, int scene_size)
{

/*
input: ray_array, scene, scene_size
output: [hit_point v3, hit_normal v3]
*/

    int i;
    int scene_index;
    int flag;
    int current_obj_i = -1;

    float l1, l2, l3;
    float t_ca;
    float d_squared;
    float radius_squared;
    float t_hc;
    float t;
    float hit_point1;
    float hit_point2;
    float hit_point3;
    float hit_normal1;
    float hit_normal2;
    float hit_normal3;
    float current_t = FLT_MAX;

    for(i = 0; i < scene_size; i++){
        flag = 0;
        scene_index = i*16;
        if (scene[scene_index] < 0.5){ /* means sphere */
            /* calculate intersect */
            l1 = scene[scene_index+1] - ray_array[0];
            l2 = scene[scene_index+2] - ray_array[1];
            l3 = scene[scene_index+3] - ray_array[2];
            t_ca = l1*ray_array[3] +
                   l2*ray_array[4] +
                   l3*ray_array[5];
            if(t_ca < 0)
                flag = 1;
            d_squared = l1*l1 + l2*l2 +l3*l3 - t_ca*t_ca;
            radius_squared = scene[scene_index+4]*scene[scene_index+4];
            if(d_squared > radius_squared)
                flag = 1;
            t_hc = sqrt(radius_squared - d_squared);
            t = t_ca - t_hc;
            if(t < 0)
                t = t_ca + t_hc;
            hit_point1 = ray_array[0] + t * ray_array[3];
            hit_point2 = ray_array[1] + t * ray_array[4];
            hit_point3 = ray_array[2] + t * ray_array[5];
            hit_normal1 = hit_point1 - scene[scene_index+1];
            hit_normal2 = hit_point2 - scene[scene_index+2];
            hit_normal3 = hit_point3 - scene[scene_index+3];
            normalize_vector(&hit_normal1, &hit_normal2, &hit_normal3);
        }
        if(flag == 0){
            if(t < current_t){
                current_t = t;
                current_obj_i = i;
                output[0] = hit_point1;
                output[1] = hit_point2;
                output[2] = hit_point3;
                output[3] = hit_normal1;
                output[4] = hit_normal2;
                output[5] = hit_normal3;
            }
        }
    }
    *hit_obj_index = current_obj_i;
}

__device__ void trace_non_diffuseGPU (float *ray, int hit_obj_index, float *hit_point, float *hit_normal,
                                      float *scene, int scene_size, int depth, int max_depth, float *output);
__device__ void trace_diffuseGPU(int obj_index, float *hit_point, float *hit_normal, float *scene, int scene_size, float *output);

__device__ void trace_recursivelyGPU(float *ray, float *scene, int scene_size, float *output, int depth, int max_depth){
    /*
    hit_object, hit_point, hit_normal = self.__intersect(ray)
    if hit_object is None:
        return Vector3(0.3, 0.3, 0.3)  # horizon
    traced_color = Vector3()
    if not hit_object.material.is_diffuse and depth < self.__max_recursion_depth:
        traced_color = self.__trace_non_diffuse(ray, hit_object, hit_point, hit_normal, depth)
    else:
        traced_color = self.__trace_diffuse(hit_object, hit_point, hit_normal)
    return traced_color + hit_object.material.emission_color
    */

    int hit_obj_index;
    float output_intersect[6];

    intersectGPU(ray, scene, output_intersect, &hit_obj_index, scene_size);

    if (hit_obj_index < 0) {
        output[0] = 0.3;
        output[1] = 0.3;
        output[2] = 0.3;
        return;
    }

    float traced_color[3];

    if (depth < max_depth && scene[16*hit_obj_index+14] < 0.5)
        /* trace_non_diffuseGPU (ray, hit_obj_index, output_intersect, output_intersect + 3,
                              scene, scene_size, depth, max_depth, traced_color);*/
        trace_diffuseGPU (hit_obj_index, output_intersect, output_intersect + 3, scene, scene_size, traced_color);
    else
        trace_diffuseGPU (hit_obj_index, output_intersect, output_intersect + 3, scene, scene_size, traced_color);

    traced_color[0] += scene[16*hit_obj_index + 8];
    traced_color[1] += scene[16*hit_obj_index + 9];
    traced_color[2] += scene[16*hit_obj_index + 10];

    output[0] = traced_color[0];
    output[1] = traced_color[1];
    output[2] = traced_color[2];

}

__device__ void trace_diffuseGPU(int obj_index, float *hit_point, float *hit_normal, float *scene, int scene_size, float *output){
    /*
    summed_color = Vector3()
    for light in filter(lambda obj: obj.is_light, self.__scene):
        transmission = Vector3(1, 1, 1)
        light_direction = (light.primitive.position - hit_point).normalize()
        for other in filter(lambda obj: obj != light, self.__scene):
            if other.primitive.intersect(Ray(hit_point + self.__bias * hit_normal,
                                         light_direction)):
                transmission = Vector3()
                break
        summed_color = summed_color + (
            hit_object.material.surface_color
            .mul_comp(transmission)
            .mul_comp(light.material.emission_color) *
            max(0, hit_normal.dot(light_direction)))
    return summed_color
    */

    int i;
    float summed_color[3] = {0, 0, 0};
    float transmission[3] = {1, 1, 1};
    int hit_obj_index;

    float output_intersect[6];
    float current_ray[7];
    float temp;


    for(i = 0; i < scene_size; i++){
        if(scene[i*16 + 15] > 0.5){ /* is light */


            current_ray[0] = hit_point[0] + 0.0001*hit_normal[0];
            current_ray[1] = hit_point[1] + 0.0001*hit_normal[1];
            current_ray[2] = hit_point[2] + 0.0001*hit_normal[2];

            current_ray[3] = scene[i*16 + 1] - hit_point[0];
            current_ray[4] = scene[i*16 + 2] - hit_point[1];
            current_ray[5] = scene[i*16 + 3] - hit_point[2];

            current_ray[6] = 1.0;

            normalize_vector(current_ray+3, current_ray+4, current_ray+5);

            for(i = 0; i < scene_size; i++){
                if(scene[i*16 + 15] < 0.5)
                    intersectGPU(current_ray, scene+i, output_intersect, &hit_obj_index, 1);

                if(hit_obj_index < 0){
                    transmission[0] = 0;
                    transmission[1] = 0;
                    transmission[2] = 0;
                    break;
                }
            }

            temp = hit_normal[0]*current_ray[3] + hit_normal[1]*current_ray[4] + hit_normal[2]*current_ray[5];
            temp = 0 > temp ? 0 : temp;

            summed_color[0] += scene[obj_index*16 + 5] * transmission[0] * scene[i*16 + 8] * temp;
            summed_color[1] += scene[obj_index*16 + 6] * transmission[1] * scene[i*16 + 9] * temp;
            summed_color[2] += scene[obj_index*16 + 7] * transmission[2] * scene[i*16 + 10] * temp;
        }

    }
    output[0] = summed_color[0];
    output[1] = summed_color[1];
    output[2] = summed_color[2];

}

__device__ void trace_non_diffuseGPU (float *ray, int hit_obj_index, float *hit_point, float *hit_normal,
                                      float *scene, int scene_size, int depth, int max_depth, float *output)
{
    /*
    inside = ray.direction.dot(hit_normal) > 0
    if inside:
        hit_normal = -hit_normal
    facing_ratio = -ray.direction.dot(hit_normal)
    fresnel = self.__mix((1 - facing_ratio) ** 2, 1, 0.1)
    reflection_ray = Ray(hit_point + self.__bias * hit_normal,
                         ray.direction.reflect(hit_normal).normalize())
    reflection = self.__trace_recursively(reflection_ray, depth + 1)
    refraction = Vector3()

    # transparent?
    if hit_object.material.transparency > 0:
        from_ior = ray.current_ior if inside else hit_object.material.ior
        to_ior = hit_object.material.ior if inside else ray.current_ior
        refraction_ray = Ray(hit_point - self.__bias * hit_normal,
                             ray.direction.refract(from_ior, to_ior, hit_normal)
                             .normalize())
        refraction = self.__trace_recursively(refraction_ray, depth + 1)

    # mix according to fresnel
    return ((reflection * fresnel +
            refraction * (1 - fresnel) * hit_object.material.transparency)
            .mul_comp(hit_object.material.surface_color))
    */

    if (ray[3]*hit_normal[0] + ray[4]*hit_normal[1] + ray[5]*hit_normal[2] > 0){
        hit_normal[0] *= -1;
        hit_normal[1] *= -1;
        hit_normal[2] *= -1;
    }
    float facing_ratio = - (ray[3]*hit_normal[0] + ray[4]*hit_normal[1] + ray[5]*hit_normal[2]);
    float fresnel = (1 - facing_ratio) * (1 - facing_ratio) * 0.9 + 0.1;

    float reflection_ray[7];

    reflection_ray[0] = hit_point[0] - 0.0001*hit_normal[0];
    reflection_ray[1] = hit_point[1] - 0.0001*hit_normal[1];
    reflection_ray[2] = hit_point[2] - 0.0001*hit_normal[2];

    float temp;
    temp = ray[0]*hit_normal[0] + ray[1]*hit_normal[1] + ray[2]*hit_normal[2];
    temp *= 2;

    reflection_ray[3] = ray[0] - temp * hit_normal[0];
    reflection_ray[4] = ray[1] - temp * hit_normal[1];
    reflection_ray[5] = ray[2] - temp * hit_normal[2];

    normalize_vector(reflection_ray+3, reflection_ray+4, reflection_ray+5);

    reflection_ray[6] = 1.0;

    float reflection[3];
    float refraction[3] = {0, 0, 0};

    trace_recursivelyGPU(reflection_ray, scene, scene_size, reflection, depth+1, max_depth);

    /*
    def refract(self, from_ior, to_ior, normal):
        # Refracts the vector with regard to material change and normal

        eta = to_ior / from_ior
        cos_i = -normal.dot(self)
        k = 1 - eta ** 2 * (1 - cos_i ** 2)
        return self * eta + normal * (eta * cos_i - math.sqrt(k))
    */

    if (scene[hit_obj_index*16 + 12] > 0){
        float from_ior, to_ior;
        if (ray[3]*hit_normal[0] + ray[4]*hit_normal[1] + ray[5]*hit_normal[2] > 0) {
            from_ior = ray[6];
            to_ior = scene[hit_obj_index*16 + 13];
        }
        else {
            from_ior = scene[hit_obj_index*16 + 13];
            to_ior = ray[6];
        }

        float refraction_ray[7];

        refraction_ray[0] = hit_point[0] - 0.0001*hit_normal[0];
        refraction_ray[1] = hit_point[1] - 0.0001*hit_normal[1];
        refraction_ray[2] = hit_point[2] - 0.0001*hit_normal[2];

        float eta = to_ior / from_ior;
        float cos_i = -(ray[3]*hit_normal[0] + ray[4]*hit_normal[1] + ray[5]*hit_normal[2]);
        float k = 1 - eta*eta * (1 - cos_i*cos_i);

        temp = eta*cos_i - sqrt(k);

        refraction_ray[3] = ray[3] * eta + hit_normal[0] * temp;
        refraction_ray[4] = ray[4] * eta + hit_normal[1] * temp;
        refraction_ray[5] = ray[5] * eta + hit_normal[2] * temp;

        normalize_vector(refraction_ray+3, refraction_ray+4, refraction_ray+5);

        refraction_ray[6] = 1;



        trace_recursivelyGPU(refraction_ray, scene, scene_size, refraction, depth+1, max_depth);

    }

    output[0] = (reflection[0] * fresnel + refraction[0] * (1-fresnel) * scene[hit_obj_index*16 + 12]) * scene[hit_obj_index*16 + 5];
    output[1] = (reflection[1] * fresnel + refraction[1] * (1-fresnel) * scene[hit_obj_index*16 + 12]) * scene[hit_obj_index*16 + 6];
    output[2] = (reflection[2] * fresnel + refraction[2] * (1-fresnel) * scene[hit_obj_index*16 + 12]) * scene[hit_obj_index*16 + 7];



}


__global__ void traceGPU(float *ray_array, float *scene, int width, int scene_size, float *output, int max_depth){

    int tx;
    int ray_array_index;

    tx = blockIdx.x*blockDim.x + threadIdx.x;


    if (tx >= width)
        return;

    ray_array_index = tx;

    int hit_obj_index;
    float output_c[3];



    trace_recursivelyGPU(ray_array + ray_array_index*7, scene, scene_size, output_c, 0, max_depth);

    output[0] = output_c[0];
    output[1] = output_c[1];
    output[2] = output_c[2];

}

	.file	"tmpxft_0030d2e7_00000000-6_kernelcode.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2015:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2015:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z16normalize_vectorPfS_S_
	.type	_Z16normalize_vectorPfS_S_, @function
_Z16normalize_vectorPfS_S_:
.LFB2008:
	.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
.LFE2008:
	.size	_Z16normalize_vectorPfS_S_, .-_Z16normalize_vectorPfS_S_
	.globl	_Z12intersectGPUPfS_S_Pii
	.type	_Z12intersectGPUPfS_S_Pii, @function
_Z12intersectGPUPfS_S_Pii:
.LFB2009:
	.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
.LFE2009:
	.size	_Z12intersectGPUPfS_S_Pii, .-_Z12intersectGPUPfS_S_Pii
	.globl	_Z20trace_recursivelyGPUPfS_iS_ii
	.type	_Z20trace_recursivelyGPUPfS_iS_ii, @function
_Z20trace_recursivelyGPUPfS_iS_ii:
.LFB2010:
	.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
.LFE2010:
	.size	_Z20trace_recursivelyGPUPfS_iS_ii, .-_Z20trace_recursivelyGPUPfS_iS_ii
	.globl	_Z16trace_diffuseGPUiPfS_S_iS_
	.type	_Z16trace_diffuseGPUiPfS_S_iS_, @function
_Z16trace_diffuseGPUiPfS_S_iS_:
.LFB2011:
	.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
.LFE2011:
	.size	_Z16trace_diffuseGPUiPfS_S_iS_, .-_Z16trace_diffuseGPUiPfS_S_iS_
	.globl	_Z20trace_non_diffuseGPUPfiS_S_S_iiiS_
	.type	_Z20trace_non_diffuseGPUPfiS_S_S_iiiS_, @function
_Z20trace_non_diffuseGPUPfiS_S_S_iiiS_:
.LFB2012:
	.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
.LFE2012:
	.size	_Z20trace_non_diffuseGPUPfiS_S_S_iiiS_, .-_Z20trace_non_diffuseGPUPfiS_S_S_iiiS_
	.globl	_Z34__device_stub__Z8traceGPUPfS_iiS_iPfS_iiS_i
	.type	_Z34__device_stub__Z8traceGPUPfS_iiS_iPfS_iiS_i, @function
_Z34__device_stub__Z8traceGPUPfS_iiS_iPfS_iiS_i:
.LFB2037:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movl	%edx, 28(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 24(%rsp)
	leaq	64(%rsp), %rcx
	movq	%r8, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L12
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z8traceGPUPfS_iiS_i(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L12:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2037:
	.size	_Z34__device_stub__Z8traceGPUPfS_iiS_iPfS_iiS_i, .-_Z34__device_stub__Z8traceGPUPfS_iiS_iPfS_iiS_i
	.globl	_Z8traceGPUPfS_iiS_i
	.type	_Z8traceGPUPfS_iiS_i, @function
_Z8traceGPUPfS_iiS_i:
.LFB2038:
	.cfi_startproc
	endbr64
	jmp	_Z34__device_stub__Z8traceGPUPfS_iiS_iPfS_iiS_i
	.cfi_endproc
.LFE2038:
	.size	_Z8traceGPUPfS_iiS_i, .-_Z8traceGPUPfS_iiS_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z8traceGPUPfS_iiS_i"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2040:
	.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	_Z8traceGPUPfS_iiS_i(%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
.LFE2040:
	.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 "math.h"
#include "float.h"

__device__ void normalize_vector(float *a, float *b, float *c)
{
    float len;
    float ta, tb, tc;

    ta = *a;
    tb = *b;
    tc = *c;
    len = ta*ta + tb*tb + tc*tc;

    if(len == 0.0)
        return;
    len = sqrt(len);
    *a = ta/len;
    *b = tb/len;
    *c = tc/len;
}

__device__ void intersectGPU(float *ray_array, float *scene, float *output, int *hit_obj_index, int scene_size)
{

/*
input: ray_array, scene, scene_size
output: [hit_point v3, hit_normal v3]
*/

    int i;
    int scene_index;
    int flag;
    int current_obj_i = -1;

    float l1, l2, l3;
    float t_ca;
    float d_squared;
    float radius_squared;
    float t_hc;
    float t;
    float hit_point1;
    float hit_point2;
    float hit_point3;
    float hit_normal1;
    float hit_normal2;
    float hit_normal3;
    float current_t = FLT_MAX;

    for(i = 0; i < scene_size; i++){
        flag = 0;
        scene_index = i*16;
        if (scene[scene_index] < 0.5){ /* means sphere */
            /* calculate intersect */
            l1 = scene[scene_index+1] - ray_array[0];
            l2 = scene[scene_index+2] - ray_array[1];
            l3 = scene[scene_index+3] - ray_array[2];
            t_ca = l1*ray_array[3] +
                   l2*ray_array[4] +
                   l3*ray_array[5];
            if(t_ca < 0)
                flag = 1;
            d_squared = l1*l1 + l2*l2 +l3*l3 - t_ca*t_ca;
            radius_squared = scene[scene_index+4]*scene[scene_index+4];
            if(d_squared > radius_squared)
                flag = 1;
            t_hc = sqrt(radius_squared - d_squared);
            t = t_ca - t_hc;
            if(t < 0)
                t = t_ca + t_hc;
            hit_point1 = ray_array[0] + t * ray_array[3];
            hit_point2 = ray_array[1] + t * ray_array[4];
            hit_point3 = ray_array[2] + t * ray_array[5];
            hit_normal1 = hit_point1 - scene[scene_index+1];
            hit_normal2 = hit_point2 - scene[scene_index+2];
            hit_normal3 = hit_point3 - scene[scene_index+3];
            normalize_vector(&hit_normal1, &hit_normal2, &hit_normal3);
        }
        if(flag == 0){
            if(t < current_t){
                current_t = t;
                current_obj_i = i;
                output[0] = hit_point1;
                output[1] = hit_point2;
                output[2] = hit_point3;
                output[3] = hit_normal1;
                output[4] = hit_normal2;
                output[5] = hit_normal3;
            }
        }
    }
    *hit_obj_index = current_obj_i;
}

__device__ void trace_non_diffuseGPU (float *ray, int hit_obj_index, float *hit_point, float *hit_normal,
                                      float *scene, int scene_size, int depth, int max_depth, float *output);
__device__ void trace_diffuseGPU(int obj_index, float *hit_point, float *hit_normal, float *scene, int scene_size, float *output);

__device__ void trace_recursivelyGPU(float *ray, float *scene, int scene_size, float *output, int depth, int max_depth){
    /*
    hit_object, hit_point, hit_normal = self.__intersect(ray)
    if hit_object is None:
        return Vector3(0.3, 0.3, 0.3)  # horizon
    traced_color = Vector3()
    if not hit_object.material.is_diffuse and depth < self.__max_recursion_depth:
        traced_color = self.__trace_non_diffuse(ray, hit_object, hit_point, hit_normal, depth)
    else:
        traced_color = self.__trace_diffuse(hit_object, hit_point, hit_normal)
    return traced_color + hit_object.material.emission_color
    */

    int hit_obj_index;
    float output_intersect[6];

    intersectGPU(ray, scene, output_intersect, &hit_obj_index, scene_size);

    if (hit_obj_index < 0) {
        output[0] = 0.3;
        output[1] = 0.3;
        output[2] = 0.3;
        return;
    }

    float traced_color[3];

    if (depth < max_depth && scene[16*hit_obj_index+14] < 0.5)
        /* trace_non_diffuseGPU (ray, hit_obj_index, output_intersect, output_intersect + 3,
                              scene, scene_size, depth, max_depth, traced_color);*/
        trace_diffuseGPU (hit_obj_index, output_intersect, output_intersect + 3, scene, scene_size, traced_color);
    else
        trace_diffuseGPU (hit_obj_index, output_intersect, output_intersect + 3, scene, scene_size, traced_color);

    traced_color[0] += scene[16*hit_obj_index + 8];
    traced_color[1] += scene[16*hit_obj_index + 9];
    traced_color[2] += scene[16*hit_obj_index + 10];

    output[0] = traced_color[0];
    output[1] = traced_color[1];
    output[2] = traced_color[2];

}

__device__ void trace_diffuseGPU(int obj_index, float *hit_point, float *hit_normal, float *scene, int scene_size, float *output){
    /*
    summed_color = Vector3()
    for light in filter(lambda obj: obj.is_light, self.__scene):
        transmission = Vector3(1, 1, 1)
        light_direction = (light.primitive.position - hit_point).normalize()
        for other in filter(lambda obj: obj != light, self.__scene):
            if other.primitive.intersect(Ray(hit_point + self.__bias * hit_normal,
                                         light_direction)):
                transmission = Vector3()
                break
        summed_color = summed_color + (
            hit_object.material.surface_color
            .mul_comp(transmission)
            .mul_comp(light.material.emission_color) *
            max(0, hit_normal.dot(light_direction)))
    return summed_color
    */

    int i;
    float summed_color[3] = {0, 0, 0};
    float transmission[3] = {1, 1, 1};
    int hit_obj_index;

    float output_intersect[6];
    float current_ray[7];
    float temp;


    for(i = 0; i < scene_size; i++){
        if(scene[i*16 + 15] > 0.5){ /* is light */


            current_ray[0] = hit_point[0] + 0.0001*hit_normal[0];
            current_ray[1] = hit_point[1] + 0.0001*hit_normal[1];
            current_ray[2] = hit_point[2] + 0.0001*hit_normal[2];

            current_ray[3] = scene[i*16 + 1] - hit_point[0];
            current_ray[4] = scene[i*16 + 2] - hit_point[1];
            current_ray[5] = scene[i*16 + 3] - hit_point[2];

            current_ray[6] = 1.0;

            normalize_vector(current_ray+3, current_ray+4, current_ray+5);

            for(i = 0; i < scene_size; i++){
                if(scene[i*16 + 15] < 0.5)
                    intersectGPU(current_ray, scene+i, output_intersect, &hit_obj_index, 1);

                if(hit_obj_index < 0){
                    transmission[0] = 0;
                    transmission[1] = 0;
                    transmission[2] = 0;
                    break;
                }
            }

            temp = hit_normal[0]*current_ray[3] + hit_normal[1]*current_ray[4] + hit_normal[2]*current_ray[5];
            temp = 0 > temp ? 0 : temp;

            summed_color[0] += scene[obj_index*16 + 5] * transmission[0] * scene[i*16 + 8] * temp;
            summed_color[1] += scene[obj_index*16 + 6] * transmission[1] * scene[i*16 + 9] * temp;
            summed_color[2] += scene[obj_index*16 + 7] * transmission[2] * scene[i*16 + 10] * temp;
        }

    }
    output[0] = summed_color[0];
    output[1] = summed_color[1];
    output[2] = summed_color[2];

}

__device__ void trace_non_diffuseGPU (float *ray, int hit_obj_index, float *hit_point, float *hit_normal,
                                      float *scene, int scene_size, int depth, int max_depth, float *output)
{
    /*
    inside = ray.direction.dot(hit_normal) > 0
    if inside:
        hit_normal = -hit_normal
    facing_ratio = -ray.direction.dot(hit_normal)
    fresnel = self.__mix((1 - facing_ratio) ** 2, 1, 0.1)
    reflection_ray = Ray(hit_point + self.__bias * hit_normal,
                         ray.direction.reflect(hit_normal).normalize())
    reflection = self.__trace_recursively(reflection_ray, depth + 1)
    refraction = Vector3()

    # transparent?
    if hit_object.material.transparency > 0:
        from_ior = ray.current_ior if inside else hit_object.material.ior
        to_ior = hit_object.material.ior if inside else ray.current_ior
        refraction_ray = Ray(hit_point - self.__bias * hit_normal,
                             ray.direction.refract(from_ior, to_ior, hit_normal)
                             .normalize())
        refraction = self.__trace_recursively(refraction_ray, depth + 1)

    # mix according to fresnel
    return ((reflection * fresnel +
            refraction * (1 - fresnel) * hit_object.material.transparency)
            .mul_comp(hit_object.material.surface_color))
    */

    if (ray[3]*hit_normal[0] + ray[4]*hit_normal[1] + ray[5]*hit_normal[2] > 0){
        hit_normal[0] *= -1;
        hit_normal[1] *= -1;
        hit_normal[2] *= -1;
    }
    float facing_ratio = - (ray[3]*hit_normal[0] + ray[4]*hit_normal[1] + ray[5]*hit_normal[2]);
    float fresnel = (1 - facing_ratio) * (1 - facing_ratio) * 0.9 + 0.1;

    float reflection_ray[7];

    reflection_ray[0] = hit_point[0] - 0.0001*hit_normal[0];
    reflection_ray[1] = hit_point[1] - 0.0001*hit_normal[1];
    reflection_ray[2] = hit_point[2] - 0.0001*hit_normal[2];

    float temp;
    temp = ray[0]*hit_normal[0] + ray[1]*hit_normal[1] + ray[2]*hit_normal[2];
    temp *= 2;

    reflection_ray[3] = ray[0] - temp * hit_normal[0];
    reflection_ray[4] = ray[1] - temp * hit_normal[1];
    reflection_ray[5] = ray[2] - temp * hit_normal[2];

    normalize_vector(reflection_ray+3, reflection_ray+4, reflection_ray+5);

    reflection_ray[6] = 1.0;

    float reflection[3];
    float refraction[3] = {0, 0, 0};

    trace_recursivelyGPU(reflection_ray, scene, scene_size, reflection, depth+1, max_depth);

    /*
    def refract(self, from_ior, to_ior, normal):
        # Refracts the vector with regard to material change and normal

        eta = to_ior / from_ior
        cos_i = -normal.dot(self)
        k = 1 - eta ** 2 * (1 - cos_i ** 2)
        return self * eta + normal * (eta * cos_i - math.sqrt(k))
    */

    if (scene[hit_obj_index*16 + 12] > 0){
        float from_ior, to_ior;
        if (ray[3]*hit_normal[0] + ray[4]*hit_normal[1] + ray[5]*hit_normal[2] > 0) {
            from_ior = ray[6];
            to_ior = scene[hit_obj_index*16 + 13];
        }
        else {
            from_ior = scene[hit_obj_index*16 + 13];
            to_ior = ray[6];
        }

        float refraction_ray[7];

        refraction_ray[0] = hit_point[0] - 0.0001*hit_normal[0];
        refraction_ray[1] = hit_point[1] - 0.0001*hit_normal[1];
        refraction_ray[2] = hit_point[2] - 0.0001*hit_normal[2];

        float eta = to_ior / from_ior;
        float cos_i = -(ray[3]*hit_normal[0] + ray[4]*hit_normal[1] + ray[5]*hit_normal[2]);
        float k = 1 - eta*eta * (1 - cos_i*cos_i);

        temp = eta*cos_i - sqrt(k);

        refraction_ray[3] = ray[3] * eta + hit_normal[0] * temp;
        refraction_ray[4] = ray[4] * eta + hit_normal[1] * temp;
        refraction_ray[5] = ray[5] * eta + hit_normal[2] * temp;

        normalize_vector(refraction_ray+3, refraction_ray+4, refraction_ray+5);

        refraction_ray[6] = 1;



        trace_recursivelyGPU(refraction_ray, scene, scene_size, refraction, depth+1, max_depth);

    }

    output[0] = (reflection[0] * fresnel + refraction[0] * (1-fresnel) * scene[hit_obj_index*16 + 12]) * scene[hit_obj_index*16 + 5];
    output[1] = (reflection[1] * fresnel + refraction[1] * (1-fresnel) * scene[hit_obj_index*16 + 12]) * scene[hit_obj_index*16 + 6];
    output[2] = (reflection[2] * fresnel + refraction[2] * (1-fresnel) * scene[hit_obj_index*16 + 12]) * scene[hit_obj_index*16 + 7];



}


__global__ void traceGPU(float *ray_array, float *scene, int width, int scene_size, float *output, int max_depth){

    int tx;
    int ray_array_index;

    tx = blockIdx.x*blockDim.x + threadIdx.x;


    if (tx >= width)
        return;

    ray_array_index = tx;

    int hit_obj_index;
    float output_c[3];



    trace_recursivelyGPU(ray_array + ray_array_index*7, scene, scene_size, output_c, 0, max_depth);

    output[0] = output_c[0];
    output[1] = output_c[1];
    output[2] = output_c[2];

}

	.text
	.file	"kernelcode.hip"
	.globl	_Z23__device_stub__traceGPUPfS_iiS_i # -- Begin function _Z23__device_stub__traceGPUPfS_iiS_i
	.type	_Z23__device_stub__traceGPUPfS_iiS_i,@function
_Z23__device_stub__traceGPUPfS_iiS_i:   # @_Z23__device_stub__traceGPUPfS_iiS_i
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	20(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	16(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%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	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z8traceGPUPfS_iiS_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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	_Z23__device_stub__traceGPUPfS_iiS_i, .Lfunc_end0-_Z23__device_stub__traceGPUPfS_iiS_i
	.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	.LBB1_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB1_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8traceGPUPfS_iiS_i, %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_end1:
	.size	__hip_module_ctor, .Lfunc_end1-__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	.LBB2_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
.LBB2_2:
	retq
.Lfunc_end2:
	.size	__hip_module_dtor, .Lfunc_end2-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z8traceGPUPfS_iiS_i,@object    # @_Z8traceGPUPfS_iiS_i
	.section	.rodata,"a",@progbits
	.globl	_Z8traceGPUPfS_iiS_i
	.p2align	3, 0x0
_Z8traceGPUPfS_iiS_i:
	.quad	_Z23__device_stub__traceGPUPfS_iiS_i
	.size	_Z8traceGPUPfS_iiS_i, 8

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

	.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 _Z23__device_stub__traceGPUPfS_iiS_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z8traceGPUPfS_iiS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z8traceGPUPfS_iiS_i    ; -- Begin function _Z8traceGPUPfS_iiS_i
	.globl	_Z8traceGPUPfS_iiS_i
	.p2align	8
	.type	_Z8traceGPUPfS_iiS_i,@function
_Z8traceGPUPfS_iiS_i:                   ; @_Z8traceGPUPfS_iiS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b64 s[12:13], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s12, v1
	s_cbranch_execz .LBB0_54
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	s_cmp_gt_i32 s13, 0
	s_mov_b32 s12, 0
	s_cselect_b32 s16, -1, 0
	s_cmp_lt_i32 s13, 1
	s_cbranch_scc1 .LBB0_10
; %bb.2:                                ; %.lr.ph.i.i
	v_mul_lo_u32 v0, v1, 7
	v_dual_mov_b32 v7, 0x7f7fffff :: v_dual_mov_b32 v6, -1
	s_waitcnt lgkmcnt(0)
	s_add_u32 s14, s6, 8
	s_addc_u32 s15, s7, 0
                                        ; implicit-def: $vgpr10
                                        ; implicit-def: $vgpr11
                                        ; implicit-def: $vgpr12
                                        ; implicit-def: $vgpr13
                                        ; implicit-def: $vgpr14
                                        ; implicit-def: $vgpr15
                                        ; implicit-def: $vgpr2
                                        ; implicit-def: $vgpr8
                                        ; implicit-def: $vgpr16
                                        ; implicit-def: $vgpr3
                                        ; implicit-def: $vgpr9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v1, vcc_lo
                                        ; implicit-def: $vgpr1
                                        ; implicit-def: $vgpr0
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	s_add_u32 s2, s14, -8
	s_addc_u32 s3, s15, -1
	s_load_b32 s2, s[2:3], 0x0
	s_waitcnt lgkmcnt(0)
	v_cmp_nlt_f32_e64 s2, s2, 0.5
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s2
	s_mov_b32 s2, 0
	s_cbranch_vccnz .LBB0_7
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=1
	s_clause 0x1
	global_load_b128 v[0:3], v[4:5], off
	global_load_b64 v[16:17], v[4:5], off offset:16
	s_add_u32 s2, s14, -4
	s_addc_u32 s3, s15, -1
	s_load_b128 s[8:11], s[2:3], 0x0
	s_waitcnt vmcnt(1) lgkmcnt(0)
	v_dual_sub_f32 v8, s9, v1 :: v_dual_sub_f32 v9, s8, v0
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_dual_sub_f32 v19, s10, v2 :: v_dual_mul_f32 v18, v8, v16
	v_mul_f32_e32 v8, v8, v8
	v_fmac_f32_e32 v18, v9, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v8, v9, v9
	v_fmac_f32_e32 v18, v19, v17
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v8, v19, v19
	v_fma_f32 v19, -v18, v18, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v8, s11, s11, -v19
	v_mul_f32_e32 v9, 0x4f800000, v8
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v8, v8, v9, vcc_lo
	v_sqrt_f32_e32 v9, v8
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v20, -1, v9
	v_add_nc_u32_e32 v21, 1, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v22, -v20, v9, v8
	v_fma_f32 v23, -v21, v9, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_f32_e64 s2, 0, v22
	v_cndmask_b32_e64 v9, v9, v20, s2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e64 s2, 0, v23
	v_cndmask_b32_e64 v9, v9, v21, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v20, 0x37800000, v9
	v_cndmask_b32_e32 v9, v9, v20, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v8, 0x260
	v_mul_f32_e64 v20, s11, s11
	v_cmp_gt_f32_e64 s2, 0, v18
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e32 v8, v9, v8, vcc_lo
	v_cmp_gt_f32_e64 s3, v19, v20
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_sub_f32_e32 v9, v18, v8
	v_add_f32_e32 v8, v18, v8
	v_cmp_gt_f32_e32 vcc_lo, 0, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v8, v9, v8, vcc_lo
	v_fma_f32 v1, v16, v8, v1
	v_fma_f32 v0, v3, v8, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_fmac_f32 v2, v17, v8 :: v_dual_subrev_f32 v3, s9, v1
	v_dual_subrev_f32 v9, s8, v0 :: v_dual_subrev_f32 v16, s10, v2
	s_mov_b32 s8, exec_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v17, v3, v3
	v_fmac_f32_e32 v17, v9, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v17, v16, v16
	v_cmpx_neq_f32_e32 0, v17
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_3 Depth=1
	v_mul_f32_e32 v18, 0x4f800000, v17
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v17
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v17, v17, v18, vcc_lo
	v_sqrt_f32_e32 v18, v17
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v19, -1, v18
	v_add_nc_u32_e32 v20, 1, v18
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v21, -v19, v18, v17
	v_fma_f32 v22, -v20, v18, v17
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_f32_e64 s4, 0, v21
	v_cndmask_b32_e64 v18, v18, v19, s4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e64 s4, 0, v22
	v_cndmask_b32_e64 v18, v18, v20, s4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v19, 0x37800000, v18
	v_cndmask_b32_e32 v18, v18, v19, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v17, 0x260
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v17, v18, v17, vcc_lo
	v_div_scale_f32 v18, null, v17, v17, v9
	v_div_scale_f32 v19, null, v17, v17, v3
	v_div_scale_f32 v20, null, v17, v17, v16
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_rcp_f32_e32 v21, v18
	v_rcp_f32_e32 v22, v19
	v_div_scale_f32 v24, vcc_lo, v9, v17, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(TRANS32_DEP_3)
	v_rcp_f32_e32 v23, v20
	v_div_scale_f32 v25, s4, v3, v17, v3
	v_div_scale_f32 v29, s5, v16, v17, v16
	v_fma_f32 v26, -v18, v21, 1.0
	s_waitcnt_depctr 0xfff
	v_fma_f32 v27, -v19, v22, 1.0
	v_fma_f32 v28, -v20, v23, 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_dual_fmac_f32 v21, v26, v21 :: v_dual_fmac_f32 v22, v27, v22
	v_fmac_f32_e32 v23, v28, v23
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v26, v24, v21
	v_mul_f32_e32 v28, v29, v23
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fma_f32 v30, -v18, v26, v24
	v_mul_f32_e32 v27, v25, v22
	v_fma_f32 v32, -v20, v28, v29
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v26, v30, v21
	v_fma_f32 v31, -v19, v27, v25
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v28, v32, v23
	v_fma_f32 v18, -v18, v26, v24
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v27, v31, v22
	v_fma_f32 v20, -v20, v28, v29
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v18, v18, v21, v26
	v_fma_f32 v19, -v19, v27, v25
	s_mov_b32 vcc_lo, s4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f32 v9, v18, v17, v9
	v_div_fmas_f32 v19, v19, v22, v27
	s_mov_b32 vcc_lo, s5
	v_div_fmas_f32 v20, v20, v23, v28
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f32 v3, v19, v17, v3
	v_div_fixup_f32 v16, v20, v17, v16
.LBB0_6:                                ; %Flow88
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s8
	s_or_b32 s2, s3, s2
.LBB0_7:                                ; %_Z16normalize_vectorPfS_S_.exit.i.i
                                        ;   in Loop: Header=BB0_3 Depth=1
	v_cmp_lt_f32_e32 vcc_lo, v8, v7
	s_xor_b32 s2, s2, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s3, s2, vcc_lo
	s_and_saveexec_b32 s2, s3
; %bb.8:                                ;   in Loop: Header=BB0_3 Depth=1
	v_dual_mov_b32 v6, s12 :: v_dual_mov_b32 v11, v3
	v_dual_mov_b32 v10, v16 :: v_dual_mov_b32 v13, v2
	v_dual_mov_b32 v12, v9 :: v_dual_mov_b32 v15, v0
	v_dual_mov_b32 v14, v1 :: v_dual_mov_b32 v7, v8
; %bb.9:                                ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s2
	s_add_i32 s12, s12, 1
	s_add_u32 s14, s14, 64
	s_addc_u32 s15, s15, 0
	s_cmp_lg_u32 s13, s12
	s_cbranch_scc1 .LBB0_3
	s_branch .LBB0_11
.LBB0_10:
	v_mov_b32_e32 v6, -1
                                        ; implicit-def: $vgpr15
                                        ; implicit-def: $vgpr14
                                        ; implicit-def: $vgpr13
                                        ; implicit-def: $vgpr12
                                        ; implicit-def: $vgpr11
                                        ; implicit-def: $vgpr10
.LBB0_11:                               ; %_Z12intersectGPUPfS_S_Pii.exit.i
	v_dual_mov_b32 v2, 0x3e99999a :: v_dual_mov_b32 v1, 0x3e99999a
	v_mov_b32_e32 v0, 0x3e99999a
	s_mov_b32 s2, -1
	s_mov_b32 s12, exec_lo
	v_cmpx_lt_i32_e32 -1, v6
	s_cbranch_execz .LBB0_53
; %bb.12:
	s_load_b32 s3, s[0:1], 0x20
	v_lshlrev_b32_e32 v0, 4, v6
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s3, 1
	s_cbranch_scc1 .LBB0_14
; %bb.13:
	v_mov_b32_e32 v1, 0
	s_mov_b32 s17, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[0:1]
	v_add_co_u32 v2, vcc_lo, s6, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	global_load_b32 v1, v[2:3], off offset:56
	s_waitcnt vmcnt(0)
	v_cmp_ngt_f32_e32 vcc_lo, 0.5, v1
	s_or_not1_b32 s2, vcc_lo, exec_lo
	s_branch .LBB0_15
.LBB0_14:
	s_mov_b32 s17, 0
                                        ; implicit-def: $vgpr2_vgpr3
.LBB0_15:                               ; %Flow85
                                        ; implicit-def: $vgpr16
                                        ; implicit-def: $vgpr17
                                        ; implicit-def: $vgpr18
	s_and_saveexec_b32 s3, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s18, exec_lo, s3
	s_cbranch_execz .LBB0_34
; %bb.16:                               ; %._crit_edge
	v_dual_mov_b32 v16, 0 :: v_dual_mov_b32 v17, 0
	v_mov_b32_e32 v18, 0
	s_and_not1_b32 vcc_lo, exec_lo, s16
	s_mov_b32 s19, 0
	s_cbranch_vccnz .LBB0_33
; %bb.17:                               ; %.lr.ph91.i24.i
	v_cvt_f64_f32_e32 v[4:5], v15
	v_cvt_f64_f32_e32 v[6:7], v12
	v_cvt_f64_f32_e32 v[8:9], v14
	v_cvt_f64_f32_e32 v[16:17], v11
	v_cvt_f64_f32_e32 v[18:19], v13
	v_cvt_f64_f32_e32 v[20:21], v10
	s_mov_b32 s2, 0xeb1c432d
	s_mov_b32 s3, 0x3f1a36e2
	s_add_u32 s4, s6, 60
	v_mov_b32_e32 v25, 0
	s_addc_u32 s5, s7, 0
	s_add_u32 s8, s6, 8
	s_addc_u32 s9, s7, 0
                                        ; implicit-def: $vgpr23
	v_mov_b32_e32 v22, 1.0
	v_fma_f64 v[4:5], v[6:7], s[2:3], v[4:5]
	v_fma_f64 v[6:7], v[16:17], s[2:3], v[8:9]
	v_mov_b32_e32 v17, 0
	v_fma_f64 v[8:9], v[20:21], s[2:3], v[18:19]
	v_mov_b32_e32 v18, 0
	v_mov_b32_e32 v16, 0
	v_cvt_f32_f64_e32 v19, v[4:5]
	v_dual_mov_b32 v5, 0 :: v_dual_mov_b32 v4, 1.0
	v_cvt_f32_f64_e32 v20, v[6:7]
	v_cvt_f32_f64_e32 v21, v[8:9]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mov_b32_e32 v1, v5
	v_lshlrev_b64 v[6:7], 2, v[0:1]
	v_mov_b32_e32 v1, 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v6, vcc_lo, s6, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v7, vcc_lo
.LBB0_18:                               ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_22 Depth 2
	v_lshlrev_b32_e32 v8, 4, v25
	s_mov_b32 s20, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v9, 31, v8
	v_lshlrev_b64 v[8:9], 2, v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v8, vcc_lo, s6, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s7, v9, vcc_lo
	global_load_b32 v24, v[8:9], off offset:60
	s_waitcnt vmcnt(0)
	v_cmpx_lt_f32_e32 0.5, v24
	s_cbranch_execz .LBB0_31
; %bb.19:                               ;   in Loop: Header=BB0_18 Depth=1
	global_load_b96 v[24:26], v[8:9], off offset:4
	s_mov_b32 s10, exec_lo
	s_waitcnt vmcnt(0)
	v_dual_sub_f32 v8, v25, v14 :: v_dual_sub_f32 v9, v24, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_sub_f32 v24, v26, v13 :: v_dual_mul_f32 v25, v8, v8
	v_fmac_f32_e32 v25, v9, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v25, v24, v24
	v_cmpx_neq_f32_e32 0, v25
	s_cbranch_execz .LBB0_21
; %bb.20:                               ;   in Loop: Header=BB0_18 Depth=1
	v_mul_f32_e32 v26, 0x4f800000, v25
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v25
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v25, v25, v26, vcc_lo
	v_sqrt_f32_e32 v26, v25
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v27, -1, v26
	v_add_nc_u32_e32 v28, 1, v26
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v29, -v27, v26, v25
	v_fma_f32 v30, -v28, v26, v25
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_f32_e64 s2, 0, v29
	v_cndmask_b32_e64 v26, v26, v27, s2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e64 s2, 0, v30
	v_cndmask_b32_e64 v26, v26, v28, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v27, 0x37800000, v26
	v_cndmask_b32_e32 v26, v26, v27, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v25, 0x260
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v25, v26, v25, vcc_lo
	v_div_scale_f32 v26, null, v25, v25, v9
	v_div_scale_f32 v27, null, v25, v25, v8
	v_div_scale_f32 v28, null, v25, v25, v24
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_rcp_f32_e32 v29, v26
	v_rcp_f32_e32 v30, v27
	v_div_scale_f32 v32, vcc_lo, v9, v25, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(TRANS32_DEP_3)
	v_rcp_f32_e32 v31, v28
	v_div_scale_f32 v33, s2, v8, v25, v8
	v_div_scale_f32 v37, s3, v24, v25, v24
	v_fma_f32 v34, -v26, v29, 1.0
	s_waitcnt_depctr 0xfff
	v_fma_f32 v35, -v27, v30, 1.0
	v_fma_f32 v36, -v28, v31, 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_dual_fmac_f32 v29, v34, v29 :: v_dual_fmac_f32 v30, v35, v30
	v_fmac_f32_e32 v31, v36, v31
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v34, v32, v29
	v_mul_f32_e32 v36, v37, v31
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fma_f32 v38, -v26, v34, v32
	v_mul_f32_e32 v35, v33, v30
	v_fma_f32 v40, -v28, v36, v37
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v34, v38, v29
	v_fma_f32 v39, -v27, v35, v33
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v36, v40, v31
	v_fma_f32 v26, -v26, v34, v32
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v35, v39, v30
	v_fma_f32 v28, -v28, v36, v37
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v26, v26, v29, v34
	v_fma_f32 v27, -v27, v35, v33
	s_mov_b32 vcc_lo, s2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f32 v9, v26, v25, v9
	v_div_fmas_f32 v27, v27, v30, v35
	s_mov_b32 vcc_lo, s3
	v_div_fmas_f32 v28, v28, v31, v36
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f32 v8, v27, v25, v8
	v_div_fixup_f32 v24, v28, v25, v24
.LBB0_21:                               ; %.lr.ph.i41.i
                                        ;   in Loop: Header=BB0_18 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	s_mov_b32 s21, 0
	s_mov_b64 s[10:11], s[4:5]
	s_mov_b64 s[14:15], s[8:9]
	s_mov_b32 s22, 0
.LBB0_22:                               ;   Parent Loop BB0_18 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_load_b32 s2, s[10:11], 0x0
	s_waitcnt lgkmcnt(0)
	v_cmp_nlt_f32_e64 s2, s2, 0.5
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB0_27
; %bb.23:                               ;   in Loop: Header=BB0_22 Depth=2
	s_add_u32 s2, s14, -8
	s_addc_u32 s3, s15, -1
	s_load_b32 s2, s[2:3], 0x0
	s_waitcnt lgkmcnt(0)
	v_cmp_nlt_f32_e64 s2, s2, 0.5
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB0_25
; %bb.24:                               ;   in Loop: Header=BB0_22 Depth=2
	s_add_u32 s2, s14, -4
	s_addc_u32 s3, s15, -1
	s_load_b128 s[24:27], s[2:3], 0x0
	s_waitcnt lgkmcnt(0)
	v_sub_f32_e32 v25, s24, v19
	v_sub_f32_e32 v23, s25, v20
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_sub_f32 v27, s26, v21 :: v_dual_mul_f32 v26, v8, v23
	v_fmac_f32_e32 v26, v9, v25
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v26, v24, v27
	v_mul_f32_e32 v23, v23, v23
	v_fmac_f32_e32 v23, v25, v25
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v23, v27, v27
	v_fma_f32 v23, -v26, v26, v23
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v25, s27, s27, -v23
	v_mul_f32_e32 v27, 0x4f800000, v25
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v25
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v25, v25, v27, vcc_lo
	v_sqrt_f32_e32 v27, v25
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v28, -1, v27
	v_add_nc_u32_e32 v29, 1, v27
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v30, -v28, v27, v25
	v_fma_f32 v31, -v29, v27, v25
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_f32_e64 s2, 0, v30
	v_cndmask_b32_e64 v27, v27, v28, s2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e64 s2, 0, v31
	v_cndmask_b32_e64 v27, v27, v29, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v28, 0x37800000, v27
	v_cndmask_b32_e32 v27, v27, v28, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v25, 0x260
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_cndmask_b32_e32 v25, v27, v25, vcc_lo
	v_mul_f32_e64 v27, s27, s27
	v_cmp_gt_f32_e32 vcc_lo, 0, v26
	v_sub_f32_e32 v28, v26, v25
	v_add_f32_e32 v25, v26, v25
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cmp_gt_f32_e64 s2, v23, v27
	v_cmp_gt_f32_e64 s3, 0, v28
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s2, s2, vcc_lo
	s_and_b32 s2, s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cndmask_b32_e64 v23, v28, v25, s3
	s_branch .LBB0_26
.LBB0_25:                               ;   in Loop: Header=BB0_22 Depth=2
	s_mov_b32 s2, 0
                                        ; implicit-def: $vgpr23
.LBB0_26:                               ; %_Z16normalize_vectorPfS_S_.exit.i.i53.i
                                        ;   in Loop: Header=BB0_22 Depth=2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_ngt_f32_e32 vcc_lo, 0x7f7fffff, v23
	s_or_b32 s2, s2, vcc_lo
	v_cndmask_b32_e64 v23, 0, -1, s2
.LBB0_27:                               ; %_Z12intersectGPUPfS_S_Pii.exit.i45.i
                                        ;   in Loop: Header=BB0_22 Depth=2
	v_dual_mov_b32 v26, 0 :: v_dual_mov_b32 v25, s22
	v_dual_mov_b32 v28, 0 :: v_dual_mov_b32 v27, 0
	s_mov_b32 s3, -1
	s_mov_b32 s2, exec_lo
	v_cmpx_lt_i32_e32 -1, v23
; %bb.28:                               ;   in Loop: Header=BB0_22 Depth=2
	s_add_i32 s22, s22, 1
	s_add_u32 s14, s14, 4
	s_addc_u32 s15, s15, 0
	s_add_u32 s10, s10, 64
	s_addc_u32 s11, s11, 0
	s_cmp_eq_u32 s13, s22
	v_dual_mov_b32 v25, s13 :: v_dual_mov_b32 v26, v1
	v_dual_mov_b32 v28, v4 :: v_dual_mov_b32 v27, v22
	s_cselect_b32 s3, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_not1_b32 s3, s3, exec_lo
; %bb.29:                               ; %Flow76
                                        ;   in Loop: Header=BB0_22 Depth=2
	s_or_b32 exec_lo, exec_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, exec_lo, s3
	s_or_b32 s21, s2, s21
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s21
	s_cbranch_execnz .LBB0_22
; %bb.30:                               ; %_Z12intersectGPUPfS_S_Pii.exit._crit_edge.i48.i
                                        ;   in Loop: Header=BB0_18 Depth=1
	s_or_b32 exec_lo, exec_lo, s21
	v_dual_mul_f32 v1, v11, v8 :: v_dual_lshlrev_b32 v4, 4, v25
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[29:30], 2, v[4:5]
	v_fmac_f32_e32 v1, v12, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v32, vcc_lo, s6, v29
	v_add_co_ci_u32_e32 v33, vcc_lo, s7, v30, vcc_lo
	s_clause 0x1
	global_load_b96 v[29:31], v[6:7], off offset:20
	global_load_b96 v[32:34], v[32:33], off offset:32
	s_waitcnt vmcnt(1)
	v_dual_fmac_f32 v1, v10, v24 :: v_dual_mul_f32 v8, v28, v30
	v_dual_mul_f32 v4, v26, v29 :: v_dual_mul_f32 v9, v27, v31
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cmp_ngt_f32_e32 vcc_lo, 0, v1
	s_waitcnt vmcnt(0)
	v_mul_f32_e32 v8, v8, v33
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_dual_mul_f32 v24, v4, v32 :: v_dual_mul_f32 v9, v9, v34
	v_dual_cndmask_b32 v22, 0, v1 :: v_dual_mov_b32 v1, v26
	v_dual_mov_b32 v4, v28 :: v_dual_fmac_f32 v17, v22, v8
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_fmac_f32_e32 v18, v22, v24
	v_fmac_f32_e32 v16, v22, v9
	v_mov_b32_e32 v22, v27
.LBB0_31:                               ; %Flow77
                                        ;   in Loop: Header=BB0_18 Depth=1
	s_or_b32 exec_lo, exec_lo, s20
	v_add_nc_u32_e32 v25, 1, v25
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_le_i32_e32 vcc_lo, s13, v25
	s_or_b32 s19, vcc_lo, s19
	s_and_not1_b32 exec_lo, exec_lo, s19
	s_cbranch_execnz .LBB0_18
; %bb.32:                               ; %Flow78
	s_or_b32 exec_lo, exec_lo, s19
.LBB0_33:                               ; %Flow79
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 s17, s17, exec_lo
.LBB0_34:                               ; %Flow86
	s_or_b32 exec_lo, exec_lo, s18
	s_and_saveexec_b32 s18, s17
	s_cbranch_execz .LBB0_52
; %bb.35:
	v_dual_mov_b32 v16, 0 :: v_dual_mov_b32 v17, 0
	v_mov_b32_e32 v18, 0
	s_and_not1_b32 vcc_lo, exec_lo, s16
	s_mov_b32 s16, 0
	s_cbranch_vccnz .LBB0_52
; %bb.36:                               ; %.lr.ph91.i.i
	v_cvt_f64_f32_e32 v[4:5], v15
	v_cvt_f64_f32_e32 v[6:7], v12
	v_cvt_f64_f32_e32 v[8:9], v14
	v_cvt_f64_f32_e32 v[16:17], v11
	v_cvt_f64_f32_e32 v[18:19], v13
	v_cvt_f64_f32_e32 v[20:21], v10
	s_mov_b32 s2, 0xeb1c432d
	s_mov_b32 s3, 0x3f1a36e2
	s_add_u32 s4, s6, 60
	s_addc_u32 s5, s7, 0
	s_add_u32 s8, s6, 8
	s_addc_u32 s9, s7, 0
	v_mov_b32_e32 v23, 0
	v_fma_f64 v[4:5], v[6:7], s[2:3], v[4:5]
	v_fma_f64 v[6:7], v[16:17], s[2:3], v[8:9]
	s_delay_alu instid0(VALU_DEP_4)
	v_fma_f64 v[16:17], v[20:21], s[2:3], v[18:19]
	v_dual_mov_b32 v19, 1.0 :: v_dual_mov_b32 v20, 1.0
	v_mov_b32_e32 v18, 0
                                        ; implicit-def: $vgpr21
	v_cvt_f32_f64_e32 v1, v[4:5]
	v_mov_b32_e32 v4, 1.0
	v_cvt_f32_f64_e32 v8, v[6:7]
	v_mov_b32_e32 v5, 0
	v_cvt_f32_f64_e32 v9, v[16:17]
	v_dual_mov_b32 v16, 0 :: v_dual_mov_b32 v17, 0
.LBB0_37:                               ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_41 Depth 2
	v_lshlrev_b32_e32 v6, 4, v23
	s_mov_b32 s17, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v7, 31, v6
	v_lshlrev_b64 v[6:7], 2, v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s6, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v7, vcc_lo
	global_load_b32 v22, v[6:7], off offset:60
	s_waitcnt vmcnt(0)
	v_cmpx_lt_f32_e32 0.5, v22
	s_cbranch_execz .LBB0_50
; %bb.38:                               ;   in Loop: Header=BB0_37 Depth=1
	global_load_b96 v[22:24], v[6:7], off offset:4
	s_mov_b32 s10, exec_lo
	s_waitcnt vmcnt(0)
	v_dual_sub_f32 v6, v23, v14 :: v_dual_sub_f32 v7, v22, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_sub_f32 v22, v24, v13 :: v_dual_mul_f32 v23, v6, v6
	v_fmac_f32_e32 v23, v7, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v23, v22, v22
	v_cmpx_neq_f32_e32 0, v23
	s_cbranch_execz .LBB0_40
; %bb.39:                               ;   in Loop: Header=BB0_37 Depth=1
	v_mul_f32_e32 v24, 0x4f800000, v23
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v23
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v23, v23, v24, vcc_lo
	v_sqrt_f32_e32 v24, v23
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v25, -1, v24
	v_add_nc_u32_e32 v26, 1, v24
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v27, -v25, v24, v23
	v_fma_f32 v28, -v26, v24, v23
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_f32_e64 s2, 0, v27
	v_cndmask_b32_e64 v24, v24, v25, s2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e64 s2, 0, v28
	v_cndmask_b32_e64 v24, v24, v26, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v25, 0x37800000, v24
	v_cndmask_b32_e32 v24, v24, v25, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v23, 0x260
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v23, v24, v23, vcc_lo
	v_div_scale_f32 v24, null, v23, v23, v7
	v_div_scale_f32 v25, null, v23, v23, v6
	v_div_scale_f32 v26, null, v23, v23, v22
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_rcp_f32_e32 v27, v24
	v_rcp_f32_e32 v28, v25
	v_div_scale_f32 v30, vcc_lo, v7, v23, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(TRANS32_DEP_3)
	v_rcp_f32_e32 v29, v26
	v_div_scale_f32 v31, s2, v6, v23, v6
	v_div_scale_f32 v35, s3, v22, v23, v22
	v_fma_f32 v32, -v24, v27, 1.0
	s_waitcnt_depctr 0xfff
	v_fma_f32 v33, -v25, v28, 1.0
	v_fma_f32 v34, -v26, v29, 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_dual_fmac_f32 v27, v32, v27 :: v_dual_fmac_f32 v28, v33, v28
	v_fmac_f32_e32 v29, v34, v29
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v32, v30, v27
	v_mul_f32_e32 v34, v35, v29
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fma_f32 v36, -v24, v32, v30
	v_mul_f32_e32 v33, v31, v28
	v_fma_f32 v38, -v26, v34, v35
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v32, v36, v27
	v_fma_f32 v37, -v25, v33, v31
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v34, v38, v29
	v_fma_f32 v24, -v24, v32, v30
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v33, v37, v28
	v_fma_f32 v26, -v26, v34, v35
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v24, v24, v27, v32
	v_fma_f32 v25, -v25, v33, v31
	s_mov_b32 vcc_lo, s2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f32 v7, v24, v23, v7
	v_div_fmas_f32 v25, v25, v28, v33
	s_mov_b32 vcc_lo, s3
	v_div_fmas_f32 v26, v26, v29, v34
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f32 v6, v25, v23, v6
	v_div_fixup_f32 v22, v26, v23, v22
.LBB0_40:                               ; %.lr.ph.i19.i
                                        ;   in Loop: Header=BB0_37 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	s_mov_b32 s19, 0
	s_mov_b64 s[10:11], s[4:5]
	s_mov_b64 s[14:15], s[8:9]
	s_mov_b32 s20, 0
.LBB0_41:                               ;   Parent Loop BB0_37 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_load_b32 s2, s[10:11], 0x0
	s_waitcnt lgkmcnt(0)
	v_cmp_nlt_f32_e64 s2, s2, 0.5
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB0_46
; %bb.42:                               ;   in Loop: Header=BB0_41 Depth=2
	s_add_u32 s2, s14, -8
	s_addc_u32 s3, s15, -1
	s_load_b32 s2, s[2:3], 0x0
	s_waitcnt lgkmcnt(0)
	v_cmp_nlt_f32_e64 s2, s2, 0.5
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB0_44
; %bb.43:                               ;   in Loop: Header=BB0_41 Depth=2
	s_add_u32 s2, s14, -4
	s_addc_u32 s3, s15, -1
	s_load_b128 s[24:27], s[2:3], 0x0
	s_waitcnt lgkmcnt(0)
	v_sub_f32_e32 v23, s24, v1
	v_sub_f32_e32 v21, s25, v8
	v_sub_f32_e32 v25, s26, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v24, v6, v21
	v_fmac_f32_e32 v24, v7, v23
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v24, v22, v25
	v_mul_f32_e32 v21, v21, v21
	v_fmac_f32_e32 v21, v23, v23
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v21, v25, v25
	v_fma_f32 v21, -v24, v24, v21
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v23, s27, s27, -v21
	v_mul_f32_e32 v25, 0x4f800000, v23
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v23
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v23, v23, v25, vcc_lo
	v_sqrt_f32_e32 v25, v23
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v26, -1, v25
	v_add_nc_u32_e32 v27, 1, v25
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v28, -v26, v25, v23
	v_fma_f32 v29, -v27, v25, v23
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_f32_e64 s2, 0, v28
	v_cndmask_b32_e64 v25, v25, v26, s2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e64 s2, 0, v29
	v_cndmask_b32_e64 v25, v25, v27, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v26, 0x37800000, v25
	v_cndmask_b32_e32 v25, v25, v26, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v23, 0x260
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_cndmask_b32_e32 v23, v25, v23, vcc_lo
	v_mul_f32_e64 v25, s27, s27
	v_cmp_gt_f32_e32 vcc_lo, 0, v24
	v_sub_f32_e32 v26, v24, v23
	v_add_f32_e32 v23, v24, v23
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cmp_gt_f32_e64 s2, v21, v25
	v_cmp_gt_f32_e64 s3, 0, v26
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s2, s2, vcc_lo
	s_and_b32 s2, s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cndmask_b32_e64 v21, v26, v23, s3
	s_branch .LBB0_45
.LBB0_44:                               ;   in Loop: Header=BB0_41 Depth=2
	s_mov_b32 s2, 0
                                        ; implicit-def: $vgpr21
.LBB0_45:                               ; %_Z16normalize_vectorPfS_S_.exit.i.i.i
                                        ;   in Loop: Header=BB0_41 Depth=2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_ngt_f32_e32 vcc_lo, 0x7f7fffff, v21
	s_or_b32 s2, s2, vcc_lo
	v_cndmask_b32_e64 v21, 0, -1, s2
.LBB0_46:                               ; %_Z12intersectGPUPfS_S_Pii.exit.i.i
                                        ;   in Loop: Header=BB0_41 Depth=2
	v_dual_mov_b32 v24, 0 :: v_dual_mov_b32 v23, s20
	v_dual_mov_b32 v26, 0 :: v_dual_mov_b32 v25, 0
	s_mov_b32 s3, -1
	s_mov_b32 s2, exec_lo
	v_cmpx_lt_i32_e32 -1, v21
; %bb.47:                               ;   in Loop: Header=BB0_41 Depth=2
	s_add_i32 s20, s20, 1
	s_add_u32 s14, s14, 4
	s_addc_u32 s15, s15, 0
	s_add_u32 s10, s10, 64
	s_addc_u32 s11, s11, 0
	s_cmp_eq_u32 s13, s20
	v_dual_mov_b32 v23, s13 :: v_dual_mov_b32 v24, v4
	v_dual_mov_b32 v26, v19 :: v_dual_mov_b32 v25, v20
	s_cselect_b32 s3, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_not1_b32 s3, s3, exec_lo
; %bb.48:                               ; %Flow81
                                        ;   in Loop: Header=BB0_41 Depth=2
	s_or_b32 exec_lo, exec_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, exec_lo, s3
	s_or_b32 s19, s2, s19
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s19
	s_cbranch_execnz .LBB0_41
; %bb.49:                               ; %_Z12intersectGPUPfS_S_Pii.exit._crit_edge.i.i
                                        ;   in Loop: Header=BB0_37 Depth=1
	s_or_b32 exec_lo, exec_lo, s19
	global_load_b96 v[27:29], v[2:3], off offset:20
	v_lshlrev_b32_e32 v4, 4, v23
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[19:20], 2, v[4:5]
	v_mul_f32_e32 v4, v11, v6
	v_add_co_u32 v19, vcc_lo, s6, v19
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v20, vcc_lo, s7, v20, vcc_lo
	global_load_b96 v[30:32], v[19:20], off offset:32
	s_waitcnt vmcnt(1)
	v_dual_mul_f32 v19, v25, v29 :: v_dual_fmac_f32 v4, v12, v7
	v_dual_mul_f32 v7, v26, v28 :: v_dual_mul_f32 v6, v24, v27
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_fmac_f32 v4, v10, v22 :: v_dual_mul_f32 v7, v7, v31
	v_cmp_ngt_f32_e32 vcc_lo, 0, v4
	v_dual_mul_f32 v22, v19, v32 :: v_dual_mov_b32 v19, v26
	v_cndmask_b32_e32 v20, 0, v4, vcc_lo
	v_mul_f32_e32 v6, v6, v30
	v_mov_b32_e32 v4, v24
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v17, v20, v7
	v_fmac_f32_e32 v18, v20, v6
	v_fmac_f32_e32 v16, v20, v22
	v_mov_b32_e32 v20, v25
.LBB0_50:                               ; %Flow82
                                        ;   in Loop: Header=BB0_37 Depth=1
	s_or_b32 exec_lo, exec_lo, s17
	v_add_nc_u32_e32 v23, 1, v23
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_le_i32_e32 vcc_lo, s13, v23
	s_or_b32 s16, vcc_lo, s16
	s_and_not1_b32 exec_lo, exec_lo, s16
	s_cbranch_execnz .LBB0_37
; %bb.51:                               ; %Flow83
	s_or_b32 exec_lo, exec_lo, s16
.LBB0_52:                               ; %_Z16trace_diffuseGPUiPfS_S_iS_.exit.i
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_or_b32 exec_lo, exec_lo, s18
	v_mov_b32_e32 v1, 0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	global_load_b96 v[0:2], v[0:1], off offset:32
	s_waitcnt vmcnt(0)
	v_dual_add_f32 v0, v18, v0 :: v_dual_add_f32 v1, v17, v1
	v_add_f32_e32 v2, v16, v2
.LBB0_53:                               ; %Flow87
	s_or_b32 exec_lo, exec_lo, s12
	s_load_b64 s[0:1], s[0:1], 0x18
	v_mov_b32_e32 v3, 0
	s_waitcnt lgkmcnt(0)
	global_store_b96 v3, v[0:2], s[0:1]
.LBB0_54:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8traceGPUPfS_iiS_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 41
		.amdhsa_next_free_sgpr 28
		.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	_Z8traceGPUPfS_iiS_i, .Lfunc_end0-_Z8traceGPUPfS_iiS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 4084
; NumSgprs: 30
; NumVgprs: 41
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 3
; VGPRBlocks: 5
; NumSGPRsForWavesPerEU: 30
; NumVGPRsForWavesPerEU: 41
; 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
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8traceGPUPfS_iiS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     30
    .sgpr_spill_count: 0
    .symbol:         _Z8traceGPUPfS_iiS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     41
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
