#include <stdio.h>
#include "imageutils.cuh"

// weights of each color channel
#define RED_WEIGHT 		(0.299f)
#define GREEN_WEIGHT 	(0.587f)
#define BLUE_WEIGHT		(0.114f)

// dimensions of the thread blocks
#define NUM_BLOCKS_X 	16
#define NUM_BLOCKS_Y	16

__global__
void rgba_to_negative(
	uchar4 *rgbaImage,
	unsigned char*grayscaleImage,
	int numRows, int numCols
) {
	// finding pixel assigned to this thread
	int thread_x = blockDim.x * blockIdx.x + threadIdx.x;
	int thread_y = blockDim.y * blockIdx.y + threadIdx.y;
	int idx = thread_x * numCols + thread_y;

	// thread is out of range (happens when block dimensions don't allign)
	if(thread_x >= numRows || thread_y >= numCols) {
	// if (idx < numRows * numCols) should also work
		return;
	}

	// averaging the values does not work well
	// as our eyes are not receptive to all colors equally
	// these weights give a better feeling grayscale image
	grayscaleImage[idx] =	rgbaImage[idx].x * RED_WEIGHT +
							rgbaImage[idx].y * GREEN_WEIGHT +
							rgbaImage[idx].z * BLUE_WEIGHT;
}

int main() {
// load input picture
	PPMImage *input_image = readPPM("../PPMImages/Poivron.ppm");
	const int dim_x = input_image->x;
	const int dim_y = input_image->y;

	// dimension and size of both arrays for testing
	const int RGB_SIZE = dim_x * dim_y;
	const int RGB_BYTES = RGB_SIZE * sizeof(uchar4);
	const int GRAYSCALE_SIZE = dim_x * dim_y;
	const int GRAYSCALE_BYTES = GRAYSCALE_SIZE * sizeof(unsigned char);

	// calculating grid and block dimensions of threads
	int grid_size_x = (dim_x + NUM_BLOCKS_X - 1) / NUM_BLOCKS_X;
	int grid_size_y = (dim_y + NUM_BLOCKS_Y - 1) / NUM_BLOCKS_Y;
	dim3 grid_dims = dim3(grid_size_x, grid_size_y, 1);
	dim3 block_dims = dim3(NUM_BLOCKS_X, NUM_BLOCKS_Y, 1);

	// memory pointers
	uchar4 *h_image_rgb;
	unsigned char *h_image_grayscale;
	uchar4 *d_image_rgb;
	unsigned char *d_image_grayscale;

	// memory allocation on host
	h_image_rgb = PPM_to_uchar4(input_image, 255);
	h_image_grayscale = (unsigned char *) malloc(GRAYSCALE_BYTES);

	// memory allocation on device
	cudaMalloc((void **) &d_image_rgb, RGB_BYTES);
	cudaMalloc((void **) &d_image_grayscale, GRAYSCALE_BYTES);

	// transferring input array to device memory
	cudaMemcpy(d_image_rgb, h_image_rgb, RGB_BYTES, cudaMemcpyHostToDevice);

	// launching kernels
	rgba_to_negative<<<grid_dims, block_dims>>>(
		d_image_rgb,
		d_image_grayscale,
		dim_x, dim_y
	);

	// getting back the negative image
	cudaMemcpy(h_image_grayscale, d_image_grayscale, GRAYSCALE_BYTES, cudaMemcpyDeviceToHost);

	// save resulting file
	writeGrayScale("../PPMResults/Poivron_gray.pgm", h_image_grayscale, dim_x, dim_y);

	// free host memory
	free(h_image_rgb);
	free(h_image_grayscale);

	// free device memory
	cudaFree(d_image_rgb);
	cudaFree(d_image_grayscale);

	return 0;
}
	.file	"tmpxft_00382582_00000000-6_grayscale.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
.LC1:
	.string	"Unable to open file '%s'\n"
.LC2:
	.string	"Invalid image format (must be 'P6')\n"
.LC3:
	.string	"Unable to allocate memory\n"
.LC4:
	.string	"%d %d"
.LC5:
	.string	"Invalid image size (error loading '%s')\n"
.LC6:
	.string	"%d"
.LC7:
	.string	"Invalid rgb component (error loading '%s')\n"
.LC8:
	.string	"'%s' does not have 8-bits components\n"
.LC9:
	.string	"Error loading image '%s'\n"
	.text
	.globl	_Z7readPPMPKc
	.type	_Z7readPPMPKc, @function
_Z7readPPMPKc:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rsi
	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
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movq	%r12, %rcx
	leaq	.LC1(%rip), %rdx
	testq	%rax, %rax
	je	.L23
	leaq	8(%rsp), %rdi
	movq	%rax, %rcx
	movl	$16, %edx
	movq	%rax, %rbx
	movl	$16, %esi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	jne	.L4
	movq	%r12, %rdi
	call	perror@PLT
.L22:
	movl	$1, %edi
	call	exit@PLT
.L4:
	cmpb	$80, 8(%rsp)
	jne	.L5
	cmpb	$54, 9(%rsp)
	je	.L6
.L5:
	leaq	.LC2(%rip), %rdx
	jmp	.L24
.L6:
	movl	$16, %edi
	call	malloc@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	jne	.L21
	leaq	.LC3(%rip), %rdx
.L24:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L22
.L9:
	movq	%rbx, %rdi
	call	getc@PLT
	cmpl	$10, %eax
	jne	.L9
.L21:
	movq	%rbx, %rdi
	call	getc@PLT
	cmpl	$35, %eax
	je	.L9
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	ungetc@PLT
	leaq	4(%rbp), %rcx
	movq	%rbp, %rdx
	movq	%rbx, %rdi
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	%r12, %rcx
	leaq	.LC5(%rip), %rdx
	cmpl	$2, %eax
	jne	.L23
	leaq	4(%rsp), %rdx
	xorl	%eax, %eax
	leaq	.LC6(%rip), %rsi
	movq	%rbx, %rdi
	call	__isoc23_fscanf@PLT
	movq	%r12, %rcx
	leaq	.LC7(%rip), %rdx
	decl	%eax
	jne	.L23
	cmpl	$255, 4(%rsp)
	leaq	.LC8(%rip), %rdx
	jne	.L23
.L12:
	movq	%rbx, %rdi
	call	fgetc@PLT
	cmpl	$10, %eax
	jne	.L12
	movl	0(%rbp), %r14d
	movl	4(%rbp), %r15d
	movl	%r14d, %r13d
	imull	%r15d, %r13d
	movslq	%r13d, %r13
	leaq	0(%r13,%r13,2), %r13
	movq	%r13, %rdi
	call	malloc@PLT
	leal	(%r14,%r14,2), %edx
	movslq	%r15d, %rcx
	movq	%rbx, %r8
	movq	%rax, 8(%rbp)
	movslq	%edx, %rdx
	movq	%rax, %rdi
	movq	%r13, %rsi
	call	__fread_chk@PLT
	movslq	4(%rbp), %rdx
	cmpq	%rax, %rdx
	je	.L13
	movq	%r12, %rcx
	leaq	.LC9(%rip), %rdx
.L23:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L22
.L13:
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbp, %rax
	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
.LFE2027:
	.size	_Z7readPPMPKc, .-_Z7readPPMPKc
	.section	.rodata.str1.1
.LC10:
	.string	"wb"
.LC11:
	.string	"P6\n"
.LC12:
	.string	"%d %d\n"
.LC13:
	.string	"%d\n"
	.text
	.globl	_Z8writePPMPKcP8PPMImage
	.type	_Z8writePPMPKcP8PPMImage, @function
_Z8writePPMPKcP8PPMImage:
.LFB2028:
	.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	.LC10(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L27
	movq	stderr(%rip), %rdi
	movq	%r12, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L27:
	movq	%rax, %rbx
	movq	%rax, %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC11(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	4(%rbp), %r8d
	movl	0(%rbp), %ecx
	movq	%rbx, %rdi
	leaq	.LC12(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	movl	$255, %ecx
	xorl	%eax, %eax
	leaq	.LC13(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	imull	$3, 0(%rbp), %esi
	movq	8(%rbp), %rdi
	movq	%rbx, %rcx
	movslq	4(%rbp), %rdx
	movslq	%esi, %rsi
	call	fwrite@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
.LFE2028:
	.size	_Z8writePPMPKcP8PPMImage, .-_Z8writePPMPKcP8PPMImage
	.section	.rodata.str1.1
.LC14:
	.string	"P2\n"
.LC15:
	.string	"%d "
.LC16:
	.string	"\n"
	.text
	.globl	_Z14writeGrayScalePKcPhii
	.type	_Z14writeGrayScalePKcPhii, @function
_Z14writeGrayScalePKcPhii:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rsi, %r15
	leaq	.LC10(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L30
	movq	stderr(%rip), %rdi
	movq	%r13, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L30:
	movq	%rax, %rbx
	movq	%rax, %rdi
	leaq	.LC14(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	xorl	%r13d, %r13d
	xorl	%r14d, %r14d
	call	__fprintf_chk@PLT
	movl	%ebp, %r8d
	movl	%r12d, %ecx
	movl	$2, %esi
	leaq	.LC12(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$255, %ecx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	leaq	.LC13(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
.L31:
	cmpl	%r12d, %r14d
	jge	.L33
	xorl	%r8d, %r8d
	movslq	%r13d, %r9
.L34:
	cmpl	%r8d, %ebp
	jle	.L36
	leaq	(%r15,%r9), %rax
	movl	$2, %esi
	movq	%rbx, %rdi
	movq	%r8, (%rsp)
	movzbl	(%rax,%r8), %ecx
	leaq	.LC15(%rip), %rdx
	xorl	%eax, %eax
	movq	%r9, 8(%rsp)
	call	__fprintf_chk@PLT
	movq	(%rsp), %r8
	movq	8(%rsp), %r9
	incq	%r8
	jmp	.L34
.L36:
	leaq	.LC16(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	incl	%r14d
	movl	$2, %esi
	addl	%ebp, %r13d
	call	__fprintf_chk@PLT
	jmp	.L31
.L33:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rdi
	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
	jmp	fclose@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z14writeGrayScalePKcPhii, .-_Z14writeGrayScalePKcPhii
	.globl	_Z13PPM_to_uchar4P8PPMImagei
	.type	_Z13PPM_to_uchar4P8PPMImagei, @function
_Z13PPM_to_uchar4P8PPMImagei:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%esi, %r12d
	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
	pushq	%rcx
	.cfi_def_cfa_offset 48
	movl	(%rdi), %r13d
	movl	4(%rdi), %ebp
	movl	%r13d, %edi
	imull	%ebp, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	xorl	%edi, %edi
	xorl	%r8d, %r8d
.L38:
	cmpl	%r8d, %r13d
	jle	.L37
	movslq	%edi, %rdx
	xorl	%ecx, %ecx
	leaq	(%rdx,%rdx,2), %rsi
	leaq	(%rax,%rdx,4), %rdx
.L41:
	cmpl	%ecx, %ebp
	jle	.L43
	movq	8(%rbx), %r9
	incl	%ecx
	addq	$4, %rdx
	addq	%rsi, %r9
	addq	$3, %rsi
	movb	(%r9), %r10b
	movb	%r10b, -4(%rdx)
	movb	2(%r9), %r10b
	movb	%r10b, -3(%rdx)
	movb	1(%r9), %r9b
	movb	%r12b, -1(%rdx)
	movb	%r9b, -2(%rdx)
	jmp	.L41
.L43:
	incl	%r8d
	addl	%ebp, %edi
	jmp	.L38
.L37:
	popq	%rdx
	.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
.LFE2030:
	.size	_Z13PPM_to_uchar4P8PPMImagei, .-_Z13PPM_to_uchar4P8PPMImagei
	.globl	_Z13uchar4_to_PPMP6uchar4ii
	.type	_Z13uchar4_to_PPMP6uchar4ii, @function
_Z13uchar4_to_PPMP6uchar4ii:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdi, %r13
	movl	$16, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	pushq	%rcx
	.cfi_def_cfa_offset 48
	call	malloc@PLT
	movl	%r12d, %edi
	imull	%ebp, %edi
	movl	%r12d, (%rax)
	movq	%rax, %rbx
	movl	%ebp, 4(%rax)
	movslq	%edi, %rdi
	leaq	(%rdi,%rdi,2), %rdi
	call	malloc@PLT
	xorl	%edi, %edi
	xorl	%r8d, %r8d
	movq	%rax, 8(%rbx)
.L45:
	cmpl	%r12d, %r8d
	jge	.L44
	movslq	%edi, %rdx
	xorl	%esi, %esi
	leaq	0(%r13,%rdx,4), %rcx
	leaq	(%rdx,%rdx,2), %rdx
	addq	%rax, %rdx
.L48:
	cmpl	%ebp, %esi
	jge	.L50
	movb	(%rcx), %r9b
	incl	%esi
	addq	$4, %rcx
	addq	$3, %rdx
	movb	%r9b, -3(%rdx)
	movb	-3(%rcx), %r9b
	movb	%r9b, -1(%rdx)
	movb	-2(%rcx), %r9b
	movb	%r9b, -2(%rdx)
	jmp	.L48
.L50:
	incl	%r8d
	addl	%ebp, %edi
	jmp	.L45
.L44:
	popq	%rdx
	.cfi_def_cfa_offset 40
	movq	%rbx, %rax
	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
.LFE2031:
	.size	_Z13uchar4_to_PPMP6uchar4ii, .-_Z13uchar4_to_PPMP6uchar4ii
	.globl	_Z46__device_stub__Z16rgba_to_negativeP6uchar4PhiiP6uchar4Phii
	.type	_Z46__device_stub__Z16rgba_to_negativeP6uchar4PhiiP6uchar4Phii, @function
_Z46__device_stub__Z16rgba_to_negativeP6uchar4PhiiP6uchar4Phii:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L51
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z16rgba_to_negativeP6uchar4Phii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L51:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L53
	call	__stack_chk_fail@PLT
.L53:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z46__device_stub__Z16rgba_to_negativeP6uchar4PhiiP6uchar4Phii, .-_Z46__device_stub__Z16rgba_to_negativeP6uchar4PhiiP6uchar4Phii
	.globl	_Z16rgba_to_negativeP6uchar4Phii
	.type	_Z16rgba_to_negativeP6uchar4Phii, @function
_Z16rgba_to_negativeP6uchar4Phii:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z46__device_stub__Z16rgba_to_negativeP6uchar4PhiiP6uchar4Phii
	.cfi_endproc
.LFE2058:
	.size	_Z16rgba_to_negativeP6uchar4Phii, .-_Z16rgba_to_negativeP6uchar4Phii
	.section	.rodata.str1.1
.LC17:
	.string	"../PPMImages/Poivron.ppm"
.LC18:
	.string	"../PPMResults/Poivron_gray.pgm"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC17(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	_Z7readPPMPKc
	movl	$16, %ecx
	movl	$255, %esi
	movl	$1, 24(%rsp)
	movl	(%rax), %r13d
	movl	4(%rax), %r14d
	movq	%rax, %rdi
	movl	$1, 36(%rsp)
	leal	15(%r13), %eax
	movl	%r13d, %ebx
	cltd
	imull	%r14d, %ebx
	idivl	%ecx
	movslq	%ebx, %r15
	sall	$2, %ebx
	movslq	%ebx, %rbx
	movl	%eax, 16(%rsp)
	leal	15(%r14), %eax
	cltd
	idivl	%ecx
	movl	%eax, 20(%rsp)
	movabsq	$68719476752, %rax
	movq	%rax, 28(%rsp)
	call	_Z13PPM_to_uchar4P8PPMImagei
	movq	%r15, %rdi
	movq	%rax, %r12
	call	malloc@PLT
	movq	%rsp, %rdi
	movq	%rbx, %rsi
	movq	%rax, %rbp
	call	cudaMalloc@PLT
	leaq	8(%rsp), %rdi
	movq	%r15, %rsi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	36(%rsp), %ecx
	movl	24(%rsp), %esi
	xorl	%r9d, %r9d
	movq	28(%rsp), %rdx
	movq	16(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L57
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	%r14d, %ecx
	movl	%r13d, %edx
	call	_Z46__device_stub__Z16rgba_to_negativeP6uchar4PhiiP6uchar4Phii
.L57:
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%r15, %rdx
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	movl	%r14d, %ecx
	movl	%r13d, %edx
	movq	%rbp, %rsi
	leaq	.LC18(%rip), %rdi
	call	_Z14writeGrayScalePKcPhii
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L58
	call	__stack_chk_fail@PLT
.L58:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	main, .-main
	.section	.rodata.str1.1
.LC19:
	.string	"_Z16rgba_to_negativeP6uchar4Phii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.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	.LC19(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z16rgba_to_negativeP6uchar4Phii(%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
.LFE2060:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include "imageutils.cuh"

// weights of each color channel
#define RED_WEIGHT 		(0.299f)
#define GREEN_WEIGHT 	(0.587f)
#define BLUE_WEIGHT		(0.114f)

// dimensions of the thread blocks
#define NUM_BLOCKS_X 	16
#define NUM_BLOCKS_Y	16

__global__
void rgba_to_negative(
	uchar4 *rgbaImage,
	unsigned char*grayscaleImage,
	int numRows, int numCols
) {
	// finding pixel assigned to this thread
	int thread_x = blockDim.x * blockIdx.x + threadIdx.x;
	int thread_y = blockDim.y * blockIdx.y + threadIdx.y;
	int idx = thread_x * numCols + thread_y;

	// thread is out of range (happens when block dimensions don't allign)
	if(thread_x >= numRows || thread_y >= numCols) {
	// if (idx < numRows * numCols) should also work
		return;
	}

	// averaging the values does not work well
	// as our eyes are not receptive to all colors equally
	// these weights give a better feeling grayscale image
	grayscaleImage[idx] =	rgbaImage[idx].x * RED_WEIGHT +
							rgbaImage[idx].y * GREEN_WEIGHT +
							rgbaImage[idx].z * BLUE_WEIGHT;
}

int main() {
// load input picture
	PPMImage *input_image = readPPM("../PPMImages/Poivron.ppm");
	const int dim_x = input_image->x;
	const int dim_y = input_image->y;

	// dimension and size of both arrays for testing
	const int RGB_SIZE = dim_x * dim_y;
	const int RGB_BYTES = RGB_SIZE * sizeof(uchar4);
	const int GRAYSCALE_SIZE = dim_x * dim_y;
	const int GRAYSCALE_BYTES = GRAYSCALE_SIZE * sizeof(unsigned char);

	// calculating grid and block dimensions of threads
	int grid_size_x = (dim_x + NUM_BLOCKS_X - 1) / NUM_BLOCKS_X;
	int grid_size_y = (dim_y + NUM_BLOCKS_Y - 1) / NUM_BLOCKS_Y;
	dim3 grid_dims = dim3(grid_size_x, grid_size_y, 1);
	dim3 block_dims = dim3(NUM_BLOCKS_X, NUM_BLOCKS_Y, 1);

	// memory pointers
	uchar4 *h_image_rgb;
	unsigned char *h_image_grayscale;
	uchar4 *d_image_rgb;
	unsigned char *d_image_grayscale;

	// memory allocation on host
	h_image_rgb = PPM_to_uchar4(input_image, 255);
	h_image_grayscale = (unsigned char *) malloc(GRAYSCALE_BYTES);

	// memory allocation on device
	hipMalloc((void **) &d_image_rgb, RGB_BYTES);
	hipMalloc((void **) &d_image_grayscale, GRAYSCALE_BYTES);

	// transferring input array to device memory
	hipMemcpy(d_image_rgb, h_image_rgb, RGB_BYTES, hipMemcpyHostToDevice);

	// launching kernels
	rgba_to_negative<<<grid_dims, block_dims>>>(
		d_image_rgb,
		d_image_grayscale,
		dim_x, dim_y
	);

	// getting back the negative image
	hipMemcpy(h_image_grayscale, d_image_grayscale, GRAYSCALE_BYTES, hipMemcpyDeviceToHost);

	// save resulting file
	writeGrayScale("../PPMResults/Poivron_gray.pgm", h_image_grayscale, dim_x, dim_y);

	// free host memory
	free(h_image_rgb);
	free(h_image_grayscale);

	// free device memory
	hipFree(d_image_rgb);
	hipFree(d_image_grayscale);

	return 0;
}
	.text
	.file	"grayscale.hip"
	.globl	_Z7readPPMPKc                   # -- Begin function _Z7readPPMPKc
	.type	_Z7readPPMPKc,@function
_Z7readPPMPKc:                          # @_Z7readPPMPKc
	.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	$32, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	$.L.str, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_14
# %bb.1:
	movq	%rax, %r14
	leaq	16(%rsp), %rdi
	movl	$16, %esi
	movq	%rax, %rdx
	callq	fgets
	testq	%rax, %rax
	je	.LBB0_15
# %bb.2:
	cmpb	$80, 16(%rsp)
	jne	.LBB0_16
# %bb.3:
	cmpb	$54, 17(%rsp)
	jne	.LBB0_16
# %bb.4:
	movl	$16, %edi
	callq	malloc
	testq	%rax, %rax
	je	.LBB0_17
# %bb.5:
	movq	%rax, %r15
.LBB0_6:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_7 Depth 2
	movq	%r14, %rdi
	callq	getc
	cmpl	$35, %eax
	jne	.LBB0_8
.LBB0_7:                                # %.preheader44
                                        #   Parent Loop BB0_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r14, %rdi
	callq	getc
	cmpl	$10, %eax
	jne	.LBB0_7
	jmp	.LBB0_6
.LBB0_8:                                # %._crit_edge
	movl	%eax, %edi
	movq	%r14, %rsi
	callq	ungetc
	movq	%r15, %rcx
	addq	$4, %rcx
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$2, %eax
	jne	.LBB0_20
# %bb.9:
	leaq	12(%rsp), %rdx
	movl	$.L.str.6, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$1, %eax
	jne	.LBB0_21
# %bb.10:
	cmpl	$255, 12(%rsp)
	jne	.LBB0_22
.LBB0_11:                               # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	callq	fgetc
	cmpl	$10, %eax
	jne	.LBB0_11
# %bb.12:
	movslq	(%r15), %rax
	movslq	4(%r15), %r12
	leaq	(%rax,%rax,2), %r13
	movq	%r13, %rdi
	imulq	%r12, %rdi
	callq	malloc
	movq	%rax, 8(%r15)
	movq	%rax, %rdi
	movq	%r13, %rsi
	movq	%r12, %rdx
	movq	%r14, %rcx
	callq	fread
	movslq	4(%r15), %rcx
	cmpq	%rcx, %rax
	jne	.LBB0_23
# %bb.13:
	movq	%r14, %rdi
	callq	fclose
	movq	%r15, %rax
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB0_14:
	.cfi_def_cfa_offset 80
	movq	stderr(%rip), %rdi
	movl	$.L.str.1, %esi
	jmp	.LBB0_24
.LBB0_15:
	movq	%rbx, %rdi
	callq	perror
	jmp	.LBB0_19
.LBB0_16:
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$36, %esi
	jmp	.LBB0_18
.LBB0_17:
	movq	stderr(%rip), %rcx
	movl	$.L.str.3, %edi
	movl	$26, %esi
.LBB0_18:
	movl	$1, %edx
	callq	fwrite
	jmp	.LBB0_19
.LBB0_20:
	movq	stderr(%rip), %rdi
	movl	$.L.str.5, %esi
	jmp	.LBB0_24
.LBB0_21:
	movq	stderr(%rip), %rdi
	movl	$.L.str.7, %esi
	jmp	.LBB0_24
.LBB0_22:
	movq	stderr(%rip), %rdi
	movl	$.L.str.8, %esi
	jmp	.LBB0_24
.LBB0_23:
	movq	stderr(%rip), %rdi
	movl	$.L.str.9, %esi
.LBB0_24:
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	fprintf
.LBB0_19:
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z7readPPMPKc, .Lfunc_end0-_Z7readPPMPKc
	.cfi_endproc
                                        # -- End function
	.globl	_Z8writePPMPKcP8PPMImage        # -- Begin function _Z8writePPMPKcP8PPMImage
	.type	_Z8writePPMPKcP8PPMImage,@function
_Z8writePPMPKcP8PPMImage:               # @_Z8writePPMPKcP8PPMImage
	.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.10, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_1
# %bb.2:
	movq	%rax, %r14
	movl	$.L.str.11, %edi
	movl	$3, %esi
	movl	$1, %edx
	movq	%rax, %rcx
	callq	fwrite
	movl	(%rbx), %edx
	movl	4(%rbx), %ecx
	movl	$.L.str.12, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	$.L.str.13, %esi
	movq	%r14, %rdi
	movl	$255, %edx
	xorl	%eax, %eax
	callq	fprintf
	movq	8(%rbx), %rdi
	movslq	(%rbx), %rax
	leaq	(%rax,%rax,2), %rsi
	movslq	4(%rbx), %rdx
	movq	%r14, %rcx
	callq	fwrite
	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
.LBB1_1:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rdi
	movl	$.L.str.1, %esi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z8writePPMPKcP8PPMImage, .Lfunc_end1-_Z8writePPMPKcP8PPMImage
	.cfi_endproc
                                        # -- End function
	.globl	_Z14writeGrayScalePKcPhii       # -- Begin function _Z14writeGrayScalePKcPhii
	.type	_Z14writeGrayScalePKcPhii,@function
_Z14writeGrayScalePKcPhii:              # @_Z14writeGrayScalePKcPhii
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%ecx, %ebx
	movl	%edx, %ebp
	movq	%rsi, 8(%rsp)                   # 8-byte Spill
	movq	%rdi, %r12
	movl	$.L.str.10, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB2_8
# %bb.1:
	movq	%rax, %r15
	movl	$.L.str.14, %edi
	movl	$3, %esi
	movl	$1, %edx
	movq	%rax, %rcx
	callq	fwrite
	movl	$.L.str.12, %esi
	movq	%r15, %rdi
	movl	%ebp, %edx
	movl	%ebx, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movl	$.L.str.13, %esi
	movq	%r15, %rdi
	movl	$255, %edx
	xorl	%eax, %eax
	callq	fprintf
	testl	%ebp, %ebp
	jle	.LBB2_7
# %bb.2:                                # %.preheader.lr.ph
	movl	%ebp, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%ebx, %r13d
	xorl	%ebp, %ebp
	xorl	%r14d, %r14d
	movl	%ebx, 4(%rsp)                   # 4-byte Spill
.LBB2_3:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_5 Depth 2
	testl	%ebx, %ebx
	jle	.LBB2_6
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB2_3 Depth=1
	movl	%ebp, %r12d
	addq	8(%rsp), %r12                   # 8-byte Folded Reload
	xorl	%ebx, %ebx
.LBB2_5:                                #   Parent Loop BB2_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movzbl	(%r12,%rbx), %edx
	movl	$.L.str.15, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%rbx
	cmpq	%rbx, %r13
	jne	.LBB2_5
.LBB2_6:                                # %._crit_edge
                                        #   in Loop: Header=BB2_3 Depth=1
	movl	$10, %edi
	movq	%r15, %rsi
	callq	fputc@PLT
	incq	%r14
	movl	4(%rsp), %ebx                   # 4-byte Reload
	addl	%ebx, %ebp
	cmpq	16(%rsp), %r14                  # 8-byte Folded Reload
	jne	.LBB2_3
.LBB2_7:                                # %._crit_edge26
	movq	%r15, %rdi
	addq	$24, %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
	jmp	fclose                          # TAILCALL
.LBB2_8:
	.cfi_def_cfa_offset 80
	movq	stderr(%rip), %rdi
	movl	$.L.str.1, %esi
	movq	%r12, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z14writeGrayScalePKcPhii, .Lfunc_end2-_Z14writeGrayScalePKcPhii
	.cfi_endproc
                                        # -- End function
	.globl	_Z13PPM_to_uchar4P8PPMImagei    # -- Begin function _Z13PPM_to_uchar4P8PPMImagei
	.type	_Z13PPM_to_uchar4P8PPMImagei,@function
_Z13PPM_to_uchar4P8PPMImagei:           # @_Z13PPM_to_uchar4P8PPMImagei
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%esi, %ebx
	movq	%rdi, %r14
	movl	(%rdi), %r15d
	movl	4(%rdi), %r12d
	movl	%r12d, %eax
	imull	%r15d, %eax
	movslq	%eax, %rdi
	shlq	$2, %rdi
	callq	malloc
	testl	%r15d, %r15d
	jle	.LBB3_6
# %bb.1:                                # %.preheader.lr.ph
	movq	%rax, %rcx
	addq	$3, %rcx
	xorl	%edx, %edx
	xorl	%esi, %esi
.LBB3_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
	testl	%r12d, %r12d
	jle	.LBB3_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB3_2 Depth=1
	movl	%edx, %edi
	leaq	(%rdi,%rdi,2), %r8
	leaq	(%rcx,%rdi,4), %rdi
	movq	8(%r14), %r9
	addq	%r9, %r8
	addq	$2, %r8
	xorl	%r9d, %r9d
.LBB3_4:                                #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movb	-2(%r8), %r10b
	movb	%r10b, -3(%rdi,%r9,4)
	movb	(%r8), %r10b
	movb	%r10b, -2(%rdi,%r9,4)
	movb	-1(%r8), %r10b
	movb	%r10b, -1(%rdi,%r9,4)
	movb	%bl, (%rdi,%r9,4)
	incq	%r9
	addq	$3, %r8
	cmpq	%r9, %r12
	jne	.LBB3_4
.LBB3_5:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	incq	%rsi
	addl	%r12d, %edx
	cmpq	%r15, %rsi
	jne	.LBB3_2
.LBB3_6:                                # %._crit_edge30
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z13PPM_to_uchar4P8PPMImagei, .Lfunc_end3-_Z13PPM_to_uchar4P8PPMImagei
	.cfi_endproc
                                        # -- End function
	.globl	_Z13uchar4_to_PPMP15HIP_vector_typeIhLj4EEii # -- Begin function _Z13uchar4_to_PPMP15HIP_vector_typeIhLj4EEii
	.type	_Z13uchar4_to_PPMP15HIP_vector_typeIhLj4EEii,@function
_Z13uchar4_to_PPMP15HIP_vector_typeIhLj4EEii: # @_Z13uchar4_to_PPMP15HIP_vector_typeIhLj4EEii
	.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
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, %r14
	movl	$16, %edi
	callq	malloc
	movq	%rax, %r15
	movl	%ebp, (%rax)
	movl	%ebx, 4(%rax)
	movl	%ebx, %eax
	imull	%ebp, %eax
	cltq
	leaq	(%rax,%rax,2), %rdi
	callq	malloc
	movq	%rax, 8(%r15)
	testl	%ebp, %ebp
	jle	.LBB4_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebp, %ecx
	movl	%ebx, %edx
	addq	$2, %rax
	addq	$2, %r14
	xorl	%esi, %esi
	xorl	%edi, %edi
.LBB4_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB4_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB4_2 Depth=1
	movl	%esi, %r9d
	leaq	(%r9,%r9,2), %r8
	addq	%rax, %r8
	leaq	(%r14,%r9,4), %r9
	xorl	%r10d, %r10d
.LBB4_4:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movb	-2(%r9,%r10,4), %r11b
	movb	%r11b, -2(%r8)
	movb	-1(%r9,%r10,4), %r11b
	movb	%r11b, (%r8)
	movb	(%r9,%r10,4), %r11b
	movb	%r11b, -1(%r8)
	incq	%r10
	addq	$3, %r8
	cmpq	%r10, %rdx
	jne	.LBB4_4
.LBB4_5:                                # %._crit_edge
                                        #   in Loop: Header=BB4_2 Depth=1
	incq	%rdi
	addl	%ebx, %esi
	cmpq	%rcx, %rdi
	jne	.LBB4_2
.LBB4_6:                                # %._crit_edge32
	movq	%r15, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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_end4:
	.size	_Z13uchar4_to_PPMP15HIP_vector_typeIhLj4EEii, .Lfunc_end4-_Z13uchar4_to_PPMP15HIP_vector_typeIhLj4EEii
	.cfi_endproc
                                        # -- End function
	.globl	_Z31__device_stub__rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii # -- Begin function _Z31__device_stub__rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
	.type	_Z31__device_stub__rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii,@function
_Z31__device_stub__rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii: # @_Z31__device_stub__rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
	.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	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%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	$_Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii, %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_end5:
	.size	_Z31__device_stub__rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii, .Lfunc_end5-_Z31__device_stub__rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function 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	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$.L.str.17, %edi
	callq	_Z7readPPMPKc
	movl	(%rax), %ebx
	movl	4(%rax), %r14d
	movl	%r14d, %ecx
	imull	%ebx, %ecx
	movslq	%ecx, %r15
	leal	15(%rbx), %ecx
	leal	30(%rbx), %edx
	testl	%ecx, %ecx
	cmovnsl	%ecx, %edx
	sarl	$4, %edx
	leal	15(%r14), %ecx
	leal	30(%r14), %ebp
	testl	%ecx, %ecx
	cmovnsl	%ecx, %ebp
	leal	(,%r15,4), %r12d
	sarl	$4, %ebp
	shlq	$32, %rbp
	orq	%rdx, %rbp
	movq	%rax, %rdi
	movl	$255, %esi
	callq	_Z13PPM_to_uchar4P8PPMImagei
	movq	%rax, %r13
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movslq	%r12d, %r12
	leaq	8(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	%rsp, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rax
	movq	(%rax), %rdi
	movq	%r13, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movq	%rbp, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_2
# %bb.1:
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movl	%ebx, %edx
	movl	%r14d, %ecx
	callq	_Z31__device_stub__rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
.LBB6_2:
	movq	(%rsp), %rsi
	movq	16(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.18, %edi
	movq	%r12, %rsi
	movl	%ebx, %edx
	movl	%r14d, %ecx
	callq	_Z14writeGrayScalePKcPhii
	movq	%r13, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	main, .Lfunc_end6-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	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii, %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_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__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	"Unable to open file '%s'\n"
	.size	.L.str.1, 26

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Invalid image format (must be 'P6')\n"
	.size	.L.str.2, 37

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Unable to allocate memory\n"
	.size	.L.str.3, 27

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%d %d"
	.size	.L.str.4, 6

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Invalid image size (error loading '%s')\n"
	.size	.L.str.5, 41

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Invalid rgb component (error loading '%s')\n"
	.size	.L.str.7, 44

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"'%s' does not have 8-bits components\n"
	.size	.L.str.8, 38

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Error loading image '%s'\n"
	.size	.L.str.9, 26

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

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"P6\n"
	.size	.L.str.11, 4

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

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

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"P2\n"
	.size	.L.str.14, 4

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"%d "
	.size	.L.str.15, 4

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

	.type	.L.str.17,@object               # @.str.17
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.17:
	.asciz	"../PPMImages/Poivron.ppm"
	.size	.L.str.17, 25

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"../PPMResults/Poivron_gray.pgm"
	.size	.L.str.18, 31

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii"
	.size	.L__unnamed_1, 50

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z31__device_stub__rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii ; -- Begin function _Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
	.globl	_Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
	.p2align	8
	.type	_Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii,@function
_Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii: ; @_Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b64 s[2:3], s[0:1], 0x10
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s5, s4, 16
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s4, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s5, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s2, v0
	v_cmp_gt_i32_e64 s2, s3, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s4, s2
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, v0, s3, v[1:2]
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_load_b32 v0, v[0:1], off
	s_waitcnt vmcnt(0)
	v_cvt_f32_ubyte1_e32 v1, v0
	v_cvt_f32_ubyte0_e32 v4, v0
	v_cvt_f32_ubyte2_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v1, 0x3f1645a2, v1
	v_fmamk_f32 v1, v4, 0x3e991687, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmamk_f32 v0, v0, 0x3de978d5, v1
	v_cvt_i32_f32_e32 v4, v0
	v_add_co_u32 v0, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v3, vcc_lo
	global_store_b8 v[0:1], v4, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 5
		.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	_Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii, .Lfunc_end0-_Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 252
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z16rgba_to_negativeP15HIP_vector_typeIhLj4EEPhii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
