#include <stdio.h>
#include <math.h>
#include <stdint.h>		//uint32_tは符号なしintで4バイトに指定
#include <stdlib.h> 	//記憶域管理を使うため
#include <cuda.h>


/*記号定数として横幅と縦幅を定義*/
#define width 1024
#define heigth 1024


/*bmpの構造体*/
#pragma pack(push,1)
typedef struct tagBITMAPFILEHEADER{	//構造体BITMAPFILEHEADERはファイルの先頭に来るもので，サイズは14 byte
	unsigned short	bfType;			//bfTypeは，bmp形式であることを示すため，"BM"が入る
	uint32_t 		bfSize;			//bfsizeは，ファイル全体のバイト数
	unsigned short	bfReserved1;	//bfReserved1と2は予約領域で，0になる
	unsigned short	bfReserved2;
	uint32_t		bf0ffBits;		//bf0ffBitsは先頭から画素データまでのバイト数
}BITMAPFILEHEADER;

#pragma pack(pop)
typedef struct tagBITMAPINFOHEADER{	//BITMAPINFOHEADERはbmpファイルの画像の情報の構造体で，サイズは40 byte
	uint32_t		biSize;				//画像のサイズ
	uint32_t		biWidth;			//横の画素数
	uint32_t		biHeight;			//縦の画素数
	unsigned short	biPlanes;			//1
	unsigned short	biBitCount;			//一画素あたりの色の数のbit数．今回は8
	uint32_t		biCompression;		//圧縮タイプを表す．bmpは非圧縮なので0
	uint32_t		biSizeImage;		//bmp配列のサイズを表す．biCompression=0なら基本的に0
	uint32_t		biXPelsPerMeter;	//biXPelsPerMeterとbiYPelsPerMeterは基本的に0
	uint32_t		biYPelsPerMeter;
	uint32_t		biCirUsed;			//0
	uint32_t		biCirImportant;		//0
}BITMAPINFOHEADER;

typedef struct tagRGBQUAD{
	unsigned char	rgbBlue;
	unsigned char	rgbGreen;
	unsigned char	rgbRed;
	unsigned char	rgbReserved;
}RGBQUAD;


/*cghの計算式のカーネル関数*/
__global__ void func_cgh_gpu(int *x_d, int *y_d, float *z_d, float *lumi_intensity_d, int *points_d){
	int i, j, k;

	j=blockDim.x*blockIdx.x+threadIdx.x;	//widthのループの置き換え
	i=blockDim.y*blockIdx.y+threadIdx.y;	//heigthのループの置き換え

	//計算に必要な変数の定義
	float interval=10.5F;				//画素間隔
	float wave_len=0.633F;				//光波長
	float wave_num=2.0*M_PI/wave_len;	//波数

	for(k=0; k<*points_d; k++){
		lumi_intensity_d[i*width+j]=lumi_intensity_d[i*width+j]+cosf(interval*wave_num*sqrt((j-x_d[k])*(j-x_d[k])+(i-y_d[k])*(i-y_d[k])+z_d[k]*z_d[k]));
	}
}


/*main関数*/
int main(){
	BITMAPFILEHEADER bmpFh;
	BITMAPINFOHEADER bmpIh;
	RGBQUAD rgbQ[256];

/*ホスト側の変数*/
	int i, j;
	int points;					//物体点
	float *lumi_intensity;		//光強度用の配列
	float min, max, mid;		//2値化に用いる
	unsigned char *img;			//bmp用の配列

	FILE *fp, *fp1;


/*BITMAPFILEHEADERの構造体*/
	bmpFh.bfType		=19778;	//'B'=0x42,'M'=0x4d,'BM'=0x4d42=19778
	bmpFh.bfSize		=14+40+1024+(width*heigth);	//1024はカラーパレットのサイズ．256階調で4 byte一組
	bmpFh.bfReserved1	=0;
	bmpFh.bfReserved2	=0;
	bmpFh.bf0ffBits		=14+40+1024;

/*BITMAPINFOHEADERの構造体*/
	bmpIh.biSize			=40;
	bmpIh.biWidth			=width;
	bmpIh.biHeight			=heigth;
	bmpIh.biPlanes			=1;
	bmpIh.biBitCount		=8;
	bmpIh.biCompression		=0;
	bmpIh.biSizeImage		=0;
	bmpIh.biXPelsPerMeter	=0;
	bmpIh.biYPelsPerMeter	=0;
	bmpIh.biCirUsed			=0;
	bmpIh.biCirImportant	=0;

/*RGBQUADの構造体*/
	for(i=0; i<256; i++){
		rgbQ[i].rgbBlue		=i;
		rgbQ[i].rgbGreen	=i;
		rgbQ[i].rgbRed		=i;
		rgbQ[i].rgbReserved	=0;
	}


/*3Dファイルの読み込み*/
	fp=fopen("cube284.3d","rb");	//バイナリで読み込み
	fread(&points, sizeof(int), 1, fp);	//データのアドレス，サイズ，個数，ファイルポインタを指定

	//取り出した物体点を入れる配列
	int x[points];				//~~データを読み込むことで初めてこの配列が定義できる~~
	int y[points];
	float z[points];
	int x_buf, y_buf, z_buf;	//データを一時的に溜めておくための変数

/*各バッファに物体点座標を取り込み，ホログラム面と物体点の位置を考慮したデータを各配列に入れる*/
	for(i=0; i<points; i++){
		fread(&x_buf, sizeof(int), 1, fp);
		fread(&y_buf, sizeof(int), 1, fp);
		fread(&z_buf, sizeof(int), 1, fp);

		x[i]=x_buf*40+width*0.5;	//物体点を離すために物体点座標に40を掛け，中心の座標を足す
		y[i]=y_buf*40+heigth*0.5;
		z[i]=((float)z_buf)*40+100000.0F;
	}
	fclose(fp);

	lumi_intensity=(float *)malloc(sizeof(float)*width*heigth);	//malloc関数でメモリを動的に確保

/*デバイス側の変数*/
	int *x_d, *y_d;
	float *z_d;
	float *lumi_intensity_d;
	int *points_d;

	dim3 block(32,32,1);  //ブロックサイズ(スレッド数)の配置
    dim3 grid(ceil(width/block.x),ceil(heigth/block.y),1);     //グリッドサイズ(ブロック数)の配置
//    dim3 grid((width+block.x-1)/block.x,(heigth+block.y-1)/block.y,1);

/*デバイス側のメモリ確保*/
	cudaMalloc((void**)&x_d, points*sizeof(int));
	cudaMalloc((void**)&y_d, points*sizeof(int));
	cudaMalloc((void**)&z_d, points*sizeof(float));
	cudaMalloc((void**)&lumi_intensity_d, width*heigth*sizeof(float));
	cudaMalloc((void**)&points_d, sizeof(int));

/*ホスト側からデバイス側へデータ転送*/
	cudaMemcpy(x_d, x, points*sizeof(int), cudaMemcpyHostToDevice);
	cudaMemcpy(y_d, y, points*sizeof(int), cudaMemcpyHostToDevice);
	cudaMemcpy(z_d, z, points*sizeof(float), cudaMemcpyHostToDevice);
	cudaMemcpy(lumi_intensity_d, lumi_intensity, width*heigth*sizeof(float), cudaMemcpyHostToDevice);
	cudaMemcpy(points_d, &points, sizeof(int), cudaMemcpyHostToDevice);

/*カーネル関数の起動*/
	func_cgh_gpu<<< grid, block >>>(x_d, y_d, z_d, lumi_intensity_d, points_d);

/*デバイス側からホスト側へデータ転送*/
	cudaMemcpy(lumi_intensity, lumi_intensity_d, width*heigth*sizeof(float), cudaMemcpyDeviceToHost);

/*デバイスのメモリ解放*/
	cudaFree(x_d);
	cudaFree(y_d);
	cudaFree(z_d);
	cudaFree(lumi_intensity_d);
	cudaFree(points_d);


	//最大・最小値用の変数を比較できるようにとりあえずlumi_intensity[0]を入れる
	min=lumi_intensity[0];
	max=lumi_intensity[0];

/*最大値，最小値を求める*/
	for(i=0; i<heigth; i++){
		for(j=0; j<width; j++){
			if(min>lumi_intensity[i*width+j]){
				min=lumi_intensity[i*width+j];
			}
			if(max<lumi_intensity[i*width+j]){
				max=lumi_intensity[i*width+j];
			}
		}
	}
	mid=(min+max)*0.5F;	//中間値（閾値）を求める
	printf("min=%lf, max=%lf, mid=%lf\n", min, max, mid);

/*malloc関数でメモリを動的に確保*/
	img=(unsigned char *)malloc(sizeof(unsigned char)*width*heigth);

/*各々の光強度配列の値を中間値と比較し，2値化する*/
	for(i=0; i<width*heigth; i++){
		if(lumi_intensity[i]<mid){
			img[i]=0;
		}
		if(lumi_intensity[i]>mid){
			img[i]=255;
		}
	}


/*宣言したfpと使用するファイル名，その読み書きモードを設定．バイナリ(b)で書き込み(w)*/
	fp1=fopen("root-gpu.bmp","wb");

/*書き込むデータのアドレス，データのサイズ，データの個数，ファイルのポインタを指定*/
	fwrite(&bmpFh, sizeof(bmpFh), 1, fp1);	//(&bmpFh.bfType, sizeof(bmpFh.bfType), 1, fp);というように個別に書くことも可能
	fwrite(&bmpIh, sizeof(bmpIh), 1, fp1);
	fwrite(&rgbQ[0], sizeof(rgbQ[0]), 256, fp1);
	fwrite(img, sizeof(unsigned char), width*heigth, fp1);	//bmpに書き込み

	printf("'root-gpu.bmp' was saved.\n\n");

/*malloc関数で確保したホスト側のメモリを開放する*/
	free(lumi_intensity);
	free(img);

	fclose(fp1);

	return 0;
}

	.file	"tmpxft_0028ec9c_00000000-6_4.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z41__device_stub__Z12func_cgh_gpuPiS_PfS0_S_PiS_PfS0_S_
	.type	_Z41__device_stub__Z12func_cgh_gpuPiS_PfS0_S_PiS_PfS0_S_, @function
_Z41__device_stub__Z12func_cgh_gpuPiS_PfS0_S_PiS_PfS0_S_:
.LFB2052:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movq	%r8, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z12func_cgh_gpuPiS_PfS0_S_(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L2:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z41__device_stub__Z12func_cgh_gpuPiS_PfS0_S_PiS_PfS0_S_, .-_Z41__device_stub__Z12func_cgh_gpuPiS_PfS0_S_PiS_PfS0_S_
	.globl	_Z12func_cgh_gpuPiS_PfS0_S_
	.type	_Z12func_cgh_gpuPiS_PfS0_S_, @function
_Z12func_cgh_gpuPiS_PfS0_S_:
.LFB2053:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z12func_cgh_gpuPiS_PfS0_S_PiS_PfS0_S_
	.cfi_endproc
.LFE2053:
	.size	_Z12func_cgh_gpuPiS_PfS0_S_, .-_Z12func_cgh_gpuPiS_PfS0_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
.LC1:
	.string	"cube284.3d"
.LC6:
	.string	"min=%lf, max=%lf, mid=%lf\n"
.LC7:
	.string	"wb"
.LC8:
	.string	"root-gpu.bmp"
.LC9:
	.string	"'root-gpu.bmp' was saved.\n\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%edx, %edx
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$1192, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	movabsq	$68790144322, %rax
	movl	$70647808, -1126(%rbp)
	movw	$0, -1122(%rbp)
	movq	%rax, -1134(%rbp)
	movabsq	$4398046511144, %rax
	movq	%rax, -1120(%rbp)
	movabsq	$2251804108653568, %rax
	movq	%rax, -1112(%rbp)
	xorl	%eax, %eax
	movq	%rax, -1104(%rbp)
	movq	%rax, -1096(%rbp)
	movq	%rax, -1088(%rbp)
	leaq	-1080(%rbp), %rax
	movq	%rax, -1232(%rbp)
.L9:
	movb	%dl, (%rax)
	addq	$4, %rax
	movb	%dl, -3(%rax)
	movb	%dl, -2(%rax)
	incl	%edx
	movb	$0, -1(%rax)
	cmpl	$256, %edx
	jne	.L9
	leaq	.LC0(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	call	fopen@PLT
	movl	$1, %ecx
	movl	$4, %edx
	movl	$4, %esi
	movq	%rax, %rbx
	leaq	-1216(%rbp), %rax
	movq	%rbx, %r8
	movq	%rax, %rdi
	movq	%rax, -1224(%rbp)
	call	__fread_chk@PLT
	movslq	-1216(%rbp), %rax
	movq	%rsp, %rcx
	leaq	15(,%rax,4), %rax
	movq	%rax, %rsi
	movq	%rax, %rdx
	andq	$-4096, %rsi
	andq	$-16, %rdx
	subq	%rsi, %rcx
.L10:
	cmpq	%rcx, %rsp
	je	.L11
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L10
.L11:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	je	.L12
	orq	$0, -8(%rsp,%rdx)
.L12:
	movq	%rax, %rsi
	movq	%rax, %rdx
	movq	%rsp, %rcx
	movq	%rsp, %r15
	andq	$-4096, %rsi
	andq	$-16, %rdx
	subq	%rsi, %rcx
.L13:
	cmpq	%rcx, %rsp
	je	.L14
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L13
.L14:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	je	.L15
	orq	$0, -8(%rsp,%rdx)
.L15:
	movq	%rax, %rdx
	movq	%rsp, %rcx
	andq	$-4096, %rax
	movq	%rsp, %r14
	andq	$-16, %rdx
	subq	%rax, %rcx
.L16:
	cmpq	%rcx, %rsp
	je	.L17
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L16
.L17:
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L18
	orq	$0, -8(%rsp,%rax)
.L18:
	movq	%rsp, %r13
	xorl	%r12d, %r12d
.L19:
	cmpl	%r12d, -1216(%rbp)
	jle	.L51
	leaq	-1212(%rbp), %rdi
	movq	%rbx, %r8
	movl	$1, %ecx
	movl	$4, %edx
	movl	$4, %esi
	call	__fread_chk@PLT
	leaq	-1208(%rbp), %rdi
	movq	%rbx, %r8
	movl	$1, %ecx
	movl	$4, %edx
	movl	$4, %esi
	call	__fread_chk@PLT
	leaq	-1204(%rbp), %rdi
	movq	%rbx, %r8
	movl	$1, %ecx
	movl	$4, %edx
	movl	$4, %esi
	call	__fread_chk@PLT
	imull	$40, -1212(%rbp), %eax
	cvtsi2sdl	%eax, %xmm0
	addsd	.LC2(%rip), %xmm0
	cvttsd2sil	%xmm0, %eax
	movl	%eax, (%r15,%r12,4)
	imull	$40, -1208(%rbp), %eax
	cvtsi2sdl	%eax, %xmm0
	addsd	.LC2(%rip), %xmm0
	cvttsd2sil	%xmm0, %eax
	cvtsi2ssl	-1204(%rbp), %xmm0
	mulss	.LC3(%rip), %xmm0
	addss	.LC4(%rip), %xmm0
	movl	%eax, (%r14,%r12,4)
	movss	%xmm0, 0(%r13,%r12,4)
	incq	%r12
	jmp	.L19
.L51:
	movabsq	$137438953504, %r12
	movq	%rbx, %rdi
	call	fclose@PLT
	movl	$4194304, %edi
	call	malloc@PLT
	movslq	-1216(%rbp), %rsi
	leaq	-1200(%rbp), %rdi
	movq	%r12, -1148(%rbp)
	movl	$1, -1140(%rbp)
	movq	%rax, %rbx
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movslq	-1216(%rbp), %rsi
	leaq	-1192(%rbp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movslq	-1216(%rbp), %rsi
	leaq	-1184(%rbp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	leaq	-1176(%rbp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	leaq	-1168(%rbp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movslq	-1216(%rbp), %rdx
	movl	$1, %ecx
	movq	%r15, %rsi
	movq	-1200(%rbp), %rdi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movslq	-1216(%rbp), %rdx
	movl	$1, %ecx
	movq	%r14, %rsi
	movq	-1192(%rbp), %rdi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movslq	-1216(%rbp), %rdx
	movl	$1, %ecx
	movq	%r13, %rsi
	movq	-1184(%rbp), %rdi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	-1176(%rbp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$4194304, %edx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$4, %edx
	movq	-1224(%rbp), %rsi
	movq	-1168(%rbp), %rdi
	call	cudaMemcpy@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r12, %rdx
	movq	-1148(%rbp), %rdi
	movl	-1140(%rbp), %esi
	movl	$1, %ecx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	movq	-1168(%rbp), %r8
	movq	-1176(%rbp), %rcx
	movq	-1184(%rbp), %rdx
	movq	-1192(%rbp), %rsi
	movq	-1200(%rbp), %rdi
	call	_Z41__device_stub__Z12func_cgh_gpuPiS_PfS0_S_PiS_PfS0_S_
.L21:
	movq	-1176(%rbp), %rsi
	movl	$2, %ecx
	movl	$4194304, %edx
	movq	%rbx, %rdi
	call	cudaMemcpy@PLT
	movq	-1200(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1192(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1184(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1176(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1168(%rbp), %rdi
	call	cudaFree@PLT
	movss	(%rbx), %xmm0
	movq	%rbx, %rdx
	xorl	%ecx, %ecx
	movaps	%xmm0, %xmm1
.L22:
	xorl	%eax, %eax
.L25:
	movss	(%rdx,%rax,4), %xmm2
	incq	%rax
	movaps	%xmm2, %xmm4
	maxss	%xmm1, %xmm2
	minss	%xmm0, %xmm4
	movaps	%xmm2, %xmm1
	movaps	%xmm4, %xmm0
	cmpq	$1024, %rax
	jne	.L25
	addl	$1024, %ecx
	addq	$4096, %rdx
	cmpl	$1048576, %ecx
	jne	.L22
	movaps	%xmm4, %xmm3
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movb	$3, %al
	addss	%xmm2, %xmm3
	mulss	.LC5(%rip), %xmm3
	cvtss2sd	%xmm4, %xmm0
	cvtss2sd	%xmm1, %xmm1
	movss	%xmm3, -1224(%rbp)
	cvtss2sd	%xmm3, %xmm2
	call	__printf_chk@PLT
	movl	$1048576, %edi
	call	malloc@PLT
	movss	-1224(%rbp), %xmm3
	movq	%rax, %r13
	xorl	%eax, %eax
.L31:
	movss	(%rbx,%rax,4), %xmm0
	comiss	%xmm0, %xmm3
	jbe	.L49
	movb	$0, 0(%r13,%rax)
	jmp	.L29
.L49:
	comiss	%xmm3, %xmm0
	jbe	.L29
	movb	$-1, 0(%r13,%rax)
.L29:
	incq	%rax
	cmpq	$1048576, %rax
	jne	.L31
	leaq	.LC7(%rip), %rsi
	leaq	.LC8(%rip), %rdi
	call	fopen@PLT
	movl	$1, %edx
	movl	$14, %esi
	leaq	-1134(%rbp), %rdi
	movq	%rax, %r12
	movq	%rax, %rcx
	call	fwrite@PLT
	leaq	-1120(%rbp), %rdi
	movq	%r12, %rcx
	movl	$1, %edx
	movl	$40, %esi
	call	fwrite@PLT
	movq	-1232(%rbp), %rdi
	movq	%r12, %rcx
	movl	$256, %edx
	movl	$4, %esi
	call	fwrite@PLT
	movq	%r12, %rcx
	movl	$1048576, %edx
	movq	%r13, %rdi
	movl	$1, %esi
	call	fwrite@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L32
	call	__stack_chk_fail@PLT
.L32:
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z12func_cgh_gpuPiS_PfS0_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.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	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z12func_cgh_gpuPiS_PfS0_S_(%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
.LFE2055:
	.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.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	0
	.long	1082130432
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC3:
	.long	1109393408
	.align 4
.LC4:
	.long	1203982336
	.align 4
.LC5:
	.long	1056964608
	.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 <stdio.h>
#include <math.h>
#include <stdint.h>		//uint32_tは符号なしintで4バイトに指定
#include <stdlib.h> 	//記憶域管理を使うため
#include <hip/hip_runtime.h>


/*記号定数として横幅と縦幅を定義*/
#define width 1024
#define heigth 1024


/*bmpの構造体*/
#pragma pack(push,1)
typedef struct tagBITMAPFILEHEADER{	//構造体BITMAPFILEHEADERはファイルの先頭に来るもので，サイズは14 byte
	unsigned short	bfType;			//bfTypeは，bmp形式であることを示すため，"BM"が入る
	uint32_t 		bfSize;			//bfsizeは，ファイル全体のバイト数
	unsigned short	bfReserved1;	//bfReserved1と2は予約領域で，0になる
	unsigned short	bfReserved2;
	uint32_t		bf0ffBits;		//bf0ffBitsは先頭から画素データまでのバイト数
}BITMAPFILEHEADER;

#pragma pack(pop)
typedef struct tagBITMAPINFOHEADER{	//BITMAPINFOHEADERはbmpファイルの画像の情報の構造体で，サイズは40 byte
	uint32_t		biSize;				//画像のサイズ
	uint32_t		biWidth;			//横の画素数
	uint32_t		biHeight;			//縦の画素数
	unsigned short	biPlanes;			//1
	unsigned short	biBitCount;			//一画素あたりの色の数のbit数．今回は8
	uint32_t		biCompression;		//圧縮タイプを表す．bmpは非圧縮なので0
	uint32_t		biSizeImage;		//bmp配列のサイズを表す．biCompression=0なら基本的に0
	uint32_t		biXPelsPerMeter;	//biXPelsPerMeterとbiYPelsPerMeterは基本的に0
	uint32_t		biYPelsPerMeter;
	uint32_t		biCirUsed;			//0
	uint32_t		biCirImportant;		//0
}BITMAPINFOHEADER;

typedef struct tagRGBQUAD{
	unsigned char	rgbBlue;
	unsigned char	rgbGreen;
	unsigned char	rgbRed;
	unsigned char	rgbReserved;
}RGBQUAD;


/*cghの計算式のカーネル関数*/
__global__ void func_cgh_gpu(int *x_d, int *y_d, float *z_d, float *lumi_intensity_d, int *points_d){
	int i, j, k;

	j=blockDim.x*blockIdx.x+threadIdx.x;	//widthのループの置き換え
	i=blockDim.y*blockIdx.y+threadIdx.y;	//heigthのループの置き換え

	//計算に必要な変数の定義
	float interval=10.5F;				//画素間隔
	float wave_len=0.633F;				//光波長
	float wave_num=2.0*M_PI/wave_len;	//波数

	for(k=0; k<*points_d; k++){
		lumi_intensity_d[i*width+j]=lumi_intensity_d[i*width+j]+cosf(interval*wave_num*sqrt((j-x_d[k])*(j-x_d[k])+(i-y_d[k])*(i-y_d[k])+z_d[k]*z_d[k]));
	}
}


/*main関数*/
int main(){
	BITMAPFILEHEADER bmpFh;
	BITMAPINFOHEADER bmpIh;
	RGBQUAD rgbQ[256];

/*ホスト側の変数*/
	int i, j;
	int points;					//物体点
	float *lumi_intensity;		//光強度用の配列
	float min, max, mid;		//2値化に用いる
	unsigned char *img;			//bmp用の配列

	FILE *fp, *fp1;


/*BITMAPFILEHEADERの構造体*/
	bmpFh.bfType		=19778;	//'B'=0x42,'M'=0x4d,'BM'=0x4d42=19778
	bmpFh.bfSize		=14+40+1024+(width*heigth);	//1024はカラーパレットのサイズ．256階調で4 byte一組
	bmpFh.bfReserved1	=0;
	bmpFh.bfReserved2	=0;
	bmpFh.bf0ffBits		=14+40+1024;

/*BITMAPINFOHEADERの構造体*/
	bmpIh.biSize			=40;
	bmpIh.biWidth			=width;
	bmpIh.biHeight			=heigth;
	bmpIh.biPlanes			=1;
	bmpIh.biBitCount		=8;
	bmpIh.biCompression		=0;
	bmpIh.biSizeImage		=0;
	bmpIh.biXPelsPerMeter	=0;
	bmpIh.biYPelsPerMeter	=0;
	bmpIh.biCirUsed			=0;
	bmpIh.biCirImportant	=0;

/*RGBQUADの構造体*/
	for(i=0; i<256; i++){
		rgbQ[i].rgbBlue		=i;
		rgbQ[i].rgbGreen	=i;
		rgbQ[i].rgbRed		=i;
		rgbQ[i].rgbReserved	=0;
	}


/*3Dファイルの読み込み*/
	fp=fopen("cube284.3d","rb");	//バイナリで読み込み
	fread(&points, sizeof(int), 1, fp);	//データのアドレス，サイズ，個数，ファイルポインタを指定

	//取り出した物体点を入れる配列
	int x[points];				//~~データを読み込むことで初めてこの配列が定義できる~~
	int y[points];
	float z[points];
	int x_buf, y_buf, z_buf;	//データを一時的に溜めておくための変数

/*各バッファに物体点座標を取り込み，ホログラム面と物体点の位置を考慮したデータを各配列に入れる*/
	for(i=0; i<points; i++){
		fread(&x_buf, sizeof(int), 1, fp);
		fread(&y_buf, sizeof(int), 1, fp);
		fread(&z_buf, sizeof(int), 1, fp);

		x[i]=x_buf*40+width*0.5;	//物体点を離すために物体点座標に40を掛け，中心の座標を足す
		y[i]=y_buf*40+heigth*0.5;
		z[i]=((float)z_buf)*40+100000.0F;
	}
	fclose(fp);

	lumi_intensity=(float *)malloc(sizeof(float)*width*heigth);	//malloc関数でメモリを動的に確保

/*デバイス側の変数*/
	int *x_d, *y_d;
	float *z_d;
	float *lumi_intensity_d;
	int *points_d;

	dim3 block(32,32,1);  //ブロックサイズ(スレッド数)の配置
    dim3 grid(ceil(width/block.x),ceil(heigth/block.y),1);     //グリッドサイズ(ブロック数)の配置
//    dim3 grid((width+block.x-1)/block.x,(heigth+block.y-1)/block.y,1);

/*デバイス側のメモリ確保*/
	hipMalloc((void**)&x_d, points*sizeof(int));
	hipMalloc((void**)&y_d, points*sizeof(int));
	hipMalloc((void**)&z_d, points*sizeof(float));
	hipMalloc((void**)&lumi_intensity_d, width*heigth*sizeof(float));
	hipMalloc((void**)&points_d, sizeof(int));

/*ホスト側からデバイス側へデータ転送*/
	hipMemcpy(x_d, x, points*sizeof(int), hipMemcpyHostToDevice);
	hipMemcpy(y_d, y, points*sizeof(int), hipMemcpyHostToDevice);
	hipMemcpy(z_d, z, points*sizeof(float), hipMemcpyHostToDevice);
	hipMemcpy(lumi_intensity_d, lumi_intensity, width*heigth*sizeof(float), hipMemcpyHostToDevice);
	hipMemcpy(points_d, &points, sizeof(int), hipMemcpyHostToDevice);

/*カーネル関数の起動*/
	func_cgh_gpu<<< grid, block >>>(x_d, y_d, z_d, lumi_intensity_d, points_d);

/*デバイス側からホスト側へデータ転送*/
	hipMemcpy(lumi_intensity, lumi_intensity_d, width*heigth*sizeof(float), hipMemcpyDeviceToHost);

/*デバイスのメモリ解放*/
	hipFree(x_d);
	hipFree(y_d);
	hipFree(z_d);
	hipFree(lumi_intensity_d);
	hipFree(points_d);


	//最大・最小値用の変数を比較できるようにとりあえずlumi_intensity[0]を入れる
	min=lumi_intensity[0];
	max=lumi_intensity[0];

/*最大値，最小値を求める*/
	for(i=0; i<heigth; i++){
		for(j=0; j<width; j++){
			if(min>lumi_intensity[i*width+j]){
				min=lumi_intensity[i*width+j];
			}
			if(max<lumi_intensity[i*width+j]){
				max=lumi_intensity[i*width+j];
			}
		}
	}
	mid=(min+max)*0.5F;	//中間値（閾値）を求める
	printf("min=%lf, max=%lf, mid=%lf\n", min, max, mid);

/*malloc関数でメモリを動的に確保*/
	img=(unsigned char *)malloc(sizeof(unsigned char)*width*heigth);

/*各々の光強度配列の値を中間値と比較し，2値化する*/
	for(i=0; i<width*heigth; i++){
		if(lumi_intensity[i]<mid){
			img[i]=0;
		}
		if(lumi_intensity[i]>mid){
			img[i]=255;
		}
	}


/*宣言したfpと使用するファイル名，その読み書きモードを設定．バイナリ(b)で書き込み(w)*/
	fp1=fopen("root-gpu.bmp","wb");

/*書き込むデータのアドレス，データのサイズ，データの個数，ファイルのポインタを指定*/
	fwrite(&bmpFh, sizeof(bmpFh), 1, fp1);	//(&bmpFh.bfType, sizeof(bmpFh.bfType), 1, fp);というように個別に書くことも可能
	fwrite(&bmpIh, sizeof(bmpIh), 1, fp1);
	fwrite(&rgbQ[0], sizeof(rgbQ[0]), 256, fp1);
	fwrite(img, sizeof(unsigned char), width*heigth, fp1);	//bmpに書き込み

	printf("'root-gpu.bmp' was saved.\n\n");

/*malloc関数で確保したホスト側のメモリを開放する*/
	free(lumi_intensity);
	free(img);

	fclose(fp1);

	return 0;
}

	.text
	.file	"4.hip"
	.globl	_Z27__device_stub__func_cgh_gpuPiS_PfS0_S_ # -- Begin function _Z27__device_stub__func_cgh_gpuPiS_PfS0_S_
	.type	_Z27__device_stub__func_cgh_gpuPiS_PfS0_S_,@function
_Z27__device_stub__func_cgh_gpuPiS_PfS0_S_: # @_Z27__device_stub__func_cgh_gpuPiS_PfS0_S_
	.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	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z12func_cgh_gpuPiS_PfS0_S_, %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	_Z27__device_stub__func_cgh_gpuPiS_PfS0_S_, .Lfunc_end0-_Z27__device_stub__func_cgh_gpuPiS_PfS0_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	40                              # 0x28
	.long	1024                            # 0x400
	.long	1024                            # 0x400
	.long	524289                          # 0x80001
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI1_1:
	.long	0x42200000                      # float 40
.LCPI1_2:
	.long	0x47c35000                      # float 1.0E+5
.LCPI1_3:
	.long	0x3f000000                      # float 0.5
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$1160, %rsp                     # imm = 0x488
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movw	$19778, -118(%rbp)              # imm = 0x4D42
	movq	$1049654, -116(%rbp)            # imm = 0x100436
	movl	$1078, -108(%rbp)               # imm = 0x436
	movaps	.LCPI1_0(%rip), %xmm0           # xmm0 = [40,1024,1024,524289]
	movups	%xmm0, -168(%rbp)
	xorps	%xmm0, %xmm0
	movups	%xmm0, -152(%rbp)
	movq	$0, -136(%rbp)
	xorl	%eax, %eax
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movb	%al, -1200(%rbp,%rax,4)
	movb	%al, -1199(%rbp,%rax,4)
	movb	%al, -1198(%rbp,%rax,4)
	movb	$0, -1197(%rbp,%rax,4)
	incq	%rax
	cmpq	$256, %rax                      # imm = 0x100
	jne	.LBB1_1
# %bb.2:
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %rbx
	leaq	-104(%rbp), %r14
	movl	$4, %esi
	movl	$1, %edx
	movq	%r14, %rdi
	movq	%rax, %rcx
	callq	fread
	movq	%rsp, -128(%rbp)                # 8-byte Spill
	movslq	(%r14), %r14
	movl	%r14d, %eax
	movq	%rsp, %r12
	leaq	15(,%rax,4), %rax
	andq	$-16, %rax
	subq	%rax, %r12
	movq	%r12, %rsp
	movq	%rsp, %r13
	subq	%rax, %r13
	movq	%r13, %rsp
	movq	%rsp, %r15
	subq	%rax, %r15
	movq	%r15, %rsp
	testq	%r14, %r14
	jle	.LBB1_6
# %bb.3:                                # %.lr.ph.preheader
	movl	%r14d, %r14d
	movq	%r15, -48(%rbp)                 # 8-byte Spill
	xorl	%r15d, %r15d
.LBB1_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$4, %esi
	movl	$1, %edx
	leaq	-100(%rbp), %rdi
	movq	%rbx, %rcx
	callq	fread
	movl	$4, %esi
	movl	$1, %edx
	leaq	-96(%rbp), %rdi
	movq	%rbx, %rcx
	callq	fread
	movl	$4, %esi
	movl	$1, %edx
	leaq	-92(%rbp), %rdi
	movq	%rbx, %rcx
	callq	fread
	movl	-100(%rbp), %eax
	leal	(%rax,%rax,4), %eax
	shll	$3, %eax
	movl	$512, %ecx                      # imm = 0x200
	addl	%ecx, %eax
	movl	%eax, (%r12,%r15,4)
	movl	-96(%rbp), %eax
	leal	(%rax,%rax,4), %eax
	shll	$3, %eax
	addl	%ecx, %eax
	movl	%eax, (%r13,%r15,4)
	xorps	%xmm0, %xmm0
	cvtsi2ssl	-92(%rbp), %xmm0
	mulss	.LCPI1_1(%rip), %xmm0
	addss	.LCPI1_2(%rip), %xmm0
	movq	-48(%rbp), %rax                 # 8-byte Reload
	movss	%xmm0, (%rax,%r15,4)
	incq	%r15
	cmpq	%r14, %r15
	jb	.LBB1_4
# %bb.5:
	movq	-48(%rbp), %r15                 # 8-byte Reload
.LBB1_6:                                # %._crit_edge
	movq	%rbx, %rdi
	callq	fclose
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %rbx
	shlq	$2, %r14
	leaq	-88(%rbp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	leaq	-80(%rbp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	leaq	-72(%rbp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	leaq	-56(%rbp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	leaq	-64(%rbp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	leaq	-88(%rbp), %rax
	movq	(%rax), %rdi
	movq	%r12, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	-80(%rbp), %rax
	movq	(%rax), %rdi
	movq	%r13, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	-72(%rbp), %rax
	movq	(%rax), %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	-56(%rbp), %rax
	movq	(%rax), %rdi
	movl	$4194304, %edx                  # imm = 0x400000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	-64(%rbp), %rax
	movq	(%rax), %rdi
	leaq	-104(%rbp), %rsi
	movl	$4, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$137438953504, %rdi             # imm = 0x2000000020
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_8
# %bb.7:
	movq	-88(%rbp), %rdi
	movq	-80(%rbp), %rsi
	movq	-72(%rbp), %rdx
	movq	-56(%rbp), %rcx
	movq	-64(%rbp), %r8
	callq	_Z27__device_stub__func_cgh_gpuPiS_PfS0_S_
.LBB1_8:
	movq	-56(%rbp), %rsi
	movl	$4194304, %edx                  # imm = 0x400000
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	-88(%rbp), %rdi
	callq	hipFree
	movq	-80(%rbp), %rdi
	callq	hipFree
	movq	-72(%rbp), %rdi
	callq	hipFree
	movq	-56(%rbp), %rdi
	callq	hipFree
	movq	-64(%rbp), %rdi
	callq	hipFree
	movss	(%rbx), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	xorl	%eax, %eax
	movq	%rbx, %rcx
	movaps	%xmm0, %xmm3
.LBB1_9:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_10 Depth 2
	xorl	%edx, %edx
.LBB1_10:                               #   Parent Loop BB1_9 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movaps	%xmm3, %xmm1
	movaps	%xmm0, %xmm2
	movss	(%rcx,%rdx,4), %xmm3            # xmm3 = mem[0],zero,zero,zero
	movaps	%xmm3, %xmm0
	minss	%xmm2, %xmm0
	maxss	%xmm1, %xmm3
	incq	%rdx
	cmpq	$1024, %rdx                     # imm = 0x400
	jne	.LBB1_10
# %bb.11:                               #   in Loop: Header=BB1_9 Depth=1
	incq	%rax
	addq	$4096, %rcx                     # imm = 0x1000
	cmpq	$1024, %rax                     # imm = 0x400
	jne	.LBB1_9
# %bb.12:
	xorps	%xmm1, %xmm1
	cvtss2sd	%xmm3, %xmm1
	addss	%xmm0, %xmm3
	mulss	.LCPI1_3(%rip), %xmm3
	movss	%xmm3, -48(%rbp)                # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	xorps	%xmm2, %xmm2
	cvtss2sd	%xmm3, %xmm2
	movl	$.L.str.2, %edi
	movb	$3, %al
	callq	printf
	movl	$1048576, %edi                  # imm = 0x100000
	callq	malloc
	movss	-48(%rbp), %xmm1                # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movq	%rax, %r14
	xorl	%eax, %eax
.LBB1_13:                               # =>This Inner Loop Header: Depth=1
	movss	(%rbx,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jbe	.LBB1_15
# %bb.14:                               #   in Loop: Header=BB1_13 Depth=1
	movb	$0, (%r14,%rax)
.LBB1_15:                               #   in Loop: Header=BB1_13 Depth=1
	ucomiss	%xmm1, %xmm0
	jbe	.LBB1_17
# %bb.16:                               #   in Loop: Header=BB1_13 Depth=1
	movb	$-1, (%r14,%rax)
.LBB1_17:                               #   in Loop: Header=BB1_13 Depth=1
	incq	%rax
	cmpq	$1048576, %rax                  # imm = 0x100000
	jne	.LBB1_13
# %bb.18:
	movl	$.L.str.3, %edi
	movl	$.L.str.4, %esi
	callq	fopen
	movq	%rax, %r15
	leaq	-118(%rbp), %rdi
	movl	$14, %esi
	movl	$1, %edx
	movq	%rax, %rcx
	callq	fwrite
	leaq	-168(%rbp), %rdi
	movl	$40, %esi
	movl	$1, %edx
	movq	%r15, %rcx
	callq	fwrite
	leaq	-1200(%rbp), %rdi
	movl	$4, %esi
	movl	$256, %edx                      # imm = 0x100
	movq	%r15, %rcx
	callq	fwrite
	movl	$1, %esi
	movl	$1048576, %edx                  # imm = 0x100000
	movq	%r14, %rdi
	movq	%r15, %rcx
	callq	fwrite
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	fclose
	movq	-128(%rbp), %rsp                # 8-byte Reload
	xorl	%eax, %eax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12func_cgh_gpuPiS_PfS0_S_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB3_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z12func_cgh_gpuPiS_PfS0_S_,@object # @_Z12func_cgh_gpuPiS_PfS0_S_
	.section	.rodata,"a",@progbits
	.globl	_Z12func_cgh_gpuPiS_PfS0_S_
	.p2align	3, 0x0
_Z12func_cgh_gpuPiS_PfS0_S_:
	.quad	_Z27__device_stub__func_cgh_gpuPiS_PfS0_S_
	.size	_Z12func_cgh_gpuPiS_PfS0_S_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"cube284.3d"
	.size	.L.str, 11

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"rb"
	.size	.L.str.1, 3

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"min=%lf, max=%lf, mid=%lf\n"
	.size	.L.str.2, 27

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"root-gpu.bmp"
	.size	.L.str.3, 13

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"wb"
	.size	.L.str.4, 3

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z12func_cgh_gpuPiS_PfS0_S_"
	.size	.L__unnamed_1, 28

	.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	"'root-gpu.bmp' was saved.\n"
	.size	.Lstr, 27

	.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 _Z27__device_stub__func_cgh_gpuPiS_PfS0_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z12func_cgh_gpuPiS_PfS0_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12func_cgh_gpuPiS_PfS0_S_ ; -- Begin function _Z12func_cgh_gpuPiS_PfS0_S_
	.globl	_Z12func_cgh_gpuPiS_PfS0_S_
	.p2align	8
	.type	_Z12func_cgh_gpuPiS_PfS0_S_,@function
_Z12func_cgh_gpuPiS_PfS0_S_:            ; @_Z12func_cgh_gpuPiS_PfS0_S_
; %bb.0:
	s_load_b64 s[2:3], s[0:1], 0x20
	s_waitcnt lgkmcnt(0)
	s_load_b32 s2, s[2:3], 0x0
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s2, 1
	s_cbranch_scc1 .LBB0_7
; %bb.1:                                ; %.lr.ph
	s_load_b32 s3, s[0:1], 0x34
	v_dual_mov_b32 v5, 0 :: v_dual_and_b32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s3, 16
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s3, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s4, v[3:4]
	s_load_b256 s[4:11], s[0:1], 0x0
	s_mov_b32 s3, 0x7fffff
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshl_add_u32 v2, v1, 10, v0
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s10, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s11, v3, vcc_lo
	s_mov_b32 s10, 0xb94c1982
	s_mov_b32 s11, 0x37d75334
	global_load_b32 v6, v[2:3], off
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	global_load_b32 v9, v5, s[8:9]
	s_load_b32 s0, s[4:5], 0x0
	s_load_b32 s1, s[6:7], 0x0
	s_waitcnt lgkmcnt(0)
	v_subrev_nc_u32_e32 v4, s0, v0
	v_subrev_nc_u32_e32 v10, s1, v1
	s_mov_b32 s1, exec_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v4, v4, v4
	v_mad_u64_u32 v[7:8], null, v10, v10, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f32_i32_e32 v4, v7
	s_waitcnt vmcnt(0)
	v_fmac_f32_e32 v4, v9, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v7, 0x4f800000, v4
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v4
	v_cndmask_b32_e32 v4, v4, v7, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_sqrt_f32_e32 v7, v4
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v8, -1, v7
	v_add_nc_u32_e32 v9, 1, v7
	v_fma_f32 v10, -v8, v7, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v11, -v9, v7, v4
	v_cmp_ge_f32_e64 s0, 0, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v7, v7, v8, s0
	v_cmp_lt_f32_e64 s0, 0, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v7, v7, v9, s0
	v_mul_f32_e32 v8, 0x37800000, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v7, v7, v8, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v4, 0x260
                                        ; implicit-def: $vgpr8
	v_cndmask_b32_e32 v4, v7, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v7, 0x42d07268, v4
                                        ; implicit-def: $vgpr4
	v_cmpx_ngt_f32_e64 0x48000000, |v7|
	s_xor_b32 s12, exec_lo, s1
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	v_and_b32_e32 v13, 0x7fffffff, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_or_b32 v16, v13, s3, 0x800000
	v_mad_u64_u32 v[8:9], null, 0xfe5163ab, v16, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v4, v9
	v_lshrrev_b32_e32 v13, 23, v13
	v_mad_u64_u32 v[9:10], null, 0x3c439041, v16, v[4:5]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v14, 0xffffff88, v13
	v_cmp_lt_u32_e32 vcc_lo, 63, v14
	v_cndmask_b32_e64 v15, 0, 0xffffffc0, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v4, v10 :: v_dual_add_nc_u32 v15, v15, v14
	v_mad_u64_u32 v[10:11], null, 0xdb629599, v16, v[4:5]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_lt_u32_e64 s0, 31, v15
	v_cndmask_b32_e32 v8, v10, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v17, 0, 0xffffffe0, s0
	v_dual_mov_b32 v4, v11 :: v_dual_add_nc_u32 v17, v17, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[11:12], null, 0xf534ddc0, v16, v[4:5]
	v_cmp_lt_u32_e64 s1, 31, v17
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v4, v12 :: v_dual_cndmask_b32 v9, v11, v9
	v_mad_u64_u32 v[12:13], null, 0xfc2757d1, v16, v[4:5]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v8, v9, v8, s0
	v_mov_b32_e32 v4, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[13:14], null, 0x4e441529, v16, v[4:5]
	v_mov_b32_e32 v4, v14
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_mad_u64_u32 v[14:15], null, 0xa2f9836e, v16, v[4:5]
	v_cndmask_b32_e64 v4, 0, 0xffffffe0, s1
	v_cndmask_b32_e32 v16, v13, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_nc_u32_e32 v4, v4, v17
	v_dual_cndmask_b32 v14, v14, v12 :: v_dual_cndmask_b32 v13, v15, v13
	v_cndmask_b32_e32 v12, v12, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v15, 32, v4
	v_cndmask_b32_e64 v11, v14, v16, s0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v13, v13, v14, s0
	v_cndmask_b32_e64 v14, v16, v12, s0
	v_cndmask_b32_e64 v12, v12, v9, s0
	v_cmp_eq_u32_e32 vcc_lo, 0, v4
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v13, v13, v11, s1
	v_cndmask_b32_e64 v11, v11, v14, s1
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v14, v14, v12, s1
	v_cndmask_b32_e64 v8, v12, v8, s1
	v_alignbit_b32 v16, v13, v11, v15
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_alignbit_b32 v10, v11, v14, v15
	v_dual_cndmask_b32 v4, v16, v13 :: v_dual_cndmask_b32 v9, v10, v11
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_alignbit_b32 v13, v14, v8, v15
	v_bfe_u32 v10, v4, 29, 1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_alignbit_b32 v11, v4, v9, 30
	v_cndmask_b32_e32 v13, v13, v14, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v12, 0, v10
	v_alignbit_b32 v9, v9, v13, 30
	v_alignbit_b32 v8, v13, v8, 30
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_xor_b32_e32 v11, v11, v12
	v_xor_b32_e32 v9, v9, v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v8, v8, v12
	v_lshrrev_b32_e32 v12, 29, v4
	v_clz_i32_u32_e32 v14, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b32_e32 v12, 31, v12
	v_min_u32_e32 v14, 32, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_or_b32_e32 v15, 0.5, v12
	v_sub_nc_u32_e32 v13, 31, v14
	v_lshlrev_b32_e32 v16, 23, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_alignbit_b32 v11, v11, v9, v13
	v_alignbit_b32 v8, v9, v8, v13
	v_sub_nc_u32_e32 v15, v15, v16
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_alignbit_b32 v9, v11, v8, 9
	v_lshrrev_b32_e32 v11, 9, v11
	v_clz_i32_u32_e32 v13, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_min_u32_e32 v13, 32, v13
	v_sub_nc_u32_e32 v17, 31, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_alignbit_b32 v8, v9, v8, v17
	v_or_b32_e32 v9, v11, v15
	v_add_lshl_u32 v11, v13, v14, 23
	v_lshrrev_b32_e32 v8, 9, v8
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v13, 0x3fc90fda, v9
	v_sub_nc_u32_e32 v8, v8, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v11, 0x3fc90fda, v9, -v13
	v_add_nc_u32_e32 v8, 0x33000000, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v11, 0x33a22168, v9
	v_or_b32_e32 v8, v8, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v11, 0x3fc90fda, v8
	v_lshrrev_b32_e32 v8, 30, v4
	v_add_f32_e32 v4, v13, v11
	s_delay_alu instid0(VALU_DEP_2)
	v_add_nc_u32_e32 v8, v10, v8
.LBB0_4:                                ; %Flow
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_and_not1_saveexec_b32 s0, s12
; %bb.5:                                ;   in Loop: Header=BB0_2 Depth=1
	v_mul_f32_e64 v4, 0x3f22f983, |v7|
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rndne_f32_e32 v8, v4
	v_fma_f32 v4, 0xbfc90fda, v8, |v7|
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v4, 0xb3a22168, v8
	v_fmac_f32_e32 v4, 0xa7c234c4, v8
	v_cvt_i32_f32_e32 v8, v8
; %bb.6:                                ; %_ZL4cosff.exit
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	s_delay_alu instid0(VALU_DEP_2)
	v_mul_f32_e32 v9, v4, v4
	s_add_i32 s2, s2, -1
	s_add_u32 s4, s4, 4
	s_addc_u32 s5, s5, 0
	s_add_u32 s6, s6, 4
	v_fmaak_f32 v10, s10, v9, 0x3c0881c4
	s_addc_u32 s7, s7, 0
	s_add_u32 s8, s8, 4
	s_addc_u32 s9, s9, 0
	s_cmp_lg_u32 s2, 0
	v_fmaak_f32 v10, v9, v10, 0xbe2aaa9d
	v_dual_fmaak_f32 v11, s11, v9, 0xbab64f3b :: v_dual_and_b32 v12, 1, v8
	v_lshlrev_b32_e32 v8, 30, v8
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_mul_f32_e32 v10, v9, v10
	v_fmaak_f32 v11, v9, v11, 0x3d2aabf7
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cmp_eq_u32_e32 vcc_lo, 0, v12
	v_and_b32_e32 v8, 0x80000000, v8
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_fmac_f32 v4, v4, v10 :: v_dual_fmaak_f32 v11, v9, v11, 0xbf000004
	v_fma_f32 v9, v9, v11, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v4, -v4, v9, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v7, 0x1f8
	v_xor_b32_e32 v4, v8, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v4, 0x7fc00000, v4, vcc_lo
	v_add_f32_e32 v6, v6, v4
	global_store_b32 v[2:3], v6, off
	s_cbranch_scc1 .LBB0_2
.LBB0_7:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12func_cgh_gpuPiS_PfS0_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 1
		.amdhsa_next_free_vgpr 18
		.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	_Z12func_cgh_gpuPiS_PfS0_S_, .Lfunc_end0-_Z12func_cgh_gpuPiS_PfS0_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1376
; NumSgprs: 18
; NumVgprs: 18
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 18
; 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: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .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:           _Z12func_cgh_gpuPiS_PfS0_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12func_cgh_gpuPiS_PfS0_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     18
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
