#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

#define CUDA 0
#define OPENMP 1
#define SPHERES 20

#define rnd( x ) (x * rand() / RAND_MAX)
#define INF 2e10f
#define DIM 2048

struct Sphere {
    float   r,b,g;
    float   radius;
    float   x,y,z;
};

__device__ float hit( float x, float y, float z, float ox, float oy, float *n,  float radius ) {
    float dx = ox - x;
    float dy = oy - y;
    if (dx*dx + dy*dy < radius*radius) {
        float dz = sqrtf( radius*radius - dx*dx - dy*dy );
        *n = dz / sqrtf( radius * radius );
        return dz + z;
    }
    return -INF;
}

__global__ void kernel(struct Sphere* s, unsigned char* ptr)
{
    int x = blockIdx.x;
    int y = blockIdx.y;
    int offset = x + y*DIM;
    float ox = (x - DIM/2);
    float oy = (y - DIM/2);

    float r=0, g=0, b=0;
    float   maxz = -INF;
    for(int i=0; i<SPHERES; i++) {
        float   n;
        float   t = hit( s[i].x, s[i].y, s[i].z, ox, oy, &n, s[i].radius );
        if (t > maxz) {
            float fscale = n;
            r = s[i].r * fscale;
            g = s[i].g * fscale;
            b = s[i].b * fscale;
            maxz = t;
        }
    }

    ptr[offset*4 + 0] = (int)(r * 255);
    ptr[offset*4 + 1] = (int)(g * 255);
    ptr[offset*4 + 2] = (int)(b * 255);
    ptr[offset*4 + 3] = 255;
}

void ppm_write(unsigned char* bitmap, int xdim,int ydim, FILE* fp)
{
    int i,x,y;
    fprintf(fp,"P3\n");
    fprintf(fp,"%d %d\n",xdim, ydim);
    fprintf(fp,"255\n");
    for (y=0;y<ydim;y++) {
        for (x=0;x<xdim;x++) {
            i=x+y*xdim;
            fprintf(fp,"%d %d %d ",bitmap[4*i],bitmap[4*i+1],bitmap[4*i+2]);
        }
        fprintf(fp,"\n");
    }
}

int main(int argc, char* argv[])
{
    double exe_time;
    clock_t start_time, end_time;
    struct Sphere *temp_s;
    unsigned char* bitmap;
    struct Sphere *d_temp_s;
    unsigned char* d_bitmap;
    dim3 blocks(DIM,DIM,1);

    // Error detection code
    if (argc!=2) {
        printf("> a.out [filename.ppm]\n");
        printf("for example, '> a.out result.ppm' means executing CUDA\n");
        exit(0);
    }

    // Start Timer
    srand(time(NULL));
    start_time = clock();

    // Allocate the memory on host
    bitmap = (unsigned char*)malloc(sizeof(unsigned char)*DIM*DIM*4);
    temp_s = (struct Sphere*)malloc(sizeof(struct Sphere) * SPHERES);
    // Allocate the memory on device
    cudaMalloc( (void**)&d_temp_s, sizeof(struct Sphere) * SPHERES );
    cudaMalloc( (void**)&d_bitmap, sizeof(unsigned char)*DIM*DIM*4 );

    // Generate the spheres
    for (int i=0; i<SPHERES; i++) {
        temp_s[i].r = rnd( 1.0f );
        temp_s[i].g = rnd( 1.0f );
        temp_s[i].b = rnd( 1.0f );
        temp_s[i].x = rnd( 2000.0f ) - 1000;
        temp_s[i].y = rnd( 2000.0f ) - 1000;
        temp_s[i].z = rnd( 2000.0f ) - 1000;
        temp_s[i].radius = rnd( 200.0f ) + 40;
    }

    //  Move data to device
    cudaMemcpy ( d_temp_s, temp_s, sizeof(struct Sphere) * SPHERES, cudaMemcpyHostToDevice );

    // Calculate the ray
    kernel<<<blocks, 1>>>(d_temp_s, d_bitmap);
    cudaDeviceSynchronize();
    cudaMemcpy ( bitmap, d_bitmap, sizeof(unsigned char)*DIM*DIM*4, cudaMemcpyDeviceToHost );

    // open the file
    FILE* fp = fopen(argv[1],"w");
    ppm_write(bitmap,DIM,DIM,fp);   // Write the image

    // Stop Timer
    end_time = clock();
    exe_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC;

    // Print the result
    printf("CUDA ray tracing: %f sec\n", exe_time);
    printf("[%s] was generated\n", argv[1]);

    // Close the file and free the memory
    fclose(fp);
    free(bitmap);
    free(temp_s);
    cudaFree(d_bitmap);
    cudaFree(d_temp_s);
    return 0;
}
	.file	"tmpxft_002f21ec_00000000-6_cuda_ray.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z3hitfffffPff
	.type	_Z3hitfffffPff, @function
_Z3hitfffffPff:
.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	_Z3hitfffffPff, .-_Z3hitfffffPff
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"P3\n"
.LC1:
	.string	"%d %d\n"
.LC2:
	.string	"255\n"
.LC3:
	.string	"%d %d %d "
.LC4:
	.string	"\n"
	.text
	.globl	_Z9ppm_writePhiiP8_IO_FILE
	.type	_Z9ppm_writePhiiP8_IO_FILE, @function
_Z9ppm_writePhiiP8_IO_FILE:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	movq	%rcx, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edx, %ebp
	leaq	.LC0(%rip), %rdx
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%esi, %ebx
	movl	$2, %esi
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%rcx, (%rsp)
	call	__fprintf_chk@PLT
	movq	(%rsp), %rdi
	movl	%ebp, %r8d
	movl	%ebx, %ecx
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rdx
	call	__fprintf_chk@PLT
.L5:
	cmpl	%ebp, %r14d
	jge	.L4
	leal	0(,%r13,4), %r10d
	xorl	%r15d, %r15d
	movslq	%r10d, %r10
	addq	%r12, %r10
.L8:
	cmpl	%ebx, %r15d
	jge	.L11
	movzbl	(%r10), %ecx
	movzbl	2(%r10), %r9d
	movl	$2, %esi
	xorl	%eax, %eax
	movzbl	1(%r10), %r8d
	movq	(%rsp), %rdi
	movq	%r10, 8(%rsp)
	incl	%r15d
	leaq	.LC3(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	8(%rsp), %r10
	addq	$4, %r10
	jmp	.L8
.L11:
	movq	(%rsp), %rdi
	leaq	.LC4(%rip), %rdx
	xorl	%eax, %eax
	incl	%r14d
	movl	$2, %esi
	addl	%ebx, %r13d
	call	__fprintf_chk@PLT
	jmp	.L5
.L4:
	addq	$24, %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	_Z9ppm_writePhiiP8_IO_FILE, .-_Z9ppm_writePhiiP8_IO_FILE
	.globl	_Z33__device_stub__Z6kernelP6SpherePhP6SpherePh
	.type	_Z33__device_stub__Z6kernelP6SpherePhP6SpherePh, @function
_Z33__device_stub__Z6kernelP6SpherePhP6SpherePh:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L12
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z6kernelP6SpherePh(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L12:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z33__device_stub__Z6kernelP6SpherePhP6SpherePh, .-_Z33__device_stub__Z6kernelP6SpherePhP6SpherePh
	.globl	_Z6kernelP6SpherePh
	.type	_Z6kernelP6SpherePh, @function
_Z6kernelP6SpherePh:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z6kernelP6SpherePhP6SpherePh
	.cfi_endproc
.LFE2055:
	.size	_Z6kernelP6SpherePh, .-_Z6kernelP6SpherePh
	.section	.rodata.str1.1
.LC5:
	.string	"> a.out [filename.ppm]\n"
.LC6:
	.string	"for example, '> a.out result.ppm' means executing CUDA\n"
.LC12:
	.string	"w"
.LC14:
	.string	"CUDA ray tracing: %f sec\n"
.LC15:
	.string	"[%s] was generated\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.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
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	movabsq	$8796093024256, %rax
	movl	$1, 24(%rsp)
	movq	%rax, 16(%rsp)
	cmpl	$2, %edi
	je	.L18
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$2, %edi
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	exit@PLT
.L18:
	xorl	%edi, %edi
	movq	%rsi, %r13
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	call	clock@PLT
	movl	$16777216, %edi
	movq	%rax, %r14
	call	malloc@PLT
	movl	$560, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movq	%rsp, %rdi
	movl	$560, %esi
	movq	%rax, %rbp
	call	cudaMalloc@PLT
	leaq	8(%rsp), %rdi
	movq	%rbp, %rbx
	movl	$16777216, %esi
	call	cudaMalloc@PLT
	leaq	560(%rbp), %r15
.L19:
	call	rand@PLT
	addq	$28, %rbx
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC7(%rip), %xmm0
	movss	%xmm0, -28(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC7(%rip), %xmm0
	movss	%xmm0, -20(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC7(%rip), %xmm0
	movss	%xmm0, -24(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC8(%rip), %xmm0
	mulss	.LC7(%rip), %xmm0
	subss	.LC9(%rip), %xmm0
	movss	%xmm0, -12(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC8(%rip), %xmm0
	mulss	.LC7(%rip), %xmm0
	subss	.LC9(%rip), %xmm0
	movss	%xmm0, -8(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC8(%rip), %xmm0
	mulss	.LC7(%rip), %xmm0
	subss	.LC9(%rip), %xmm0
	movss	%xmm0, -4(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC10(%rip), %xmm0
	mulss	.LC7(%rip), %xmm0
	addss	.LC11(%rip), %xmm0
	movss	%xmm0, -16(%rbx)
	cmpq	%r15, %rbx
	jne	.L19
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movl	$560, %edx
	movq	%rbp, %rsi
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	24(%rsp), %esi
	movl	$1, %ecx
	movabsq	$4294967297, %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L20
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	call	_Z33__device_stub__Z6kernelP6SpherePhP6SpherePh
.L20:
	call	cudaDeviceSynchronize@PLT
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	movl	$16777216, %edx
	call	cudaMemcpy@PLT
	movq	8(%r13), %rdi
	leaq	.LC12(%rip), %rsi
	call	fopen@PLT
	movl	$2048, %edx
	movl	$2048, %esi
	movq	%r12, %rdi
	movq	%rax, %rcx
	movq	%rax, %rbx
	call	_Z9ppm_writePhiiP8_IO_FILE
	call	clock@PLT
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	subq	%r14, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC13(%rip), %xmm0
	call	__printf_chk@PLT
	movq	8(%r13), %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC15(%rip), %rsi
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC16:
	.string	"_Z6kernelP6SpherePh"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.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	.LC16(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6kernelP6SpherePh(%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
.LFE2057:
	.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
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC7:
	.long	805306368
	.align 4
.LC8:
	.long	1157234688
	.align 4
.LC9:
	.long	1148846080
	.align 4
.LC10:
	.long	1128792064
	.align 4
.LC11:
	.long	1109393408
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC13:
	.long	0
	.long	1093567616
	.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 <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

#define CUDA 0
#define OPENMP 1
#define SPHERES 20

#define rnd( x ) (x * rand() / RAND_MAX)
#define INF 2e10f
#define DIM 2048

struct Sphere {
    float   r,b,g;
    float   radius;
    float   x,y,z;
};

__device__ float hit( float x, float y, float z, float ox, float oy, float *n,  float radius ) {
    float dx = ox - x;
    float dy = oy - y;
    if (dx*dx + dy*dy < radius*radius) {
        float dz = sqrtf( radius*radius - dx*dx - dy*dy );
        *n = dz / sqrtf( radius * radius );
        return dz + z;
    }
    return -INF;
}

__global__ void kernel(struct Sphere* s, unsigned char* ptr)
{
    int x = blockIdx.x;
    int y = blockIdx.y;
    int offset = x + y*DIM;
    float ox = (x - DIM/2);
    float oy = (y - DIM/2);

    float r=0, g=0, b=0;
    float   maxz = -INF;
    for(int i=0; i<SPHERES; i++) {
        float   n;
        float   t = hit( s[i].x, s[i].y, s[i].z, ox, oy, &n, s[i].radius );
        if (t > maxz) {
            float fscale = n;
            r = s[i].r * fscale;
            g = s[i].g * fscale;
            b = s[i].b * fscale;
            maxz = t;
        }
    }

    ptr[offset*4 + 0] = (int)(r * 255);
    ptr[offset*4 + 1] = (int)(g * 255);
    ptr[offset*4 + 2] = (int)(b * 255);
    ptr[offset*4 + 3] = 255;
}

void ppm_write(unsigned char* bitmap, int xdim,int ydim, FILE* fp)
{
    int i,x,y;
    fprintf(fp,"P3\n");
    fprintf(fp,"%d %d\n",xdim, ydim);
    fprintf(fp,"255\n");
    for (y=0;y<ydim;y++) {
        for (x=0;x<xdim;x++) {
            i=x+y*xdim;
            fprintf(fp,"%d %d %d ",bitmap[4*i],bitmap[4*i+1],bitmap[4*i+2]);
        }
        fprintf(fp,"\n");
    }
}

int main(int argc, char* argv[])
{
    double exe_time;
    clock_t start_time, end_time;
    struct Sphere *temp_s;
    unsigned char* bitmap;
    struct Sphere *d_temp_s;
    unsigned char* d_bitmap;
    dim3 blocks(DIM,DIM,1);

    // Error detection code
    if (argc!=2) {
        printf("> a.out [filename.ppm]\n");
        printf("for example, '> a.out result.ppm' means executing CUDA\n");
        exit(0);
    }

    // Start Timer
    srand(time(NULL));
    start_time = clock();

    // Allocate the memory on host
    bitmap = (unsigned char*)malloc(sizeof(unsigned char)*DIM*DIM*4);
    temp_s = (struct Sphere*)malloc(sizeof(struct Sphere) * SPHERES);
    // Allocate the memory on device
    hipMalloc( (void**)&d_temp_s, sizeof(struct Sphere) * SPHERES );
    hipMalloc( (void**)&d_bitmap, sizeof(unsigned char)*DIM*DIM*4 );

    // Generate the spheres
    for (int i=0; i<SPHERES; i++) {
        temp_s[i].r = rnd( 1.0f );
        temp_s[i].g = rnd( 1.0f );
        temp_s[i].b = rnd( 1.0f );
        temp_s[i].x = rnd( 2000.0f ) - 1000;
        temp_s[i].y = rnd( 2000.0f ) - 1000;
        temp_s[i].z = rnd( 2000.0f ) - 1000;
        temp_s[i].radius = rnd( 200.0f ) + 40;
    }

    //  Move data to device
    hipMemcpy ( d_temp_s, temp_s, sizeof(struct Sphere) * SPHERES, hipMemcpyHostToDevice );

    // Calculate the ray
    kernel<<<blocks, 1>>>(d_temp_s, d_bitmap);
    hipDeviceSynchronize();
    hipMemcpy ( bitmap, d_bitmap, sizeof(unsigned char)*DIM*DIM*4, hipMemcpyDeviceToHost );

    // open the file
    FILE* fp = fopen(argv[1],"w");
    ppm_write(bitmap,DIM,DIM,fp);   // Write the image

    // Stop Timer
    end_time = clock();
    exe_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC;

    // Print the result
    printf("CUDA ray tracing: %f sec\n", exe_time);
    printf("[%s] was generated\n", argv[1]);

    // Close the file and free the memory
    fclose(fp);
    free(bitmap);
    free(temp_s);
    hipFree(d_bitmap);
    hipFree(d_temp_s);
    return 0;
}
	.text
	.file	"cuda_ray.hip"
	.globl	_Z21__device_stub__kernelP6SpherePh # -- Begin function _Z21__device_stub__kernelP6SpherePh
	.type	_Z21__device_stub__kernelP6SpherePh,@function
_Z21__device_stub__kernelP6SpherePh:    # @_Z21__device_stub__kernelP6SpherePh
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z6kernelP6SpherePh, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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	_Z21__device_stub__kernelP6SpherePh, .Lfunc_end0-_Z21__device_stub__kernelP6SpherePh
	.cfi_endproc
                                        # -- End function
	.globl	_Z9ppm_writePhiiP8_IO_FILE      # -- Begin function _Z9ppm_writePhiiP8_IO_FILE
	.type	_Z9ppm_writePhiiP8_IO_FILE,@function
_Z9ppm_writePhiiP8_IO_FILE:             # @_Z9ppm_writePhiiP8_IO_FILE
	.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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, %rbx
	movl	%edx, %ebp
	movl	%esi, %r14d
	movq	%rdi, %r15
	movl	$.L.str, %edi
	movl	$3, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$.L.str.1, %esi
	movq	%rbx, %rdi
	movq	%r14, 16(%rsp)                  # 8-byte Spill
	movl	%r14d, %edx
	movl	%ebp, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movl	$.L.str.2, %edi
	movl	$4, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fwrite@PLT
	testl	%ebp, %ebp
	jle	.LBB1_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebp, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movq	16(%rsp), %rax                  # 8-byte Reload
	movl	%eax, %ecx
	movq	%rcx, 24(%rsp)                  # 8-byte Spill
	leal	(,%rax,4), %eax
	movl	%eax, 12(%rsp)                  # 4-byte Spill
	xorl	%r13d, %r13d
	xorl	%r14d, %r14d
.LBB1_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	cmpl	$0, 16(%rsp)                    # 4-byte Folded Reload
	jle	.LBB1_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movq	24(%rsp), %r12                  # 8-byte Reload
	movl	%r13d, %ebp
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%ebp, %eax
	movzbl	(%r15,%rax), %edx
	leal	1(%rbp), %eax
	movzbl	(%r15,%rax), %ecx
	leal	2(%rbp), %eax
	movzbl	(%r15,%rax), %r8d
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	addl	$4, %ebp
	decq	%r12
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	$10, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	incq	%r14
	addl	12(%rsp), %r13d                 # 4-byte Folded Reload
	cmpq	32(%rsp), %r14                  # 8-byte Folded Reload
	jne	.LBB1_2
.LBB1_6:                                # %._crit_edge25
	addq	$40, %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	_Z9ppm_writePhiiP8_IO_FILE, .Lfunc_end1-_Z9ppm_writePhiiP8_IO_FILE
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI2_1:
	.long	0x44fa0000                      # float 2000
.LCPI2_2:
	.long	0xc47a0000                      # float -1000
.LCPI2_3:
	.long	0x43480000                      # float 200
.LCPI2_4:
	.long	0x42200000                      # float 40
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI2_5:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.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	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	cmpl	$2, %edi
	jne	.LBB2_6
# %bb.1:
	movq	%rsi, %rbx
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	callq	clock
	movq	%rax, %r12
	movl	$16777216, %edi                 # imm = 0x1000000
	callq	malloc
	movq	%rax, %r14
	movl	$560, %edi                      # imm = 0x230
	callq	malloc
	movq	%rax, %r15
	leaq	8(%rsp), %rdi
	movl	$560, %esi                      # imm = 0x230
	callq	hipMalloc
	movq	%rsp, %rdi
	movl	$16777216, %esi                 # imm = 0x1000000
	callq	hipMalloc
	movl	$24, %r13d
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movss	%xmm0, -24(%r15,%r13)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, -16(%r15,%r13)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, -20(%r15,%r13)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	movss	.LCPI2_2(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	addss	%xmm1, %xmm0
	movss	%xmm0, -8(%r15,%r13)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_1(%rip), %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	addss	.LCPI2_2(%rip), %xmm0
	movss	%xmm0, -4(%r15,%r13)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_1(%rip), %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	addss	.LCPI2_2(%rip), %xmm0
	movss	%xmm0, (%r15,%r13)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_3(%rip), %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	addss	.LCPI2_4(%rip), %xmm0
	movss	%xmm0, -12(%r15,%r13)
	addq	$28, %r13
	cmpq	$584, %r13                      # imm = 0x248
	jne	.LBB2_2
# %bb.3:
	movq	8(%rsp), %rdi
	movl	$560, %edx                      # imm = 0x230
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$8796093024256, %rdi            # imm = 0x80000000800
	movabsq	$4294967297, %rdx               # imm = 0x100000001
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_5
# %bb.4:
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	callq	_Z21__device_stub__kernelP6SpherePh
.LBB2_5:
	callq	hipDeviceSynchronize
	movq	(%rsp), %rsi
	movl	$16777216, %edx                 # imm = 0x1000000
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rbx), %rdi
	movl	$.L.str.7, %esi
	callq	fopen
	movq	%rax, %r13
	movq	%r14, %rdi
	movl	$2048, %esi                     # imm = 0x800
	movl	$2048, %edx                     # imm = 0x800
	movq	%rax, %rcx
	callq	_Z9ppm_writePhiiP8_IO_FILE
	callq	clock
	subq	%r12, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI2_5(%rip), %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	movq	8(%rbx), %rsi
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movq	%r13, %rdi
	callq	fclose
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	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
.LBB2_6:
	.cfi_def_cfa_offset 64
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	xorl	%edi, %edi
	callq	exit
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6kernelP6SpherePh, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z6kernelP6SpherePh,@object     # @_Z6kernelP6SpherePh
	.section	.rodata,"a",@progbits
	.globl	_Z6kernelP6SpherePh
	.p2align	3, 0x0
_Z6kernelP6SpherePh:
	.quad	_Z21__device_stub__kernelP6SpherePh
	.size	_Z6kernelP6SpherePh, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"P3\n"
	.size	.L.str, 4

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"%d %d\n"
	.size	.L.str.1, 7

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"255\n"
	.size	.L.str.2, 5

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%d %d %d "
	.size	.L.str.3, 10

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"w"
	.size	.L.str.7, 2

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"CUDA ray tracing: %f sec\n"
	.size	.L.str.8, 26

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"[%s] was generated\n"
	.size	.L.str.9, 20

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6kernelP6SpherePh"
	.size	.L__unnamed_1, 20

	.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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"> a.out [filename.ppm]"
	.size	.Lstr, 23

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"for example, '> a.out result.ppm' means executing CUDA"
	.size	.Lstr.1, 55

	.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 _Z21__device_stub__kernelP6SpherePh
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6kernelP6SpherePh
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6kernelP6SpherePh     ; -- Begin function _Z6kernelP6SpherePh
	.globl	_Z6kernelP6SpherePh
	.p2align	8
	.type	_Z6kernelP6SpherePh,@function
_Z6kernelP6SpherePh:                    ; @_Z6kernelP6SpherePh
; %bb.0:
	s_load_b128 s[4:7], s[0:1], 0x0
	s_add_i32 s0, s14, 0xfffffc00
	s_add_i32 s1, s15, 0xfffffc00
	v_cvt_f32_i32_e32 v3, s0
	v_cvt_f32_i32_e32 v4, s1
	v_dual_mov_b32 v0, 0 :: v_dual_mov_b32 v5, 0xd09502f9
	v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v1, 0
	s_mov_b64 s[2:3], 0
                                        ; implicit-def: $vgpr6
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	s_waitcnt lgkmcnt(0)
	s_add_u32 s8, s4, s2
	s_addc_u32 s9, s5, s3
	s_clause 0x1
	s_load_b32 s10, s[8:9], 0x14
	s_load_b64 s[0:1], s[8:9], 0xc
	s_waitcnt lgkmcnt(0)
	v_dual_subrev_f32 v7, s10, v4 :: v_dual_subrev_f32 v10, s1, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v9, v7, v7
	v_mul_f32_e64 v7, s0, s0
	v_fma_f32 v8, v10, v10, v9
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_nlt_f32_e32 vcc_lo, v8, v7
	v_mov_b32_e32 v8, 0xd09502f9
	s_cbranch_vccnz .LBB0_3
; %bb.2:                                ;   in Loop: Header=BB0_1 Depth=1
	v_mul_f32_e32 v8, 0x4f800000, v7
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v7
	v_mul_f32_e32 v6, v10, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_f32_e32 v6, v7, v6
	v_dual_cndmask_b32 v7, v7, v8 :: v_dual_sub_f32 v6, v6, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sqrt_f32_e32 v8, v7
	v_mul_f32_e32 v9, 0x4f800000, v6
	v_cmp_gt_f32_e64 s0, 0xf800000, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v6, v6, v9, s0
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v10, -1, v8
	v_add_nc_u32_e32 v12, 1, v8
	v_sqrt_f32_e32 v9, v6
	v_fma_f32 v13, -v10, v8, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v16, -v12, v8, v7
	v_cmp_ge_f32_e64 s1, 0, v13
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v11, -1, v9
	v_add_nc_u32_e32 v14, 1, v9
	v_cndmask_b32_e64 v8, v8, v10, s1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fma_f32 v15, -v11, v9, v6
	v_fma_f32 v10, -v14, v9, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_f32_e64 s1, 0, v15
	v_cndmask_b32_e64 v9, v9, v11, s1
	v_cmp_lt_f32_e64 s1, 0, v16
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v8, v8, v12, s1
	v_cmp_lt_f32_e64 s1, 0, v10
	v_mul_f32_e32 v10, 0x37800000, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v9, v9, v14, s1
	v_dual_cndmask_b32 v8, v8, v10 :: v_dual_mul_f32 v11, 0x37800000, v9
	v_cmp_class_f32_e64 vcc_lo, v7, 0x260
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v9, v9, v11, s0
	v_cndmask_b32_e32 v7, v8, v7, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v6, 0x260
	s_load_b32 s0, s[8:9], 0x18
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v8, v9, v6, vcc_lo
	v_div_scale_f32 v6, null, v7, v7, v8
	v_div_scale_f32 v11, vcc_lo, v8, v7, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v9, v6
	s_waitcnt_depctr 0xfff
	v_fma_f32 v10, -v6, v9, 1.0
	v_fmac_f32_e32 v9, v10, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v10, v11, v9
	v_fma_f32 v12, -v6, v10, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v10, v12, v9
	v_fma_f32 v6, -v6, v10, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f32 v6, v6, v9, v10
	v_div_fixup_f32 v6, v6, v7, v8
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v8, s0, v8
.LBB0_3:                                ; %_Z3hitfffffPff.exit
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ngt_f32_e32 vcc_lo, v8, v5
	s_cbranch_vccnz .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_1 Depth=1
	s_clause 0x1
	s_load_b64 s[0:1], s[8:9], 0x0
	s_load_b32 s8, s[8:9], 0x8
	s_waitcnt lgkmcnt(0)
	v_dual_mov_b32 v5, v8 :: v_dual_mul_f32 v0, s0, v6
	v_mul_f32_e32 v2, s8, v6
	v_mul_f32_e32 v1, s1, v6
.LBB0_5:                                ;   in Loop: Header=BB0_1 Depth=1
	s_add_u32 s2, s2, 28
	s_addc_u32 s3, s3, 0
	s_cmpk_eq_i32 s2, 0x230
	s_cbranch_scc0 .LBB0_1
; %bb.6:
	v_dual_mul_f32 v2, 0x437f0000, v2 :: v_dual_mul_f32 v1, 0x437f0000, v1
	s_lshl_b32 s0, s15, 13
	s_lshl_b32 s1, s14, 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_add_i32 s0, s0, s1
	v_cvt_i32_f32_e32 v1, v1
	v_cvt_i32_f32_e32 v2, v2
	s_ashr_i32 s1, s0, 31
	s_add_u32 s0, s6, s0
	s_addc_u32 s1, s7, s1
	v_or_b32_e32 v1, 0xffffff00, v1
	v_mul_f32_e32 v0, 0x437f0000, v0
	v_lshlrev_b16 v2, 8, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b32_e32 v1, 16, v1
	v_cvt_i32_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v0, 0xff, v0
	v_or_b32_e32 v0, v0, v2
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v0, 0xffff, v0
	v_or_b32_e32 v0, v0, v1
	global_store_b32 v2, v0, s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6kernelP6SpherePh
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 16
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 17
		.amdhsa_next_free_sgpr 16
		.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	_Z6kernelP6SpherePh, .Lfunc_end0-_Z6kernelP6SpherePh
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 748
; NumSgprs: 18
; NumVgprs: 17
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 17
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; 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
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 16
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6kernelP6SpherePh
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6kernelP6SpherePh.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     17
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
