//
// nvcc Blur.cu
// ./a.out Clown.256.ppm - original imge
// other Clown images are blurred with 2 different kenrel values

#include <stdio.h>

#define CHANNEL 3
#define N 1000

struct PPMImage {
    int width;
    int height;
    unsigned int bytes; //amount if bytes, as each pixel in 3 colors
    unsigned char *image;
    unsigned char *dev_img;
};
// Reads a color PPM image fname
int readImg(const char * fname, PPMImage & img, int & rgb_comp_color) {

    char p, s;
    FILE *file;

    if (!(file = fopen(fname, "rb")))
    {
        printf("Couldn't open file %s for reading.\n", fname);
        return 1;
    }

    fscanf(file, "%c%c\n", &p, &s);
    if (p != 'P' || (s != '6' && s!='3')) // P6 or P3
    {
        printf("Not a valid PPM file (%c %c)\n", p, s);
        exit(1);
    }

    fscanf(file, "%d %d\n", &img.width, &img.height);
    fscanf(file, "%d\n", &rgb_comp_color); //максимальное значения цвета

    int pixels = img.width * img.height; //total num of pixels
    img.bytes = pixels * 3;  // colored image with r, g, and b channels
    img.image = (unsigned char *)malloc(img.bytes);
    
    fread(img.image, sizeof(unsigned char), img.bytes, file);
    fclose(file);
    return 0;
}

// Write a color image into a file using PPM file format.
int writeOutImg(unsigned char * image, const char * fname, const PPMImage & blurred, const int  rgb_comp_color) {

    FILE *out;
    if (!(out = fopen(fname, "wb")))
    {
        printf("Couldn't open file for output.\n");
        return 1;
    }
    fprintf(out, "P6\n%d %d\n%d\n", blurred.width, blurred.height,  rgb_comp_color);
    fwrite(image, sizeof(unsigned char), blurred.bytes, out);
    fclose(out);
    return 0;
}

//Array of weights is square, so its height is the same as its width.
// We refer to the array of weights as a filter, and we refer to its width with the
// variable filterWidth.
__global__ void blur(unsigned char* input_image, unsigned char* output_image, int width, int height, int filterWidth, double * filter, const int s) {

    int px = blockIdx.x * blockDim.x + threadIdx.x;
    int py = blockIdx.y * blockDim.y + threadIdx.y;
    if (px >= width || py >= height) {
    	
        return;
    }

    int r = 0;
    int g = 0;
    int b = 0;
    for (int fx = 0; fx < filterWidth; fx++) {
      for (int fy = 0; fy < filterWidth; fy++) {
        int imagex = px + fx - filterWidth / 2;
        int imagey = py + fy - filterWidth / 2;
        //imagex = min(max(imagex,0),width-1);
        //imagey = min(max(imagey,0),height-1);
        if (imagex >=0 && imagex < width && imagey >= 0 && imagey < height)
        {
         	r += (input_image[imagey*width*3+imagex*3]);
         	g += (input_image[imagey*width*3+imagex*3+1]);
         	b += (input_image[imagey*width*3+imagex*3+2]);
	 }
      }
    }


    int index = width * 3 * py + px*3; //position of pixel
    output_image[index] = r/s;//output image is average of 9 pixels
    output_image[index+1] = g/s;
    output_image[index+2] = b/s;
}
__global__ void Init(int size, double *filter, double s) //size = kernelwidth**2
{
    int globalidx = threadIdx.x;


    if((globalidx<size)&&(globalidx%2 == 0)) filter[globalidx]=-1.0;
	else if((globalidx<size)&&(globalidx%2 != 0)) filter[globalidx]=1.0; 
    // if(globalidx<size) filter[globalidx] = globalidx;
	//if(globalidx<size) filter[globalidx]=globalidx/25;
    __syncthreads();
    s+=filter[globalidx];
}


int main(int argc, char **argv)
{

    unsigned char * img;
    unsigned char * output;
    unsigned char * output_image;
    int kernelw = 5;
    double * filter;
    double * filter_host;
    filter_host = (double *)malloc(kernelw*kernelw*sizeof(double));
    
    cudaMalloc((double**)&filter, sizeof(double)*kernelw*kernelw);
    cudaMemcpy(filter, filter_host, kernelw*kernelw*sizeof(double), cudaMemcpyHostToDevice);
    
    int s=25;
    Init<<<1,kernelw*kernelw>>>(kernelw*kernelw, filter, s);
    /*cudaMemcpy(filter_host,filter, sizeof(double)*kernelw*kernelw, cudaMemcpyDeviceToHost);
    
    for (i = 0; i<kernelw*kernelw; i++){
        s+=filter_host[i];
    }*/

    if(argc != 2)
    {
        printf("Usage: exec filename\n");
        exit(1);
    }
    char *fname = argv[1];
    PPMImage input;
    
    int  rgb_comp_color;
    
    if (readImg(fname, input, rgb_comp_color) != 0)  exit(1);
    float grid = (input.width * input.height);
    grid = grid * 3 * sizeof(unsigned char);

    cudaMalloc((void**)&img, grid);

    cudaMemcpy(img, input.image, grid, cudaMemcpyHostToDevice);

    cudaMalloc((void**)&output, grid);

    dim3 block(16, 16);
    dim3 gridsize(input.width/block.x + 1, input.height / block.x + 1);

    printf("%d %d", input.width, input.height);
    blur <<<gridsize, block >>>(img, output,input.width,input.height, kernelw, filter, s);
    cudaDeviceSynchronize();
    //get output image from device
    output_image = (unsigned char *) malloc(grid);
    cudaMemcpy(output_image, output, grid, cudaMemcpyDeviceToHost);

    //use output image from device as image to print
    if (writeOutImg(output_image,"blurr.ppm", input,  rgb_comp_color) != 0)
        exit(1);

    cudaFree(img);//free up memory dedicated to pointers
    cudaFree(output);
    free(output_image);

    exit(0);
}



	.file	"tmpxft_00313e98_00000000-6_blur_im.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
.LC1:
	.string	"Couldn't open file %s for reading.\n"
.LC2:
	.string	"%c%c\n"
.LC3:
	.string	"Not a valid PPM file (%c %c)\n"
.LC4:
	.string	"%d %d\n"
.LC5:
	.string	"%d\n"
	.text
	.globl	_Z7readImgPKcR8PPMImageRi
	.type	_Z7readImgPKcR8PPMImageRi, @function
_Z7readImgPKcR8PPMImageRi:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	leaq	.LC0(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L3
	movq	%rbx, %rdx
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L2
.L3:
	leaq	6(%rsp), %rdx
	movq	%rax, %rdi
	leaq	7(%rsp), %rcx
	movq	%rax, %rbp
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movsbl	6(%rsp), %edx
	cmpb	$80, %dl
	jne	.L5
	movb	7(%rsp), %al
	cmpb	$54, %al
	je	.L6
	cmpb	$51, %al
	je	.L6
.L5:
	movsbl	7(%rsp), %ecx
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L6:
	leaq	4(%r12), %rcx
	movq	%r12, %rdx
	movq	%rbp, %rdi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movq	%r13, %rdx
	movq	%rbp, %rdi
	xorl	%eax, %eax
	leaq	.LC5(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movl	(%r12), %ebx
	imull	4(%r12), %ebx
	imull	$3, %ebx, %ebx
	movl	%ebx, 8(%r12)
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbp, %r8
	movq	%rbx, %rcx
	movl	$1, %edx
	movq	%rax, 16(%r12)
	movq	%rax, %rdi
	movq	%rbx, %rsi
	call	__fread_chk@PLT
	movq	%rbp, %rdi
	call	fclose@PLT
	xorl	%eax, %eax
.L2:
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z7readImgPKcR8PPMImageRi, .-_Z7readImgPKcR8PPMImageRi
	.section	.rodata.str1.1
.LC6:
	.string	"wb"
.LC7:
	.string	"Couldn't open file for output.\n"
.LC8:
	.string	"P6\n%d %d\n%d\n"
	.text
	.globl	_Z11writeOutImgPhPKcRK8PPMImagei
	.type	_Z11writeOutImgPhPKcRK8PPMImagei, @function
_Z11writeOutImgPhPKcRK8PPMImagei:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	movq	%rsi, %rdi
	leaq	.LC6(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movl	%ecx, 12(%rsp)
	call	fopen@PLT
	movl	12(%rsp), %r9d
	testq	%rax, %rax
	jne	.L17
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L16
.L17:
	movl	4(%rbp), %r8d
	movl	0(%rbp), %ecx
	movq	%rax, %rbx
	movq	%rax, %rdi
	leaq	.LC8(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	8(%rbp), %edx
	movq	%rbx, %rcx
	movl	$1, %esi
	movq	%r12, %rdi
	call	fwrite@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	xorl	%eax, %eax
.L16:
	addq	$16, %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
.LFE2028:
	.size	_Z11writeOutImgPhPKcRK8PPMImagei, .-_Z11writeOutImgPhPKcRK8PPMImagei
	.globl	_Z31__device_stub__Z4blurPhS_iiiPdiPhS_iiiPdi
	.type	_Z31__device_stub__Z4blurPhS_iiiPdiPhS_iiiPdi, @function
_Z31__device_stub__Z4blurPhS_iiiPdiPhS_iiiPdi:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movl	%edx, 28(%rsp)
	leaq	48(%rsp), %rdx
	movl	%ecx, 24(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 20(%rsp)
	movq	%r9, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%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	28(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	192(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L20
	pushq	56(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z4blurPhS_iiiPdi(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 208
	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 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L20:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z31__device_stub__Z4blurPhS_iiiPdiPhS_iiiPdi, .-_Z31__device_stub__Z4blurPhS_iiiPdiPhS_iiiPdi
	.globl	_Z4blurPhS_iiiPdi
	.type	_Z4blurPhS_iiiPdi, @function
_Z4blurPhS_iiiPdi:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z4blurPhS_iiiPdiPhS_iiiPdi
	.cfi_endproc
.LFE2055:
	.size	_Z4blurPhS_iiiPdi, .-_Z4blurPhS_iiiPdi
	.globl	_Z25__device_stub__Z4InitiPddiPdd
	.type	_Z25__device_stub__Z4InitiPddiPdd, @function
_Z25__device_stub__Z4InitiPddiPdd:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movl	%edi, 28(%rsp)
	leaq	40(%rsp), %rcx
	leaq	32(%rsp), %rdx
	movq	%rsi, 16(%rsp)
	leaq	48(%rsp), %rdi
	leaq	60(%rsp), %rsi
	movsd	%xmm0, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z4InitiPdd(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L25:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z25__device_stub__Z4InitiPddiPdd, .-_Z25__device_stub__Z4InitiPddiPdd
	.globl	_Z4InitiPdd
	.type	_Z4InitiPdd, @function
_Z4InitiPdd:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z25__device_stub__Z4InitiPddiPdd
	.cfi_endproc
.LFE2057:
	.size	_Z4InitiPdd, .-_Z4InitiPdd
	.section	.rodata.str1.1
.LC10:
	.string	"Usage: exec filename\n"
.LC13:
	.string	"%d %d"
.LC14:
	.string	"blurr.ppm"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%edi, %ebp
	movl	$200, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rsi, %rbx
	subq	$96, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	leaq	24(%rsp), %rdi
	movl	$200, %esi
	movq	%rax, %r12
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$200, %edx
	call	cudaMemcpy@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$4294967321, %rdx
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movl	$1, 64(%rsp)
	movq	%rdx, 56(%rsp)
	movq	%rdi, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movsd	.LC9(%rip), %xmm0
	movq	24(%rsp), %rsi
	movl	$25, %edi
	call	_Z25__device_stub__Z4InitiPddiPdd
.L31:
	cmpl	$2, %ebp
	je	.L32
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L37
.L32:
	leaq	56(%rsp), %r12
	movq	8(%rbx), %rdi
	leaq	4(%rsp), %rdx
	movq	%r12, %rsi
	call	_Z7readImgPKcR8PPMImageRi
	testl	%eax, %eax
	je	.L33
.L37:
	movl	$1, %edi
	jmp	.L40
.L33:
	movl	56(%rsp), %eax
	imull	60(%rsp), %eax
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC11(%rip), %xmm0
	comiss	.LC12(%rip), %xmm0
	jnb	.L34
	cvttss2siq	%xmm0, %rbx
	jmp	.L35
.L34:
	subss	.LC12(%rip), %xmm0
	cvttss2siq	%xmm0, %rbx
	btcq	$63, %rbx
.L35:
	leaq	8(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	72(%rsp), %rsi
	movq	8(%rsp), %rdi
	movq	%rbx, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leaq	16(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movl	56(%rsp), %edx
	movl	60(%rsp), %ecx
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	movl	$1, 52(%rsp)
	movl	%edx, %eax
	shrl	$4, %eax
	incl	%eax
	movl	%eax, 44(%rsp)
	movl	%ecx, %eax
	shrl	$4, %eax
	incl	%eax
	movl	%eax, 48(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	44(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	52(%rsp), %esi
	movl	$1, %ecx
	movabsq	$68719476752, %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L36
	pushq	%rax
	.cfi_def_cfa_offset 136
	movl	$5, %r8d
	pushq	$25
	.cfi_def_cfa_offset 144
	movq	40(%rsp), %r9
	movl	76(%rsp), %ecx
	movl	72(%rsp), %edx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z31__device_stub__Z4blurPhS_iiiPdiPhS_iiiPdi
	popq	%rdx
	.cfi_def_cfa_offset 136
	popq	%rcx
	.cfi_def_cfa_offset 128
.L36:
	call	cudaDeviceSynchronize@PLT
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%rax, %rdi
	movq	%rax, %rbp
	call	cudaMemcpy@PLT
	movl	4(%rsp), %ecx
	movq	%r12, %rdx
	movq	%rbp, %rdi
	leaq	.LC14(%rip), %rsi
	call	_Z11writeOutImgPhPKcRK8PPMImagei
	testl	%eax, %eax
	jne	.L37
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%edi, %edi
.L40:
	call	exit@PLT
	.cfi_endproc
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC15:
	.string	"_Z4InitiPdd"
.LC16:
	.string	"_Z4blurPhS_iiiPdi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC15(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z4InitiPdd(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC16(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z4blurPhS_iiiPdi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2059:
	.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
.LC9:
	.long	0
	.long	1077477376
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC11:
	.long	1077936128
	.align 4
.LC12:
	.long	1593835520
	.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:

//
// nvcc Blur.cu
// ./a.out Clown.256.ppm - original imge
// other Clown images are blurred with 2 different kenrel values


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

#define CHANNEL 3
#define N 1000

struct PPMImage {
    int width;
    int height;
    unsigned int bytes; //amount if bytes, as each pixel in 3 colors
    unsigned char *image;
    unsigned char *dev_img;
};
// Reads a color PPM image fname
int readImg(const char * fname, PPMImage & img, int & rgb_comp_color) {

    char p, s;
    FILE *file;

    if (!(file = fopen(fname, "rb")))
    {
        printf("Couldn't open file %s for reading.\n", fname);
        return 1;
    }

    fscanf(file, "%c%c\n", &p, &s);
    if (p != 'P' || (s != '6' && s!='3')) // P6 or P3
    {
        printf("Not a valid PPM file (%c %c)\n", p, s);
        exit(1);
    }

    fscanf(file, "%d %d\n", &img.width, &img.height);
    fscanf(file, "%d\n", &rgb_comp_color); //максимальное значения цвета

    int pixels = img.width * img.height; //total num of pixels
    img.bytes = pixels * 3;  // colored image with r, g, and b channels
    img.image = (unsigned char *)malloc(img.bytes);
    
    fread(img.image, sizeof(unsigned char), img.bytes, file);
    fclose(file);
    return 0;
}

// Write a color image into a file using PPM file format.
int writeOutImg(unsigned char * image, const char * fname, const PPMImage & blurred, const int  rgb_comp_color) {

    FILE *out;
    if (!(out = fopen(fname, "wb")))
    {
        printf("Couldn't open file for output.\n");
        return 1;
    }
    fprintf(out, "P6\n%d %d\n%d\n", blurred.width, blurred.height,  rgb_comp_color);
    fwrite(image, sizeof(unsigned char), blurred.bytes, out);
    fclose(out);
    return 0;
}

//Array of weights is square, so its height is the same as its width.
// We refer to the array of weights as a filter, and we refer to its width with the
// variable filterWidth.
__global__ void blur(unsigned char* input_image, unsigned char* output_image, int width, int height, int filterWidth, double * filter, const int s) {

    int px = blockIdx.x * blockDim.x + threadIdx.x;
    int py = blockIdx.y * blockDim.y + threadIdx.y;
    if (px >= width || py >= height) {
    	
        return;
    }

    int r = 0;
    int g = 0;
    int b = 0;
    for (int fx = 0; fx < filterWidth; fx++) {
      for (int fy = 0; fy < filterWidth; fy++) {
        int imagex = px + fx - filterWidth / 2;
        int imagey = py + fy - filterWidth / 2;
        //imagex = min(max(imagex,0),width-1);
        //imagey = min(max(imagey,0),height-1);
        if (imagex >=0 && imagex < width && imagey >= 0 && imagey < height)
        {
         	r += (input_image[imagey*width*3+imagex*3]);
         	g += (input_image[imagey*width*3+imagex*3+1]);
         	b += (input_image[imagey*width*3+imagex*3+2]);
	 }
      }
    }


    int index = width * 3 * py + px*3; //position of pixel
    output_image[index] = r/s;//output image is average of 9 pixels
    output_image[index+1] = g/s;
    output_image[index+2] = b/s;
}
__global__ void Init(int size, double *filter, double s) //size = kernelwidth**2
{
    int globalidx = threadIdx.x;


    if((globalidx<size)&&(globalidx%2 == 0)) filter[globalidx]=-1.0;
	else if((globalidx<size)&&(globalidx%2 != 0)) filter[globalidx]=1.0; 
    // if(globalidx<size) filter[globalidx] = globalidx;
	//if(globalidx<size) filter[globalidx]=globalidx/25;
    __syncthreads();
    s+=filter[globalidx];
}


int main(int argc, char **argv)
{

    unsigned char * img;
    unsigned char * output;
    unsigned char * output_image;
    int kernelw = 5;
    double * filter;
    double * filter_host;
    filter_host = (double *)malloc(kernelw*kernelw*sizeof(double));
    
    hipMalloc((double**)&filter, sizeof(double)*kernelw*kernelw);
    hipMemcpy(filter, filter_host, kernelw*kernelw*sizeof(double), hipMemcpyHostToDevice);
    
    int s=25;
    Init<<<1,kernelw*kernelw>>>(kernelw*kernelw, filter, s);
    /*cudaMemcpy(filter_host,filter, sizeof(double)*kernelw*kernelw, cudaMemcpyDeviceToHost);
    
    for (i = 0; i<kernelw*kernelw; i++){
        s+=filter_host[i];
    }*/

    if(argc != 2)
    {
        printf("Usage: exec filename\n");
        exit(1);
    }
    char *fname = argv[1];
    PPMImage input;
    
    int  rgb_comp_color;
    
    if (readImg(fname, input, rgb_comp_color) != 0)  exit(1);
    float grid = (input.width * input.height);
    grid = grid * 3 * sizeof(unsigned char);

    hipMalloc((void**)&img, grid);

    hipMemcpy(img, input.image, grid, hipMemcpyHostToDevice);

    hipMalloc((void**)&output, grid);

    dim3 block(16, 16);
    dim3 gridsize(input.width/block.x + 1, input.height / block.x + 1);

    printf("%d %d", input.width, input.height);
    blur <<<gridsize, block >>>(img, output,input.width,input.height, kernelw, filter, s);
    hipDeviceSynchronize();
    //get output image from device
    output_image = (unsigned char *) malloc(grid);
    hipMemcpy(output_image, output, grid, hipMemcpyDeviceToHost);

    //use output image from device as image to print
    if (writeOutImg(output_image,"blurr.ppm", input,  rgb_comp_color) != 0)
        exit(1);

    hipFree(img);//free up memory dedicated to pointers
    hipFree(output);
    free(output_image);

    exit(0);
}



	.text
	.file	"blur_im.hip"
	.globl	_Z7readImgPKcR8PPMImageRi       # -- Begin function _Z7readImgPKcR8PPMImageRi
	.type	_Z7readImgPKcR8PPMImageRi,@function
_Z7readImgPKcR8PPMImageRi:              # @_Z7readImgPKcR8PPMImageRi
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, %r15
	movq	%rsi, %r14
	movq	%rdi, %r12
	movl	$.L.str, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_1
# %bb.2:
	movq	%rax, %rbx
	leaq	7(%rsp), %r12
	leaq	6(%rsp), %r13
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	movq	%r12, %rdx
	movq	%r13, %rcx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movsbl	(%r12), %esi
	movsbl	(%r13), %edx
	cmpl	$80, %esi
	jne	.LBB0_7
# %bb.3:
	cmpb	$51, %dl
	je	.LBB0_5
# %bb.4:
	movzbl	%dl, %eax
	cmpl	$54, %eax
	jne	.LBB0_7
.LBB0_5:
	leaq	4(%r14), %rcx
	xorl	%ebp, %ebp
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$.L.str.5, %esi
	movq	%rbx, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	(%r14), %eax
	imull	4(%r14), %eax
	leal	(%rax,%rax,2), %r15d
	movl	%r15d, 8(%r14)
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, 16(%r14)
	movl	$1, %esi
	movq	%rax, %rdi
	movq	%r15, %rdx
	movq	%rbx, %rcx
	callq	fread
	movq	%rbx, %rdi
	callq	fclose
	jmp	.LBB0_6
.LBB0_1:
	movl	$.L.str.1, %edi
	movq	%r12, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %ebp
.LBB0_6:
	movl	%ebp, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB0_7:
	.cfi_def_cfa_offset 64
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z7readImgPKcR8PPMImageRi, .Lfunc_end0-_Z7readImgPKcR8PPMImageRi
	.cfi_endproc
                                        # -- End function
	.globl	_Z11writeOutImgPhPKcRK8PPMImagei # -- Begin function _Z11writeOutImgPhPKcRK8PPMImagei
	.type	_Z11writeOutImgPhPKcRK8PPMImagei,@function
_Z11writeOutImgPhPKcRK8PPMImagei:       # @_Z11writeOutImgPhPKcRK8PPMImagei
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%ecx, %r12d
	movq	%rdx, %r15
	movq	%rsi, %rax
	movq	%rdi, %rbx
	movl	$.L.str.6, %esi
	movq	%rax, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_1
# %bb.2:
	movq	%rax, %r14
	movl	(%r15), %edx
	movl	4(%r15), %ecx
	xorl	%ebp, %ebp
	movl	$.L.str.8, %esi
	movq	%rax, %rdi
	movl	%r12d, %r8d
	xorl	%eax, %eax
	callq	fprintf
	movl	8(%r15), %edx
	movl	$1, %esi
	movq	%rbx, %rdi
	movq	%r14, %rcx
	callq	fwrite
	movq	%r14, %rdi
	callq	fclose
	jmp	.LBB1_3
.LBB1_1:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$1, %ebp
.LBB1_3:
	movl	%ebp, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z11writeOutImgPhPKcRK8PPMImagei, .Lfunc_end1-_Z11writeOutImgPhPKcRK8PPMImagei
	.cfi_endproc
                                        # -- End function
	.globl	_Z19__device_stub__blurPhS_iiiPdi # -- Begin function _Z19__device_stub__blurPhS_iiiPdi
	.type	_Z19__device_stub__blurPhS_iiiPdi,@function
_Z19__device_stub__blurPhS_iiiPdi:      # @_Z19__device_stub__blurPhS_iiiPdi
	.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	20(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	16(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	40(%rsp), %r8
	movq	%r9, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	208(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z4blurPhS_iiiPdi, %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_end2:
	.size	_Z19__device_stub__blurPhS_iiiPdi, .Lfunc_end2-_Z19__device_stub__blurPhS_iiiPdi
	.cfi_endproc
                                        # -- End function
	.globl	_Z19__device_stub__InitiPdd     # -- Begin function _Z19__device_stub__InitiPdd
	.type	_Z19__device_stub__InitiPdd,@function
_Z19__device_stub__InitiPdd:            # @_Z19__device_stub__InitiPdd
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	12(%rsp), %rax
	movl	%edi, (%rax)
	leaq	40(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	32(%rsp), %rdx
	movsd	%xmm0, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rdx, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%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	$_Z4InitiPdd, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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_end3:
	.size	_Z19__device_stub__InitiPdd, .Lfunc_end3-_Z19__device_stub__InitiPdd
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI4_0:
	.quad	0x4039000000000000              # double 25
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI4_1:
	.long	0x40400000                      # float 3
.LCPI4_2:
	.long	0x5f000000                      # float 9.22337203E+18
	.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	%rbx
	.cfi_def_cfa_offset 40
	subq	$72, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	movl	$200, %edi
	callq	malloc
	movq	%rax, %r14
	leaq	24(%rsp), %r15
	movl	$200, %esi
	movq	%r15, %rdi
	callq	hipMalloc
	movq	(%r15), %rdi
	movl	$200, %edx
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	leaq	24(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_2
# %bb.1:
	movq	24(%rsp), %rsi
	movsd	.LCPI4_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	$25, %edi
	callq	_Z19__device_stub__InitiPdd
.LBB4_2:
	cmpl	$2, %ebp
	jne	.LBB4_3
# %bb.5:
	movq	8(%rbx), %rdi
	leaq	40(%rsp), %rsi
	leaq	20(%rsp), %rdx
	callq	_Z7readImgPKcR8PPMImageRi
	testl	%eax, %eax
	jne	.LBB4_4
# %bb.6:
	movl	44(%rsp), %eax
	imull	40(%rsp), %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI4_1(%rip), %xmm0
	cvttss2si	%xmm0, %rax
	movq	%rax, %rcx
	sarq	$63, %rcx
	subss	.LCPI4_2(%rip), %xmm0
	cvttss2si	%xmm0, %rbx
	andq	%rcx, %rbx
	orq	%rax, %rbx
	leaq	32(%rsp), %r14
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	56(%rsp), %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	8(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movl	40(%rsp), %esi
	movl	44(%rsp), %edx
	movl	%esi, %eax
	shrl	$4, %eax
	movl	%edx, %ecx
	shrl	$4, %ecx
	incl	%ecx
	shlq	$32, %rcx
	leaq	(%rax,%rcx), %r14
	incq	%r14
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movq	%r14, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_8
# %bb.7:
	movq	32(%rsp), %rdi
	movq	8(%rsp), %rsi
	movl	40(%rsp), %edx
	movl	44(%rsp), %ecx
	movq	24(%rsp), %r9
	movl	$25, (%rsp)
	movl	$5, %r8d
	callq	_Z19__device_stub__blurPhS_iiiPdi
.LBB4_8:
	callq	hipDeviceSynchronize
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	8(%rsp), %rsi
	movq	%rax, %rdi
	movq	%rbx, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	20(%rsp), %ecx
	leaq	40(%rsp), %rdx
	movl	$.L.str.11, %esi
	movq	%r14, %rdi
	callq	_Z11writeOutImgPhPKcRK8PPMImagei
	testl	%eax, %eax
	jne	.LBB4_4
# %bb.9:
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%r14, %rdi
	callq	free
	xorl	%edi, %edi
	callq	exit
.LBB4_3:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
.LBB4_4:
	movl	$1, %edi
	callq	exit
.Lfunc_end4:
	.size	main, .Lfunc_end4-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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4blurPhS_iiiPdi, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4InitiPdd, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.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	"Couldn't open file %s for reading.\n"
	.size	.L.str.1, 36

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%c%c\n"
	.size	.L.str.2, 6

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Not a valid PPM file (%c %c)\n"
	.size	.L.str.3, 30

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

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

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"P6\n%d %d\n%d\n"
	.size	.L.str.8, 13

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

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

	.type	.L.str.10,@object               # @.str.10
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.10:
	.asciz	"%d %d"
	.size	.L.str.10, 6

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"blurr.ppm"
	.size	.L.str.11, 10

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z4blurPhS_iiiPdi"
	.size	.L__unnamed_1, 18

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z4InitiPdd"
	.size	.L__unnamed_2, 12

	.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	"Couldn't open file for output."
	.size	.Lstr, 31

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Usage: exec filename"
	.size	.Lstr.1, 21

	.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 _Z19__device_stub__blurPhS_iiiPdi
	.addrsig_sym _Z19__device_stub__InitiPdd
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z4blurPhS_iiiPdi
	.addrsig_sym _Z4InitiPdd
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4blurPhS_iiiPdi       ; -- Begin function _Z4blurPhS_iiiPdi
	.globl	_Z4blurPhS_iiiPdi
	.p2align	8
	.type	_Z4blurPhS_iiiPdi,@function
_Z4blurPhS_iiiPdi:                      ; @_Z4blurPhS_iiiPdi
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x3c
	s_load_b128 s[16:19], s[0:1], 0x10
	v_bfe_u32 v2, v0, 10, 10
	v_and_b32_e32 v6, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s2, 0xffff
	s_lshr_b32 s2, s2, 16
	s_mul_i32 s14, s14, s3
	v_mad_u64_u32 v[0:1], null, s15, s2, v[2:3]
	v_add_nc_u32_e32 v1, s14, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cmp_gt_i32_e32 vcc_lo, s16, v1
	v_cmp_gt_i32_e64 s2, s17, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_11
; %bb.1:                                ; %.preheader74
	s_load_b128 s[8:11], s[0:1], 0x0
	v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v3, 0
	v_mov_b32_e32 v4, 0
	s_cmp_lt_i32 s18, 1
	s_mov_b32 s5, 0
	s_cbranch_scc1 .LBB0_10
; %bb.2:                                ; %.preheader.lr.ph
	s_lshr_b32 s2, s18, 1
	s_mul_i32 s6, s16, 3
	v_subrev_nc_u32_e32 v5, s2, v0
	v_mov_b32_e32 v3, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v2, s16, v5
	v_add3_u32 v2, v6, v2, s14
	v_subrev_nc_u32_e32 v6, s2, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v4, s2, v2
	v_mov_b32_e32 v2, 0
	v_lshl_add_u32 v7, v4, 1, v4
	v_mov_b32_e32 v4, 0
.LBB0_3:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	v_add_nc_u32_e32 v8, s5, v6
	s_mov_b32 s7, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_i32_e32 vcc_lo, -1, v8
	v_cmp_gt_i32_e64 s2, s16, v8
	v_mov_b32_e32 v8, v7
.LBB0_4:                                ;   Parent Loop BB0_3 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_and_saveexec_b32 s12, vcc_lo
	s_cbranch_execz .LBB0_8
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=2
	v_add_nc_u32_e32 v9, s7, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cmp_lt_i32_e64 s3, -1, v9
	v_cmp_gt_i32_e64 s4, s17, v9
	s_and_b32 s3, s2, s3
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	s_and_b32 s3, s3, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s4, s3
	s_cbranch_execz .LBB0_7
; %bb.6:                                ;   in Loop: Header=BB0_4 Depth=2
	v_ashrrev_i32_e32 v10, 31, v8
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v9, s3, s8, v8
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v10, s3, s9, v10, s3
	s_clause 0x1
	global_load_u16 v11, v[9:10], off
	global_load_u8 v9, v[9:10], off offset:2
	s_waitcnt vmcnt(1)
	v_and_b32_e32 v10, 0xff, v11
	v_lshrrev_b32_e32 v11, 8, v11
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v4, v4, v9
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v2, v2, v10
	v_add_nc_u32_e32 v3, v3, v11
.LBB0_7:                                ; %Flow
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s4
.LBB0_8:                                ;   in Loop: Header=BB0_4 Depth=2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_or_b32 exec_lo, exec_lo, s12
	v_add_nc_u32_e32 v8, s6, v8
	s_add_i32 s7, s7, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s18, s7
	s_cbranch_scc0 .LBB0_4
; %bb.9:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_3 Depth=1
	v_add_nc_u32_e32 v7, 3, v7
	s_add_i32 s5, s5, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s5, s18
	s_cbranch_scc0 .LBB0_3
.LBB0_10:                               ; %._crit_edge85
	s_load_b32 s0, s[0:1], 0x28
	v_ashrrev_i32_e32 v7, 31, v2
	v_ashrrev_i32_e32 v8, 31, v3
	v_ashrrev_i32_e32 v9, 31, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v2, v2, v7
	v_add_nc_u32_e32 v4, v4, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_xor_b32_e32 v10, v2, v7
	v_xor_b32_e32 v4, v4, v9
	s_waitcnt lgkmcnt(0)
	s_ashr_i32 s2, s0, 31
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s0, s0, s2
	s_xor_b32 s3, s0, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f32_u32_e32 v5, s3
	s_sub_i32 s0, 0, s3
	v_rcp_iflag_f32_e32 v5, v5
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v5, 0x4f7ffffe, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v5, v5
	v_mul_lo_u32 v6, s0, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v6, v5, v6
	v_add_nc_u32_e32 v2, v5, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v6, v10, v2
	v_add_nc_u32_e32 v3, v3, v8
	v_mul_hi_u32 v12, v4, v2
	v_xor_b32_e32 v5, v3, v8
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v13, v6, s3
	v_mul_hi_u32 v11, v5, v2
	v_mad_u64_u32 v[2:3], null, v0, s16, v[1:2]
	v_xor_b32_e32 v3, s2, v8
	v_mul_lo_u32 v0, v12, s3
	v_sub_nc_u32_e32 v8, v10, v13
	v_xor_b32_e32 v1, s2, v7
	v_add_nc_u32_e32 v7, 1, v6
	v_mul_lo_u32 v14, v11, s3
	v_add_nc_u32_e32 v10, 1, v11
	v_cmp_le_u32_e32 vcc_lo, s3, v8
	v_lshl_add_u32 v2, v2, 1, v2
	v_sub_nc_u32_e32 v0, v4, v0
	v_cndmask_b32_e32 v4, v6, v7, vcc_lo
	v_sub_nc_u32_e32 v5, v5, v14
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_le_u32_e64 s1, s3, v0
	v_subrev_nc_u32_e32 v6, s3, v5
	v_cmp_le_u32_e64 s0, s3, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v7, v11, v10, s0
	v_subrev_nc_u32_e32 v10, s3, v8
	v_cndmask_b32_e64 v5, v5, v6, s0
	v_add_nc_u32_e32 v13, 1, v12
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_nc_u32_e32 v6, 1, v7
	v_cndmask_b32_e32 v8, v8, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cmp_le_u32_e32 vcc_lo, s3, v5
	v_cndmask_b32_e64 v11, v12, v13, s1
	v_subrev_nc_u32_e32 v12, s3, v0
	v_dual_cndmask_b32 v5, v7, v6 :: v_dual_add_nc_u32 v10, 1, v4
	v_cmp_le_u32_e32 vcc_lo, s3, v8
	s_delay_alu instid0(VALU_DEP_3)
	v_cndmask_b32_e64 v0, v0, v12, s1
	v_add_nc_u32_e32 v6, 1, v11
	v_xor_b32_e32 v7, s2, v9
	v_xor_b32_e32 v5, v5, v3
	v_cndmask_b32_e32 v4, v4, v10, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s3, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v3, v5, v3
	v_xor_b32_e32 v4, v4, v1
	v_cndmask_b32_e32 v0, v11, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b16 v3, 8, v3
	v_sub_nc_u32_e32 v1, v4, v1
	v_ashrrev_i32_e32 v4, 31, v2
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v5, v0, v7
	v_add_co_u32 v0, vcc_lo, s10, v2
	v_and_b32_e32 v6, 0xff, v1
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_ci_u32_e32 v1, vcc_lo, s11, v4, vcc_lo
	v_sub_nc_u32_e32 v2, v5, v7
	s_delay_alu instid0(VALU_DEP_3)
	v_or_b32_e32 v3, v6, v3
	s_clause 0x1
	global_store_b8 v[0:1], v2, off offset:2
	global_store_b16 v[0:1], v3, off
.LBB0_11:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4blurPhS_iiiPdi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 304
		.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 15
		.amdhsa_next_free_sgpr 20
		.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	_Z4blurPhS_iiiPdi, .Lfunc_end0-_Z4blurPhS_iiiPdi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 896
; NumSgprs: 22
; NumVgprs: 15
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 22
; NumVGPRsForWavesPerEU: 15
; 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
	.protected	_Z4InitiPdd             ; -- Begin function _Z4InitiPdd
	.globl	_Z4InitiPdd
	.p2align	8
	.type	_Z4InitiPdd,@function
_Z4InitiPdd:                            ; @_Z4InitiPdd
; %bb.0:
	s_load_b32 s2, s[0:1], 0x0
	v_and_b32_e32 v1, 1, v0
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_cmp_eq_u32_e64 s2, 0, v1
	v_mov_b32_e32 v1, 0
	v_mov_b32_e32 v2, 0xbff00000
	s_and_b32 s3, s2, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_xor_b32 s5, s3, -1
	s_and_saveexec_b32 s4, s5
; %bb.1:
	s_xor_b32 s5, vcc_lo, -1
	v_mov_b32_e32 v1, 0
	s_or_b32 s2, s2, s5
	v_mov_b32_e32 v2, 0x3ff00000
	s_xor_b32 s2, s2, -1
	s_and_not1_b32 s3, s3, exec_lo
	s_and_b32 s2, s2, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s3, s3, s2
; %bb.2:                                ; %Flow
	s_or_b32 exec_lo, exec_lo, s4
	s_and_saveexec_b32 s2, s3
	s_cbranch_execz .LBB1_4
; %bb.3:                                ; %.sink.split
	s_load_b64 s[0:1], s[0:1], 0x8
	v_lshlrev_b32_e32 v0, 3, v0
	s_waitcnt lgkmcnt(0)
	global_store_b64 v0, v[1:2], s[0:1]
.LBB1_4:
	s_or_b32 exec_lo, exec_lo, s2
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4InitiPdd
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 24
		.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 3
		.amdhsa_next_free_sgpr 6
		.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_end1:
	.size	_Z4InitiPdd, .Lfunc_end1-_Z4InitiPdd
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 160
; NumSgprs: 8
; NumVgprs: 3
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 8
; NumVGPRsForWavesPerEU: 3
; 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
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .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: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 304
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4blurPhS_iiiPdi
    .private_segment_fixed_size: 0
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z4blurPhS_iiiPdi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     15
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           8
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 24
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4InitiPdd
    .private_segment_fixed_size: 0
    .sgpr_count:     8
    .sgpr_spill_count: 0
    .symbol:         _Z4InitiPdd.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     3
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
