#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <iostream>
#include <ctype.h>
#include <cuda.h>
#include <math.h>

#define	CEIL(a,b)		((a+b-1)/b)
#define SWAP(a,b,t)		t=b; b=a; a=t;
#define DATAMB(bytes)			(bytes/1024/1024)
#define DATABW(bytes,timems)	((float)bytes/(timems * 1.024*1024.0*1024.0))
#define PI 3.14159265
typedef unsigned char uch;
typedef unsigned long ul;
typedef unsigned int  ui;

uch *TheImg, *CopyImg;					// Where images are stored in CPU
uch *GPUImg, *GPUCopyImg, *GPUResult;	// Where images are stored in GPU

struct ImgProp{
	int Hpixels;
	int Vpixels;
	uch HeaderInfo[54];
	ul Hbytes;
} ip;

#define	IPHB		ip.Hbytes
#define	IPH			ip.Hpixels
#define	IPV			ip.Vpixels
#define	IMAGESIZE	(IPHB*IPV)
#define	IMAGEPIX	(IPH*IPV)



// Kernel that flips the given image horizontally
// each thread only flips a single pixel (R,G,B)
__global__
void imrotate(uch *ImgDst, uch *ImgSrc, ui Vpixels, ui Hpixels, ui BlkPerRow, ui RowBytes, double cosRot, double sinRot)
{	
	__shared__ uch PixBuffer[3072*16];

	ui ThrPerBlk = blockDim.x;
	ui MYbid = blockIdx.x;
	ui MYtid = threadIdx.x;
	ui MYgtid = ThrPerBlk * MYbid + MYtid;

	ui MYrow = MYbid / BlkPerRow;
	ui MYcol = MYgtid - MYrow*BlkPerRow*ThrPerBlk;
	if (MYcol >= Hpixels) return;			// col out of range
	ui MYsrcOffset = MYrow * RowBytes;
	ui MYsrcIndex = MYsrcOffset + 3 * MYcol;

	////////////// find destination index	
	int c, h, v, X, Y, NewCol, NewRow;
	double newX, newY, H, V, Diagonal, ScaleFactor;

	c=MYcol;  		h=Hpixels/2;   v=Vpixels/2;	// integer div
	X=(double)c-(double)h;
	Y=(double)v-(double)MYrow;
	
	// pixel rotation matrix
	newX=cosRot*X-sinRot*Y;
	newY=sinRot*X+cosRot*Y;
	
	// Scale to fit everything in the image box
	H=(double)Hpixels;
	V=(double)Vpixels;
	Diagonal=sqrt(H*H+V*V);
	ScaleFactor=(Hpixels>Vpixels) ? V/Diagonal : H/Diagonal;
	newX=newX*ScaleFactor;
	newY=newY*ScaleFactor;
	
	// convert back from Cartesian to image coordinates
	NewCol=((int) newX+h);
	NewRow=v-(int)newY;
	ui MYdstOffset = NewRow*RowBytes;
	ui MYdstIndex = MYdstOffset + 3 * NewCol;
	///////////////	
	ui Mytid3 = MYtid*3;
	PixBuffer[Mytid3] = ImgSrc[MYsrcIndex];
	PixBuffer[Mytid3+1] = ImgSrc[MYsrcIndex+1];
	PixBuffer[Mytid3+2] = ImgSrc[MYsrcIndex+2];
	__syncthreads();

	// swap pixels RGB   @MYcol , @MYmirrorcol
	ImgDst[MYdstIndex] = PixBuffer[Mytid3];
	ImgDst[MYdstIndex + 1] = PixBuffer[Mytid3+1];
	ImgDst[MYdstIndex + 2] = PixBuffer[Mytid3+2];
}






// Read a 24-bit/pixel BMP file into a 1D linear array.
// Allocate memory to store the 1D image and return its pointer.
uch *ReadBMPlin(char* fn)
{
	static uch *Img;
	FILE* f = fopen(fn, "rb");
	if (f == NULL){	printf("\n\n%s NOT FOUND\n\n", fn);	exit(EXIT_FAILURE); }

	uch HeaderInfo[54];
	fread(HeaderInfo, sizeof(uch), 54, f); // read the 54-byte header
	// extract image height and width from header
	int width = *(int*)&HeaderInfo[18];			ip.Hpixels = width;
	int height = *(int*)&HeaderInfo[22];		ip.Vpixels = height;
	int RowBytes = (width * 3 + 3) & (~3);		ip.Hbytes = RowBytes;
	//save header for re-use
	memcpy(ip.HeaderInfo, HeaderInfo,54);
	printf("\n Input File name: %17s  (%d x %d)   File Size=%lu", fn, 
			ip.Hpixels, ip.Vpixels, IMAGESIZE);
	// allocate memory to store the main image (1 Dimensional array)
	Img  = (uch *)malloc(IMAGESIZE);
	if (Img == NULL) return Img;      // Cannot allocate memory
	// read the image from disk
	fread(Img, sizeof(uch), IMAGESIZE, f);
	fclose(f);
	return Img;
}


// Write the 1D linear-memory stored image into file.
void WriteBMPlin(uch *Img, char* fn)
{
	FILE* f = fopen(fn, "wb");
	if (f == NULL){ printf("\n\nFILE CREATION ERROR: %s\n\n", fn); exit(1); }
	//write header
	fwrite(ip.HeaderInfo, sizeof(uch), 54, f);
	//write data
	fwrite(Img, sizeof(uch), IMAGESIZE, f);
	printf("\nOutput File name: %17s  (%u x %u)   File Size=%lu", fn, ip.Hpixels, ip.Vpixels, IMAGESIZE);
	fclose(f);
}


int main(int argc, char **argv)
{
	// char			Flip = 'H';
	float			tmpKernelExcutionTime, totalKernelExecutionTime; // GPU code run times
	cudaError_t		cudaStatus, cudaStatus2;
	cudaEvent_t		time1, time2;
	char			InputFileName[255], OutputFileName[255], ProgName[255];
	ui				BlkPerRow;
	// ui 			BlkPerRowInt, BlkPerRowInt2;
	ui				ThrPerBlk = 128, NumBlocks;
	// ui 				NB2, NB4, NB8, RowInts;
	ui				RowBytes;
	cudaDeviceProp	GPUprop;
	ul				SupportedKBlocks, SupportedMBlocks, MaxThrPerBlk;
	// ui				*GPUCopyImg32, *GPUImg32;
	char			SupportedBlocks[100];
	// int				KernelNum=1;
	char			KernelName[255];
	double			RotAngle, deltaAngle;					// rotation angle
	int 			RotIter;
	int 			TotalIters;
	double 			cosRot, sinRot;
	strcpy(ProgName, "imrotateG");
	if(argc!=4){
		printf("\n\nUsage: ./imrotateG infile outfile N");
		return 0;
	}
	strcpy(InputFileName, argv[1]);
	strcpy(OutputFileName, argv[2]);

	// Create CPU memory to store the input and output images
	TheImg = ReadBMPlin(InputFileName); // Read the input image if memory can be allocated
	if (TheImg == NULL){
		printf("Cannot allocate memory for the input image...\n");
		exit(EXIT_FAILURE);
	}
	CopyImg = (uch *)malloc(IMAGESIZE);
	if (CopyImg == NULL){
		free(TheImg);
		printf("Cannot allocate memory for the input image...\n");
		exit(EXIT_FAILURE);
	}

	// Choose which GPU to run on, change this on a multi-GPU system.
	cudaStatus = cudaSetDevice(0);
	if (cudaStatus != cudaSuccess) {
		fprintf(stderr, "cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?");
		exit(EXIT_FAILURE);
	}
	cudaGetDeviceProperties(&GPUprop, 0);
	SupportedKBlocks = (ui)GPUprop.maxGridSize[0] * (ui)GPUprop.maxGridSize[1] * (ui)GPUprop.maxGridSize[2] / 1024;
	SupportedMBlocks = SupportedKBlocks / 1024;
	sprintf(SupportedBlocks, "%lu %c", (SupportedMBlocks >= 5) ? SupportedMBlocks : SupportedKBlocks, (SupportedMBlocks >= 5) ? 'M' : 'K');
	MaxThrPerBlk = (ui)GPUprop.maxThreadsPerBlock;

	// Allocate GPU buffer for the input and output images	
	cudaStatus = cudaMalloc((void**)&GPUImg, IMAGESIZE);
	cudaStatus2 = cudaMalloc((void**)&GPUCopyImg, IMAGESIZE);
	if ((cudaStatus != cudaSuccess) || (cudaStatus2 != cudaSuccess)){
		fprintf(stderr, "cudaMalloc failed! Can't allocate GPU memory");
		exit(EXIT_FAILURE);
	}
	// Copy input vectors from host memory to GPU buffers.
	cudaStatus = cudaMemcpy(GPUImg, TheImg, IMAGESIZE, cudaMemcpyHostToDevice);
	if (cudaStatus != cudaSuccess) {
		fprintf(stderr, "cudaMemcpy  CPU to GPU  failed!");
		exit(EXIT_FAILURE);
	}
	RowBytes = (IPH * 3 + 3) & (~3);
	RowBytes = (IPH * 3 + 3) & (~3);
	BlkPerRow = CEIL(IPH,ThrPerBlk);
	NumBlocks = IPV*BlkPerRow; 

	printf("\nNum blocks: %d\n", NumBlocks);
	printf("\nThread per block: %d\n", ThrPerBlk);
	TotalIters = atoi(argv[3]);
	if(TotalIters > 30){
		printf("\nN is too large, should be less or equal to 30\n");
	}
	deltaAngle = 2*PI/float(TotalIters);
	printf("\nTotal iterations: %d\n", TotalIters);

	// iteration to find all images

	strcpy(OutputFileName, argv[2]);
	char* token = strtok(OutputFileName, ".");
	char* OutputFirstName = token;
	token = strtok(NULL, ".");
	char* OutputLastName = token;

	for(RotIter=1; RotIter<=TotalIters; RotIter++){
		char outName[128]="";		
		char tmp[10];
		sprintf(tmp, "%d", RotIter);
		strcat(outName, OutputFirstName);
		strcat(outName, tmp);
		strcat(outName, ".");
		strcat(outName, OutputLastName);

		cudaEventCreate(&time1);
		cudaEventCreate(&time2);
		cudaEventRecord(time1, 0); // record time1 in the first iteration

		RotAngle = (double)(RotIter-1)*deltaAngle;
		cosRot = cos(RotAngle);
		sinRot = sin(RotAngle);
		printf("\nRotation angle = %lf\n", RotAngle);
		imrotate <<< NumBlocks, ThrPerBlk >>> (GPUCopyImg, GPUImg, IPV, IPH, BlkPerRow, RowBytes, cosRot, sinRot);

		cudaEventRecord(time2, 0); //record time2 in teh last iteration
		cudaEventSynchronize(time1);
		cudaEventSynchronize(time2);
		cudaEventElapsedTime(&tmpKernelExcutionTime, time1, time2);
		totalKernelExecutionTime += tmpKernelExcutionTime;



		strcpy(KernelName, "imrotate : Each thread rotate 1 pixel. Computes everything.\n");
		cudaStatus = cudaDeviceSynchronize();
		if (cudaStatus != cudaSuccess) {
			fprintf(stderr, "\n\ncudaDeviceSynchronize returned error code %d after launching the kernel!\n", cudaStatus);
			exit(EXIT_FAILURE);
		}
		GPUResult = GPUCopyImg;
		cudaStatus = cudaMemcpy(CopyImg, GPUResult, IMAGESIZE, cudaMemcpyDeviceToHost);
		if (cudaStatus != cudaSuccess) {
			fprintf(stderr, "cudaMemcpy GPU to CPU  failed!");
			exit(EXIT_FAILURE);
		}
		cudaStatus = cudaDeviceSynchronize();
			//checkError(cudaGetLastError());	// screen for errors in kernel launches
		if (cudaStatus != cudaSuccess) {
			fprintf(stderr, "\n Program failed after cudaDeviceSynchronize()!");
			free(TheImg);
			free(CopyImg);
			exit(EXIT_FAILURE);
		}
		WriteBMPlin(CopyImg, outName);		// Write the flipped image back to disk
		memset(CopyImg, 0, IMAGESIZE);
		cudaMemset(GPUCopyImg, 0, IMAGESIZE);

	}

	printf("\nTotal Kernel Execution    =%7.2f ms\n", totalKernelExecutionTime);
	
	cudaFree(GPUImg);
	cudaFree(GPUCopyImg);

	cudaStatus = cudaDeviceReset();
	if (cudaStatus != cudaSuccess) {
		fprintf(stderr, "cudaDeviceReset failed!");
		free(TheImg);
		free(CopyImg);
		exit(EXIT_FAILURE);
	}
	free(TheImg);
	free(CopyImg);
	return(EXIT_SUCCESS);
}




	.file	"tmpxft_0038a4c1_00000000-6_imrotateGS.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3640:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3640:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
.LC1:
	.string	"\n\n%s NOT FOUND\n\n"
.LC2:
	.string	"\n Input File name: %17s  (%d x %d)   File Size=%lu"
	.text
	.globl	_Z10ReadBMPlinPc
	.type	_Z10ReadBMPlinPc, @function
_Z10ReadBMPlinPc:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$64, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L3
	movl	$2, %edi
	movq	%rbp, %rdx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L3:
	leaq	2(%rsp), %r12
	movq	%rax, %r8
	movl	$54, %ecx
	movq	%rax, %rbx
	movl	$1, %edx
	movl	$54, %esi
	movq	%r12, %rdi
	call	__fread_chk@PLT
	movl	20(%rsp), %edx
	movl	24(%rsp), %r8d
	movq	%r12, %rsi
	leaq	8+ip(%rip), %r9
	movl	$54, %ecx
	leal	1(%rdx), %eax
	movq	%r9, %rdi
	movslq	%r8d, %r9
	movl	%edx, ip(%rip)
	rep movsb
	leal	(%rax,%rax,2), %eax
	movl	%edx, %ecx
	leaq	.LC2(%rip), %rsi
	andl	$-4, %eax
	movq	%rbp, %rdx
	movl	$2, %edi
	movl	%r8d, 4+ip(%rip)
	cltq
	imulq	%rax, %r9
	movq	%rax, 64+ip(%rip)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movslq	4+ip(%rip), %rbp
	imulq	64+ip(%rip), %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rax, _ZZ10ReadBMPlinPcE3Img(%rip)
	testq	%rax, %rax
	je	.L2
	movq	%rbx, %r8
	movq	%rbp, %rcx
	movl	$1, %edx
	movq	%rbp, %rsi
	movq	%rax, %rdi
	call	__fread_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	_ZZ10ReadBMPlinPcE3Img(%rip), %rax
.L2:
	movq	56(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$64, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z10ReadBMPlinPc, .-_Z10ReadBMPlinPc
	.section	.rodata.str1.1
.LC3:
	.string	"wb"
.LC4:
	.string	"\n\nFILE CREATION ERROR: %s\n\n"
.LC5:
	.string	"\nOutput File name: %17s  (%u x %u)   File Size=%lu"
	.text
	.globl	_Z11WriteBMPlinPhPc
	.type	_Z11WriteBMPlinPhPc, @function
_Z11WriteBMPlinPhPc:
.LFB3636:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rsi, %rbp
	leaq	.LC3(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rbp, %rdi
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L12
	movl	$2, %edi
	movq	%rbp, %rdx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L12:
	movq	%rax, %rcx
	movl	$54, %edx
	movl	$1, %esi
	movq	%rax, %rbx
	leaq	8+ip(%rip), %rdi
	call	fwrite@PLT
	movq	%rbx, %rcx
	movq	%r12, %rdi
	movl	$1, %esi
	movslq	4+ip(%rip), %rdx
	imulq	64+ip(%rip), %rdx
	call	fwrite@PLT
	movl	ip(%rip), %ecx
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movslq	4+ip(%rip), %r9
	imulq	64+ip(%rip), %r9
	movl	$2, %edi
	leaq	.LC5(%rip), %rsi
	movl	4+ip(%rip), %r8d
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE3636:
	.size	_Z11WriteBMPlinPhPc, .-_Z11WriteBMPlinPhPc
	.globl	_Z35__device_stub__Z8imrotatePhS_jjjjddPhS_jjjjdd
	.type	_Z35__device_stub__Z8imrotatePhS_jjjjddPhS_jjjjdd, @function
_Z35__device_stub__Z8imrotatePhS_jjjjddPhS_jjjjdd:
.LFB3662:
	.cfi_startproc
	endbr64
	subq	$200, %rsp
	.cfi_def_cfa_offset 208
	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
	movl	%r8d, 20(%rsp)
	movl	%r9d, 16(%rsp)
	movsd	%xmm0, 8(%rsp)
	movsd	%xmm1, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 184(%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	20(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 168(%rsp)
	movq	%rsp, %rax
	movq	%rax, 176(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	pushq	64(%rsp)
	.cfi_def_cfa_offset 216
	leaq	_Z8imrotatePhS_jjjjdd(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 224
	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 216
	popq	%rdx
	.cfi_def_cfa_offset 208
.L14:
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$200, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3662:
	.size	_Z35__device_stub__Z8imrotatePhS_jjjjddPhS_jjjjdd, .-_Z35__device_stub__Z8imrotatePhS_jjjjddPhS_jjjjdd
	.globl	_Z8imrotatePhS_jjjjdd
	.type	_Z8imrotatePhS_jjjjdd, @function
_Z8imrotatePhS_jjjjdd:
.LFB3663:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z8imrotatePhS_jjjjddPhS_jjjjdd
	.cfi_endproc
.LFE3663:
	.size	_Z8imrotatePhS_jjjjdd, .-_Z8imrotatePhS_jjjjdd
	.section	.rodata.str1.1
.LC6:
	.string	"\n\nUsage: ./imrotateG infile outfile N"
.LC7:
	.string	"Cannot allocate memory for the input image...\n"
.LC8:
	.string	"cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?"
.LC9:
	.string	"%lu %c"
.LC10:
	.string	"cudaMalloc failed! Can't allocate GPU memory"
.LC11:
	.string	"cudaMemcpy  CPU to GPU  failed!"
.LC12:
	.string	"\nNum blocks: %d\n"
.LC13:
	.string	"\nThread per block: %d\n"
.LC14:
	.string	"\nN is too large, should be less or equal to 30\n"
.LC16:
	.string	"\nTotal iterations: %d\n"
.LC17:
	.string	"."
.LC18:
	.string	"%d"
.LC19:
	.string	"\nRotation angle = %lf\n"
.LC20:
	.string	"imrotate : Each thread rotate 1 pixel. Computes everything.\n"
.LC21:
	.string	"\n\ncudaDeviceSynchronize returned error code %d after launching the kernel!\n"
.LC22:
	.string	"cudaMemcpy GPU to CPU  failed!"
.LC23:
	.string	"\n Program failed after cudaDeviceSynchronize()!"
.LC24:
	.string	"\nTotal Kernel Execution    =%7.2f ms\n"
.LC25:
	.string	"cudaDeviceReset failed!"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3637:
	.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	$2424, %rsp
	.cfi_def_cfa_offset 2480
	movq	%fs:40, %rax
	movq	%rax, 2408(%rsp)
	movabsq	$7310575247843028329, %rax
	movw	$71, 1906(%rsp)
	movq	%rax, 1898(%rsp)
	cmpl	$4, %edi
	je	.L20
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L21
.L20:
	leaq	1388(%rsp), %rbx
	movq	%rsi, %r12
	movq	8(%rsi), %rsi
	movl	$255, %edx
	movq	%rbx, %rdi
	leaq	1643(%rsp), %r13
	call	__strcpy_chk@PLT
	movq	16(%r12), %rsi
	movl	$255, %edx
	movq	%r13, %rdi
	call	__strcpy_chk@PLT
	movq	%rbx, %rdi
	call	_Z10ReadBMPlinPc
	movq	%rax, TheImg(%rip)
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.L39
	movslq	4+ip(%rip), %rdi
	imulq	64+ip(%rip), %rdi
	call	malloc@PLT
	movq	%rax, CopyImg(%rip)
	testq	%rax, %rax
	jne	.L23
	movq	%rbx, %rdi
	call	free@PLT
.L39:
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L40:
	movl	$1, %edi
	call	exit@PLT
.L23:
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	leaq	.LC8(%rip), %rdx
	testl	%eax, %eax
	jne	.L41
	leaq	112(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaGetDeviceProperties_v2@PLT
	movl	448(%rsp), %eax
	imull	452(%rsp), %eax
	movl	$75, %r9d
	imull	456(%rsp), %eax
	shrl	$10, %eax
	movl	%eax, %r8d
	cmpl	$5119, %eax
	jbe	.L25
	shrq	$10, %r8
	movl	$77, %r9d
.L25:
	movl	$100, %edx
	leaq	.LC9(%rip), %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	1160(%rsp), %rdi
	call	__sprintf_chk@PLT
	movslq	4+ip(%rip), %rsi
	imulq	64+ip(%rip), %rsi
	leaq	GPUImg(%rip), %rdi
	call	cudaMalloc@PLT
	movslq	4+ip(%rip), %rsi
	imulq	64+ip(%rip), %rsi
	leaq	GPUCopyImg(%rip), %rdi
	movl	%eax, %ebx
	call	cudaMalloc@PLT
	leaq	.LC10(%rip), %rdx
	orl	%ebx, %eax
	jne	.L41
	movslq	4+ip(%rip), %rdx
	imulq	64+ip(%rip), %rdx
	movl	$1, %ecx
	movq	TheImg(%rip), %rsi
	movq	GPUImg(%rip), %rdi
	call	cudaMemcpy@PLT
	leaq	.LC11(%rip), %rdx
	testl	%eax, %eax
	jne	.L41
	movl	ip(%rip), %ebx
	movl	4+ip(%rip), %r14d
	movl	$2, %edi
	leaq	.LC12(%rip), %rsi
	leal	1(%rbx), %eax
	addl	$127, %ebx
	shrl	$7, %ebx
	leal	(%rax,%rax,2), %eax
	imull	%ebx, %r14d
	andl	$-4, %eax
	movl	%eax, 12(%rsp)
	xorl	%eax, %eax
	movl	%r14d, %edx
	call	__printf_chk@PLT
	movl	$128, %edx
	leaq	.LC13(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	24(%r12), %rdi
	call	atoi@PLT
	movl	%eax, %ebp
	cmpl	$30, %eax
	jle	.L28
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L28:
	cvtsi2ssl	%ebp, %xmm0
	movsd	.LC15(%rip), %xmm1
	movl	%ebp, %edx
	xorl	%eax, %eax
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	cvtss2sd	%xmm0, %xmm0
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 16(%rsp)
	call	__printf_chk@PLT
	movq	16(%r12), %rsi
	movl	$255, %edx
	movq	%r13, %rdi
	leaq	.LC17(%rip), %r12
	call	__strcpy_chk@PLT
	movq	%r12, %rsi
	movq	%r13, %rdi
	call	strtok@PLT
	movq	%r12, %rsi
	xorl	%edi, %edi
	movl	$1, %r12d
	movq	%rax, 24(%rsp)
	call	strtok@PLT
	movq	%rax, 32(%rsp)
	jmp	.L29
.L31:
	movslq	4+ip(%rip), %rdx
	imulq	64+ip(%rip), %rdx
	movl	$2, %ecx
	movq	GPUCopyImg(%rip), %rsi
	movq	CopyImg(%rip), %rdi
	movq	%rsi, GPUResult(%rip)
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L32
	leaq	.LC22(%rip), %rdx
.L41:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L40
.L33:
	movq	CopyImg(%rip), %rdi
	movq	%r13, %rsi
	incl	%r12d
	call	_Z11WriteBMPlinPhPc
	movslq	4+ip(%rip), %rcx
	xorl	%eax, %eax
	xorl	%esi, %esi
	imulq	64+ip(%rip), %rcx
	movq	CopyImg(%rip), %rdi
	rep stosb
	movslq	4+ip(%rip), %rdx
	imulq	64+ip(%rip), %rdx
	movq	GPUCopyImg(%rip), %rdi
	call	cudaMemset@PLT
.L29:
	cmpl	%ebp, %r12d
	jg	.L43
	xorl	%eax, %eax
	movl	$32, %ecx
	movl	%r12d, %r8d
	movl	$10, %edx
	leaq	1150(%rsp), %r15
	leaq	1260(%rsp), %rdi
	movl	$2, %esi
	rep stosl
	leaq	.LC18(%rip), %rcx
	movq	%r15, %rdi
	leaq	1260(%rsp), %r13
	call	__sprintf_chk@PLT
	movq	24(%rsp), %rsi
	movl	$128, %edx
	movq	%r13, %rdi
	call	__strcat_chk@PLT
	movl	$128, %edx
	movq	%r15, %rsi
	movq	%r13, %rdi
	call	__strcat_chk@PLT
	movl	$128, %edx
	leaq	.LC17(%rip), %rsi
	movq	%r13, %rdi
	call	__strcat_chk@PLT
	movq	32(%rsp), %rsi
	movl	$128, %edx
	movq	%r13, %rdi
	call	__strcat_chk@PLT
	leaq	72(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	80(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	leal	-1(%r12), %eax
	movl	$2, %edi
	leaq	.LC19(%rip), %rsi
	cvtsi2sdl	%eax, %xmm0
	mulsd	16(%rsp), %xmm0
	movb	$1, %al
	movsd	%xmm0, 40(%rsp)
	call	__printf_chk@PLT
	movl	%r14d, 88(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	$33554433, %edx
	movl	$1, %ecx
	movq	%rax, 92(%rsp)
	movq	88(%rsp), %rdi
	salq	$7, %rdx
	movl	96(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	movsd	40(%rsp), %xmm0
	testl	%eax, %eax
	jne	.L30
	leaq	56(%rsp), %rdi
	leaq	48(%rsp), %rsi
	call	sincos@PLT
	movsd	56(%rsp), %xmm1
	movl	12(%rsp), %r9d
	movl	%ebx, %r8d
	movsd	48(%rsp), %xmm0
	movl	ip(%rip), %ecx
	movl	4+ip(%rip), %edx
	movq	GPUImg(%rip), %rsi
	movq	GPUCopyImg(%rip), %rdi
	call	_Z35__device_stub__Z8imrotatePhS_jjjjddPhS_jjjjdd
.L30:
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	72(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	80(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	80(%rsp), %rdx
	movq	72(%rsp), %rsi
	leaq	68(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movss	8(%rsp), %xmm2
	addss	68(%rsp), %xmm2
	leaq	2153(%rsp), %rax
	movq	%rax, %rdi
	leaq	.LC20(%rip), %rsi
	movl	$61, %ecx
	rep movsb
	movss	%xmm2, 8(%rsp)
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %ecx
	testl	%eax, %eax
	je	.L31
	movq	stderr(%rip), %rdi
	leaq	.LC21(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L40
.L32:
	call	cudaDeviceSynchronize@PLT
	testl	%eax, %eax
	je	.L33
	leaq	.LC23(%rip), %rdx
	jmp	.L42
.L43:
	leaq	.LC24(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	8(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	GPUImg(%rip), %rdi
	call	cudaFree@PLT
	movq	GPUCopyImg(%rip), %rdi
	call	cudaFree@PLT
	call	cudaDeviceReset@PLT
	testl	%eax, %eax
	je	.L35
	leaq	.LC25(%rip), %rdx
.L42:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	TheImg(%rip), %rdi
	call	free@PLT
	movq	CopyImg(%rip), %rdi
	call	free@PLT
	jmp	.L40
.L35:
	movq	TheImg(%rip), %rdi
	call	free@PLT
	movq	CopyImg(%rip), %rdi
	call	free@PLT
.L21:
	movq	2408(%rsp), %rax
	subq	%fs:40, %rax
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	addq	$2424, %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
.LFE3637:
	.size	main, .-main
	.section	.rodata.str1.1
.LC27:
	.string	"_Z8imrotatePhS_jjjjdd"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3665:
	.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	.LC27(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z8imrotatePhS_jjjjdd(%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
.LFE3665:
	.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
	.local	_ZZ10ReadBMPlinPcE3Img
	.comm	_ZZ10ReadBMPlinPcE3Img,8,8
	.globl	ip
	.bss
	.align 32
	.type	ip, @object
	.size	ip, 72
ip:
	.zero	72
	.globl	GPUResult
	.align 8
	.type	GPUResult, @object
	.size	GPUResult, 8
GPUResult:
	.zero	8
	.globl	GPUCopyImg
	.align 8
	.type	GPUCopyImg, @object
	.size	GPUCopyImg, 8
GPUCopyImg:
	.zero	8
	.globl	GPUImg
	.align 8
	.type	GPUImg, @object
	.size	GPUImg, 8
GPUImg:
	.zero	8
	.globl	CopyImg
	.align 8
	.type	CopyImg, @object
	.size	CopyImg, 8
CopyImg:
	.zero	8
	.globl	TheImg
	.align 8
	.type	TheImg, @object
	.size	TheImg, 8
TheImg:
	.zero	8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC15:
	.long	1405670641
	.long	1075388923
	.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 <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <iostream>
#include <ctype.h>

#include <math.h>

#define	CEIL(a,b)		((a+b-1)/b)
#define SWAP(a,b,t)		t=b; b=a; a=t;
#define DATAMB(bytes)			(bytes/1024/1024)
#define DATABW(bytes,timems)	((float)bytes/(timems * 1.024*1024.0*1024.0))
#define PI 3.14159265
typedef unsigned char uch;
typedef unsigned long ul;
typedef unsigned int  ui;

uch *TheImg, *CopyImg;					// Where images are stored in CPU
uch *GPUImg, *GPUCopyImg, *GPUResult;	// Where images are stored in GPU

struct ImgProp{
	int Hpixels;
	int Vpixels;
	uch HeaderInfo[54];
	ul Hbytes;
} ip;

#define	IPHB		ip.Hbytes
#define	IPH			ip.Hpixels
#define	IPV			ip.Vpixels
#define	IMAGESIZE	(IPHB*IPV)
#define	IMAGEPIX	(IPH*IPV)



// Kernel that flips the given image horizontally
// each thread only flips a single pixel (R,G,B)
__global__
void imrotate(uch *ImgDst, uch *ImgSrc, ui Vpixels, ui Hpixels, ui BlkPerRow, ui RowBytes, double cosRot, double sinRot)
{	
	__shared__ uch PixBuffer[3072*16];

	ui ThrPerBlk = blockDim.x;
	ui MYbid = blockIdx.x;
	ui MYtid = threadIdx.x;
	ui MYgtid = ThrPerBlk * MYbid + MYtid;

	ui MYrow = MYbid / BlkPerRow;
	ui MYcol = MYgtid - MYrow*BlkPerRow*ThrPerBlk;
	if (MYcol >= Hpixels) return;			// col out of range
	ui MYsrcOffset = MYrow * RowBytes;
	ui MYsrcIndex = MYsrcOffset + 3 * MYcol;

	////////////// find destination index	
	int c, h, v, X, Y, NewCol, NewRow;
	double newX, newY, H, V, Diagonal, ScaleFactor;

	c=MYcol;  		h=Hpixels/2;   v=Vpixels/2;	// integer div
	X=(double)c-(double)h;
	Y=(double)v-(double)MYrow;
	
	// pixel rotation matrix
	newX=cosRot*X-sinRot*Y;
	newY=sinRot*X+cosRot*Y;
	
	// Scale to fit everything in the image box
	H=(double)Hpixels;
	V=(double)Vpixels;
	Diagonal=sqrt(H*H+V*V);
	ScaleFactor=(Hpixels>Vpixels) ? V/Diagonal : H/Diagonal;
	newX=newX*ScaleFactor;
	newY=newY*ScaleFactor;
	
	// convert back from Cartesian to image coordinates
	NewCol=((int) newX+h);
	NewRow=v-(int)newY;
	ui MYdstOffset = NewRow*RowBytes;
	ui MYdstIndex = MYdstOffset + 3 * NewCol;
	///////////////	
	ui Mytid3 = MYtid*3;
	PixBuffer[Mytid3] = ImgSrc[MYsrcIndex];
	PixBuffer[Mytid3+1] = ImgSrc[MYsrcIndex+1];
	PixBuffer[Mytid3+2] = ImgSrc[MYsrcIndex+2];
	__syncthreads();

	// swap pixels RGB   @MYcol , @MYmirrorcol
	ImgDst[MYdstIndex] = PixBuffer[Mytid3];
	ImgDst[MYdstIndex + 1] = PixBuffer[Mytid3+1];
	ImgDst[MYdstIndex + 2] = PixBuffer[Mytid3+2];
}






// Read a 24-bit/pixel BMP file into a 1D linear array.
// Allocate memory to store the 1D image and return its pointer.
uch *ReadBMPlin(char* fn)
{
	static uch *Img;
	FILE* f = fopen(fn, "rb");
	if (f == NULL){	printf("\n\n%s NOT FOUND\n\n", fn);	exit(EXIT_FAILURE); }

	uch HeaderInfo[54];
	fread(HeaderInfo, sizeof(uch), 54, f); // read the 54-byte header
	// extract image height and width from header
	int width = *(int*)&HeaderInfo[18];			ip.Hpixels = width;
	int height = *(int*)&HeaderInfo[22];		ip.Vpixels = height;
	int RowBytes = (width * 3 + 3) & (~3);		ip.Hbytes = RowBytes;
	//save header for re-use
	memcpy(ip.HeaderInfo, HeaderInfo,54);
	printf("\n Input File name: %17s  (%d x %d)   File Size=%lu", fn, 
			ip.Hpixels, ip.Vpixels, IMAGESIZE);
	// allocate memory to store the main image (1 Dimensional array)
	Img  = (uch *)malloc(IMAGESIZE);
	if (Img == NULL) return Img;      // Cannot allocate memory
	// read the image from disk
	fread(Img, sizeof(uch), IMAGESIZE, f);
	fclose(f);
	return Img;
}


// Write the 1D linear-memory stored image into file.
void WriteBMPlin(uch *Img, char* fn)
{
	FILE* f = fopen(fn, "wb");
	if (f == NULL){ printf("\n\nFILE CREATION ERROR: %s\n\n", fn); exit(1); }
	//write header
	fwrite(ip.HeaderInfo, sizeof(uch), 54, f);
	//write data
	fwrite(Img, sizeof(uch), IMAGESIZE, f);
	printf("\nOutput File name: %17s  (%u x %u)   File Size=%lu", fn, ip.Hpixels, ip.Vpixels, IMAGESIZE);
	fclose(f);
}


int main(int argc, char **argv)
{
	// char			Flip = 'H';
	float			tmpKernelExcutionTime, totalKernelExecutionTime; // GPU code run times
	hipError_t		cudaStatus, cudaStatus2;
	hipEvent_t		time1, time2;
	char			InputFileName[255], OutputFileName[255], ProgName[255];
	ui				BlkPerRow;
	// ui 			BlkPerRowInt, BlkPerRowInt2;
	ui				ThrPerBlk = 128, NumBlocks;
	// ui 				NB2, NB4, NB8, RowInts;
	ui				RowBytes;
	hipDeviceProp_t	GPUprop;
	ul				SupportedKBlocks, SupportedMBlocks, MaxThrPerBlk;
	// ui				*GPUCopyImg32, *GPUImg32;
	char			SupportedBlocks[100];
	// int				KernelNum=1;
	char			KernelName[255];
	double			RotAngle, deltaAngle;					// rotation angle
	int 			RotIter;
	int 			TotalIters;
	double 			cosRot, sinRot;
	strcpy(ProgName, "imrotateG");
	if(argc!=4){
		printf("\n\nUsage: ./imrotateG infile outfile N");
		return 0;
	}
	strcpy(InputFileName, argv[1]);
	strcpy(OutputFileName, argv[2]);

	// Create CPU memory to store the input and output images
	TheImg = ReadBMPlin(InputFileName); // Read the input image if memory can be allocated
	if (TheImg == NULL){
		printf("Cannot allocate memory for the input image...\n");
		exit(EXIT_FAILURE);
	}
	CopyImg = (uch *)malloc(IMAGESIZE);
	if (CopyImg == NULL){
		free(TheImg);
		printf("Cannot allocate memory for the input image...\n");
		exit(EXIT_FAILURE);
	}

	// Choose which GPU to run on, change this on a multi-GPU system.
	cudaStatus = hipSetDevice(0);
	if (cudaStatus != hipSuccess) {
		fprintf(stderr, "hipSetDevice failed!  Do you have a CUDA-capable GPU installed?");
		exit(EXIT_FAILURE);
	}
	hipGetDeviceProperties(&GPUprop, 0);
	SupportedKBlocks = (ui)GPUprop.maxGridSize[0] * (ui)GPUprop.maxGridSize[1] * (ui)GPUprop.maxGridSize[2] / 1024;
	SupportedMBlocks = SupportedKBlocks / 1024;
	sprintf(SupportedBlocks, "%lu %c", (SupportedMBlocks >= 5) ? SupportedMBlocks : SupportedKBlocks, (SupportedMBlocks >= 5) ? 'M' : 'K');
	MaxThrPerBlk = (ui)GPUprop.maxThreadsPerBlock;

	// Allocate GPU buffer for the input and output images	
	cudaStatus = hipMalloc((void**)&GPUImg, IMAGESIZE);
	cudaStatus2 = hipMalloc((void**)&GPUCopyImg, IMAGESIZE);
	if ((cudaStatus != hipSuccess) || (cudaStatus2 != hipSuccess)){
		fprintf(stderr, "hipMalloc failed! Can't allocate GPU memory");
		exit(EXIT_FAILURE);
	}
	// Copy input vectors from host memory to GPU buffers.
	cudaStatus = hipMemcpy(GPUImg, TheImg, IMAGESIZE, hipMemcpyHostToDevice);
	if (cudaStatus != hipSuccess) {
		fprintf(stderr, "hipMemcpy  CPU to GPU  failed!");
		exit(EXIT_FAILURE);
	}
	RowBytes = (IPH * 3 + 3) & (~3);
	RowBytes = (IPH * 3 + 3) & (~3);
	BlkPerRow = CEIL(IPH,ThrPerBlk);
	NumBlocks = IPV*BlkPerRow; 

	printf("\nNum blocks: %d\n", NumBlocks);
	printf("\nThread per block: %d\n", ThrPerBlk);
	TotalIters = atoi(argv[3]);
	if(TotalIters > 30){
		printf("\nN is too large, should be less or equal to 30\n");
	}
	deltaAngle = 2*PI/float(TotalIters);
	printf("\nTotal iterations: %d\n", TotalIters);

	// iteration to find all images

	strcpy(OutputFileName, argv[2]);
	char* token = strtok(OutputFileName, ".");
	char* OutputFirstName = token;
	token = strtok(NULL, ".");
	char* OutputLastName = token;

	for(RotIter=1; RotIter<=TotalIters; RotIter++){
		char outName[128]="";		
		char tmp[10];
		sprintf(tmp, "%d", RotIter);
		strcat(outName, OutputFirstName);
		strcat(outName, tmp);
		strcat(outName, ".");
		strcat(outName, OutputLastName);

		hipEventCreate(&time1);
		hipEventCreate(&time2);
		hipEventRecord(time1, 0); // record time1 in the first iteration

		RotAngle = (double)(RotIter-1)*deltaAngle;
		cosRot = cos(RotAngle);
		sinRot = sin(RotAngle);
		printf("\nRotation angle = %lf\n", RotAngle);
		imrotate <<< NumBlocks, ThrPerBlk >>> (GPUCopyImg, GPUImg, IPV, IPH, BlkPerRow, RowBytes, cosRot, sinRot);

		hipEventRecord(time2, 0); //record time2 in teh last iteration
		hipEventSynchronize(time1);
		hipEventSynchronize(time2);
		hipEventElapsedTime(&tmpKernelExcutionTime, time1, time2);
		totalKernelExecutionTime += tmpKernelExcutionTime;



		strcpy(KernelName, "imrotate : Each thread rotate 1 pixel. Computes everything.\n");
		cudaStatus = hipDeviceSynchronize();
		if (cudaStatus != hipSuccess) {
			fprintf(stderr, "\n\nhipDeviceSynchronize returned error code %d after launching the kernel!\n", cudaStatus);
			exit(EXIT_FAILURE);
		}
		GPUResult = GPUCopyImg;
		cudaStatus = hipMemcpy(CopyImg, GPUResult, IMAGESIZE, hipMemcpyDeviceToHost);
		if (cudaStatus != hipSuccess) {
			fprintf(stderr, "hipMemcpy GPU to CPU  failed!");
			exit(EXIT_FAILURE);
		}
		cudaStatus = hipDeviceSynchronize();
			//checkError(cudaGetLastError());	// screen for errors in kernel launches
		if (cudaStatus != hipSuccess) {
			fprintf(stderr, "\n Program failed after cudaDeviceSynchronize()!");
			free(TheImg);
			free(CopyImg);
			exit(EXIT_FAILURE);
		}
		WriteBMPlin(CopyImg, outName);		// Write the flipped image back to disk
		memset(CopyImg, 0, IMAGESIZE);
		hipMemset(GPUCopyImg, 0, IMAGESIZE);

	}

	printf("\nTotal Kernel Execution    =%7.2f ms\n", totalKernelExecutionTime);
	
	hipFree(GPUImg);
	hipFree(GPUCopyImg);

	cudaStatus = hipDeviceReset();
	if (cudaStatus != hipSuccess) {
		fprintf(stderr, "hipDeviceReset failed!");
		free(TheImg);
		free(CopyImg);
		exit(EXIT_FAILURE);
	}
	free(TheImg);
	free(CopyImg);
	return(EXIT_SUCCESS);
}




	.text
	.file	"imrotateGS.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z23__device_stub__imrotatePhS_jjjjdd # -- Begin function _Z23__device_stub__imrotatePhS_jjjjdd
	.type	_Z23__device_stub__imrotatePhS_jjjjdd,@function
_Z23__device_stub__imrotatePhS_jjjjdd:  # @_Z23__device_stub__imrotatePhS_jjjjdd
	.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	$160, %rsp
	.cfi_def_cfa_offset 208
	.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	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	movq	%rsp, %r8
	movl	%r9d, (%r8)
	leaq	40(%rsp), %r9
	movsd	%xmm0, (%r9)
	leaq	32(%rsp), %r10
	movsd	%xmm1, (%r10)
	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)
	movq	%r9, 48(%rbx)
	movq	%r10, 56(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z8imrotatePhS_jjjjdd, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	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__imrotatePhS_jjjjdd, .Lfunc_end0-_Z23__device_stub__imrotatePhS_jjjjdd
	.cfi_endproc
                                        # -- End function
	.globl	_Z10ReadBMPlinPc                # -- Begin function _Z10ReadBMPlinPc
	.type	_Z10ReadBMPlinPc,@function
_Z10ReadBMPlinPc:                       # @_Z10ReadBMPlinPc
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$64, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %r14
	movl	$.L.str, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_4
# %bb.1:
	movq	%rax, %rbx
	movq	%rsp, %r15
	movl	$1, %esi
	movl	$54, %edx
	movq	%r15, %rdi
	movq	%rax, %rcx
	callq	fread
	movslq	18(%r15), %rdx
	movl	%edx, ip(%rip)
	movslq	22(%r15), %rcx
	movl	%ecx, ip+4(%rip)
	leaq	(%rdx,%rdx,2), %r8
	addq	$3, %r8
	andq	$-4, %r8
	movq	%r8, ip+64(%rip)
	movaps	(%r15), %xmm0
	movaps	16(%r15), %xmm1
	movaps	32(%r15), %xmm2
	movups	%xmm0, ip+8(%rip)
	movups	%xmm1, ip+24(%rip)
	movups	%xmm2, ip+40(%rip)
	movq	46(%r15), %rax
	movq	%rax, ip+54(%rip)
	imulq	%rcx, %r8
	xorl	%r15d, %r15d
	movl	$.L.str.2, %edi
	movq	%r14, %rsi
                                        # kill: def $edx killed $edx killed $rdx
                                        # kill: def $ecx killed $ecx killed $rcx
	xorl	%eax, %eax
	callq	printf
	movslq	ip+4(%rip), %r14
	imulq	ip+64(%rip), %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, _ZZ10ReadBMPlinPcE3Img(%rip)
	testq	%rax, %rax
	je	.LBB1_3
# %bb.2:
	movl	$1, %esi
	movq	%rax, %rdi
	movq	%r14, %rdx
	movq	%rbx, %rcx
	callq	fread
	movq	%rbx, %rdi
	callq	fclose
	movq	_ZZ10ReadBMPlinPcE3Img(%rip), %r15
.LBB1_3:
	movq	%r15, %rax
	addq	$64, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB1_4:
	.cfi_def_cfa_offset 96
	movl	$.L.str.1, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z10ReadBMPlinPc, .Lfunc_end1-_Z10ReadBMPlinPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z11WriteBMPlinPhPc             # -- Begin function _Z11WriteBMPlinPhPc
	.type	_Z11WriteBMPlinPhPc,@function
_Z11WriteBMPlinPhPc:                    # @_Z11WriteBMPlinPhPc
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r15
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB2_1
# %bb.2:
	movq	%rax, %r14
	movl	$ip+8, %edi
	movl	$1, %esi
	movl	$54, %edx
	movq	%rax, %rcx
	callq	fwrite
	movslq	ip+4(%rip), %rdx
	imulq	ip+64(%rip), %rdx
	movl	$1, %esi
	movq	%r15, %rdi
	movq	%r14, %rcx
	callq	fwrite
	movl	ip(%rip), %edx
	movslq	ip+4(%rip), %rcx
	movq	%rcx, %r8
	imulq	ip+64(%rip), %r8
	movl	$.L.str.5, %edi
	movq	%rbx, %rsi
                                        # kill: def $ecx killed $ecx killed $rcx
	xorl	%eax, %eax
	callq	printf
	movq	%r14, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.LBB2_1:
	.cfi_def_cfa_offset 32
	movl	$.L.str.4, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z11WriteBMPlinPhPc, .Lfunc_end2-_Z11WriteBMPlinPhPc
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI3_0:
	.quad	0x401921fb53c8d4f1              # double 6.2831853000000004
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.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	$2344, %rsp                     # imm = 0x928
	.cfi_def_cfa_offset 2400
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$4, %edi
	jne	.LBB3_17
# %bb.1:
	movq	%rsi, %rbx
	movq	8(%rsi), %rsi
	leaq	608(%rsp), %r14
	movq	%r14, %rdi
	callq	strcpy
	movq	16(%rbx), %rsi
	leaq	352(%rsp), %rdi
	callq	strcpy
	movq	%r14, %rdi
	callq	_Z10ReadBMPlinPc
	movq	%rax, TheImg(%rip)
	testq	%rax, %rax
	je	.LBB3_25
# %bb.2:
	movq	%rax, %r14
	movslq	ip+4(%rip), %rdi
	imulq	ip+64(%rip), %rdi
	callq	malloc
	movq	%rax, CopyImg(%rip)
	testq	%rax, %rax
	je	.LBB3_24
# %bb.3:
	xorl	%edi, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB3_27
# %bb.4:
	leaq	872(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	movl	340(%r14), %eax
	imull	336(%r14), %eax
	imull	344(%r14), %eax
	movl	%eax, %ecx
	shrl	$10, %ecx
	movl	%eax, %edx
	shrl	$20, %edx
	xorl	%esi, %esi
	cmpl	$5242880, %eax                  # imm = 0x500000
	setae	%sil
	cmovbq	%rcx, %rdx
	leal	75(,%rsi,2), %ecx
	leaq	240(%rsp), %rdi
	movl	$.L.str.10, %esi
	xorl	%eax, %eax
	callq	sprintf
	movslq	ip+4(%rip), %rsi
	imulq	ip+64(%rip), %rsi
	movl	$GPUImg, %edi
	callq	hipMalloc
	movl	%eax, %ebp
	movslq	ip+4(%rip), %rsi
	imulq	ip+64(%rip), %rsi
	movl	$GPUCopyImg, %edi
	callq	hipMalloc
	orl	%ebp, %eax
	jne	.LBB3_28
# %bb.5:
	movq	GPUImg(%rip), %rdi
	movq	TheImg(%rip), %rsi
	movslq	ip+4(%rip), %rdx
	imulq	ip+64(%rip), %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_29
# %bb.6:
	movl	ip(%rip), %eax
	leal	(%rax,%rax,2), %ecx
	addl	$3, %ecx
	movl	%ecx, 12(%rsp)                  # 4-byte Spill
	addl	$127, %eax
	shrl	$7, %eax
	movl	ip+4(%rip), %ebp
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	imull	%eax, %ebp
	movl	$.L.str.13, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.14, %edi
	movl	$128, %esi
	xorl	%eax, %eax
	callq	printf
	movq	24(%rbx), %rdi
	callq	atoi
	movl	%eax, 16(%rsp)                  # 4-byte Spill
	cmpl	$31, %eax
	jl	.LBB3_8
# %bb.7:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB3_8:                                # %.lr.ph
	andl	$-4, 12(%rsp)                   # 4-byte Folded Spill
	movl	16(%rsp), %esi                  # 4-byte Reload
	cvtsi2ss	%esi, %xmm0
	movabsq	$4294967296, %r12               # imm = 0x100000000
	cvtss2sd	%xmm0, %xmm0
	movsd	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 72(%rsp)                 # 8-byte Spill
	movl	$.L.str.16, %edi
	xorl	%eax, %eax
	callq	printf
	movq	16(%rbx), %rsi
	leaq	352(%rsp), %rbx
	movq	%rbx, %rdi
	callq	strcpy
	movl	$.L.str.17, %esi
	movq	%rbx, %rdi
	callq	strtok
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	movl	$.L.str.17, %esi
	xorl	%edi, %edi
	callq	strtok
	movq	%rax, %r13
	movl	%ebp, %ebp
	btsq	$32, %rbp
	movl	$1, %ebx
	leaq	102(%rsp), %r14
	leaq	112(%rsp), %r15
	subq	$-128, %r12
                                        # implicit-def: $xmm0
                                        # kill: killed $xmm0
.LBB3_9:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	movaps	%xmm0, 224(%rsp)
	movaps	%xmm0, 208(%rsp)
	movaps	%xmm0, 192(%rsp)
	movaps	%xmm0, 176(%rsp)
	movaps	%xmm0, 160(%rsp)
	movaps	%xmm0, 144(%rsp)
	movaps	%xmm0, 128(%rsp)
	movaps	%xmm0, 112(%rsp)
	movl	$.L.str.18, %esi
	movq	%r14, %rdi
	movl	%ebx, %edx
	xorl	%eax, %eax
	callq	sprintf
	movq	%r15, %rdi
	movq	64(%rsp), %rsi                  # 8-byte Reload
	callq	strcat
	movq	%r15, %rdi
	movq	%r14, %rsi
	callq	strcat
	movq	%r15, %rdi
	callq	strlen@PLT
	movw	$46, 112(%rsp,%rax)
	movq	%r15, %rdi
	movq	%r13, %rsi
	callq	strcat
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	decl	%ebx
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ebx, %xmm0
	mulsd	72(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 48(%rsp)                 # 8-byte Spill
	callq	cos
	movsd	%xmm0, 88(%rsp)                 # 8-byte Spill
	movsd	48(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sin
	movsd	%xmm0, 80(%rsp)                 # 8-byte Spill
	movl	$.L.str.19, %edi
	movsd	48(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movq	%rbp, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_11
# %bb.10:                               #   in Loop: Header=BB3_9 Depth=1
	movq	GPUCopyImg(%rip), %rdi
	movq	GPUImg(%rip), %rsi
	movl	ip+4(%rip), %edx
	movl	ip(%rip), %ecx
	movq	56(%rsp), %r8                   # 8-byte Reload
                                        # kill: def $r8d killed $r8d killed $r8
	movl	12(%rsp), %r9d                  # 4-byte Reload
	movsd	88(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movsd	80(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	callq	_Z23__device_stub__imrotatePhS_jjjjdd
.LBB3_11:                               #   in Loop: Header=BB3_9 Depth=1
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	32(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rdi
	callq	hipEventSynchronize
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdx
	leaq	44(%rsp), %rdi
	callq	hipEventElapsedTime
	movss	20(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	addss	44(%rsp), %xmm0
	movss	%xmm0, 20(%rsp)                 # 4-byte Spill
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB3_23
# %bb.12:                               #   in Loop: Header=BB3_9 Depth=1
	movq	GPUCopyImg(%rip), %rsi
	movq	%rsi, GPUResult(%rip)
	movq	CopyImg(%rip), %rdi
	movslq	ip+4(%rip), %rdx
	imulq	ip+64(%rip), %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_21
# %bb.13:                               #   in Loop: Header=BB3_9 Depth=1
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB3_19
# %bb.14:                               #   in Loop: Header=BB3_9 Depth=1
	movq	CopyImg(%rip), %rdi
	movq	%r15, %rsi
	callq	_Z11WriteBMPlinPhPc
	movq	CopyImg(%rip), %rdi
	movslq	ip+4(%rip), %rdx
	imulq	ip+64(%rip), %rdx
	xorl	%esi, %esi
	callq	memset@PLT
	movq	GPUCopyImg(%rip), %rdi
	movslq	ip+4(%rip), %rdx
	imulq	ip+64(%rip), %rdx
	xorl	%esi, %esi
	callq	hipMemset
	leal	1(%rbx), %eax
	addl	$2, %ebx
	cmpl	16(%rsp), %eax                  # 4-byte Folded Reload
	jne	.LBB3_9
# %bb.15:                               # %._crit_edge.loopexit
	xorps	%xmm0, %xmm0
	cvtss2sd	20(%rsp), %xmm0                 # 4-byte Folded Reload
	movl	$.L.str.24, %edi
	movb	$1, %al
	callq	printf
	movq	GPUImg(%rip), %rdi
	callq	hipFree
	movq	GPUCopyImg(%rip), %rdi
	callq	hipFree
	callq	hipDeviceReset
	testl	%eax, %eax
	jne	.LBB3_30
# %bb.16:
	movq	TheImg(%rip), %rdi
	callq	free
	movq	CopyImg(%rip), %rdi
	callq	free
	jmp	.LBB3_18
.LBB3_17:
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
.LBB3_18:
	xorl	%eax, %eax
	addq	$2344, %rsp                     # imm = 0x928
	.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
.LBB3_19:
	.cfi_def_cfa_offset 2400
	movq	stderr(%rip), %rcx
	movl	$.L.str.23, %edi
	movl	$47, %esi
.LBB3_20:
	movl	$1, %edx
	callq	fwrite
	movq	TheImg(%rip), %rdi
	callq	free
	movq	CopyImg(%rip), %rdi
	callq	free
	jmp	.LBB3_26
.LBB3_21:
	movq	stderr(%rip), %rcx
	movl	$.L.str.22, %edi
	movl	$29, %esi
.LBB3_22:
	movl	$1, %edx
	callq	fwrite
	jmp	.LBB3_26
.LBB3_23:
	movq	stderr(%rip), %rdi
	movl	$.L.str.21, %esi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
.LBB3_26:
	movl	$1, %edi
	callq	exit
.LBB3_24:
	movq	%r14, %rdi
	callq	free
.LBB3_25:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	jmp	.LBB3_26
.LBB3_27:
	movq	stderr(%rip), %rcx
	movl	$.L.str.9, %edi
	movl	$63, %esi
	jmp	.LBB3_22
.LBB3_28:
	movq	stderr(%rip), %rcx
	movl	$.L.str.11, %edi
	movl	$43, %esi
	jmp	.LBB3_22
.LBB3_29:
	movq	stderr(%rip), %rcx
	movl	$.L.str.12, %edi
	movl	$30, %esi
	jmp	.LBB3_22
.LBB3_30:
	movq	stderr(%rip), %rcx
	movl	$.L.str.25, %edi
	movl	$22, %esi
	jmp	.LBB3_20
.Lfunc_end3:
	.size	main, .Lfunc_end3-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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8imrotatePhS_jjjjdd, %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_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	TheImg,@object                  # @TheImg
	.bss
	.globl	TheImg
	.p2align	3, 0x0
TheImg:
	.quad	0
	.size	TheImg, 8

	.type	CopyImg,@object                 # @CopyImg
	.globl	CopyImg
	.p2align	3, 0x0
CopyImg:
	.quad	0
	.size	CopyImg, 8

	.type	GPUImg,@object                  # @GPUImg
	.globl	GPUImg
	.p2align	3, 0x0
GPUImg:
	.quad	0
	.size	GPUImg, 8

	.type	GPUCopyImg,@object              # @GPUCopyImg
	.globl	GPUCopyImg
	.p2align	3, 0x0
GPUCopyImg:
	.quad	0
	.size	GPUCopyImg, 8

	.type	GPUResult,@object               # @GPUResult
	.globl	GPUResult
	.p2align	3, 0x0
GPUResult:
	.quad	0
	.size	GPUResult, 8

	.type	ip,@object                      # @ip
	.globl	ip
	.p2align	3, 0x0
ip:
	.zero	72
	.size	ip, 72

	.type	_Z8imrotatePhS_jjjjdd,@object   # @_Z8imrotatePhS_jjjjdd
	.section	.rodata,"a",@progbits
	.globl	_Z8imrotatePhS_jjjjdd
	.p2align	3, 0x0
_Z8imrotatePhS_jjjjdd:
	.quad	_Z23__device_stub__imrotatePhS_jjjjdd
	.size	_Z8imrotatePhS_jjjjdd, 8

	.type	_ZZ10ReadBMPlinPcE3Img,@object  # @_ZZ10ReadBMPlinPcE3Img
	.local	_ZZ10ReadBMPlinPcE3Img
	.comm	_ZZ10ReadBMPlinPcE3Img,8,8
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"rb"
	.size	.L.str, 3

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"\n\n%s NOT FOUND\n\n"
	.size	.L.str.1, 17

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\n Input File name: %17s  (%d x %d)   File Size=%lu"
	.size	.L.str.2, 51

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\n\nFILE CREATION ERROR: %s\n\n"
	.size	.L.str.4, 28

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\nOutput File name: %17s  (%u x %u)   File Size=%lu"
	.size	.L.str.5, 51

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"\n\nUsage: ./imrotateG infile outfile N"
	.size	.L.str.7, 38

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"hipSetDevice failed!  Do you have a CUDA-capable GPU installed?"
	.size	.L.str.9, 64

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"%lu %c"
	.size	.L.str.10, 7

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"hipMalloc failed! Can't allocate GPU memory"
	.size	.L.str.11, 44

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"hipMemcpy  CPU to GPU  failed!"
	.size	.L.str.12, 31

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"\nNum blocks: %d\n"
	.size	.L.str.13, 17

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"\nThread per block: %d\n"
	.size	.L.str.14, 23

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"\nTotal iterations: %d\n"
	.size	.L.str.16, 23

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

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

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"\nRotation angle = %lf\n"
	.size	.L.str.19, 23

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"\n\nhipDeviceSynchronize returned error code %d after launching the kernel!\n"
	.size	.L.str.21, 75

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"hipMemcpy GPU to CPU  failed!"
	.size	.L.str.22, 30

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"\n Program failed after cudaDeviceSynchronize()!"
	.size	.L.str.23, 48

	.type	.L.str.24,@object               # @.str.24
.L.str.24:
	.asciz	"\nTotal Kernel Execution    =%7.2f ms\n"
	.size	.L.str.24, 38

	.type	.L.str.25,@object               # @.str.25
.L.str.25:
	.asciz	"hipDeviceReset failed!"
	.size	.L.str.25, 23

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z8imrotatePhS_jjjjdd"
	.size	.L__unnamed_1, 22

	.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	"\nN is too large, should be less or equal to 30"
	.size	.Lstr, 47

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Cannot allocate memory for the input image..."
	.size	.Lstr.2, 46

	.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__imrotatePhS_jjjjdd
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym GPUImg
	.addrsig_sym GPUCopyImg
	.addrsig_sym ip
	.addrsig_sym _Z8imrotatePhS_jjjjdd
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z8imrotatePhS_jjjjdd   ; -- Begin function _Z8imrotatePhS_jjjjdd
	.globl	_Z8imrotatePhS_jjjjdd
	.p2align	8
	.type	_Z8imrotatePhS_jjjjdd,@function
_Z8imrotatePhS_jjjjdd:                  ; @_Z8imrotatePhS_jjjjdd
; %bb.0:
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x10
	s_load_b32 s2, s[0:1], 0x3c
	s_waitcnt lgkmcnt(0)
	v_cvt_f32_u32_e32 v1, s6
	s_sub_i32 s8, 0, s6
	s_and_b32 s9, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v1, v1
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	v_cvt_u32_f32_e32 v1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_readfirstlane_b32 s3, v1
	s_mul_i32 s8, s8, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s8, s3, s8
	s_add_i32 s3, s3, s8
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s3, s15, s3
	s_mul_i32 s8, s3, s6
	s_delay_alu instid0(SALU_CYCLE_1)
	s_sub_i32 s2, s15, s8
	s_add_i32 s8, s3, 1
	s_sub_i32 s10, s2, s6
	s_cmp_ge_u32 s2, s6
	s_cselect_b32 s3, s8, s3
	s_cselect_b32 s2, s10, s2
	s_add_i32 s8, s3, 1
	s_cmp_ge_u32 s2, s6
	s_cselect_b32 s2, s8, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s3, s2, s6
	s_sub_i32 s3, s15, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s3, s9, v[0:1]
	s_mov_b32 s3, exec_lo
	v_cmpx_gt_u32_e64 s5, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_cvt_f64_u32_e32 v[2:3], s5
	v_cvt_f64_u32_e32 v[4:5], s4
	s_lshr_b32 s6, s4, 1
	s_lshr_b32 s12, s5, 1
	s_sub_i32 s13, s6, s2
	s_load_b128 s[8:11], s[0:1], 0x0
	s_mul_i32 s2, s2, s7
	v_cvt_f64_i32_e32 v[14:15], s13
	v_mul_u32_u24_e32 v0, 3, v0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[2:3], v[2:3], v[2:3]
	v_fma_f64 v[2:3], v[4:5], v[4:5], v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_cmp_gt_f64_e32 vcc_lo, 0x10000000, v[2:3]
	v_cndmask_b32_e64 v4, 0, 1, vcc_lo
	s_and_b32 s3, vcc_lo, exec_lo
	s_cselect_b32 s3, 0xffffff80, 0
	v_lshlrev_b32_e32 v4, 8, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ldexp_f64 v[2:3], v[2:3], v4
	v_rsq_f64_e32 v[4:5], v[2:3]
	v_cmp_class_f64_e64 vcc_lo, v[2:3], 0x260
	s_waitcnt_depctr 0xfff
	v_mul_f64 v[6:7], v[2:3], v[4:5]
	v_mul_f64 v[4:5], v[4:5], 0.5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 0.5
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	v_fma_f64 v[4:5], v[4:5], v[8:9], v[4:5]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[8:9], -v[6:7], v[6:7], v[2:3]
	v_fma_f64 v[6:7], v[8:9], v[4:5], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[8:9], -v[6:7], v[6:7], v[2:3]
	v_fma_f64 v[4:5], v[8:9], v[4:5], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_ldexp_f64 v[4:5], v[4:5], s3
	s_min_u32 s3, s5, s4
	v_cvt_f64_u32_e32 v[6:7], s3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_cndmask_b32 v3, v5, v3 :: v_dual_cndmask_b32 v2, v4, v2
	v_div_scale_f64 v[4:5], null, v[2:3], v[2:3], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[8:9], v[4:5]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[10:11], -v[4:5], v[8:9], 1.0
	v_fma_f64 v[8:9], v[8:9], v[10:11], v[8:9]
	v_mad_u64_u32 v[10:11], null, v1, 3, s[2:3]
	v_subrev_nc_u32_e32 v1, s12, v1
	s_load_b128 s[0:3], s[0:1], 0x20
	s_delay_alu instid0(VALU_DEP_2)
	v_add_nc_u32_e32 v11, 1, v10
	v_add_nc_u32_e32 v12, 2, v10
	s_waitcnt lgkmcnt(0)
	s_clause 0x2
	global_load_u8 v18, v10, s[10:11]
	global_load_u8 v19, v11, s[10:11]
	global_load_u8 v20, v12, s[10:11]
	v_div_scale_f64 v[12:13], vcc_lo, v[6:7], v[2:3], v[6:7]
	s_waitcnt vmcnt(2)
	ds_store_b8 v0, v18
	s_waitcnt vmcnt(1)
	ds_store_b8 v0, v19 offset:1
	s_waitcnt vmcnt(0)
	ds_store_b8 v0, v20 offset:2
	v_fma_f64 v[10:11], -v[4:5], v[8:9], 1.0
	v_mul_f64 v[16:17], v[14:15], s[2:3]
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_fma_f64 v[8:9], v[8:9], v[10:11], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[12:13], v[8:9]
	v_fma_f64 v[4:5], -v[4:5], v[10:11], v[12:13]
	v_cvt_f64_i32_e32 v[12:13], v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fmas_f64 v[4:5], v[4:5], v[8:9], v[10:11]
	v_mul_f64 v[8:9], v[12:13], s[2:3]
	v_fma_f64 v[10:11], v[12:13], s[0:1], -v[16:17]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_div_fixup_f64 v[1:2], v[4:5], v[2:3], v[6:7]
	v_fma_f64 v[3:4], v[14:15], s[0:1], v[8:9]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f64 v[5:6], v[1:2], v[10:11]
	v_mul_f64 v[1:2], v[1:2], v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_i32_f64_e32 v3, v[5:6]
	v_cvt_i32_f64_e32 v1, v[1:2]
	s_delay_alu instid0(VALU_DEP_2)
	v_add_nc_u32_e32 v2, s12, v3
	ds_load_u8 v3, v0
	ds_load_u8 v4, v0 offset:1
	ds_load_u8 v5, v0 offset:2
	v_sub_nc_u32_e32 v6, s6, v1
	v_lshl_add_u32 v0, v2, 1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, v6, s7, v[0:1]
	v_add_nc_u32_e32 v0, 1, v1
	v_add_nc_u32_e32 v2, 2, v1
	s_waitcnt lgkmcnt(2)
	global_store_b8 v1, v3, s[8:9]
	s_waitcnt lgkmcnt(1)
	global_store_b8 v0, v4, s[8:9]
	s_waitcnt lgkmcnt(0)
	global_store_b8 v2, v5, s[8:9]
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8imrotatePhS_jjjjdd
		.amdhsa_group_segment_fixed_size 49152
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 304
		.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 21
		.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	_Z8imrotatePhS_jjjjdd, .Lfunc_end0-_Z8imrotatePhS_jjjjdd
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 824
; NumSgprs: 18
; NumVgprs: 21
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 49152 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 21
; 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
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           8
        .value_kind:     by_value
      - .offset:         40
        .size:           8
        .value_kind:     by_value
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         52
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         60
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         62
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         64
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         66
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         68
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         70
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         112
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 49152
    .kernarg_segment_align: 8
    .kernarg_segment_size: 304
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8imrotatePhS_jjjjdd
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z8imrotatePhS_jjjjdd.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     21
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
