#include <stdlib.h>
#include <stdio.h>
//#include <mpi.h>
#include <png.h>

#define checkCuda(error) __checkCuda(error, __FILE__, __LINE__)

typedef struct {
    int r;
    int g;
    int b;
    int a;
} RGBA;

typedef struct{
    int size;
    int width, height;
    png_byte color_type;
    png_byte bit_depth;
    png_bytep *row_pointers;
    RGBA* pixels;
}PNG_DATA;

void copy_pixels(RGBA *position, png_bytep px2){
    position->r = px2[0];
    position->g = px2[1];
    position->b = px2[2];
    position->a = px2[3];
}

void copy_positions(RGBA position, png_bytep px2){
    px2[0] = position.r;
    px2[1] = position.g;
    px2[2] = position.b;
    px2[3] = position.a;
}

RGBA* translate_px_to_vec(PNG_DATA* dados) {
    int x,y;
    int height = dados->height;
    int width = dados->width;
    RGBA *pixels = (RGBA*)malloc(sizeof(RGBA)* dados->size);
    for (y = 0; y < height; y++) {
        png_bytep row = dados->row_pointers[y];
        for (x = 0; x < width; x++) {
            png_bytep px = &(row[x * 4]);
            copy_pixels(&(pixels[y*width+x]),px);
        }
    }
    return pixels;
}

void translate_vec_to_px(RGBA* input, PNG_DATA* dados){
    int x,y;
    int height = dados->height;
    int width = dados->width;
    for (y = 0; y < height; y++) {
        png_bytep row = dados->row_pointers[y];
        for (x = 0; x < width; x++) {
            png_bytep px = &(row[x * 4]);
            copy_positions(input[y*width+x],px);
        }
    }
}



/*** Leitura e escrita no png ***/
PNG_DATA* read_png_file(char *filename) {
    int y;
    PNG_DATA *novo = (PNG_DATA*)malloc(sizeof(PNG_DATA));
    FILE *fp = fopen(filename, "rb");

    png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    png_infop info = png_create_info_struct(png);
    if (!png || !info)
        abort();

    if (setjmp(png_jmpbuf(png)))
        abort();

    png_init_io(png, fp);

    png_read_info(png, info);

    novo->width = png_get_image_width(png, info);
    novo->height = png_get_image_height(png, info);
    novo->size = novo->width*novo->height;
    novo->color_type = png_get_color_type(png, info);
    novo->bit_depth = png_get_bit_depth(png, info);

    // Read any color_type into 8bit depth, RGBA format.
    // See http://www.libpng.org/pub/png/libpng-manual.txt

    if (novo->bit_depth == 16)
        png_set_strip_16(png);

    if (novo->color_type == PNG_COLOR_TYPE_PALETTE)
        png_set_palette_to_rgb(png);

    // PNG_COLOR_TYPE_GRAY_ALPHA is always 8 or 16bit depth.
    if (novo->color_type == PNG_COLOR_TYPE_GRAY && novo->bit_depth < 8)
        png_set_expand_gray_1_2_4_to_8(png);

    if (png_get_valid(png, info, PNG_INFO_tRNS))
        png_set_tRNS_to_alpha(png);

    // These color_type don't have an alpha channel then fill it with 0xff.
    if (novo->color_type == PNG_COLOR_TYPE_RGB || novo->color_type == PNG_COLOR_TYPE_GRAY ||
            novo->color_type == PNG_COLOR_TYPE_PALETTE)
        png_set_filler(png, 0xFF, PNG_FILLER_AFTER);

    if (novo->color_type == PNG_COLOR_TYPE_GRAY ||
            novo->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
        png_set_gray_to_rgb(png);

    png_read_update_info(png, info);

    novo->row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * novo->height);
    for (y = 0; y < novo->height; y++) {
        novo->row_pointers[y] = (png_byte *)malloc(png_get_rowbytes(png, info));
    }

    png_read_image(png, novo->row_pointers);

    fclose(fp);
    return novo;
}

void write_png_file(char *filename, PNG_DATA* dados) {
    
    int width = dados->width;
    int height = dados->height;

    FILE *fp = fopen(filename, "wb");
    if (!fp)
        abort();

    png_structp png =
            png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!png)
        abort();

    png_infop info = png_create_info_struct(png);
    if (!info)
        abort();

    if (setjmp(png_jmpbuf(png)))
        abort();

    png_init_io(png, fp);

    // Output is 8bit depth, RGBA format.
    png_set_IHDR(png, info, width, height, 8, PNG_COLOR_TYPE_RGBA,
                             PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
                             PNG_FILTER_TYPE_DEFAULT);
    png_write_info(png, info);

    // To remove the alpha channel for PNG_COLOR_TYPE_RGB format,
    // Use png_set_filler().
    // png_set_filler(png, 0, PNG_FILLER_AFTER);

    png_write_image(png, dados->row_pointers);
    png_write_end(png, NULL);

    /*for (y = 0; y < height; y++) {
        free(dados->row_pointers[y]);
    }*/
    //free(dados->row_pointers);

    fclose(fp);
}

/*=============================================================================================*/

__global__ void grayscale(RGBA *pixels){
    int id = blockIdx.x*blockDim.x + threadIdx.x;   
    int result = 0.21f * pixels[id].r + 0.72f * pixels[id].g + 0.07f * pixels[id].b;
    pixels[id].r = pixels[id].g = pixels[id].b = result;
}
__global__ void negative(RGBA *pixels){
    int id = blockIdx.x*blockDim.x + threadIdx.x;   
    pixels[id].r = 255-pixels[id].r;
    pixels[id].g = 255-pixels[id].g;
    pixels[id].b = 255-pixels[id].b;
}

__global__ void sepia(RGBA *pixels){
    int id = blockIdx.x*blockDim.x + threadIdx.x;   
    pixels[id].r = (pixels[id].r * 0.393f) + (pixels[id].g * 0.769f) + (pixels[id].b * 0.189f);
    pixels[id].g = (pixels[id].r * 0.349f) + (pixels[id].g * 0.686f) + (pixels[id].b * 0.168f);
    pixels[id].b = (pixels[id].r * 0.272f) + (pixels[id].g * 0.534f) + (pixels[id].b * 0.131f);
}

int size=150*100;
int testSize = 1000;
int processar = 400;

int main(int argc, char *argv[]){  
	int cont = 0;  
	int gpu1 = 0;
	int gpu2 = 1;
	RGBA *d1_buffer;
	RGBA *d2_buffer;
	RGBA* result;

	clock_t start,end;
	start=clock();    

	char test[] = "150x100.png";
	PNG_DATA* imageData = read_png_file(test);

	cudaSetDevice(gpu1);
	cudaMalloc(&d1_buffer, (size*sizeof(RGBA)));
	cudaSetDevice(gpu2);
	cudaMalloc(&d2_buffer, (size*sizeof(RGBA)));
	cudaMalloc(&result, (size*sizeof(RGBA)));

	while (cont < testSize) {
		cudaSetDevice(gpu1);  

		//cudaStream_t stream_0;
		//cudaStreamCreate(&stream_0);

		//cudaMalloc(&d1_buffer, (size*sizeof(RGBA)));

		//RGBA* result = translate_px_to_vec(imageData);
		result = translate_px_to_vec(imageData);
		
		//cudaSetDevice(gpu2);
		//cudaMalloc(&d2_buffer, (size*sizeof(RGBA)));

		cudaMemcpyPeer(d2_buffer, gpu2, result, gpu1, (size*sizeof(RGBA)));
		cudaDeviceSynchronize();
		
		cudaSetDevice(gpu2);
		for (int i = 0; i < processar/2; i++){
			
			sepia<<<size/512,512>>>(d2_buffer);
			
			cudaMemcpyPeer(d1_buffer, gpu1, d2_buffer, gpu2, (size*sizeof(RGBA)));
			cudaDeviceSynchronize();
			
			cudaSetDevice(gpu1); 
			negative<<<size/512,512>>>(d1_buffer);
			
			cudaMemcpyPeer(d2_buffer, gpu2, d1_buffer, gpu1, (size*sizeof(RGBA)));
			cudaDeviceSynchronize();
			
			cudaSetDevice(gpu2);
		}
		
		cudaMemcpy(result,d2_buffer,(size*sizeof(RGBA)),cudaMemcpyDeviceToHost);
		translate_vec_to_px(result,imageData); 

		cont++;

		char test[16];
		sprintf(test,"finalteste1.png");
		write_png_file(test,imageData);
	}


	cudaFree(d1_buffer);
	cudaSetDevice(gpu2);
	cudaFree(d2_buffer);
	cudaFree(result);
	

    end = clock();
    double duration = (double)(end - start) / CLOCKS_PER_SEC;
    printf("EXECUTION_TIME = %f\n",duration);



}

	.file	"tmpxft_003287c1_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2036:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2036:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z11copy_pixelsP4RGBAPh
	.type	_Z11copy_pixelsP4RGBAPh, @function
_Z11copy_pixelsP4RGBAPh:
.LFB2027:
	.cfi_startproc
	endbr64
	movzbl	(%rsi), %eax
	movl	%eax, (%rdi)
	movzbl	1(%rsi), %eax
	movl	%eax, 4(%rdi)
	movzbl	2(%rsi), %eax
	movl	%eax, 8(%rdi)
	movzbl	3(%rsi), %eax
	movl	%eax, 12(%rdi)
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z11copy_pixelsP4RGBAPh, .-_Z11copy_pixelsP4RGBAPh
	.globl	_Z14copy_positions4RGBAPh
	.type	_Z14copy_positions4RGBAPh, @function
_Z14copy_positions4RGBAPh:
.LFB2028:
	.cfi_startproc
	endbr64
	movb	%dil, (%rdx)
	sarq	$32, %rdi
	movb	%sil, 2(%rdx)
	sarq	$32, %rsi
	movb	%dil, 1(%rdx)
	movb	%sil, 3(%rdx)
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z14copy_positions4RGBAPh, .-_Z14copy_positions4RGBAPh
	.globl	_Z19translate_px_to_vecP8PNG_DATA
	.type	_Z19translate_px_to_vecP8PNG_DATA, @function
_Z19translate_px_to_vecP8PNG_DATA:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movl	8(%rdi), %r12d
	movl	4(%rdi), %ebp
	movslq	(%rdi), %rdi
	salq	$4, %rdi
	call	malloc@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
.L5:
	cmpl	%r8d, %r12d
	jle	.L11
	movq	16(%rbx), %rcx
	movslq	%r9d, %rdx
	xorl	%r10d, %r10d
	salq	$4, %rdx
	movq	(%rcx,%r8,8), %rsi
	addq	%rax, %rdx
.L6:
	cmpl	%ebp, %r10d
	jge	.L12
	movq	%rdx, %rdi
	movq	%rax, 8(%rsp)
	incl	%r10d
	addq	$16, %rdx
	call	_Z11copy_pixelsP4RGBAPh
	movq	8(%rsp), %rax
	addq	$4, %rsi
	jmp	.L6
.L12:
	incq	%r8
	addl	%ebp, %r9d
	jmp	.L5
.L11:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z19translate_px_to_vecP8PNG_DATA, .-_Z19translate_px_to_vecP8PNG_DATA
	.globl	_Z19translate_vec_to_pxP4RGBAP8PNG_DATA
	.type	_Z19translate_vec_to_pxP4RGBAP8PNG_DATA, @function
_Z19translate_vec_to_pxP4RGBAP8PNG_DATA:
.LFB2030:
	.cfi_startproc
	endbr64
	movl	8(%rsi), %r11d
	movl	4(%rsi), %r10d
	movq	%rsi, %rcx
	xorl	%esi, %esi
	movq	%rdi, %r9
	xorl	%r8d, %r8d
	cmpl	%esi, %r11d
	jg	.L20
	ret
.L20:
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
.L17:
	movq	16(%rcx), %rax
	xorl	%edx, %edx
	movq	(%rax,%rsi,8), %rdi
	movslq	%r8d, %rax
	salq	$4, %rax
	addq	%r9, %rax
.L15:
	cmpl	%edx, %r10d
	jle	.L21
	movl	4(%rax), %r12d
	movl	8(%rax), %ebp
	addq	$16, %rax
	movl	-4(%rax), %ebx
	movb	-16(%rax), %r14b
	movb	%r12b, 1(%rdi,%rdx,4)
	movb	%r14b, (%rdi,%rdx,4)
	movb	%bpl, 2(%rdi,%rdx,4)
	movb	%bl, 3(%rdi,%rdx,4)
	incq	%rdx
	jmp	.L15
.L21:
	incq	%rsi
	addl	%r10d, %r8d
	cmpl	%esi, %r11d
	jg	.L17
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z19translate_vec_to_pxP4RGBAP8PNG_DATA, .-_Z19translate_vec_to_pxP4RGBAP8PNG_DATA
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
.LC1:
	.string	"1.6.43"
	.text
	.globl	_Z13read_png_filePc
	.type	_Z13read_png_filePc, @function
_Z13read_png_filePc:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	movl	$32, %edi
	subq	$40, %rsp
	.cfi_def_cfa_offset 64
	call	malloc@PLT
	leaq	.LC0(%rip), %rsi
	movq	%rbx, %rdi
	movq	%rax, 8(%rsp)
	call	fopen@PLT
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	xorl	%esi, %esi
	leaq	.LC1(%rip), %rdi
	movq	%rax, 24(%rsp)
	call	png_create_read_struct@PLT
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	png_create_info_struct@PLT
	cmpq	$0, (%rsp)
	movq	%rax, 16(%rsp)
	je	.L26
	testq	%rax, %rax
	jne	.L23
.L26:
	call	abort@PLT
.L23:
	movq	(%rsp), %rdi
	movq	__longjmp_chk@GOTPCREL(%rip), %rsi
	movl	$200, %edx
	call	png_set_longjmp_fn@PLT
	movq	%rax, %rdi
	call	_setjmp@PLT
	endbr64
	testl	%eax, %eax
	jne	.L26
	movq	24(%rsp), %rsi
	movq	(%rsp), %rdi
	call	png_init_io@PLT
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdi
	call	png_read_info@PLT
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdi
	call	png_get_image_width@PLT
	movq	8(%rsp), %rcx
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	%eax, 4(%rcx)
	call	png_get_image_height@PLT
	movq	8(%rsp), %rcx
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	%eax, 8(%rcx)
	imull	4(%rcx), %eax
	movl	%eax, (%rcx)
	call	png_get_color_type@PLT
	movq	8(%rsp), %rbx
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdi
	movb	%al, 12(%rbx)
	call	png_get_bit_depth@PLT
	movq	8(%rsp), %rcx
	movb	%al, 13(%rcx)
	cmpb	$16, %al
	je	.L27
.L30:
	movq	8(%rsp), %rax
	cmpb	$3, 12(%rax)
	jne	.L29
	jmp	.L44
.L27:
	movq	(%rsp), %rdi
	call	png_set_strip_16@PLT
	jmp	.L30
.L44:
	movq	(%rsp), %rdi
	call	png_set_palette_to_rgb@PLT
.L29:
	movq	8(%rsp), %rax
	cmpb	$0, 12(%rax)
	jne	.L32
	movq	8(%rsp), %rax
	cmpb	$7, 13(%rax)
	ja	.L32
	movq	(%rsp), %rdi
	call	png_set_expand_gray_1_2_4_to_8@PLT
.L32:
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	$16, %edx
	call	png_get_valid@PLT
	testl	%eax, %eax
	je	.L37
	movq	(%rsp), %rdi
	call	png_set_tRNS_to_alpha@PLT
.L37:
	movq	8(%rsp), %rax
	movb	12(%rax), %al
	leal	-2(%rax), %edx
	cmpb	$1, %dl
	jbe	.L35
	testb	%al, %al
	jne	.L36
.L35:
	movq	(%rsp), %rdi
	movl	$1, %edx
	movl	$255, %esi
	call	png_set_filler@PLT
.L36:
	movq	8(%rsp), %rax
	testb	$-5, 12(%rax)
	jne	.L39
	movq	(%rsp), %rdi
	call	png_set_gray_to_rgb@PLT
.L39:
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdi
	xorl	%ebx, %ebx
	call	png_read_update_info@PLT
	movq	8(%rsp), %rax
	movslq	8(%rax), %rdi
	salq	$3, %rdi
	call	malloc@PLT
	movq	8(%rsp), %rdx
	movq	%rax, 16(%rdx)
.L41:
	movq	8(%rsp), %rax
	cmpl	%ebx, 8(%rax)
	jle	.L45
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdi
	call	png_get_rowbytes@PLT
	movq	%rax, %rdi
	movq	8(%rsp), %rax
	movq	16(%rax), %rax
	leaq	(%rax,%rbx,8), %rbp
	incq	%rbx
	call	malloc@PLT
	movq	%rax, 0(%rbp)
	jmp	.L41
.L45:
	movq	(%rsp), %rdi
	movq	16(%rax), %rsi
	call	png_read_image@PLT
	movq	24(%rsp), %rdi
	call	fclose@PLT
	movq	8(%rsp), %rax
	addq	$40, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z13read_png_filePc, .-_Z13read_png_filePc
	.section	.rodata.str1.1
.LC2:
	.string	"wb"
	.text
	.globl	_Z14write_png_filePcP8PNG_DATA
	.type	_Z14write_png_filePcP8PNG_DATA, @function
_Z14write_png_filePcP8PNG_DATA:
.LFB2032:
	.cfi_startproc
	endbr64
	subq	$56, %rsp
	.cfi_def_cfa_offset 64
	movl	4(%rsi), %eax
	movq	%rsi, 16(%rsp)
	movl	%eax, 40(%rsp)
	movl	8(%rsi), %eax
	leaq	.LC2(%rip), %rsi
	movl	%eax, 44(%rsp)
	call	fopen@PLT
	movq	%rax, 24(%rsp)
	testq	%rax, %rax
	jne	.L47
.L48:
	call	abort@PLT
.L47:
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	leaq	.LC1(%rip), %rdi
	xorl	%esi, %esi
	call	png_create_write_struct@PLT
	movq	%rax, 8(%rsp)
	testq	%rax, %rax
	je	.L48
	movq	%rax, %rdi
	call	png_create_info_struct@PLT
	movq	%rax, 32(%rsp)
	testq	%rax, %rax
	je	.L48
	movq	8(%rsp), %rdi
	movq	__longjmp_chk@GOTPCREL(%rip), %rsi
	movl	$200, %edx
	call	png_set_longjmp_fn@PLT
	movq	%rax, %rdi
	call	_setjmp@PLT
	endbr64
	testl	%eax, %eax
	jne	.L48
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	png_init_io@PLT
	movl	$6, %r9d
	movl	$8, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 72
	pushq	$0
	.cfi_def_cfa_offset 80
	pushq	$0
	.cfi_def_cfa_offset 88
	pushq	$0
	.cfi_def_cfa_offset 96
	movl	76(%rsp), %ecx
	movl	72(%rsp), %edx
	movq	64(%rsp), %rsi
	movq	40(%rsp), %rdi
	call	png_set_IHDR@PLT
	movq	64(%rsp), %rsi
	movq	40(%rsp), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 64
	call	png_write_info@PLT
	movq	16(%rsp), %rax
	movq	8(%rsp), %rdi
	movq	16(%rax), %rsi
	call	png_write_image@PLT
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	png_write_end@PLT
	movq	24(%rsp), %rdi
	call	fclose@PLT
	addq	$56, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z14write_png_filePcP8PNG_DATA, .-_Z14write_png_filePcP8PNG_DATA
	.globl	_Z32__device_stub__Z9grayscaleP4RGBAP4RGBA
	.type	_Z32__device_stub__Z9grayscaleP4RGBAP4RGBA, @function
_Z32__device_stub__Z9grayscaleP4RGBAP4RGBA:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L51
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z9grayscaleP4RGBA(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L51:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L53
	call	__stack_chk_fail@PLT
.L53:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z32__device_stub__Z9grayscaleP4RGBAP4RGBA, .-_Z32__device_stub__Z9grayscaleP4RGBAP4RGBA
	.globl	_Z9grayscaleP4RGBA
	.type	_Z9grayscaleP4RGBA, @function
_Z9grayscaleP4RGBA:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z9grayscaleP4RGBAP4RGBA
	.cfi_endproc
.LFE2059:
	.size	_Z9grayscaleP4RGBA, .-_Z9grayscaleP4RGBA
	.globl	_Z31__device_stub__Z8negativeP4RGBAP4RGBA
	.type	_Z31__device_stub__Z8negativeP4RGBAP4RGBA, @function
_Z31__device_stub__Z8negativeP4RGBAP4RGBA:
.LFB2060:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L56
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z8negativeP4RGBA(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L56:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L58
	call	__stack_chk_fail@PLT
.L58:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2060:
	.size	_Z31__device_stub__Z8negativeP4RGBAP4RGBA, .-_Z31__device_stub__Z8negativeP4RGBAP4RGBA
	.globl	_Z8negativeP4RGBA
	.type	_Z8negativeP4RGBA, @function
_Z8negativeP4RGBA:
.LFB2061:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z8negativeP4RGBAP4RGBA
	.cfi_endproc
.LFE2061:
	.size	_Z8negativeP4RGBA, .-_Z8negativeP4RGBA
	.globl	_Z28__device_stub__Z5sepiaP4RGBAP4RGBA
	.type	_Z28__device_stub__Z5sepiaP4RGBAP4RGBA, @function
_Z28__device_stub__Z5sepiaP4RGBAP4RGBA:
.LFB2062:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L61
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z5sepiaP4RGBA(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L61:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L63
	call	__stack_chk_fail@PLT
.L63:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2062:
	.size	_Z28__device_stub__Z5sepiaP4RGBAP4RGBA, .-_Z28__device_stub__Z5sepiaP4RGBAP4RGBA
	.globl	_Z5sepiaP4RGBA
	.type	_Z5sepiaP4RGBA, @function
_Z5sepiaP4RGBA:
.LFB2063:
	.cfi_startproc
	endbr64
	jmp	_Z28__device_stub__Z5sepiaP4RGBAP4RGBA
	.cfi_endproc
.LFE2063:
	.size	_Z5sepiaP4RGBA, .-_Z5sepiaP4RGBA
	.section	.rodata.str1.1
.LC3:
	.string	"finalteste1.png"
.LC5:
	.string	"EXECUTION_TIME = %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	$8388609, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	salq	$9, %rbp
	subq	$96, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	clock@PLT
	leaq	60(%rsp), %rdi
	movl	$6778480, 68(%rsp)
	movq	%rax, %r12
	movabsq	$3328213113654752561, %rax
	movq	%rax, 60(%rsp)
	call	_Z13read_png_filePc
	xorl	%edi, %edi
	movq	%rax, %rbx
	call	cudaSetDevice@PLT
	movslq	size(%rip), %rsi
	leaq	8(%rsp), %rdi
	salq	$4, %rsi
	call	cudaMalloc@PLT
	movl	$1, %edi
	call	cudaSetDevice@PLT
	movslq	size(%rip), %rsi
	leaq	16(%rsp), %rdi
	salq	$4, %rsi
	call	cudaMalloc@PLT
	movslq	size(%rip), %rsi
	leaq	24(%rsp), %rdi
	salq	$4, %rsi
	call	cudaMalloc@PLT
.L67:
	cmpl	%r13d, testSize(%rip)
	jle	.L75
	xorl	%edi, %edi
	xorl	%r14d, %r14d
	call	cudaSetDevice@PLT
	movq	%rbx, %rdi
	call	_Z19translate_px_to_vecP8PNG_DATA
	movslq	size(%rip), %r8
	movq	16(%rsp), %rdi
	xorl	%ecx, %ecx
	movq	%rax, %rdx
	movl	$1, %esi
	movq	%rax, 24(%rsp)
	salq	$4, %r8
	call	cudaMemcpyPeer@PLT
	call	cudaDeviceSynchronize@PLT
	movl	$1, %edi
	call	cudaSetDevice@PLT
.L68:
	movl	processar(%rip), %eax
	movl	$2, %esi
	movl	size(%rip), %ecx
	cltd
	idivl	%esi
	cmpl	%r14d, %eax
	jle	.L76
	movl	%ecx, %eax
	movl	$512, %esi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	cltd
	movl	$1, %ecx
	movq	%rbp, 48(%rsp)
	idivl	%esi
	movl	$1, 56(%rsp)
	movq	%rbp, %rdx
	movl	%eax, 36(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	36(%rsp), %rdi
	movl	44(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L69
	movq	16(%rsp), %rdi
	call	_Z28__device_stub__Z5sepiaP4RGBAP4RGBA
.L69:
	movslq	size(%rip), %r8
	movq	16(%rsp), %rdx
	xorl	%esi, %esi
	movl	$1, %ecx
	movq	8(%rsp), %rdi
	salq	$4, %r8
	call	cudaMemcpyPeer@PLT
	call	cudaDeviceSynchronize@PLT
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	movl	$512, %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	size(%rip), %eax
	movq	%rbp, 48(%rsp)
	movl	$1, 56(%rsp)
	cltd
	idivl	%ecx
	movq	%rbp, %rdx
	movl	$1, %ecx
	movl	%eax, 36(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	36(%rsp), %rdi
	movl	44(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L70
	movq	8(%rsp), %rdi
	call	_Z31__device_stub__Z8negativeP4RGBAP4RGBA
.L70:
	movq	8(%rsp), %rdx
	movq	16(%rsp), %rdi
	xorl	%ecx, %ecx
	incl	%r14d
	movslq	size(%rip), %r8
	movl	$1, %esi
	salq	$4, %r8
	call	cudaMemcpyPeer@PLT
	call	cudaDeviceSynchronize@PLT
	movl	$1, %edi
	call	cudaSetDevice@PLT
	jmp	.L68
.L76:
	movq	16(%rsp), %rsi
	movq	24(%rsp), %rdi
	movslq	%ecx, %rdx
	incl	%r13d
	salq	$4, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	_Z19translate_vec_to_pxP4RGBAP8PNG_DATA
	leaq	72(%rsp), %rdi
	leaq	.LC3(%rip), %rsi
	call	strcpy@PLT
	movq	%rbx, %rsi
	movq	%rax, %rdi
	call	_Z14write_png_filePcP8PNG_DATA
	jmp	.L67
.L75:
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %edi
	call	cudaSetDevice@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	call	clock@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	subq	%r12, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC4(%rip), %xmm0
	call	__printf_chk@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L73
	call	__stack_chk_fail@PLT
.L73:
	addq	$96, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	main, .-main
	.section	.rodata.str1.1
.LC6:
	.string	"_Z5sepiaP4RGBA"
.LC7:
	.string	"_Z8negativeP4RGBA"
.LC8:
	.string	"_Z9grayscaleP4RGBA"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2065:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC6(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z5sepiaP4RGBA(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC7(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z8negativeP4RGBA(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC8(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z9grayscaleP4RGBA(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2065:
	.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
	.globl	processar
	.data
	.align 4
	.type	processar, @object
	.size	processar, 4
processar:
	.long	400
	.globl	testSize
	.align 4
	.type	testSize, @object
	.size	testSize, 4
testSize:
	.long	1000
	.globl	size
	.align 4
	.type	size, @object
	.size	size, 4
size:
	.long	15000
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC4:
	.long	0
	.long	1093567616
	.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 <stdlib.h>
#include <stdio.h>
//#include <mpi.h>
#include <png.h>

#define checkCuda(error) __checkCuda(error, __FILE__, __LINE__)

typedef struct {
    int r;
    int g;
    int b;
    int a;
} RGBA;

typedef struct{
    int size;
    int width, height;
    png_byte color_type;
    png_byte bit_depth;
    png_bytep *row_pointers;
    RGBA* pixels;
}PNG_DATA;

void copy_pixels(RGBA *position, png_bytep px2){
    position->r = px2[0];
    position->g = px2[1];
    position->b = px2[2];
    position->a = px2[3];
}

void copy_positions(RGBA position, png_bytep px2){
    px2[0] = position.r;
    px2[1] = position.g;
    px2[2] = position.b;
    px2[3] = position.a;
}

RGBA* translate_px_to_vec(PNG_DATA* dados) {
    int x,y;
    int height = dados->height;
    int width = dados->width;
    RGBA *pixels = (RGBA*)malloc(sizeof(RGBA)* dados->size);
    for (y = 0; y < height; y++) {
        png_bytep row = dados->row_pointers[y];
        for (x = 0; x < width; x++) {
            png_bytep px = &(row[x * 4]);
            copy_pixels(&(pixels[y*width+x]),px);
        }
    }
    return pixels;
}

void translate_vec_to_px(RGBA* input, PNG_DATA* dados){
    int x,y;
    int height = dados->height;
    int width = dados->width;
    for (y = 0; y < height; y++) {
        png_bytep row = dados->row_pointers[y];
        for (x = 0; x < width; x++) {
            png_bytep px = &(row[x * 4]);
            copy_positions(input[y*width+x],px);
        }
    }
}



/*** Leitura e escrita no png ***/
PNG_DATA* read_png_file(char *filename) {
    int y;
    PNG_DATA *novo = (PNG_DATA*)malloc(sizeof(PNG_DATA));
    FILE *fp = fopen(filename, "rb");

    png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    png_infop info = png_create_info_struct(png);
    if (!png || !info)
        abort();

    if (setjmp(png_jmpbuf(png)))
        abort();

    png_init_io(png, fp);

    png_read_info(png, info);

    novo->width = png_get_image_width(png, info);
    novo->height = png_get_image_height(png, info);
    novo->size = novo->width*novo->height;
    novo->color_type = png_get_color_type(png, info);
    novo->bit_depth = png_get_bit_depth(png, info);

    // Read any color_type into 8bit depth, RGBA format.
    // See http://www.libpng.org/pub/png/libpng-manual.txt

    if (novo->bit_depth == 16)
        png_set_strip_16(png);

    if (novo->color_type == PNG_COLOR_TYPE_PALETTE)
        png_set_palette_to_rgb(png);

    // PNG_COLOR_TYPE_GRAY_ALPHA is always 8 or 16bit depth.
    if (novo->color_type == PNG_COLOR_TYPE_GRAY && novo->bit_depth < 8)
        png_set_expand_gray_1_2_4_to_8(png);

    if (png_get_valid(png, info, PNG_INFO_tRNS))
        png_set_tRNS_to_alpha(png);

    // These color_type don't have an alpha channel then fill it with 0xff.
    if (novo->color_type == PNG_COLOR_TYPE_RGB || novo->color_type == PNG_COLOR_TYPE_GRAY ||
            novo->color_type == PNG_COLOR_TYPE_PALETTE)
        png_set_filler(png, 0xFF, PNG_FILLER_AFTER);

    if (novo->color_type == PNG_COLOR_TYPE_GRAY ||
            novo->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
        png_set_gray_to_rgb(png);

    png_read_update_info(png, info);

    novo->row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * novo->height);
    for (y = 0; y < novo->height; y++) {
        novo->row_pointers[y] = (png_byte *)malloc(png_get_rowbytes(png, info));
    }

    png_read_image(png, novo->row_pointers);

    fclose(fp);
    return novo;
}

void write_png_file(char *filename, PNG_DATA* dados) {
    
    int width = dados->width;
    int height = dados->height;

    FILE *fp = fopen(filename, "wb");
    if (!fp)
        abort();

    png_structp png =
            png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!png)
        abort();

    png_infop info = png_create_info_struct(png);
    if (!info)
        abort();

    if (setjmp(png_jmpbuf(png)))
        abort();

    png_init_io(png, fp);

    // Output is 8bit depth, RGBA format.
    png_set_IHDR(png, info, width, height, 8, PNG_COLOR_TYPE_RGBA,
                             PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
                             PNG_FILTER_TYPE_DEFAULT);
    png_write_info(png, info);

    // To remove the alpha channel for PNG_COLOR_TYPE_RGB format,
    // Use png_set_filler().
    // png_set_filler(png, 0, PNG_FILLER_AFTER);

    png_write_image(png, dados->row_pointers);
    png_write_end(png, NULL);

    /*for (y = 0; y < height; y++) {
        free(dados->row_pointers[y]);
    }*/
    //free(dados->row_pointers);

    fclose(fp);
}

/*=============================================================================================*/

__global__ void grayscale(RGBA *pixels){
    int id = blockIdx.x*blockDim.x + threadIdx.x;   
    int result = 0.21f * pixels[id].r + 0.72f * pixels[id].g + 0.07f * pixels[id].b;
    pixels[id].r = pixels[id].g = pixels[id].b = result;
}
__global__ void negative(RGBA *pixels){
    int id = blockIdx.x*blockDim.x + threadIdx.x;   
    pixels[id].r = 255-pixels[id].r;
    pixels[id].g = 255-pixels[id].g;
    pixels[id].b = 255-pixels[id].b;
}

__global__ void sepia(RGBA *pixels){
    int id = blockIdx.x*blockDim.x + threadIdx.x;   
    pixels[id].r = (pixels[id].r * 0.393f) + (pixels[id].g * 0.769f) + (pixels[id].b * 0.189f);
    pixels[id].g = (pixels[id].r * 0.349f) + (pixels[id].g * 0.686f) + (pixels[id].b * 0.168f);
    pixels[id].b = (pixels[id].r * 0.272f) + (pixels[id].g * 0.534f) + (pixels[id].b * 0.131f);
}

int size=150*100;
int testSize = 1000;
int processar = 400;

int main(int argc, char *argv[]){  
	int cont = 0;  
	int gpu1 = 0;
	int gpu2 = 1;
	RGBA *d1_buffer;
	RGBA *d2_buffer;
	RGBA* result;

	clock_t start,end;
	start=clock();    

	char test[] = "150x100.png";
	PNG_DATA* imageData = read_png_file(test);

	hipSetDevice(gpu1);
	hipMalloc(&d1_buffer, (size*sizeof(RGBA)));
	hipSetDevice(gpu2);
	hipMalloc(&d2_buffer, (size*sizeof(RGBA)));
	hipMalloc(&result, (size*sizeof(RGBA)));

	while (cont < testSize) {
		hipSetDevice(gpu1);  

		//cudaStream_t stream_0;
		//cudaStreamCreate(&stream_0);

		//cudaMalloc(&d1_buffer, (size*sizeof(RGBA)));

		//RGBA* result = translate_px_to_vec(imageData);
		result = translate_px_to_vec(imageData);
		
		//cudaSetDevice(gpu2);
		//cudaMalloc(&d2_buffer, (size*sizeof(RGBA)));

		hipMemcpyPeer(d2_buffer, gpu2, result, gpu1, (size*sizeof(RGBA)));
		hipDeviceSynchronize();
		
		hipSetDevice(gpu2);
		for (int i = 0; i < processar/2; i++){
			
			sepia<<<size/512,512>>>(d2_buffer);
			
			hipMemcpyPeer(d1_buffer, gpu1, d2_buffer, gpu2, (size*sizeof(RGBA)));
			hipDeviceSynchronize();
			
			hipSetDevice(gpu1); 
			negative<<<size/512,512>>>(d1_buffer);
			
			hipMemcpyPeer(d2_buffer, gpu2, d1_buffer, gpu1, (size*sizeof(RGBA)));
			hipDeviceSynchronize();
			
			hipSetDevice(gpu2);
		}
		
		hipMemcpy(result,d2_buffer,(size*sizeof(RGBA)),hipMemcpyDeviceToHost);
		translate_vec_to_px(result,imageData); 

		cont++;

		char test[16];
		sprintf(test,"finalteste1.png");
		write_png_file(test,imageData);
	}


	hipFree(d1_buffer);
	hipSetDevice(gpu2);
	hipFree(d2_buffer);
	hipFree(result);
	

    end = clock();
    double duration = (double)(end - start) / CLOCKS_PER_SEC;
    printf("EXECUTION_TIME = %f\n",duration);



}

	.text
	.file	"main.hip"
	.globl	_Z11copy_pixelsP4RGBAPh         # -- Begin function _Z11copy_pixelsP4RGBAPh
	.type	_Z11copy_pixelsP4RGBAPh,@function
_Z11copy_pixelsP4RGBAPh:                # @_Z11copy_pixelsP4RGBAPh
	.cfi_startproc
# %bb.0:
	movzbl	(%rsi), %eax
	movl	%eax, (%rdi)
	movzbl	1(%rsi), %eax
	movl	%eax, 4(%rdi)
	movzbl	2(%rsi), %eax
	movl	%eax, 8(%rdi)
	movzbl	3(%rsi), %eax
	movl	%eax, 12(%rdi)
	retq
.Lfunc_end0:
	.size	_Z11copy_pixelsP4RGBAPh, .Lfunc_end0-_Z11copy_pixelsP4RGBAPh
	.cfi_endproc
                                        # -- End function
	.globl	_Z14copy_positions4RGBAPh       # -- Begin function _Z14copy_positions4RGBAPh
	.type	_Z14copy_positions4RGBAPh,@function
_Z14copy_positions4RGBAPh:              # @_Z14copy_positions4RGBAPh
	.cfi_startproc
# %bb.0:
	movb	%dil, (%rdx)
	shrq	$32, %rdi
	movb	%dil, 1(%rdx)
	movb	%sil, 2(%rdx)
	shrq	$32, %rsi
	movb	%sil, 3(%rdx)
	retq
.Lfunc_end1:
	.size	_Z14copy_positions4RGBAPh, .Lfunc_end1-_Z14copy_positions4RGBAPh
	.cfi_endproc
                                        # -- End function
	.globl	_Z19translate_px_to_vecP8PNG_DATA # -- Begin function _Z19translate_px_to_vecP8PNG_DATA
	.type	_Z19translate_px_to_vecP8PNG_DATA,@function
_Z19translate_px_to_vecP8PNG_DATA:      # @_Z19translate_px_to_vecP8PNG_DATA
	.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	%rdi, %rbx
	movl	4(%rdi), %r14d
	movl	8(%rdi), %r15d
	movslq	(%rdi), %rdi
	shlq	$4, %rdi
	callq	malloc
	testl	%r15d, %r15d
	jle	.LBB2_6
# %bb.1:                                # %.lr.ph23
	movq	16(%rbx), %rcx
	movq	%rax, %rdx
	addq	$12, %rdx
	leaq	(,%r14,4), %rsi
	xorl	%edi, %edi
	xorl	%r8d, %r8d
.LBB2_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	testl	%r14d, %r14d
	jle	.LBB2_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	%edi, %r9d
	shlq	$4, %r9
	addq	%rdx, %r9
	movq	(%rcx,%r8,8), %r10
	xorl	%r11d, %r11d
.LBB2_4:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movzbl	(%r10,%r11), %ebx
	movl	%ebx, -12(%r9,%r11,4)
	movzbl	1(%r10,%r11), %ebx
	movl	%ebx, -8(%r9,%r11,4)
	movzbl	2(%r10,%r11), %ebx
	movl	%ebx, -4(%r9,%r11,4)
	movzbl	3(%r10,%r11), %ebx
	movl	%ebx, (%r9,%r11,4)
	addq	$4, %r11
	cmpq	%r11, %rsi
	jne	.LBB2_4
.LBB2_5:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r8
	addl	%r14d, %edi
	cmpq	%r15, %r8
	jne	.LBB2_2
.LBB2_6:                                # %._crit_edge24
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z19translate_px_to_vecP8PNG_DATA, .Lfunc_end2-_Z19translate_px_to_vecP8PNG_DATA
	.cfi_endproc
                                        # -- End function
	.globl	_Z19translate_vec_to_pxP4RGBAP8PNG_DATA # -- Begin function _Z19translate_vec_to_pxP4RGBAP8PNG_DATA
	.type	_Z19translate_vec_to_pxP4RGBAP8PNG_DATA,@function
_Z19translate_vec_to_pxP4RGBAP8PNG_DATA: # @_Z19translate_vec_to_pxP4RGBAP8PNG_DATA
	.cfi_startproc
# %bb.0:
	movl	8(%rsi), %eax
	testl	%eax, %eax
	jle	.LBB3_7
# %bb.1:                                # %.lr.ph21
	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
	movl	4(%rsi), %ecx
	addq	$8, %rdi
	leaq	(,%rcx,4), %rdx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
.LBB3_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
	testl	%ecx, %ecx
	jle	.LBB3_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB3_2 Depth=1
	movl	%r8d, %r10d
	shlq	$4, %r10
	addq	%rdi, %r10
	movq	16(%rsi), %r11
	movq	(%r11,%r9,8), %r11
	xorl	%ebx, %ebx
.LBB3_4:                                #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	-8(%r10,%rbx,4), %r14
	movq	(%r10,%rbx,4), %r15
	movb	%r14b, (%r11,%rbx)
	shrq	$32, %r14
	movb	%r14b, 1(%r11,%rbx)
	movb	%r15b, 2(%r11,%rbx)
	shrq	$32, %r15
	movb	%r15b, 3(%r11,%rbx)
	addq	$4, %rbx
	cmpq	%rbx, %rdx
	jne	.LBB3_4
.LBB3_5:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	incq	%r9
	addl	%ecx, %r8d
	cmpq	%rax, %r9
	jne	.LBB3_2
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB3_7:                                # %._crit_edge22
	retq
.Lfunc_end3:
	.size	_Z19translate_vec_to_pxP4RGBAP8PNG_DATA, .Lfunc_end3-_Z19translate_vec_to_pxP4RGBAP8PNG_DATA
	.cfi_endproc
                                        # -- End function
	.globl	_Z13read_png_filePc             # -- Begin function _Z13read_png_filePc
	.type	_Z13read_png_filePc,@function
_Z13read_png_filePc:                    # @_Z13read_png_filePc
	.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	%rdi, %rbx
	movl	$32, %edi
	callq	malloc
	movq	%rax, %r14
	movl	$.L.str, %esi
	movq	%rbx, %rdi
	callq	fopen
	movq	%rax, %r15
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	movl	%eax, %ecx
	movq	%rcx, %rsi
	movq	%rcx, %rdx
	callq	png_create_read_struct
	movq	%rax, %rbx
	movq	%rax, %rdi
	callq	png_create_info_struct
	testq	%rbx, %rbx
	je	.LBB4_21
# %bb.1:
	movq	%rax, %r12
	testq	%rax, %rax
	je	.LBB4_21
# %bb.2:
	movl	$longjmp, %esi
	movl	$200, %edx
	movq	%rbx, %rdi
	callq	png_set_longjmp_fn
	movq	%rax, %rdi
	callq	_setjmp
	testl	%eax, %eax
	jne	.LBB4_21
# %bb.3:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	movq	%r15, 16(%rsp)                  # 8-byte Spill
	callq	png_init_io
	movq	%rbx, %rdi
	movq	%r12, %rsi
	callq	png_read_info
	movq	%rbx, %rdi
	movq	%r12, %rsi
	callq	png_get_image_width
	movl	%eax, %r15d
	movl	%eax, 4(%r14)
	movq	%rbx, %rdi
	movq	%r12, %rsi
	callq	png_get_image_height
	movl	%eax, %ebp
	movl	%eax, 8(%r14)
	imull	%eax, %r15d
	movl	%r15d, (%r14)
	movq	%rbx, %rdi
	movq	%r12, %rsi
	callq	png_get_color_type
	movl	%eax, %r13d
	movb	%al, 12(%r14)
	movq	%rbx, %rdi
	movq	%r12, %rsi
	callq	png_get_bit_depth
	movl	%eax, %r15d
	movq	%r14, 8(%rsp)                   # 8-byte Spill
	movb	%al, 13(%r14)
	cmpb	$16, %al
	jne	.LBB4_5
# %bb.4:
	movq	%rbx, %rdi
	callq	png_set_strip_16
.LBB4_5:
	movzbl	%r13b, %r14d
	testb	%r13b, %r13b
	je	.LBB4_8
# %bb.6:
	cmpl	$3, %r14d
	jne	.LBB4_10
# %bb.7:                                # %.thread
	movq	%rbx, %rdi
	callq	png_set_palette_to_rgb
	jmp	.LBB4_10
.LBB4_8:
	cmpb	$7, %r15b
	ja	.LBB4_10
# %bb.9:
	movq	%rbx, %rdi
	callq	png_set_expand_gray_1_2_4_to_8
.LBB4_10:
	movq	%rbx, %rdi
	movq	%r12, %rsi
	movl	$16, %edx
	callq	png_get_valid
	testl	%eax, %eax
	je	.LBB4_12
# %bb.11:
	movq	%rbx, %rdi
	callq	png_set_tRNS_to_alpha
.LBB4_12:
	movl	%r14d, %eax
	addl	$-2, %eax
	cmpl	$2, %eax
	jb	.LBB4_15
# %bb.13:
	cmpl	$4, %r14d
	je	.LBB4_16
# %bb.14:
	testl	%r14d, %r14d
	jne	.LBB4_17
.LBB4_15:
	movq	%rbx, %rdi
	movl	$255, %esi
	movl	$1, %edx
	callq	png_set_filler
	testb	%r13b, %r13b
	jne	.LBB4_17
.LBB4_16:
	movq	%rbx, %rdi
	callq	png_set_gray_to_rgb
.LBB4_17:
	movq	%rbx, %rdi
	movq	%r12, %rsi
	callq	png_read_update_info
	movslq	%ebp, %rdi
	shlq	$3, %rdi
	callq	malloc
	movq	%rax, %r13
	movq	8(%rsp), %rcx                   # 8-byte Reload
	movq	%rax, 16(%rcx)
	testl	%ebp, %ebp
	jle	.LBB4_20
# %bb.18:                               # %.lr.ph.preheader
	movl	%ebp, %ebp
	movl	%ebp, %r14d
	xorl	%eax, %eax
                                        # kill: def $rax killed $eax
.LBB4_19:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%rax, %r15
	movq	%rbx, %rdi
	movq	%r12, %rsi
	callq	png_get_rowbytes
	movq	%rax, %rdi
	callq	malloc
	movq	%rax, (%r13,%r15,8)
	incq	%r15
	movq	%r15, %rax
	cmpq	%r15, %r14
	jne	.LBB4_19
.LBB4_20:                               # %._crit_edge
	movq	%rbx, %rdi
	movq	%r13, %rsi
	callq	png_read_image
	movq	16(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	8(%rsp), %rax                   # 8-byte Reload
	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
.LBB4_21:
	.cfi_def_cfa_offset 80
	callq	abort
.Lfunc_end4:
	.size	_Z13read_png_filePc, .Lfunc_end4-_Z13read_png_filePc
	.cfi_endproc
                                        # -- End function
	.globl	_Z14write_png_filePcP8PNG_DATA  # -- Begin function _Z14write_png_filePcP8PNG_DATA
	.type	_Z14write_png_filePcP8PNG_DATA,@function
_Z14write_png_filePcP8PNG_DATA:         # @_Z14write_png_filePcP8PNG_DATA
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	4(%rsi), %r14d
	movl	8(%rsi), %ebp
	movl	$.L.str.2, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB5_5
# %bb.1:
	movq	%rax, %r12
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	movl	%eax, %ecx
	movq	%rcx, %rsi
	movq	%rcx, %rdx
	callq	png_create_write_struct
	testq	%rax, %rax
	je	.LBB5_5
# %bb.2:
	movq	%rax, %r15
	movq	%rax, %rdi
	callq	png_create_info_struct
	testq	%rax, %rax
	je	.LBB5_5
# %bb.3:
	movq	%rax, %r13
	movl	%ebp, 4(%rsp)                   # 4-byte Spill
	movl	$longjmp, %esi
	movl	$200, %edx
	movq	%r15, %rdi
	callq	png_set_longjmp_fn
	movq	%rax, %rdi
	callq	_setjmp
	testl	%eax, %eax
	jne	.LBB5_5
# %bb.4:
	movq	%r15, %rdi
	movq	%r12, %rsi
	callq	png_init_io
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	xorl	%ebp, %ebp
	movl	%ebp, %eax
	movq	%r15, %rdi
	movq	%r13, %rsi
	movl	%r14d, %edx
	movl	12(%rsp), %ecx                  # 4-byte Reload
	movl	$8, %r8d
	movl	$6, %r9d
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	callq	png_set_IHDR
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movq	%r15, %rdi
	movq	%r13, %rsi
	callq	png_write_info
	movq	16(%rbx), %rsi
	movq	%r15, %rdi
	callq	png_write_image
	movl	%ebp, %esi
	movq	%r15, %rdi
	callq	png_write_end
	movq	%r12, %rdi
	callq	fclose
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB5_5:
	.cfi_def_cfa_offset 64
	callq	abort
.Lfunc_end5:
	.size	_Z14write_png_filePcP8PNG_DATA, .Lfunc_end5-_Z14write_png_filePcP8PNG_DATA
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__grayscaleP4RGBA # -- Begin function _Z24__device_stub__grayscaleP4RGBA
	.type	_Z24__device_stub__grayscaleP4RGBA,@function
_Z24__device_stub__grayscaleP4RGBA:     # @_Z24__device_stub__grayscaleP4RGBA
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z9grayscaleP4RGBA, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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_end6:
	.size	_Z24__device_stub__grayscaleP4RGBA, .Lfunc_end6-_Z24__device_stub__grayscaleP4RGBA
	.cfi_endproc
                                        # -- End function
	.globl	_Z23__device_stub__negativeP4RGBA # -- Begin function _Z23__device_stub__negativeP4RGBA
	.type	_Z23__device_stub__negativeP4RGBA,@function
_Z23__device_stub__negativeP4RGBA:      # @_Z23__device_stub__negativeP4RGBA
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z8negativeP4RGBA, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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_end7:
	.size	_Z23__device_stub__negativeP4RGBA, .Lfunc_end7-_Z23__device_stub__negativeP4RGBA
	.cfi_endproc
                                        # -- End function
	.globl	_Z20__device_stub__sepiaP4RGBA  # -- Begin function _Z20__device_stub__sepiaP4RGBA
	.type	_Z20__device_stub__sepiaP4RGBA,@function
_Z20__device_stub__sepiaP4RGBA:         # @_Z20__device_stub__sepiaP4RGBA
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z5sepiaP4RGBA, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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_end8:
	.size	_Z20__device_stub__sepiaP4RGBA, .Lfunc_end8-_Z20__device_stub__sepiaP4RGBA
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI9_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	callq	clock
	movq	%rax, %rbx
	movabsq	$3328213113654752561, %rax      # imm = 0x2E30303178303531
	leaq	28(%rsp), %rdi
	movq	%rax, (%rdi)
	movl	$6778480, 8(%rdi)               # imm = 0x676E70
	callq	_Z13read_png_filePc
	movq	%rax, %r14
	xorl	%r12d, %r12d
	xorl	%edi, %edi
	callq	hipSetDevice
	movslq	size(%rip), %rsi
	shlq	$4, %rsi
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	movl	$1, %edi
	callq	hipSetDevice
	movslq	size(%rip), %rsi
	shlq	$4, %rsi
	movq	%rsp, %rdi
	callq	hipMalloc
	movslq	size(%rip), %rsi
	shlq	$4, %rsi
	leaq	8(%rsp), %rdi
	callq	hipMalloc
	cmpl	$0, testSize(%rip)
	jle	.LBB9_10
# %bb.1:                                # %.lr.ph43.preheader
	movabsq	$4294967296, %r13               # imm = 0x100000000
	leaq	512(%r13), %r15
.LBB9_2:                                # %.lr.ph43
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB9_4 Depth 2
	xorl	%edi, %edi
	callq	hipSetDevice
	movq	%r14, %rdi
	callq	_Z19translate_px_to_vecP8PNG_DATA
	movq	%rax, 8(%rsp)
	movq	(%rsp), %rdi
	movslq	size(%rip), %r8
	shlq	$4, %r8
	movl	$1, %esi
	movq	%rax, %rdx
	xorl	%ecx, %ecx
	callq	hipMemcpyPeer
	callq	hipDeviceSynchronize
	movl	$1, %edi
	callq	hipSetDevice
	cmpl	$2, processar(%rip)
	jl	.LBB9_9
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB9_2 Depth=1
	xorl	%ebp, %ebp
.LBB9_4:                                # %.lr.ph
                                        #   Parent Loop BB9_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	size(%rip), %eax
	leal	511(%rax), %edi
	testl	%eax, %eax
	cmovnsl	%eax, %edi
	sarl	$9, %edi
	orq	%r13, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB9_6
# %bb.5:                                #   in Loop: Header=BB9_4 Depth=2
	movq	(%rsp), %rdi
	callq	_Z20__device_stub__sepiaP4RGBA
.LBB9_6:                                #   in Loop: Header=BB9_4 Depth=2
	movq	16(%rsp), %rdi
	movq	(%rsp), %rdx
	movslq	size(%rip), %r8
	shlq	$4, %r8
	xorl	%esi, %esi
	movl	$1, %ecx
	callq	hipMemcpyPeer
	callq	hipDeviceSynchronize
	xorl	%edi, %edi
	callq	hipSetDevice
	movl	size(%rip), %eax
	leal	511(%rax), %edi
	testl	%eax, %eax
	cmovnsl	%eax, %edi
	sarl	$9, %edi
	orq	%r13, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB9_8
# %bb.7:                                #   in Loop: Header=BB9_4 Depth=2
	movq	16(%rsp), %rdi
	callq	_Z23__device_stub__negativeP4RGBA
.LBB9_8:                                #   in Loop: Header=BB9_4 Depth=2
	movq	(%rsp), %rdi
	movq	16(%rsp), %rdx
	movslq	size(%rip), %r8
	shlq	$4, %r8
	movl	$1, %esi
	xorl	%ecx, %ecx
	callq	hipMemcpyPeer
	callq	hipDeviceSynchronize
	movl	$1, %edi
	callq	hipSetDevice
	incl	%ebp
	movl	processar(%rip), %eax
	movl	%eax, %ecx
	shrl	$31, %ecx
	addl	%eax, %ecx
	sarl	%ecx
	cmpl	%ecx, %ebp
	jl	.LBB9_4
.LBB9_9:                                # %._crit_edge
                                        #   in Loop: Header=BB9_2 Depth=1
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movslq	size(%rip), %rdx
	shlq	$4, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	movq	%r14, %rsi
	callq	_Z19translate_vec_to_pxP4RGBAP8PNG_DATA
	incl	%r12d
	movl	$.L.str.3, %edi
	movq	%r14, %rsi
	callq	_Z14write_png_filePcP8PNG_DATA
	cmpl	testSize(%rip), %r12d
	jl	.LBB9_2
.LBB9_10:                               # %._crit_edge44
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	$1, %edi
	callq	hipSetDevice
	movq	(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	callq	clock
	subq	%rbx, %rax
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI9_0(%rip), %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$40, %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_end9:
	.size	main, .Lfunc_end9-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB10_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB10_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9grayscaleP4RGBA, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8negativeP4RGBA, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z5sepiaP4RGBA, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end10:
	.size	__hip_module_ctor, .Lfunc_end10-__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	.LBB11_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
.LBB11_2:
	retq
.Lfunc_end11:
	.size	__hip_module_dtor, .Lfunc_end11-__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	"1.6.43"
	.size	.L.str.1, 7

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

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

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

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

	.type	size,@object                    # @size
	.data
	.globl	size
	.p2align	2, 0x0
size:
	.long	15000                           # 0x3a98
	.size	size, 4

	.type	testSize,@object                # @testSize
	.globl	testSize
	.p2align	2, 0x0
testSize:
	.long	1000                            # 0x3e8
	.size	testSize, 4

	.type	processar,@object               # @processar
	.globl	processar
	.p2align	2, 0x0
processar:
	.long	400                             # 0x190
	.size	processar, 4

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.16,"aMS",@progbits,1
	.p2align	4, 0x0
.L.str.3:
	.asciz	"finalteste1.png"
	.size	.L.str.3, 16

	.type	.L.str.4,@object                # @.str.4
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.4:
	.asciz	"EXECUTION_TIME = %f\n"
	.size	.L.str.4, 21

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

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z8negativeP4RGBA"
	.size	.L__unnamed_2, 18

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z5sepiaP4RGBA"
	.size	.L__unnamed_3, 15

	.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 longjmp
	.addrsig_sym _Z24__device_stub__grayscaleP4RGBA
	.addrsig_sym _Z23__device_stub__negativeP4RGBA
	.addrsig_sym _Z20__device_stub__sepiaP4RGBA
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9grayscaleP4RGBA
	.addrsig_sym _Z8negativeP4RGBA
	.addrsig_sym _Z5sepiaP4RGBA
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9grayscaleP4RGBA      ; -- Begin function _Z9grayscaleP4RGBA
	.globl	_Z9grayscaleP4RGBA
	.p2align	8
	.type	_Z9grayscaleP4RGBA,@function
_Z9grayscaleP4RGBA:                     ; @_Z9grayscaleP4RGBA
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x14
	s_load_b64 s[0:1], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 4, v[1:2]
	v_add_co_u32 v3, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v1, vcc_lo
	global_load_b96 v[0:2], v[3:4], off
	s_waitcnt vmcnt(0)
	v_cvt_f32_i32_e32 v1, v1
	v_cvt_f32_i32_e32 v0, v0
	v_cvt_f32_i32_e32 v2, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v1, 0x3f3851ec, v1
	v_fmamk_f32 v0, v0, 0x3e570a3d, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmamk_f32 v0, v2, 0x3d8f5c29, v0
	v_cvt_i32_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_mov_b32_e32 v2, v0
	v_mov_b32_e32 v1, v0
	global_store_b96 v[3:4], v[0:2], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9grayscaleP4RGBA
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.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 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	_Z9grayscaleP4RGBA, .Lfunc_end0-_Z9grayscaleP4RGBA
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 168
; 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: 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
	.protected	_Z8negativeP4RGBA       ; -- Begin function _Z8negativeP4RGBA
	.globl	_Z8negativeP4RGBA
	.p2align	8
	.type	_Z8negativeP4RGBA,@function
_Z8negativeP4RGBA:                      ; @_Z8negativeP4RGBA
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x14
	s_load_b64 s[0:1], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 4, v[1:2]
	v_add_co_u32 v3, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v1, vcc_lo
	global_load_b96 v[0:2], v[3:4], off
	s_waitcnt vmcnt(0)
	v_sub_nc_u32_e32 v0, 0xff, v0
	v_sub_nc_u32_e32 v1, 0xff, v1
	v_sub_nc_u32_e32 v2, 0xff, v2
	global_store_b96 v[3:4], v[0:2], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8negativeP4RGBA
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.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 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_end1:
	.size	_Z8negativeP4RGBA, .Lfunc_end1-_Z8negativeP4RGBA
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 132
; 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: 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
	.protected	_Z5sepiaP4RGBA          ; -- Begin function _Z5sepiaP4RGBA
	.globl	_Z5sepiaP4RGBA
	.p2align	8
	.type	_Z5sepiaP4RGBA,@function
_Z5sepiaP4RGBA:                         ; @_Z5sepiaP4RGBA
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x14
	s_load_b64 s[0:1], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 4, v[1:2]
	v_add_co_u32 v3, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v1, vcc_lo
	global_load_b96 v[0:2], v[3:4], off
	s_waitcnt vmcnt(0)
	v_cvt_f32_i32_e32 v1, v1
	v_cvt_f32_i32_e32 v0, v0
	v_cvt_f32_i32_e32 v2, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v5, 0x3f44dd2f, v1
	v_fmamk_f32 v0, v0, 0x3ec9374c, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmamk_f32 v0, v2, 0x3e418937, v0
	v_cvt_i32_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f32_i32_e32 v5, v0
	v_mul_f32_e32 v6, 0x3eb2b021, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmamk_f32 v1, v1, 0x3f2f9db2, v6
	v_fmamk_f32 v1, v2, 0x3e2c0831, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_i32_f32_e32 v1, v1
	v_cvt_f32_i32_e32 v6, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v6, 0x3f08b439, v6
	v_fmamk_f32 v5, v5, 0x3e8b4396, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmamk_f32 v2, v2, 0x3e0624dd, v5
	v_cvt_i32_f32_e32 v2, v2
	global_store_b96 v[3:4], v[0:2], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z5sepiaP4RGBA
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.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 7
		.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_end2:
	.size	_Z5sepiaP4RGBA, .Lfunc_end2-_Z5sepiaP4RGBA
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 240
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; 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
      - .offset:         8
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9grayscaleP4RGBA
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9grayscaleP4RGBA.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8negativeP4RGBA
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z8negativeP4RGBA.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z5sepiaP4RGBA
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z5sepiaP4RGBA.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
