
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <fstream>

cudaError_t addWithCuda(unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue, unsigned int size);
int checkSize(char* filename);
void appendHeader(char* filename, char* origin);
void readBMP(char* filename, unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue);
void writeBMP(char* filename, char* origin, unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue);
void get(unsigned char* color_from, unsigned char* color_to, int start, int end);
void set(unsigned char* color_from, unsigned char* color_to, int start, int end);

__global__ void addKernel(unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue)
{
	int i = threadIdx.x;
	/*int value_red = (((int)p_red[i]) <= 0) ?  (-1 * (int)p_red[i]) : (128 + (int)p_red[i]);
	int value_green = (((int)p_green[i]) <= 0) ? (-1 * (int)p_green[i]) : (128 + (int)p_green[i]);
	int value_blue = (((int)p_blue[i]) <= 0) ? (-1 * (int)p_blue[i]) : (128 + (int)p_blue[i]);
	char avg = (value_red * 299 + value_green * 587 + value_blue * 114) / 1000 - 128;*/
	int red_value = p_red[i];
	int green_value = p_green[i];
	int blue_value = p_blue[i];
	/*char avg = (red_value * 299 + green_value * 587 + blue_value * 114) / 1000;*/
	char avg = (red_value + green_value + blue_value) / 3;
	/*if (avg > 128)
	{
		avg -= (avg - 128) * 0.95;
	} else {
		avg += (128 - avg) * 0.95;
	}*/
	/*if (p_red[i] > 128)
	{
		p_red[i] -= (p_red[i] - 128) * 0.99;
	}
	else {
		p_red[i] += (128 - p_red[i]) * 0.99;
	}

	if (p_green[i] > 128)
	{
		p_green[i] -= (p_green[i] - 128) * 0.98;
	}
	else {
		p_green[i] += (128 - p_green[i]) * 0.98;
	}

	if (p_blue[i] > 128)
	{
		p_blue[i] -= (p_blue[i] - 128) * 0.95;
	}
	else {
		p_blue[i] += (128 - p_blue[i]) * 0.94;
	}*/

	p_red[i] = avg;
	p_green[i] = avg;
	p_blue[i] = avg;
}

int main()
{
	const int Block = 1024;
	int size = checkSize("C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\test.bmp");
	unsigned char* red = new unsigned char[size];
	unsigned char* green = new unsigned char[size];
	unsigned char* blue = new unsigned char[size];
	readBMP("C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\test.bmp", red, green, blue);
	int current_size = size;
	cudaError_t cudaStatus;
	while (current_size > 0)
	{
		if (current_size >= Block)
		{
			unsigned char* temp_red = new unsigned char[Block];
			unsigned char* temp_green = new unsigned char[Block];
			unsigned char* temp_blue = new unsigned char[Block];
			get(red, temp_red, size - current_size, size - current_size + Block);
			get(green, temp_green, size - current_size, size - current_size + Block);
			get(blue, temp_blue, size - current_size, size - current_size + Block);
			//int value = temp_red[500];
			cudaStatus = addWithCuda(temp_red, temp_green, temp_blue, Block);
			set(temp_red, red, size - current_size, size - current_size + Block);
			set(temp_green, green, size - current_size, size - current_size + Block);
			set(temp_blue, blue, size - current_size, size - current_size + Block);
			current_size -= Block;
			delete temp_red;
			delete temp_green;
			delete temp_blue;
		} else {
			unsigned char* temp_red = new unsigned char[current_size];
			unsigned char* temp_green = new unsigned char[current_size];
			unsigned char* temp_blue = new unsigned char[current_size];
			get(red, temp_red, size - current_size, size);
			get(green, temp_green, size - current_size, size);
			get(blue, temp_blue, size - current_size, size);
			cudaStatus = addWithCuda(temp_red, temp_green, temp_blue, current_size);
			set(temp_red, red, size - current_size, size);
			set(temp_green, green, size - current_size, size);
			set(temp_blue, blue, size - current_size, size);
			current_size -= current_size;
			delete temp_red;
			delete temp_green;
			delete temp_blue;
		}
		if (cudaStatus != cudaSuccess) {
			fprintf(stderr, "addWithCuda failed!");
			return 1;
		}
	}
    
    

    // cudaDeviceReset must be called before exiting in order for profiling and
    // tracing tools such as Nsight and Visual Profiler to show complete traces.
    cudaStatus = cudaDeviceReset();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceReset failed!");
        return 1;
    }
	writeBMP("C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\output.bmp", "C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\test.bmp", red, green, blue);
	delete red;
	delete green;
	delete blue;
    return 0;
}

void get(unsigned char* color_from, unsigned char* color_to, int start, int end)
{
	int index = 0;
	for (int i = start; i < end - start; i++)
	{
		color_to[index] = color_from[i];
		index++;
	}
}

void set(unsigned char* color_from, unsigned char* color_to, int start, int end)
{
	int index = 0;
	for (int i = start; i < end - start; i++)
	{
		color_to[i] = color_from[index];
		index++;
	}
}

int checkSize(char* filename)
{
	FILE* f = fopen(filename, "rb");
	unsigned char info[54];
	fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header

	// extract image height and width from header
	int width = *(int*)&info[18];
	int height = *(int*)&info[22];
	int size = width * height;
	fclose(f);
	return size;
}

void appendHeader(char* filename, char* origin)
{
	FILE* f = fopen(origin, "rb");
	unsigned char* info = new unsigned char[54];
	fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header
	fclose(f);
	f = fopen(filename, "wb");
	fwrite(info, sizeof(unsigned char), 54, f);
	fclose(f);
	delete info;
}

void readBMP(char* filename, unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue)
{
	int i;
	FILE* f = fopen(filename, "rb");
	unsigned char info[54];
	fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header

	// extract image height and width from header
	int width = *(int*)&info[18];
	int height = *(int*)&info[22];

	int size = 3 * width * height;
	unsigned char* data = new unsigned char[size];
	fread(data, sizeof(unsigned char), size, f); // read the rest of the data at once
	fclose(f);

	int index = 0;

	for (i = 0; i < size; i += 3)
	{
		int red = data[i];
		int green = data[i + 1];
		int blue = data[i + 2];
		p_red[index] = red;
		p_green[index] = green;
		p_blue[index] = blue;
		index++;
	}
	delete data;
}

void writeBMP(char* filename, char* originfile, unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue)
{
	int i;
	appendHeader(filename, originfile);

	FILE* f = fopen(filename, "a+b");

	int size = 3 * checkSize(originfile);
	unsigned char* data = new unsigned char[size];

	int index = 0;

	for (i = 0; i < size; i += 3)
	{
		data[i] = p_red[index];
		data[i + 1] = p_green[index];
		data[i + 2] = p_blue[index];
		index++;
	}

	fwrite(data, sizeof(unsigned char), size, f); // read the rest of the data at once
	fclose(f);
	delete data;
}

// Helper function for using CUDA to add vectors in parallel.
cudaError_t addWithCuda(unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue, unsigned int size)
{
	unsigned char *dev_a = 0;
	unsigned char *dev_b = 0;
	unsigned char *dev_c = 0;
    cudaError_t cudaStatus;

    // Choose which GPU to run on, change this on a multi-GPU system.
    cudaStatus = cudaSetDevice(0);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?");
        goto Error;
    }

    cudaStatus = cudaMalloc((void**)&dev_a, size * sizeof(unsigned char));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

    cudaStatus = cudaMalloc((void**)&dev_b, size * sizeof(unsigned char));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }

	// Allocate GPU buffers for three vectors (two input, one output)    .
	cudaStatus = cudaMalloc((void**)&dev_c, size * sizeof(unsigned char));
	if (cudaStatus != cudaSuccess) {
		fprintf(stderr, "cudaMalloc failed!");
		goto Error;
	}

    // Copy input vectors from host memory to GPU buffers.
    cudaStatus = cudaMemcpy(dev_a, p_red, size * sizeof(unsigned char), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

    cudaStatus = cudaMemcpy(dev_b, p_green, size * sizeof(unsigned char), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

	cudaStatus = cudaMemcpy(dev_c, p_blue, size * sizeof(unsigned char), cudaMemcpyHostToDevice);
	if (cudaStatus != cudaSuccess) {
		fprintf(stderr, "cudaMemcpy failed!");
		goto Error;
	}

    // Launch a kernel on the GPU with one thread for each element.
    addKernel<<<1, size>>>(dev_a, dev_b, dev_c);

    // Check for any errors launching the kernel
    cudaStatus = cudaGetLastError();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus));
        goto Error;
    }
    
    // cudaDeviceSynchronize waits for the kernel to finish, and returns
    // any errors encountered during the launch.
    cudaStatus = cudaDeviceSynchronize();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
        goto Error;
    }

	cudaStatus = cudaMemcpy(p_red, dev_a, size * sizeof(unsigned char), cudaMemcpyDeviceToHost);
	if (cudaStatus != cudaSuccess) {
		fprintf(stderr, "cudaMemcpy failed!");
		goto Error;
	}

	cudaStatus = cudaMemcpy(p_green, dev_b, size * sizeof(unsigned char), cudaMemcpyDeviceToHost);
	if (cudaStatus != cudaSuccess) {
		fprintf(stderr, "cudaMemcpy failed!");
		goto Error;
	}

    // Copy output vector from GPU buffer to host memory.
    cudaStatus = cudaMemcpy(p_blue, dev_c, size * sizeof(unsigned char), cudaMemcpyDeviceToHost);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }

Error:
    cudaFree(dev_a);
    cudaFree(dev_b);
	cudaFree(dev_c);

    return cudaStatus;
}
	.file	"tmpxft_002cc072_00000000-6_kernel.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3776:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3776:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z3getPhS_ii
	.type	_Z3getPhS_ii, @function
_Z3getPhS_ii:
.LFB3767:
	.cfi_startproc
	endbr64
	movslq	%edx, %rax
	subl	%edx, %ecx
	subq	%rax, %rsi
.L3:
	cmpl	%eax, %ecx
	jle	.L6
	movb	(%rdi,%rax), %dl
	movb	%dl, (%rsi,%rax)
	incq	%rax
	jmp	.L3
.L6:
	ret
	.cfi_endproc
.LFE3767:
	.size	_Z3getPhS_ii, .-_Z3getPhS_ii
	.globl	_Z3setPhS_ii
	.type	_Z3setPhS_ii, @function
_Z3setPhS_ii:
.LFB3768:
	.cfi_startproc
	endbr64
	movslq	%edx, %rax
	subl	%edx, %ecx
	subq	%rax, %rdi
.L8:
	cmpl	%eax, %ecx
	jle	.L10
	movb	(%rdi,%rax), %dl
	movb	%dl, (%rsi,%rax)
	incq	%rax
	jmp	.L8
.L10:
	ret
	.cfi_endproc
.LFE3768:
	.size	_Z3setPhS_ii, .-_Z3setPhS_ii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
	.text
	.globl	_Z9checkSizePc
	.type	_Z9checkSizePc, @function
_Z9checkSizePc:
.LFB3769:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$72, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	leaq	2(%rsp), %rdi
	movl	$54, %ecx
	movl	$1, %edx
	movq	%rax, %rbx
	movq	%rax, %r8
	movl	$54, %esi
	call	__fread_chk@PLT
	movq	%rbx, %rdi
	movl	20(%rsp), %ebp
	imull	24(%rsp), %ebp
	call	fclose@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	addq	$72, %rsp
	.cfi_def_cfa_offset 24
	movl	%ebp, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3769:
	.size	_Z9checkSizePc, .-_Z9checkSizePc
	.section	.rodata.str1.1
.LC1:
	.string	"wb"
	.text
	.globl	_Z12appendHeaderPcS_
	.type	_Z12appendHeaderPcS_, @function
_Z12appendHeaderPcS_:
.LFB3770:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	movq	%rsi, %rdi
	leaq	.LC0(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	fopen@PLT
	movl	$54, %edi
	movq	%rax, %rbp
	call	_Znam@PLT
	movq	%rbp, %r8
	movl	$54, %ecx
	movl	$1, %edx
	movl	$54, %esi
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	__fread_chk@PLT
	movq	%rbp, %rdi
	call	fclose@PLT
	movq	%r12, %rdi
	leaq	.LC1(%rip), %rsi
	call	fopen@PLT
	movl	$1, %esi
	movq	%rbx, %rdi
	movl	$54, %edx
	movq	%rax, %rbp
	movq	%rax, %rcx
	call	fwrite@PLT
	movq	%rbp, %rdi
	call	fclose@PLT
	movq	%rbx, %rdi
	movl	$1, %esi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	_ZdlPvm@PLT
	.cfi_endproc
.LFE3770:
	.size	_Z12appendHeaderPcS_, .-_Z12appendHeaderPcS_
	.globl	_Z7readBMPPcPhS0_S0_
	.type	_Z7readBMPPcPhS0_S0_, @function
_Z7readBMPPcPhS0_S0_:
.LFB3771:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rcx, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rsi, %r13
	leaq	.LC0(%rip), %rsi
	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	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movl	$54, %ecx
	movl	$1, %edx
	leaq	18(%rsp), %rdi
	movq	%rax, %r8
	movl	$54, %esi
	movq	%rax, %r12
	call	__fread_chk@PLT
	movl	36(%rsp), %ebp
	imull	40(%rsp), %ebp
	leal	0(%rbp,%rbp,2), %ebp
	movslq	%ebp, %rsi
	movq	%rsi, %rdi
	movq	%rsi, 8(%rsp)
	call	_Znam@PLT
	movq	8(%rsp), %rsi
	movl	$1, %edx
	movq	%r12, %r8
	movq	%rax, %rdi
	movq	%rax, %rbx
	movq	%rsi, %rcx
	call	__fread_chk@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	xorl	%eax, %eax
	xorl	%edx, %edx
.L17:
	cmpl	%eax, %ebp
	jle	.L21
	movb	1(%rbx,%rax), %sil
	movb	2(%rbx,%rax), %cl
	movb	(%rbx,%rax), %dil
	addq	$3, %rax
	movb	%dil, 0(%r13,%rdx)
	movb	%sil, (%r14,%rdx)
	movb	%cl, (%r15,%rdx)
	incq	%rdx
	jmp	.L17
.L21:
	movl	$1, %esi
	movq	%rbx, %rdi
	call	_ZdlPvm@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3771:
	.size	_Z7readBMPPcPhS0_S0_, .-_Z7readBMPPcPhS0_S0_
	.section	.rodata.str1.1
.LC2:
	.string	"a+b"
	.text
	.globl	_Z8writeBMPPcS_PhS0_S0_
	.type	_Z8writeBMPPcS_PhS0_S0_, @function
_Z8writeBMPPcS_PhS0_S0_:
.LFB3772:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rcx, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	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
	movq	%rsi, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%r8, 8(%rsp)
	movq	%rdi, (%rsp)
	call	_Z12appendHeaderPcS_
	movq	(%rsp), %rdi
	leaq	.LC2(%rip), %rsi
	call	fopen@PLT
	movq	%rbx, %rdi
	movq	%rax, %rbp
	call	_Z9checkSizePc
	leal	(%rax,%rax,2), %r12d
	movslq	%r12d, %r14
	movq	%r14, %rdi
	call	_Znam@PLT
	movq	8(%rsp), %r8
	xorl	%edx, %edx
	movq	%rax, %rbx
	xorl	%eax, %eax
.L23:
	cmpl	%eax, %r12d
	jle	.L26
	movb	0(%r13,%rdx), %cl
	movb	%cl, (%rbx,%rax)
	movb	(%r15,%rdx), %cl
	movb	%cl, 1(%rbx,%rax)
	movb	(%r8,%rdx), %cl
	incq	%rdx
	movb	%cl, 2(%rbx,%rax)
	addq	$3, %rax
	jmp	.L23
.L26:
	movq	%rbp, %rcx
	movq	%r14, %rdx
	movl	$1, %esi
	movq	%rbx, %rdi
	call	fwrite@PLT
	movq	%rbp, %rdi
	call	fclose@PLT
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rdi
	movl	$1, %esi
	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	_ZdlPvm@PLT
	.cfi_endproc
.LFE3772:
	.size	_Z8writeBMPPcS_PhS0_S0_, .-_Z8writeBMPPcS_PhS0_S0_
	.globl	_Z32__device_stub__Z9addKernelPhS_S_PhS_S_
	.type	_Z32__device_stub__Z9addKernelPhS_S_PhS_S_, @function
_Z32__device_stub__Z9addKernelPhS_S_PhS_S_:
.LFB3798:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%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	.L27
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z9addKernelPhS_S_(%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
.L27:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L29
	call	__stack_chk_fail@PLT
.L29:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3798:
	.size	_Z32__device_stub__Z9addKernelPhS_S_PhS_S_, .-_Z32__device_stub__Z9addKernelPhS_S_PhS_S_
	.globl	_Z9addKernelPhS_S_
	.type	_Z9addKernelPhS_S_, @function
_Z9addKernelPhS_S_:
.LFB3799:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z9addKernelPhS_S_PhS_S_
	.cfi_endproc
.LFE3799:
	.size	_Z9addKernelPhS_S_, .-_Z9addKernelPhS_S_
	.section	.rodata.str1.1
.LC3:
	.string	"cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?"
.LC4:
	.string	"cudaMalloc failed!"
.LC5:
	.string	"cudaMemcpy failed!"
.LC6:
	.string	"addKernel launch failed: %s\n"
.LC7:
	.string	"cudaDeviceSynchronize returned error code %d after launching addKernel!\n"
	.text
	.globl	_Z11addWithCudaPhS_S_j
	.type	_Z11addWithCudaPhS_S_j, @function
_Z11addWithCudaPhS_S_j:
.LFB3773:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%ecx, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	xorl	%edi, %edi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	xorl	%eax, %eax
	movq	%rax, 8(%rsp)
	movq	%rax, 16(%rsp)
	movq	%rax, 24(%rsp)
	call	cudaSetDevice@PLT
	leaq	.LC3(%rip), %rdx
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L50
	movl	%r15d, %ebp
	leaq	8(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L53
	leaq	16(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L53
	leaq	24(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L37
.L53:
	leaq	.LC4(%rip), %rdx
	jmp	.L50
.L37:
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L51
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L51
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	%r12, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L51
	movl	%r15d, 44(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movq	%rdi, 48(%rsp)
	movl	52(%rsp), %ecx
	movq	44(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L41
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	_Z32__device_stub__Z9addKernelPhS_S_PhS_S_
.L41:
	call	cudaGetLastError@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L42
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC6(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L34
.L42:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L43
	movq	stderr(%rip), %rdi
	movl	%eax, %ecx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC7(%rip), %rdx
	call	__fprintf_chk@PLT
	jmp	.L34
.L43:
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdx
	movq	%r14, %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L51
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L51
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdx
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L34
.L51:
	leaq	.LC5(%rip), %rdx
.L50:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L34:
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L48
	call	__stack_chk_fail@PLT
.L48:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebx, %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
.LFE3773:
	.size	_Z11addWithCudaPhS_S_j, .-_Z11addWithCudaPhS_S_j
	.section	.rodata.str1.1
.LC8:
	.string	"C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\test.bmp"
.LC9:
	.string	"addWithCuda failed!"
.LC10:
	.string	"cudaDeviceReset failed!"
.LC11:
	.string	"C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\output.bmp"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3766:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC8(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	call	_Z9checkSizePc
	movslq	%eax, %rbx
	movq	%rbx, %rdi
	movq	%rbx, %rbp
	call	_Znam@PLT
	movq	%rbx, %rdi
	movq	%rax, 16(%rsp)
	call	_Znam@PLT
	movq	%rbx, %rdi
	movq	%rax, 24(%rsp)
	call	_Znam@PLT
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movq	%r12, %rdi
	movq	%rax, %rcx
	movq	%rax, 32(%rsp)
	call	_Z7readBMPPcPhS0_S0_
.L55:
	testl	%ebx, %ebx
	jle	.L66
	movl	%ebp, %eax
	subl	%ebx, %eax
	movl	%eax, 12(%rsp)
	cmpl	$1023, %ebx
	jle	.L56
	movl	$1024, %edi
	subl	$1024, %ebx
	call	_Znam@PLT
	movl	$1024, %edi
	movq	%rax, %r14
	call	_Znam@PLT
	movl	$1024, %edi
	movq	%rax, %r13
	call	_Znam@PLT
	movq	16(%rsp), %rdi
	movq	%r14, %rsi
	movq	%rax, 40(%rsp)
	movl	12(%rsp), %eax
	leal	1024(%rax), %r15d
	movl	%eax, %edx
	movl	%r15d, %ecx
	call	_Z3getPhS_ii
	movl	12(%rsp), %edx
	movl	%r15d, %ecx
	movq	%r13, %rsi
	movq	24(%rsp), %rdi
	call	_Z3getPhS_ii
	movl	12(%rsp), %edx
	movq	40(%rsp), %rsi
	movl	%r15d, %ecx
	movq	32(%rsp), %rdi
	call	_Z3getPhS_ii
	movq	40(%rsp), %rdx
	movq	%r13, %rsi
	movq	%r14, %rdi
	movl	$1024, %ecx
	call	_Z11addWithCudaPhS_S_j
	movl	12(%rsp), %edx
	movl	%r15d, %ecx
	movq	%r14, %rdi
	movq	16(%rsp), %rsi
	movl	%eax, %r12d
	call	_Z3setPhS_ii
	movl	12(%rsp), %edx
	movl	%r15d, %ecx
	movq	%r13, %rdi
	movq	24(%rsp), %rsi
	call	_Z3setPhS_ii
	movl	12(%rsp), %edx
	movq	32(%rsp), %rsi
	movl	%r15d, %ecx
	movq	40(%rsp), %rdi
	call	_Z3setPhS_ii
	movq	%r14, %rdi
	movl	$1, %esi
	call	_ZdlPvm@PLT
	movq	%r13, %rdi
	movl	$1, %esi
	call	_ZdlPvm@PLT
	movq	40(%rsp), %rdi
	movl	$1, %esi
	call	_ZdlPvm@PLT
	jmp	.L57
.L56:
	movslq	%ebx, %r12
	movq	%r12, %rdi
	call	_Znam@PLT
	movq	%r12, %rdi
	movq	%rax, %r15
	call	_Znam@PLT
	movq	%r12, %rdi
	movq	%rax, %r14
	call	_Znam@PLT
	movl	12(%rsp), %edx
	movq	16(%rsp), %rdi
	movl	%ebp, %ecx
	movq	%r15, %rsi
	movq	%rax, %r13
	call	_Z3getPhS_ii
	movl	12(%rsp), %edx
	movq	24(%rsp), %rdi
	movl	%ebp, %ecx
	movq	%r14, %rsi
	call	_Z3getPhS_ii
	movl	12(%rsp), %edx
	movq	32(%rsp), %rdi
	movl	%ebp, %ecx
	movq	%r13, %rsi
	call	_Z3getPhS_ii
	movl	%ebx, %ecx
	movq	%r13, %rdx
	movq	%r14, %rsi
	movq	%r15, %rdi
	xorl	%ebx, %ebx
	call	_Z11addWithCudaPhS_S_j
	movl	12(%rsp), %edx
	movq	16(%rsp), %rsi
	movl	%ebp, %ecx
	movq	%r15, %rdi
	movl	%eax, %r12d
	call	_Z3setPhS_ii
	movl	12(%rsp), %edx
	movq	24(%rsp), %rsi
	movl	%ebp, %ecx
	movq	%r14, %rdi
	call	_Z3setPhS_ii
	movl	12(%rsp), %edx
	movq	32(%rsp), %rsi
	movl	%ebp, %ecx
	movq	%r13, %rdi
	call	_Z3setPhS_ii
	movl	$1, %esi
	movq	%r15, %rdi
	call	_ZdlPvm@PLT
	movl	$1, %esi
	movq	%r14, %rdi
	call	_ZdlPvm@PLT
	movl	$1, %esi
	movq	%r13, %rdi
	call	_ZdlPvm@PLT
.L57:
	testl	%r12d, %r12d
	je	.L55
	leaq	.LC9(%rip), %rdx
	jmp	.L65
.L66:
	call	cudaDeviceReset@PLT
	testl	%eax, %eax
	je	.L60
	leaq	.LC10(%rip), %rdx
.L65:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L54
.L60:
	movq	32(%rsp), %r8
	movq	24(%rsp), %rcx
	leaq	.LC8(%rip), %rsi
	leaq	.LC11(%rip), %rdi
	movq	16(%rsp), %rdx
	call	_Z8writeBMPPcS_PhS0_S0_
	movq	16(%rsp), %rdi
	movl	$1, %esi
	call	_ZdlPvm@PLT
	movq	24(%rsp), %rdi
	movl	$1, %esi
	call	_ZdlPvm@PLT
	movq	32(%rsp), %rdi
	movl	$1, %esi
	call	_ZdlPvm@PLT
	xorl	%eax, %eax
.L54:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3766:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z9addKernelPhS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3801:
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z9addKernelPhS_S_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3801:
	.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 <fstream>

hipError_t addWithCuda(unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue, unsigned int size);
int checkSize(char* filename);
void appendHeader(char* filename, char* origin);
void readBMP(char* filename, unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue);
void writeBMP(char* filename, char* origin, unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue);
void get(unsigned char* color_from, unsigned char* color_to, int start, int end);
void set(unsigned char* color_from, unsigned char* color_to, int start, int end);

__global__ void addKernel(unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue)
{
	int i = threadIdx.x;
	/*int value_red = (((int)p_red[i]) <= 0) ?  (-1 * (int)p_red[i]) : (128 + (int)p_red[i]);
	int value_green = (((int)p_green[i]) <= 0) ? (-1 * (int)p_green[i]) : (128 + (int)p_green[i]);
	int value_blue = (((int)p_blue[i]) <= 0) ? (-1 * (int)p_blue[i]) : (128 + (int)p_blue[i]);
	char avg = (value_red * 299 + value_green * 587 + value_blue * 114) / 1000 - 128;*/
	int red_value = p_red[i];
	int green_value = p_green[i];
	int blue_value = p_blue[i];
	/*char avg = (red_value * 299 + green_value * 587 + blue_value * 114) / 1000;*/
	char avg = (red_value + green_value + blue_value) / 3;
	/*if (avg > 128)
	{
		avg -= (avg - 128) * 0.95;
	} else {
		avg += (128 - avg) * 0.95;
	}*/
	/*if (p_red[i] > 128)
	{
		p_red[i] -= (p_red[i] - 128) * 0.99;
	}
	else {
		p_red[i] += (128 - p_red[i]) * 0.99;
	}

	if (p_green[i] > 128)
	{
		p_green[i] -= (p_green[i] - 128) * 0.98;
	}
	else {
		p_green[i] += (128 - p_green[i]) * 0.98;
	}

	if (p_blue[i] > 128)
	{
		p_blue[i] -= (p_blue[i] - 128) * 0.95;
	}
	else {
		p_blue[i] += (128 - p_blue[i]) * 0.94;
	}*/

	p_red[i] = avg;
	p_green[i] = avg;
	p_blue[i] = avg;
}

int main()
{
	const int Block = 1024;
	int size = checkSize("C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\test.bmp");
	unsigned char* red = new unsigned char[size];
	unsigned char* green = new unsigned char[size];
	unsigned char* blue = new unsigned char[size];
	readBMP("C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\test.bmp", red, green, blue);
	int current_size = size;
	hipError_t cudaStatus;
	while (current_size > 0)
	{
		if (current_size >= Block)
		{
			unsigned char* temp_red = new unsigned char[Block];
			unsigned char* temp_green = new unsigned char[Block];
			unsigned char* temp_blue = new unsigned char[Block];
			get(red, temp_red, size - current_size, size - current_size + Block);
			get(green, temp_green, size - current_size, size - current_size + Block);
			get(blue, temp_blue, size - current_size, size - current_size + Block);
			//int value = temp_red[500];
			cudaStatus = addWithCuda(temp_red, temp_green, temp_blue, Block);
			set(temp_red, red, size - current_size, size - current_size + Block);
			set(temp_green, green, size - current_size, size - current_size + Block);
			set(temp_blue, blue, size - current_size, size - current_size + Block);
			current_size -= Block;
			delete temp_red;
			delete temp_green;
			delete temp_blue;
		} else {
			unsigned char* temp_red = new unsigned char[current_size];
			unsigned char* temp_green = new unsigned char[current_size];
			unsigned char* temp_blue = new unsigned char[current_size];
			get(red, temp_red, size - current_size, size);
			get(green, temp_green, size - current_size, size);
			get(blue, temp_blue, size - current_size, size);
			cudaStatus = addWithCuda(temp_red, temp_green, temp_blue, current_size);
			set(temp_red, red, size - current_size, size);
			set(temp_green, green, size - current_size, size);
			set(temp_blue, blue, size - current_size, size);
			current_size -= current_size;
			delete temp_red;
			delete temp_green;
			delete temp_blue;
		}
		if (cudaStatus != hipSuccess) {
			fprintf(stderr, "addWithCuda failed!");
			return 1;
		}
	}
    
    

    // cudaDeviceReset must be called before exiting in order for profiling and
    // tracing tools such as Nsight and Visual Profiler to show complete traces.
    cudaStatus = hipDeviceReset();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipDeviceReset failed!");
        return 1;
    }
	writeBMP("C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\output.bmp", "C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\test.bmp", red, green, blue);
	delete red;
	delete green;
	delete blue;
    return 0;
}

void get(unsigned char* color_from, unsigned char* color_to, int start, int end)
{
	int index = 0;
	for (int i = start; i < end - start; i++)
	{
		color_to[index] = color_from[i];
		index++;
	}
}

void set(unsigned char* color_from, unsigned char* color_to, int start, int end)
{
	int index = 0;
	for (int i = start; i < end - start; i++)
	{
		color_to[i] = color_from[index];
		index++;
	}
}

int checkSize(char* filename)
{
	FILE* f = fopen(filename, "rb");
	unsigned char info[54];
	fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header

	// extract image height and width from header
	int width = *(int*)&info[18];
	int height = *(int*)&info[22];
	int size = width * height;
	fclose(f);
	return size;
}

void appendHeader(char* filename, char* origin)
{
	FILE* f = fopen(origin, "rb");
	unsigned char* info = new unsigned char[54];
	fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header
	fclose(f);
	f = fopen(filename, "wb");
	fwrite(info, sizeof(unsigned char), 54, f);
	fclose(f);
	delete info;
}

void readBMP(char* filename, unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue)
{
	int i;
	FILE* f = fopen(filename, "rb");
	unsigned char info[54];
	fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header

	// extract image height and width from header
	int width = *(int*)&info[18];
	int height = *(int*)&info[22];

	int size = 3 * width * height;
	unsigned char* data = new unsigned char[size];
	fread(data, sizeof(unsigned char), size, f); // read the rest of the data at once
	fclose(f);

	int index = 0;

	for (i = 0; i < size; i += 3)
	{
		int red = data[i];
		int green = data[i + 1];
		int blue = data[i + 2];
		p_red[index] = red;
		p_green[index] = green;
		p_blue[index] = blue;
		index++;
	}
	delete data;
}

void writeBMP(char* filename, char* originfile, unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue)
{
	int i;
	appendHeader(filename, originfile);

	FILE* f = fopen(filename, "a+b");

	int size = 3 * checkSize(originfile);
	unsigned char* data = new unsigned char[size];

	int index = 0;

	for (i = 0; i < size; i += 3)
	{
		data[i] = p_red[index];
		data[i + 1] = p_green[index];
		data[i + 2] = p_blue[index];
		index++;
	}

	fwrite(data, sizeof(unsigned char), size, f); // read the rest of the data at once
	fclose(f);
	delete data;
}

// Helper function for using CUDA to add vectors in parallel.
hipError_t addWithCuda(unsigned char* p_red, unsigned char* p_green, unsigned char* p_blue, unsigned int size)
{
	unsigned char *dev_a = 0;
	unsigned char *dev_b = 0;
	unsigned char *dev_c = 0;
    hipError_t cudaStatus;

    // Choose which GPU to run on, change this on a multi-GPU system.
    cudaStatus = hipSetDevice(0);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipSetDevice failed!  Do you have a CUDA-capable GPU installed?");
        goto Error;
    }

    cudaStatus = hipMalloc((void**)&dev_a, size * sizeof(unsigned char));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
        goto Error;
    }

    cudaStatus = hipMalloc((void**)&dev_b, size * sizeof(unsigned char));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
        goto Error;
    }

	// Allocate GPU buffers for three vectors (two input, one output)    .
	cudaStatus = hipMalloc((void**)&dev_c, size * sizeof(unsigned char));
	if (cudaStatus != hipSuccess) {
		fprintf(stderr, "hipMalloc failed!");
		goto Error;
	}

    // Copy input vectors from host memory to GPU buffers.
    cudaStatus = hipMemcpy(dev_a, p_red, size * sizeof(unsigned char), hipMemcpyHostToDevice);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
        goto Error;
    }

    cudaStatus = hipMemcpy(dev_b, p_green, size * sizeof(unsigned char), hipMemcpyHostToDevice);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
        goto Error;
    }

	cudaStatus = hipMemcpy(dev_c, p_blue, size * sizeof(unsigned char), hipMemcpyHostToDevice);
	if (cudaStatus != hipSuccess) {
		fprintf(stderr, "hipMemcpy failed!");
		goto Error;
	}

    // Launch a kernel on the GPU with one thread for each element.
    addKernel<<<1, size>>>(dev_a, dev_b, dev_c);

    // Check for any errors launching the kernel
    cudaStatus = hipGetLastError();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "addKernel launch failed: %s\n", hipGetErrorString(cudaStatus));
        goto Error;
    }
    
    // cudaDeviceSynchronize waits for the kernel to finish, and returns
    // any errors encountered during the launch.
    cudaStatus = hipDeviceSynchronize();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
        goto Error;
    }

	cudaStatus = hipMemcpy(p_red, dev_a, size * sizeof(unsigned char), hipMemcpyDeviceToHost);
	if (cudaStatus != hipSuccess) {
		fprintf(stderr, "hipMemcpy failed!");
		goto Error;
	}

	cudaStatus = hipMemcpy(p_green, dev_b, size * sizeof(unsigned char), hipMemcpyDeviceToHost);
	if (cudaStatus != hipSuccess) {
		fprintf(stderr, "hipMemcpy failed!");
		goto Error;
	}

    // Copy output vector from GPU buffer to host memory.
    cudaStatus = hipMemcpy(p_blue, dev_c, size * sizeof(unsigned char), hipMemcpyDeviceToHost);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
        goto Error;
    }

Error:
    hipFree(dev_a);
    hipFree(dev_b);
	hipFree(dev_c);

    return cudaStatus;
}
	.text
	.file	"kernel.hip"
	.globl	_Z24__device_stub__addKernelPhS_S_ # -- Begin function _Z24__device_stub__addKernelPhS_S_
	.type	_Z24__device_stub__addKernelPhS_S_,@function
_Z24__device_stub__addKernelPhS_S_:     # @_Z24__device_stub__addKernelPhS_S_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$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), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z9addKernelPhS_S_, %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_end0:
	.size	_Z24__device_stub__addKernelPhS_S_, .Lfunc_end0-_Z24__device_stub__addKernelPhS_S_
	.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	$88, %rsp
	.cfi_def_cfa_offset 144
	.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, %edi
	callq	_Z9checkSizePc
	movl	%eax, %ebp
	movslq	%eax, %rbx
	movq	%rbx, %rdi
	callq	_Znam
	movq	%rax, %r14
	movq	%rbx, %rdi
	callq	_Znam
	movq	%rax, %r15
	movq	%rbx, %rdi
	callq	_Znam
	movq	%rax, %r12
	movl	$.L.str, %edi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movq	%rax, %rcx
	callq	_Z7readBMPPcPhS0_S0_
	movq	%r14, 80(%rsp)                  # 8-byte Spill
	addq	%rbx, %r14
	movq	%r14, 56(%rsp)                  # 8-byte Spill
	movq	%r15, 72(%rsp)                  # 8-byte Spill
	addq	%rbx, %r15
	movq	%r15, 48(%rsp)                  # 8-byte Spill
	movq	%r12, 64(%rsp)                  # 8-byte Spill
	addq	%rbx, %r12
	movq	%r12, 40(%rsp)                  # 8-byte Spill
	movl	%ebp, %r12d
	movl	%ebp, 20(%rsp)                  # 4-byte Spill
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	testl	%r12d, %r12d
	jle	.LBB1_14
# %bb.2:                                #   in Loop: Header=BB1_1 Depth=1
	cmpl	$1024, %r12d                    # imm = 0x400
	jb	.LBB1_7
# %bb.3:                                #   in Loop: Header=BB1_1 Depth=1
	movl	$1024, %edi                     # imm = 0x400
	callq	_Znam
	movq	%rax, %rbx
	movl	$1024, %edi                     # imm = 0x400
	callq	_Znam
	movq	%rax, %r14
	movl	$1024, %edi                     # imm = 0x400
	callq	_Znam
	movq	%rax, %r13
	movl	%ebp, %eax
	subl	%r12d, %eax
	cmpl	$1023, %eax                     # imm = 0x3FF
	jg	.LBB1_5
# %bb.4:                                # %.lr.ph.preheader.i
                                        #   in Loop: Header=BB1_1 Depth=1
	movl	%eax, %ecx
	addl	%ecx, %ecx
	negl	%ecx
	leal	(%rax,%rcx), %ebp
	addl	$1024, %ebp                     # imm = 0x400
	movq	%r14, 24(%rsp)                  # 8-byte Spill
	movl	%r12d, %r14d
	movq	%r13, (%rsp)                    # 8-byte Spill
	movq	56(%rsp), %r13                  # 8-byte Reload
	subq	%r14, %r13
	movq	%rbx, %rdi
	movq	%r13, %rsi
	movq	%rbp, %rdx
	callq	memcpy@PLT
	movq	%rbx, 8(%rsp)                   # 8-byte Spill
	movq	48(%rsp), %rbx                  # 8-byte Reload
	subq	%r14, %rbx
	movq	24(%rsp), %rdi                  # 8-byte Reload
	movq	%rbx, %rsi
	movq	%rbp, %rdx
	callq	memcpy@PLT
	movq	40(%rsp), %r15                  # 8-byte Reload
	subq	%r14, %r15
	movq	24(%rsp), %r14                  # 8-byte Reload
	movq	(%rsp), %rdi                    # 8-byte Reload
	movq	%r15, %rsi
	movq	%rbp, %rdx
	callq	memcpy@PLT
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movq	%r14, %rsi
	movq	(%rsp), %rdx                    # 8-byte Reload
	movl	$1024, %ecx                     # imm = 0x400
	callq	_Z11addWithCudaPhS_S_j
	movl	%eax, 36(%rsp)                  # 4-byte Spill
	movq	%r13, %rdi
	movq	(%rsp), %r13                    # 8-byte Reload
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movq	%rbp, %rdx
	callq	memcpy@PLT
	movq	%rbx, %rdi
	movq	8(%rsp), %rbx                   # 8-byte Reload
	movq	%r14, %rsi
	movq	%rbp, %rdx
	callq	memcpy@PLT
	movq	%r15, %rdi
	movl	36(%rsp), %r15d                 # 4-byte Reload
	movq	%r13, %rsi
	movq	%rbp, %rdx
	movl	20(%rsp), %ebp                  # 4-byte Reload
	callq	memcpy@PLT
	jmp	.LBB1_6
.LBB1_7:                                #   in Loop: Header=BB1_1 Depth=1
	movl	%r12d, %r15d
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %rbx
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r14
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r13
	movl	%ebp, %eax
	subl	%r12d, %eax
	cmpl	%eax, %r12d
	jle	.LBB1_9
# %bb.8:                                # %.lr.ph.preheader.i149
                                        #   in Loop: Header=BB1_1 Depth=1
	addl	%eax, %eax
	movl	20(%rsp), %ecx                  # 4-byte Reload
	movl	%ecx, %ebp
	subl	%eax, %ebp
	movq	%r13, (%rsp)                    # 8-byte Spill
	movq	56(%rsp), %r13                  # 8-byte Reload
	subq	%r15, %r13
	movq	%rbx, %rdi
	movq	%r13, %rsi
	movq	%rbp, %rdx
	callq	memcpy@PLT
	movq	%rbx, 8(%rsp)                   # 8-byte Spill
	movq	48(%rsp), %rbx                  # 8-byte Reload
	subq	%r15, %rbx
	movq	%r14, %rdi
	movq	%rbx, %rsi
	movq	%rbp, %rdx
	callq	memcpy@PLT
	movq	%r14, 24(%rsp)                  # 8-byte Spill
	movq	40(%rsp), %r14                  # 8-byte Reload
	subq	%r15, %r14
	movq	(%rsp), %rdi                    # 8-byte Reload
	movq	%r14, %rsi
	movq	%rbp, %rdx
	callq	memcpy@PLT
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movq	24(%rsp), %rsi                  # 8-byte Reload
	movq	(%rsp), %rdx                    # 8-byte Reload
	movl	%r12d, %ecx
	callq	_Z11addWithCudaPhS_S_j
	movl	%eax, %r15d
	movq	%r13, %rdi
	movq	(%rsp), %r13                    # 8-byte Reload
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movq	%rbp, %rdx
	callq	memcpy@PLT
	movq	%rbx, %rdi
	movq	8(%rsp), %rbx                   # 8-byte Reload
	movq	24(%rsp), %rsi                  # 8-byte Reload
	movq	%rbp, %rdx
	callq	memcpy@PLT
	movq	%r14, %rdi
	movq	24(%rsp), %r14                  # 8-byte Reload
	movq	%r13, %rsi
	movq	%rbp, %rdx
	movl	20(%rsp), %ebp                  # 4-byte Reload
	callq	memcpy@PLT
	jmp	.LBB1_10
.LBB1_5:                                # %_Z3getPhS_ii.exit122.thread
                                        #   in Loop: Header=BB1_1 Depth=1
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%r13, %rdx
	movl	$1024, %ecx                     # imm = 0x400
	callq	_Z11addWithCudaPhS_S_j
	movl	%eax, %r15d
.LBB1_6:                                # %_Z3setPhS_ii.exit148
                                        #   in Loop: Header=BB1_1 Depth=1
	addl	$-1024, %r12d                   # imm = 0xFC00
	jmp	.LBB1_11
.LBB1_9:                                # %_Z3getPhS_ii.exit175.thread
                                        #   in Loop: Header=BB1_1 Depth=1
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%r13, %rdx
	movl	%r12d, %ecx
	callq	_Z11addWithCudaPhS_S_j
	movl	%eax, %r15d
.LBB1_10:                               # %_Z3setPhS_ii.exit202
                                        #   in Loop: Header=BB1_1 Depth=1
	xorl	%r12d, %r12d
.LBB1_11:                               # %_Z3setPhS_ii.exit202
                                        #   in Loop: Header=BB1_1 Depth=1
	movq	%rbx, %rdi
	callq	_ZdlPv
	movq	%r14, %rdi
	callq	_ZdlPv
	movq	%r13, %rdi
	callq	_ZdlPv
	testl	%r15d, %r15d
	je	.LBB1_1
# %bb.12:
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$19, %esi
	jmp	.LBB1_13
.LBB1_14:
	callq	hipDeviceReset
	testl	%eax, %eax
	jne	.LBB1_15
# %bb.16:
	movl	$.L.str.3, %edi
	movl	$.L.str, %esi
	movq	80(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdx
	movq	72(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rcx
	movq	64(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %r8
	callq	_Z8writeBMPPcS_PhS0_S0_
	movq	%rbx, %rdi
	callq	_ZdlPv
	movq	%r14, %rdi
	callq	_ZdlPv
	movq	%r15, %rdi
	callq	_ZdlPv
	xorl	%eax, %eax
.LBB1_17:
	addq	$88, %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
.LBB1_15:
	.cfi_def_cfa_offset 144
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$22, %esi
.LBB1_13:
	movl	$1, %edx
	callq	fwrite
	movl	$1, %eax
	jmp	.LBB1_17
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z9checkSizePc                  # -- Begin function _Z9checkSizePc
	.type	_Z9checkSizePc,@function
_Z9checkSizePc:                         # @_Z9checkSizePc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$64, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movl	$.L.str.4, %esi
	callq	fopen
	movq	%rax, %rbx
	movq	%rsp, %r14
	movl	$1, %esi
	movl	$54, %edx
	movq	%r14, %rdi
	movq	%rax, %rcx
	callq	fread
	movl	22(%r14), %ebp
	imull	18(%r14), %ebp
	movq	%rbx, %rdi
	callq	fclose
	movl	%ebp, %eax
	addq	$64, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z9checkSizePc, .Lfunc_end2-_Z9checkSizePc
	.cfi_endproc
                                        # -- End function
	.globl	_Z7readBMPPcPhS0_S0_            # -- Begin function _Z7readBMPPcPhS0_S0_
	.type	_Z7readBMPPcPhS0_S0_,@function
_Z7readBMPPcPhS0_S0_:                   # @_Z7readBMPPcPhS0_S0_
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, %rbx
	movq	%rdx, %r14
	movq	%rsi, %r15
	movl	$.L.str.4, %esi
	callq	fopen
	movq	%rax, %r13
	movq	%rsp, %r12
	movl	$1, %esi
	movl	$54, %edx
	movq	%r12, %rdi
	movq	%rax, %rcx
	callq	fread
	movslq	18(%r12), %rax
	movslq	22(%r12), %rcx
	imulq	%rax, %rcx
	leaq	(%rcx,%rcx,2), %rbp
	movq	%rbp, %rdi
	callq	_Znam
	movq	%rax, %r12
	movl	$1, %esi
	movq	%rax, %rdi
	movq	%rbp, %rdx
	movq	%r13, %rcx
	callq	fread
	movq	%r13, %rdi
	callq	fclose
	testl	%ebp, %ebp
	jle	.LBB3_3
# %bb.1:                                # %.lr.ph.preheader
	leal	-1(%rbp), %ecx
	movl	$2863311531, %eax               # imm = 0xAAAAAAAB
	imulq	%rcx, %rax
	shrq	$33, %rax
	incl	%eax
	movq	%r12, %rcx
	addq	$2, %rcx
	xorl	%edx, %edx
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movb	-2(%rcx), %sil
	movb	-1(%rcx), %dil
	movb	(%rcx), %r8b
	movb	%sil, (%r15,%rdx)
	movb	%dil, (%r14,%rdx)
	movb	%r8b, (%rbx,%rdx)
	incq	%rdx
	addq	$3, %rcx
	cmpq	%rdx, %rax
	jne	.LBB3_2
.LBB3_3:                                # %._crit_edge
	movq	%r12, %rdi
	addq	$56, %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	_ZdlPv                          # TAILCALL
.Lfunc_end3:
	.size	_Z7readBMPPcPhS0_S0_, .Lfunc_end3-_Z7readBMPPcPhS0_S0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z3getPhS_ii                    # -- Begin function _Z3getPhS_ii
	.type	_Z3getPhS_ii,@function
_Z3getPhS_ii:                           # @_Z3getPhS_ii
	.cfi_startproc
# %bb.0:
                                        # kill: def $ecx killed $ecx def $rcx
	movl	%ecx, %eax
	subl	%edx, %eax
	cmpl	%edx, %eax
	jle	.LBB4_3
# %bb.1:                                # %.lr.ph.preheader
	movslq	%edx, %rax
	addl	%edx, %edx
	subl	%edx, %ecx
	addq	%rax, %rdi
	xorl	%eax, %eax
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movb	(%rdi,%rax), %dl
	movb	%dl, (%rsi,%rax)
	incq	%rax
	cmpq	%rax, %rcx
	jne	.LBB4_2
.LBB4_3:                                # %._crit_edge
	retq
.Lfunc_end4:
	.size	_Z3getPhS_ii, .Lfunc_end4-_Z3getPhS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z11addWithCudaPhS_S_j          # -- Begin function _Z11addWithCudaPhS_S_j
	.type	_Z11addWithCudaPhS_S_j,@function
_Z11addWithCudaPhS_S_j:                 # @_Z11addWithCudaPhS_S_j
	.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, %ebp
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %r13
	xorl	%eax, %eax
	movq	%rax, 16(%rsp)
	movq	%rax, 8(%rsp)
	movq	%rax, (%rsp)
	xorl	%edi, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB5_1
# %bb.2:
	movl	%ebp, %r12d
	leaq	16(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB5_3
# %bb.6:
	leaq	8(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB5_3
# %bb.7:
	movq	%rsp, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB5_3
# %bb.8:
	movq	16(%rsp), %rdi
	movq	%r13, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB5_9
# %bb.10:
	movq	8(%rsp), %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB5_9
# %bb.11:
	movq	(%rsp), %rdi
	movq	%r14, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB5_9
# %bb.12:
	movq	%r12, %rdx
	btsq	$32, %rdx
	movabsq	$4294967296, %rdi               # imm = 0x100000000
	orq	$1, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_14
# %bb.13:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	callq	_Z24__device_stub__addKernelPhS_S_
.LBB5_14:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB5_15
# %bb.16:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB5_17
# %bb.18:
	movq	16(%rsp), %rsi
	movq	%r13, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB5_9
# %bb.19:
	movq	8(%rsp), %rsi
	movq	%r15, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB5_9
# %bb.20:
	movq	(%rsp), %rsi
	movq	%r14, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	xorl	%ebx, %ebx
	testl	%eax, %eax
	je	.LBB5_22
# %bb.21:
	movl	%eax, %ebp
	movq	stderr(%rip), %rcx
	movl	$.L.str.9, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite
	movl	%ebp, %ebx
	jmp	.LBB5_22
.LBB5_9:
	movl	%eax, %ebx
	movq	stderr(%rip), %rcx
	movl	$.L.str.9, %edi
	jmp	.LBB5_4
.LBB5_3:
	movl	%eax, %ebx
	movq	stderr(%rip), %rcx
	movl	$.L.str.8, %edi
.LBB5_4:
	movl	$17, %esi
.LBB5_5:
	movl	$1, %edx
	callq	fwrite
.LBB5_22:
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movl	%ebx, %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
.LBB5_1:
	.cfi_def_cfa_offset 80
	movl	%eax, %ebx
	movq	stderr(%rip), %rcx
	movl	$.L.str.7, %edi
	movl	$63, %esi
	jmp	.LBB5_5
.LBB5_15:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB5_22
.LBB5_17:
	movl	%eax, %ebx
	movq	stderr(%rip), %rdi
	movl	$.L.str.11, %esi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB5_22
.Lfunc_end5:
	.size	_Z11addWithCudaPhS_S_j, .Lfunc_end5-_Z11addWithCudaPhS_S_j
	.cfi_endproc
                                        # -- End function
	.globl	_Z3setPhS_ii                    # -- Begin function _Z3setPhS_ii
	.type	_Z3setPhS_ii,@function
_Z3setPhS_ii:                           # @_Z3setPhS_ii
	.cfi_startproc
# %bb.0:
                                        # kill: def $ecx killed $ecx def $rcx
	movl	%ecx, %eax
	subl	%edx, %eax
	cmpl	%edx, %eax
	jle	.LBB6_3
# %bb.1:                                # %.lr.ph.preheader
	movslq	%edx, %rax
	addl	%edx, %edx
	subl	%edx, %ecx
	addq	%rax, %rsi
	xorl	%eax, %eax
.LBB6_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movb	(%rdi,%rax), %dl
	movb	%dl, (%rsi,%rax)
	incq	%rax
	cmpq	%rax, %rcx
	jne	.LBB6_2
.LBB6_3:                                # %._crit_edge
	retq
.Lfunc_end6:
	.size	_Z3setPhS_ii, .Lfunc_end6-_Z3setPhS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z8writeBMPPcS_PhS0_S0_         # -- Begin function _Z8writeBMPPcS_PhS0_S0_
	.type	_Z8writeBMPPcS_PhS0_S0_,@function
_Z8writeBMPPcS_PhS0_S0_:                # @_Z8writeBMPPcS_PhS0_S0_
	.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
	movq	%r8, %rbx
	movq	%rcx, %r14
	movq	%rdx, %r15
	movq	%rsi, %r13
	movq	%rdi, %r12
	callq	_Z12appendHeaderPcS_
	movl	$.L.str.6, %esi
	movq	%r12, %rdi
	callq	fopen
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movq	%r13, %rdi
	callq	_Z9checkSizePc
	movl	%eax, %r12d
	leal	(%r12,%r12,2), %ebp
	movslq	%ebp, %rdi
	movq	%rdi, 8(%rsp)                   # 8-byte Spill
	callq	_Znam
	movq	%rax, %r13
	testl	%r12d, %r12d
	jle	.LBB7_3
# %bb.1:                                # %.lr.ph.preheader
	cmpl	$4, %ebp
	movl	$3, %ecx
	cmovgel	%ebp, %ecx
	decl	%ecx
	movl	$2863311531, %eax               # imm = 0xAAAAAAAB
	imulq	%rcx, %rax
	shrq	$33, %rax
	incl	%eax
	movq	%r13, %rcx
	addq	$2, %rcx
	xorl	%edx, %edx
.LBB7_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movb	(%r15,%rdx), %sil
	movb	%sil, -2(%rcx)
	movb	(%r14,%rdx), %sil
	movb	%sil, -1(%rcx)
	movb	(%rbx,%rdx), %sil
	movb	%sil, (%rcx)
	incq	%rdx
	addq	$3, %rcx
	cmpq	%rdx, %rax
	jne	.LBB7_2
.LBB7_3:                                # %._crit_edge
	movl	$1, %esi
	movq	%r13, %rdi
	movq	8(%rsp), %rdx                   # 8-byte Reload
	movq	16(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rcx
	callq	fwrite
	movq	%rbx, %rdi
	callq	fclose
	movq	%r13, %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	_ZdlPv                          # TAILCALL
.Lfunc_end7:
	.size	_Z8writeBMPPcS_PhS0_S0_, .Lfunc_end7-_Z8writeBMPPcS_PhS0_S0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z12appendHeaderPcS_            # -- Begin function _Z12appendHeaderPcS_
	.type	_Z12appendHeaderPcS_,@function
_Z12appendHeaderPcS_:                   # @_Z12appendHeaderPcS_
	.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, %rax
	movq	%rdi, %r14
	movl	$.L.str.4, %esi
	movq	%rax, %rdi
	callq	fopen
	movq	%rax, %r15
	movl	$54, %edi
	callq	_Znam
	movq	%rax, %rbx
	movl	$1, %esi
	movl	$54, %edx
	movq	%rax, %rdi
	movq	%r15, %rcx
	callq	fread
	movq	%r15, %rdi
	callq	fclose
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	callq	fopen
	movq	%rax, %r14
	movl	$1, %esi
	movl	$54, %edx
	movq	%rbx, %rdi
	movq	%rax, %rcx
	callq	fwrite
	movq	%r14, %rdi
	callq	fclose
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	_ZdlPv                          # TAILCALL
.Lfunc_end8:
	.size	_Z12appendHeaderPcS_, .Lfunc_end8-_Z12appendHeaderPcS_
	.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	.LBB9_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB9_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9addKernelPhS_S_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end9:
	.size	__hip_module_ctor, .Lfunc_end9-__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	.LBB10_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
.LBB10_2:
	retq
.Lfunc_end10:
	.size	__hip_module_dtor, .Lfunc_end10-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z9addKernelPhS_S_,@object      # @_Z9addKernelPhS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z9addKernelPhS_S_
	.p2align	3, 0x0
_Z9addKernelPhS_S_:
	.quad	_Z24__device_stub__addKernelPhS_S_
	.size	_Z9addKernelPhS_S_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\test.bmp"
	.size	.L.str, 52

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"addWithCuda failed!"
	.size	.L.str.1, 20

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"C:\\Users\\mateu\\source\\repos\\cuda\\x64\\Debug\\output.bmp"
	.size	.L.str.3, 54

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

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"a+b"
	.size	.L.str.6, 4

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"hipMalloc failed!"
	.size	.L.str.8, 18

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"hipMemcpy failed!"
	.size	.L.str.9, 18

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"addKernel launch failed: %s\n"
	.size	.L.str.10, 29

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"hipDeviceSynchronize returned error code %d after launching addKernel!\n"
	.size	.L.str.11, 72

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9addKernelPhS_S_"
	.size	.L__unnamed_1, 19

	.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 _Z24__device_stub__addKernelPhS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9addKernelPhS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9addKernelPhS_S_      ; -- Begin function _Z9addKernelPhS_S_
	.globl	_Z9addKernelPhS_S_
	.p2align	8
	.type	_Z9addKernelPhS_S_,@function
_Z9addKernelPhS_S_:                     ; @_Z9addKernelPhS_S_
; %bb.0:
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_clause 0x2
	global_load_u8 v1, v0, s[4:5]
	global_load_u8 v2, v0, s[6:7]
	global_load_u8 v3, v0, s[0:1]
	s_waitcnt vmcnt(1)
	v_add_nc_u16 v1, v2, v1
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u16 v1, v1, v3
	v_and_b32_e32 v1, 0xffff, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_u32_u24_e32 v1, 0x5556, v1
	v_lshrrev_b32_e32 v1, 16, v1
	s_clause 0x2
	global_store_b8 v0, v1, s[4:5]
	global_store_b8 v0, v1, s[6:7]
	global_store_b8 v0, v1, s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9addKernelPhS_S_
		.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 4
		.amdhsa_next_free_sgpr 8
		.amdhsa_reserve_vcc 0
		.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	_Z9addKernelPhS_S_, .Lfunc_end0-_Z9addKernelPhS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 144
; NumSgprs: 8
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 8
; NumVGPRsForWavesPerEU: 4
; 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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
    .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:           _Z9addKernelPhS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     8
    .sgpr_spill_count: 0
    .symbol:         _Z9addKernelPhS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
