#include <iostream>
#include <time.h>
#include <cuda_runtime.h>

/*
 *  Lectura Archivo
 */
void Read(float** R, float** G, float** B, 
	int *N, int *S, int **ordenamiento, int* P, const char *filename) {    
    FILE *fp;
    fp = fopen(filename, "r");
    fscanf(fp, "%d %d\n", N, S);

    int imsize = (*N) * (*N);
    *P = (*N)/ (*S);
    int P2 = (*P) * (*P) ;

    float* R1 = new float[imsize];
    float* G1 = new float[imsize];
    float* B1 = new float[imsize];
    int *orden_temp = new int[P2];

    for(int i = 0; i < P2; i++)
	    fscanf(fp, "%d ", &(orden_temp[i]));
	for(int i = 0; i < imsize; i++)
	    fscanf(fp, "%f ", &(R1[i]));
	for(int i = 0; i < imsize; i++)
	    fscanf(fp, "%f ", &(G1[i]));
	for(int i = 0; i < imsize; i++)
	    fscanf(fp, "%f ", &(B1[i]));
    fclose(fp);
    *R = R1; *G = G1; *B = B1;
    *ordenamiento = orden_temp;
}

/*
 *  Escritura Archivo
 */
void Write(float* R, float* G, float* B, 
	int M, int N, const char *filename) {
    FILE *fp;
    fp = fopen(filename, "w");
    fprintf(fp, "%d %d\n", M, N);
    for(int i = 0; i < M*N-1; i++)
        fprintf(fp, "%f ", R[i]);
    fprintf(fp, "%f\n", R[M*N-1]);
    for(int i = 0; i < M*N-1; i++)
        fprintf(fp, "%f ", G[i]);
    fprintf(fp, "%f\n", G[M*N-1]);
    for(int i = 0; i < M*N-1; i++)
        fprintf(fp, "%f ", B[i]);
    fprintf(fp, "%f\n", B[M*N-1]);
    fclose(fp);
}

/*
 *  Procesamiento Imagen CPU
 */
void funcionCPU(float* R,float* G,float* B, float* Rout,float* Gout,float* Bout, int N, int S, int P, int* ordenamiento){
	for (int i = 0; i< N*N; i++){
        int x = i % N;
        int y = i / N;

        int x_bloque_escritura = x / S;
        int y_bloque_escritura = y /S;

        int indice_bloque_escritura = x_bloque_escritura + y_bloque_escritura * P;
        int indice_bloque_lectura = ordenamiento[indice_bloque_escritura];

        int x_bloque_lectura = indice_bloque_lectura % P;
        int y_bloque_lectura = indice_bloque_lectura / P;

        int shift_horizontal = x_bloque_lectura - x_bloque_escritura;
        int shift_vertical = y_bloque_lectura - y_bloque_escritura;

        x = x + shift_horizontal * S;
        y = y + shift_vertical * S;

        Rout[i] = R[x + y*N];
        Gout[i] = G[x + y*N];
        Bout[i] = B[x + y*N]; 

  }
}

/*
 *  Procesamiento Imagen GPU
 */
__global__ void kernelGPU(float* R,float* G,float* B, float* Rout,float* Gout,float* Bout, int N, int S, int P, int* ordenamiento){
  
	int i = threadIdx.x + blockDim.x* blockIdx.x;
	if (i < N*N){
		int x = i % N;
        int y = i / N;

        int x_bloque_escritura = x / S;
        int y_bloque_escritura = y /S;

        int indice_bloque_escritura = x_bloque_escritura + y_bloque_escritura * P;
        int indice_bloque_lectura = ordenamiento[indice_bloque_escritura];

        int x_bloque_lectura = indice_bloque_lectura % P;
        int y_bloque_lectura = indice_bloque_lectura / P;

        int shift_horizontal = x_bloque_lectura - x_bloque_escritura;
        int shift_vertical = y_bloque_lectura - y_bloque_escritura;

        x = x + shift_horizontal * S;
        y = y + shift_vertical * S;

        Rout[i] = R[x + y*N];
        Gout[i] = G[x + y*N];
        Bout[i] = B[x + y*N]; 
  }
}

/*
 *  Codigo Principal
 */
int main(int argc, char **argv){

    /*
        *  Inicializacion
        */
    clock_t t1, t2;
    cudaEvent_t ct1, ct2;
    double ms;
    float dt;
    int N, S;
    int P;
    int *ordenamiento;   //arreglo con el ordenamiento
    int* ordenamiento_dev;
    float *Rhost, *Ghost, *Bhost;
    float *Rhostout, *Ghostout, *Bhostout;
    float *Rdev, *Gdev, *Bdev;
    float *Rdevout, *Gdevout, *Bdevout;
    char names[1][3][20] = {{"img100x100.txt\0", "img100x100CPU.txt\0", "img100x100GPU.txt\0"}};

    for (int i=0; i<1; i++){
	    Read(&Rhost, &Ghost, &Bhost, &N, &S, &ordenamiento, &P,  names[i][0]);


	    /*
	     *  Parte CPU
	     */
	    Rhostout = new float[N*N];
	    Ghostout = new float[N*N];
	    Bhostout = new float[N*N];

	    t1 = clock();
	    funcionCPU(Rhost,Ghost,Bhost, Rhostout,Ghostout,Bhostout, N, S, P, ordenamiento); // Agregar parametros!
	    t2 = clock();
	    ms = 1000.0 * (double)(t2 - t1) / CLOCKS_PER_SEC;
	    std::cout << "Tiempo CPU: " << ms << "[ms]" << std::endl;
	    Write(Rhostout, Ghostout, Bhostout, N, N, names[i][1]);

	    delete[] Rhostout; delete[] Ghostout; delete[] Bhostout;
	    
	    /*
	     *  Parte GPU
	     */
	    int grid_size, block_size = 256;
	    grid_size = (int)ceil((float) N * N / block_size);
	        
	    cudaMalloc((void**)&Rdev, N * N * sizeof(float));
	    cudaMalloc((void**)&Gdev, N * N * sizeof(float));
	    cudaMalloc((void**)&Bdev, N * N * sizeof(float));
        cudaMalloc((void**)&ordenamiento_dev, (P*P) * sizeof(int));
	    cudaMemcpy(Rdev, Rhost, N * N * sizeof(float), cudaMemcpyHostToDevice);
	    cudaMemcpy(Gdev, Ghost, N * N * sizeof(float), cudaMemcpyHostToDevice);
	    cudaMemcpy(Bdev, Bhost, N * N * sizeof(float), cudaMemcpyHostToDevice);
        cudaMemcpy(ordenamiento_dev, ordenamiento, (P*P) * sizeof(int), cudaMemcpyHostToDevice);
	        
	    cudaMalloc((void**)&Rdevout, N * N * sizeof(float));
	    cudaMalloc((void**)&Gdevout, N * N * sizeof(float));
	    cudaMalloc((void**)&Bdevout, N * N * sizeof(float));
	    
	    cudaEventCreate(&ct1);
	    cudaEventCreate(&ct2);
	    cudaEventRecord(ct1);
	    kernelGPU<<<grid_size, block_size>>>(Rdev,Gdev,Bdev, Rdevout,Gdevout,Bdevout, N, S, P,  ordenamiento_dev); // Agregar parametros!
	    cudaEventRecord(ct2);
	    cudaEventSynchronize(ct2);
	    cudaEventElapsedTime(&dt, ct1, ct2);
	    std::cout << "Tiempo GPU: " << dt << "[ms]" << std::endl;

	    Rhostout = new float[N*N];
	    Ghostout = new float[N*N];
	    Bhostout = new float[N*N];
	    cudaMemcpy(Rhostout, Rdevout, N * N * sizeof(float), cudaMemcpyDeviceToHost);
	    cudaMemcpy(Ghostout, Gdevout, N * N * sizeof(float), cudaMemcpyDeviceToHost);
	    cudaMemcpy(Bhostout, Bdevout, N * N * sizeof(float), cudaMemcpyDeviceToHost);
	    Write(Rhostout, Ghostout, Bhostout, N, N, names[i][2]);

    	cudaFree(Rdev); cudaFree(Gdev); cudaFree(Bdev);
    	cudaFree(Rdevout); cudaFree(Gdevout); cudaFree(Bdevout);
        cudaFree(ordenamiento_dev);
    	delete[] Rhost; delete[] Ghost; delete[] Bhost;
    	delete[] Rhostout; delete[] Ghostout; delete[] Bhostout;
        delete[] ordenamiento;  
	}
	return 0;
}
	.file	"tmpxft_0037459b_00000000-6_lab1.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3641:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3641:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"r"
.LC2:
	.string	"%d %d\n"
.LC3:
	.string	"%d "
.LC4:
	.string	"%f "
	.text
	.globl	_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc
	.type	_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc, @function
_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc:
.LFB3635:
	.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
	movq	%r8, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rcx, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	movq	120(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	.LC1(%rip), %rsi
	movq	%r9, 32(%rsp)
	movq	%rdx, 24(%rsp)
	call	fopen@PLT
	movq	%r12, %rcx
	leaq	.LC2(%rip), %rsi
	movq	%rbx, %rdx
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movl	(%rbx), %eax
	movl	%eax, %ebp
	cltd
	imull	%eax, %ebp
	idivl	(%r12)
	movslq	%ebp, %rbp
	leaq	0(,%rbp,4), %r12
	movq	%r12, %rdi
	movl	%eax, %ebx
	movq	112(%rsp), %rax
	movl	%ebx, (%rax)
	imull	%ebx, %ebx
	call	_Znam@PLT
	movslq	%ebx, %rbx
	movq	%r12, %rdi
	salq	$2, %rbx
	movq	%rax, %r15
	call	_Znam@PLT
	movq	%r12, %rdi
	movq	%rax, %r14
	call	_Znam@PLT
	movq	%rbx, %rdi
	movq	%rax, %r13
	call	_Znam@PLT
	movq	%rax, %r12
	movq	%rax, %rdx
	addq	%rax, %rbx
.L3:
	cmpq	%rbx, %rdx
	je	.L13
	movq	(%rsp), %rdi
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	movq	%rdx, 40(%rsp)
	call	__isoc23_fscanf@PLT
	movq	40(%rsp), %rdx
	addq	$4, %rdx
	jmp	.L3
.L13:
	salq	$2, %rbp
	movq	%r15, %rdx
	leaq	(%r15,%rbp), %rbx
.L5:
	cmpq	%rbx, %rdx
	je	.L14
	movq	(%rsp), %rdi
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	movq	%rdx, 40(%rsp)
	call	__isoc23_fscanf@PLT
	movq	40(%rsp), %rdx
	addq	$4, %rdx
	jmp	.L5
.L14:
	movq	%r14, %rdx
	leaq	(%r14,%rbp), %rbx
.L7:
	cmpq	%rbx, %rdx
	je	.L15
	movq	(%rsp), %rdi
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	movq	%rdx, 40(%rsp)
	call	__isoc23_fscanf@PLT
	movq	40(%rsp), %rdx
	addq	$4, %rdx
	jmp	.L7
.L15:
	movq	%r13, %rbx
	addq	%r13, %rbp
.L9:
	cmpq	%rbp, %rbx
	je	.L16
	movq	(%rsp), %rdi
	movq	%rbx, %rdx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	addq	$4, %rbx
	call	__isoc23_fscanf@PLT
	jmp	.L9
.L16:
	movq	(%rsp), %rdi
	call	fclose@PLT
	movq	8(%rsp), %rax
	movq	%r15, (%rax)
	movq	16(%rsp), %rax
	movq	%r14, (%rax)
	movq	24(%rsp), %rax
	movq	%r13, (%rax)
	movq	32(%rsp), %rax
	movq	%r12, (%rax)
	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
.LFE3635:
	.size	_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc, .-_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc
	.section	.rodata.str1.1
.LC5:
	.string	"w"
.LC6:
	.string	"%f\n"
	.text
	.globl	_Z5WritePfS_S_iiPKc
	.type	_Z5WritePfS_S_iiPKc, @function
_Z5WritePfS_S_iiPKc:
.LFB3636:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%r8d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%ecx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	movq	%r9, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	leaq	.LC5(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdx, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	fopen@PLT
	movl	%r15d, %r8d
	imull	%r13d, %r15d
	movl	%r13d, %ecx
	movq	%rax, 8(%rsp)
	movq	%rax, %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rdx
	call	__fprintf_chk@PLT
	leal	-1(%r15), %r13d
.L18:
	cmpl	%r14d, %r13d
	jle	.L25
	movq	8(%rsp), %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	movb	$1, %al
	cvtss2sd	(%r12,%r14,4), %xmm0
	incq	%r14
	call	__fprintf_chk@PLT
	jmp	.L18
.L25:
	movq	8(%rsp), %rdi
	movslq	%r15d, %r15
	movl	$2, %esi
	movb	$1, %al
	leaq	.LC6(%rip), %rdx
	cvtss2sd	-4(%r12,%r15,4), %xmm0
	leaq	0(,%r15,4), %r14
	xorl	%r12d, %r12d
	call	__fprintf_chk@PLT
	leaq	.LC4(%rip), %r15
.L20:
	cmpl	%r12d, %r13d
	jle	.L26
	movq	8(%rsp), %rdi
	movq	%r15, %rdx
	movl	$2, %esi
	movb	$1, %al
	cvtss2sd	0(%rbp,%r12,4), %xmm0
	incq	%r12
	call	__fprintf_chk@PLT
	jmp	.L20
.L26:
	movq	8(%rsp), %rdi
	movl	$2, %esi
	movb	$1, %al
	xorl	%r15d, %r15d
	leaq	.LC6(%rip), %rdx
	cvtss2sd	-4(%rbp,%r14), %xmm0
	leaq	.LC4(%rip), %rbp
	call	__fprintf_chk@PLT
.L22:
	cmpl	%r15d, %r13d
	jle	.L27
	movq	8(%rsp), %rdi
	movq	%rbp, %rdx
	movl	$2, %esi
	movb	$1, %al
	cvtss2sd	(%rbx,%r15,4), %xmm0
	incq	%r15
	call	__fprintf_chk@PLT
	jmp	.L22
.L27:
	movq	8(%rsp), %rdi
	leaq	.LC6(%rip), %rdx
	movl	$2, %esi
	movb	$1, %al
	cvtss2sd	-4(%rbx,%r14), %xmm0
	call	__fprintf_chk@PLT
	movq	8(%rsp), %rdi
	addq	$24, %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
	jmp	fclose@PLT
	.cfi_endproc
.LFE3636:
	.size	_Z5WritePfS_S_iiPKc, .-_Z5WritePfS_S_iiPKc
	.globl	_Z10funcionCPUPfS_S_S_S_S_iiiPi
	.type	_Z10funcionCPUPfS_S_S_S_S_iiiPi, @function
_Z10funcionCPUPfS_S_S_S_S_iiiPi:
.LFB3637:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r11
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rcx, %r12
	xorl	%ecx, %ecx
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	56(%rsp), %r10d
	movq	%rsi, %rbx
	movl	64(%rsp), %edi
	movl	%r10d, %r15d
	imull	%r10d, %r15d
.L29:
	movl	%ecx, %eax
	cmpl	%ecx, %r15d
	jle	.L32
	cltd
	idivl	%r10d
	movl	%eax, %esi
	movl	%edx, %eax
	movl	%edx, -4(%rsp)
	cltd
	idivl	%edi
	movl	%eax, %r13d
	movl	%esi, %eax
	cltd
	idivl	%edi
	movq	80(%rsp), %rdx
	movl	%eax, %r14d
	imull	72(%rsp), %eax
	addl	%r13d, %eax
	cltq
	movl	(%rdx,%rax,4), %eax
	cltd
	idivl	72(%rsp)
	subl	%r14d, %eax
	subl	%r13d, %edx
	imull	%edi, %eax
	imull	%edi, %edx
	addl	%esi, %eax
	movl	-4(%rsp), %esi
	imull	%r10d, %eax
	addl	%esi, %edx
	addl	%edx, %eax
	cltq
	movss	(%r11,%rax,4), %xmm0
	movss	%xmm0, (%r12,%rcx,4)
	movss	(%rbx,%rax,4), %xmm0
	movss	%xmm0, (%r8,%rcx,4)
	movss	0(%rbp,%rax,4), %xmm0
	movss	%xmm0, (%r9,%rcx,4)
	incq	%rcx
	jmp	.L29
.L32:
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3637:
	.size	_Z10funcionCPUPfS_S_S_S_S_iiiPi, .-_Z10funcionCPUPfS_S_S_S_S_iiiPi
	.globl	_Z43__device_stub__Z9kernelGPUPfS_S_S_S_S_iiiPiPfS_S_S_S_S_iiiPi
	.type	_Z43__device_stub__Z9kernelGPUPfS_S_S_S_S_iiiPiPfS_S_S_S_S_iiiPi, @function
_Z43__device_stub__Z9kernelGPUPfS_S_S_S_S_iiiPiPfS_S_S_S_S_iiiPi:
.LFB3663:
	.cfi_startproc
	endbr64
	subq	$232, %rsp
	.cfi_def_cfa_offset 240
	movq	264(%rsp), %rax
	movq	%rdi, 56(%rsp)
	leaq	88(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	100(%rsp), %rsi
	movq	%rdx, 40(%rsp)
	leaq	72(%rsp), %rdx
	movq	%rcx, 32(%rsp)
	leaq	80(%rsp), %rcx
	movq	%r8, 24(%rsp)
	movq	%r9, 16(%rsp)
	movq	%rax, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 216(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 96(%rsp)
	movq	%rax, 136(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	240(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	248(%rsp), %rax
	movq	%rax, 192(%rsp)
	leaq	256(%rsp), %rax
	movq	%rax, 200(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 208(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 88(%rsp)
	movq	%rax, 100(%rsp)
	movl	$1, 108(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	pushq	80(%rsp)
	.cfi_def_cfa_offset 248
	leaq	_Z9kernelGPUPfS_S_S_S_S_iiiPi(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 256
	movq	116(%rsp), %rcx
	movl	124(%rsp), %r8d
	movq	104(%rsp), %rsi
	movl	112(%rsp), %edx
	leaq	152(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 248
	popq	%rdx
	.cfi_def_cfa_offset 240
.L33:
	movq	216(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$232, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3663:
	.size	_Z43__device_stub__Z9kernelGPUPfS_S_S_S_S_iiiPiPfS_S_S_S_S_iiiPi, .-_Z43__device_stub__Z9kernelGPUPfS_S_S_S_S_iiiPiPfS_S_S_S_S_iiiPi
	.globl	_Z9kernelGPUPfS_S_S_S_S_iiiPi
	.type	_Z9kernelGPUPfS_S_S_S_S_iiiPi, @function
_Z9kernelGPUPfS_S_S_S_S_iiiPi:
.LFB3664:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z9kernelGPUPfS_S_S_S_S_iiiPiPfS_S_S_S_S_iiiPi
	.cfi_endproc
.LFE3664:
	.size	_Z9kernelGPUPfS_S_S_S_S_iiiPi, .-_Z9kernelGPUPfS_S_S_S_S_iiiPi
	.section	.rodata.str1.1
.LC9:
	.string	"Tiempo CPU: "
.LC10:
	.string	"[ms]"
.LC12:
	.string	"Tiempo GPU: "
	.section	.rodata
	.align 32
.LC0:
	.string	"img100x100.txt"
	.string	""
	.zero	4
	.string	"img100x100CPU.txt"
	.string	""
	.zero	1
	.string	"img100x100GPU.txt"
	.string	""
	.zero	1
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3638:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rsi
	movl	$15, %ecx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$264, %rsp
	.cfi_def_cfa_offset 320
	movq	%fs:40, %rax
	movq	%rax, 248(%rsp)
	xorl	%eax, %eax
	leaq	188(%rsp), %rax
	leaq	188(%rsp), %rdi
	rep movsl
	leaq	104(%rsp), %rdx
	leaq	44(%rsp), %rcx
	leaq	96(%rsp), %rsi
	leaq	88(%rsp), %rdi
	pushq	%rax
	.cfi_def_cfa_offset 328
	leaq	60(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 336
	leaq	88(%rsp), %r9
	leaq	64(%rsp), %r8
	call	_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc
	movl	60(%rsp), %edi
	popq	%rax
	.cfi_def_cfa_offset 328
	popq	%rdx
	.cfi_def_cfa_offset 320
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	_Znam@PLT
	movl	44(%rsp), %edi
	movq	%rax, 8(%rsp)
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	_Znam@PLT
	movl	44(%rsp), %edi
	movq	%rax, 16(%rsp)
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	_Znam@PLT
	movq	%rax, %r12
	call	clock@PLT
	movl	52(%rsp), %ebp
	movq	72(%rsp), %r13
	movq	%r12, %r9
	movq	%rax, %rbx
	movq	104(%rsp), %rax
	movq	96(%rsp), %r14
	movq	88(%rsp), %r15
	movq	%rax, (%rsp)
	movq	%r14, %rsi
	pushq	%r13
	.cfi_def_cfa_offset 328
	movq	%r15, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 336
	movl	64(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 344
	movl	68(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 352
	movq	48(%rsp), %r8
	movq	32(%rsp), %rdx
	movq	40(%rsp), %rcx
	call	_Z10funcionCPUPfS_S_S_S_S_iiiPi
	addq	$32, %rsp
	.cfi_def_cfa_offset 320
	call	clock@PLT
	leaq	.LC9(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	subq	%rbx, %rax
	cvtsi2sdq	%rax, %xmm0
	mulsd	.LC7(%rip), %xmm0
	divsd	.LC8(%rip), %xmm0
	movsd	%xmm0, 24(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	24(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	44(%rsp), %ecx
	movq	%r12, %rdx
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdi
	leaq	208(%rsp), %r9
	movl	%ecx, %r8d
	call	_Z5WritePfS_S_iiPKc
	movq	8(%rsp), %rdi
	call	_ZdaPv@PLT
	movq	16(%rsp), %rdi
	call	_ZdaPv@PLT
	movq	%r12, %rdi
	call	_ZdaPv@PLT
	movl	44(%rsp), %ebx
	cvtsi2ssl	%ebx, %xmm0
	imull	%ebx, %ebx
	mulss	%xmm0, %xmm0
	mulss	.LC11(%rip), %xmm0
	call	ceilf@PLT
	movslq	%ebx, %rsi
	leaq	112(%rsp), %rdi
	movl	%ebp, %ebx
	salq	$2, %rsi
	movss	%xmm0, 8(%rsp)
	call	cudaMalloc@PLT
	movl	44(%rsp), %esi
	leaq	120(%rsp), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	44(%rsp), %esi
	leaq	128(%rsp), %rdi
	imull	%esi, %esi
	imull	%ebp, %ebx
	movslq	%esi, %rsi
	movslq	%ebx, %rbx
	salq	$2, %rsi
	call	cudaMalloc@PLT
	salq	$2, %rbx
	leaq	80(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movl	44(%rsp), %edx
	movq	112(%rsp), %rdi
	movq	%r15, %rsi
	movl	$1, %ecx
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	44(%rsp), %edx
	movq	120(%rsp), %rdi
	movq	%r14, %rsi
	movl	$1, %ecx
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	44(%rsp), %edx
	movq	(%rsp), %rsi
	movl	$1, %ecx
	movq	128(%rsp), %rdi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	80(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	44(%rsp), %esi
	leaq	136(%rsp), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	44(%rsp), %esi
	leaq	144(%rsp), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	44(%rsp), %esi
	leaq	152(%rsp), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$16777217, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movss	8(%rsp), %xmm0
	salq	$8, %rdx
	movl	$1, %ecx
	movl	$1, 184(%rsp)
	movq	%rdx, 176(%rsp)
	cvttss2sil	%xmm0, %eax
	movl	%eax, 164(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 168(%rsp)
	movq	164(%rsp), %rdi
	movl	172(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L39
	pushq	80(%rsp)
	.cfi_def_cfa_offset 328
	pushq	%rbp
	.cfi_def_cfa_offset 336
	movl	64(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 344
	movl	68(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 352
	movq	184(%rsp), %r9
	movq	176(%rsp), %r8
	movq	168(%rsp), %rcx
	movq	160(%rsp), %rdx
	movq	152(%rsp), %rsi
	movq	144(%rsp), %rdi
	call	_Z43__device_stub__Z9kernelGPUPfS_S_S_S_S_iiiPiPfS_S_S_S_S_iiiPi
	addq	$32, %rsp
	.cfi_def_cfa_offset 320
.L39:
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	leaq	176(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC12(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	176(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	44(%rsp), %edi
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	_Znam@PLT
	movl	44(%rsp), %edi
	movq	%rax, %r12
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	_Znam@PLT
	movl	44(%rsp), %edi
	movq	%rax, %rbp
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	_Znam@PLT
	movl	44(%rsp), %edx
	movl	$2, %ecx
	movq	%r12, %rdi
	movq	136(%rsp), %rsi
	movq	%rax, %rbx
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	44(%rsp), %edx
	movl	$2, %ecx
	movq	%rbp, %rdi
	movq	144(%rsp), %rsi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	44(%rsp), %edx
	movl	$2, %ecx
	movq	%rbx, %rdi
	movq	152(%rsp), %rsi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	44(%rsp), %ecx
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	leaq	228(%rsp), %r9
	movq	%r12, %rdi
	movl	%ecx, %r8d
	call	_Z5WritePfS_S_iiPKc
	movq	112(%rsp), %rdi
	call	cudaFree@PLT
	movq	120(%rsp), %rdi
	call	cudaFree@PLT
	movq	128(%rsp), %rdi
	call	cudaFree@PLT
	movq	136(%rsp), %rdi
	call	cudaFree@PLT
	movq	144(%rsp), %rdi
	call	cudaFree@PLT
	movq	152(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	testq	%r15, %r15
	je	.L40
	movq	%r15, %rdi
	call	_ZdaPv@PLT
.L40:
	testq	%r14, %r14
	je	.L41
	movq	%r14, %rdi
	call	_ZdaPv@PLT
.L41:
	cmpq	$0, (%rsp)
	je	.L42
	movq	(%rsp), %rdi
	call	_ZdaPv@PLT
.L42:
	movq	%r12, %rdi
	call	_ZdaPv@PLT
	movq	%rbp, %rdi
	call	_ZdaPv@PLT
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
	testq	%r13, %r13
	je	.L43
	movq	%r13, %rdi
	call	_ZdaPv@PLT
.L43:
	movq	248(%rsp), %rax
	subq	%fs:40, %rax
	je	.L44
	call	__stack_chk_fail@PLT
.L44:
	addq	$264, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3638:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z9kernelGPUPfS_S_S_S_S_iiiPi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3666:
	.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	.LC14(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z9kernelGPUPfS_S_S_S_S_iiiPi(%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
.LFE3666:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC7:
	.long	0
	.long	1083129856
	.align 8
.LC8:
	.long	0
	.long	1093567616
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC11:
	.long	998244352
	.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 <iostream>
#include <time.h>
#include <hip/hip_runtime.h>

/*
 *  Lectura Archivo
 */
void Read(float** R, float** G, float** B, 
	int *N, int *S, int **ordenamiento, int* P, const char *filename) {    
    FILE *fp;
    fp = fopen(filename, "r");
    fscanf(fp, "%d %d\n", N, S);

    int imsize = (*N) * (*N);
    *P = (*N)/ (*S);
    int P2 = (*P) * (*P) ;

    float* R1 = new float[imsize];
    float* G1 = new float[imsize];
    float* B1 = new float[imsize];
    int *orden_temp = new int[P2];

    for(int i = 0; i < P2; i++)
	    fscanf(fp, "%d ", &(orden_temp[i]));
	for(int i = 0; i < imsize; i++)
	    fscanf(fp, "%f ", &(R1[i]));
	for(int i = 0; i < imsize; i++)
	    fscanf(fp, "%f ", &(G1[i]));
	for(int i = 0; i < imsize; i++)
	    fscanf(fp, "%f ", &(B1[i]));
    fclose(fp);
    *R = R1; *G = G1; *B = B1;
    *ordenamiento = orden_temp;
}

/*
 *  Escritura Archivo
 */
void Write(float* R, float* G, float* B, 
	int M, int N, const char *filename) {
    FILE *fp;
    fp = fopen(filename, "w");
    fprintf(fp, "%d %d\n", M, N);
    for(int i = 0; i < M*N-1; i++)
        fprintf(fp, "%f ", R[i]);
    fprintf(fp, "%f\n", R[M*N-1]);
    for(int i = 0; i < M*N-1; i++)
        fprintf(fp, "%f ", G[i]);
    fprintf(fp, "%f\n", G[M*N-1]);
    for(int i = 0; i < M*N-1; i++)
        fprintf(fp, "%f ", B[i]);
    fprintf(fp, "%f\n", B[M*N-1]);
    fclose(fp);
}

/*
 *  Procesamiento Imagen CPU
 */
void funcionCPU(float* R,float* G,float* B, float* Rout,float* Gout,float* Bout, int N, int S, int P, int* ordenamiento){
	for (int i = 0; i< N*N; i++){
        int x = i % N;
        int y = i / N;

        int x_bloque_escritura = x / S;
        int y_bloque_escritura = y /S;

        int indice_bloque_escritura = x_bloque_escritura + y_bloque_escritura * P;
        int indice_bloque_lectura = ordenamiento[indice_bloque_escritura];

        int x_bloque_lectura = indice_bloque_lectura % P;
        int y_bloque_lectura = indice_bloque_lectura / P;

        int shift_horizontal = x_bloque_lectura - x_bloque_escritura;
        int shift_vertical = y_bloque_lectura - y_bloque_escritura;

        x = x + shift_horizontal * S;
        y = y + shift_vertical * S;

        Rout[i] = R[x + y*N];
        Gout[i] = G[x + y*N];
        Bout[i] = B[x + y*N]; 

  }
}

/*
 *  Procesamiento Imagen GPU
 */
__global__ void kernelGPU(float* R,float* G,float* B, float* Rout,float* Gout,float* Bout, int N, int S, int P, int* ordenamiento){
  
	int i = threadIdx.x + blockDim.x* blockIdx.x;
	if (i < N*N){
		int x = i % N;
        int y = i / N;

        int x_bloque_escritura = x / S;
        int y_bloque_escritura = y /S;

        int indice_bloque_escritura = x_bloque_escritura + y_bloque_escritura * P;
        int indice_bloque_lectura = ordenamiento[indice_bloque_escritura];

        int x_bloque_lectura = indice_bloque_lectura % P;
        int y_bloque_lectura = indice_bloque_lectura / P;

        int shift_horizontal = x_bloque_lectura - x_bloque_escritura;
        int shift_vertical = y_bloque_lectura - y_bloque_escritura;

        x = x + shift_horizontal * S;
        y = y + shift_vertical * S;

        Rout[i] = R[x + y*N];
        Gout[i] = G[x + y*N];
        Bout[i] = B[x + y*N]; 
  }
}

/*
 *  Codigo Principal
 */
int main(int argc, char **argv){

    /*
        *  Inicializacion
        */
    clock_t t1, t2;
    hipEvent_t ct1, ct2;
    double ms;
    float dt;
    int N, S;
    int P;
    int *ordenamiento;   //arreglo con el ordenamiento
    int* ordenamiento_dev;
    float *Rhost, *Ghost, *Bhost;
    float *Rhostout, *Ghostout, *Bhostout;
    float *Rdev, *Gdev, *Bdev;
    float *Rdevout, *Gdevout, *Bdevout;
    char names[1][3][20] = {{"img100x100.txt\0", "img100x100CPU.txt\0", "img100x100GPU.txt\0"}};

    for (int i=0; i<1; i++){
	    Read(&Rhost, &Ghost, &Bhost, &N, &S, &ordenamiento, &P,  names[i][0]);


	    /*
	     *  Parte CPU
	     */
	    Rhostout = new float[N*N];
	    Ghostout = new float[N*N];
	    Bhostout = new float[N*N];

	    t1 = clock();
	    funcionCPU(Rhost,Ghost,Bhost, Rhostout,Ghostout,Bhostout, N, S, P, ordenamiento); // Agregar parametros!
	    t2 = clock();
	    ms = 1000.0 * (double)(t2 - t1) / CLOCKS_PER_SEC;
	    std::cout << "Tiempo CPU: " << ms << "[ms]" << std::endl;
	    Write(Rhostout, Ghostout, Bhostout, N, N, names[i][1]);

	    delete[] Rhostout; delete[] Ghostout; delete[] Bhostout;
	    
	    /*
	     *  Parte GPU
	     */
	    int grid_size, block_size = 256;
	    grid_size = (int)ceil((float) N * N / block_size);
	        
	    hipMalloc((void**)&Rdev, N * N * sizeof(float));
	    hipMalloc((void**)&Gdev, N * N * sizeof(float));
	    hipMalloc((void**)&Bdev, N * N * sizeof(float));
        hipMalloc((void**)&ordenamiento_dev, (P*P) * sizeof(int));
	    hipMemcpy(Rdev, Rhost, N * N * sizeof(float), hipMemcpyHostToDevice);
	    hipMemcpy(Gdev, Ghost, N * N * sizeof(float), hipMemcpyHostToDevice);
	    hipMemcpy(Bdev, Bhost, N * N * sizeof(float), hipMemcpyHostToDevice);
        hipMemcpy(ordenamiento_dev, ordenamiento, (P*P) * sizeof(int), hipMemcpyHostToDevice);
	        
	    hipMalloc((void**)&Rdevout, N * N * sizeof(float));
	    hipMalloc((void**)&Gdevout, N * N * sizeof(float));
	    hipMalloc((void**)&Bdevout, N * N * sizeof(float));
	    
	    hipEventCreate(&ct1);
	    hipEventCreate(&ct2);
	    hipEventRecord(ct1);
	    kernelGPU<<<grid_size, block_size>>>(Rdev,Gdev,Bdev, Rdevout,Gdevout,Bdevout, N, S, P,  ordenamiento_dev); // Agregar parametros!
	    hipEventRecord(ct2);
	    hipEventSynchronize(ct2);
	    hipEventElapsedTime(&dt, ct1, ct2);
	    std::cout << "Tiempo GPU: " << dt << "[ms]" << std::endl;

	    Rhostout = new float[N*N];
	    Ghostout = new float[N*N];
	    Bhostout = new float[N*N];
	    hipMemcpy(Rhostout, Rdevout, N * N * sizeof(float), hipMemcpyDeviceToHost);
	    hipMemcpy(Ghostout, Gdevout, N * N * sizeof(float), hipMemcpyDeviceToHost);
	    hipMemcpy(Bhostout, Bdevout, N * N * sizeof(float), hipMemcpyDeviceToHost);
	    Write(Rhostout, Ghostout, Bhostout, N, N, names[i][2]);

    	hipFree(Rdev); hipFree(Gdev); hipFree(Bdev);
    	hipFree(Rdevout); hipFree(Gdevout); hipFree(Bdevout);
        hipFree(ordenamiento_dev);
    	delete[] Rhost; delete[] Ghost; delete[] Bhost;
    	delete[] Rhostout; delete[] Ghostout; delete[] Bhostout;
        delete[] ordenamiento;  
	}
	return 0;
}
	.text
	.file	"lab1.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc # -- Begin function _Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc
	.type	_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc,@function
_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc:        # @_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.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	%r9, 64(%rsp)                   # 8-byte Spill
	movq	%r8, %rbx
	movq	%rcx, %r14
	movq	%rdx, 56(%rsp)                  # 8-byte Spill
	movq	%rsi, 48(%rsp)                  # 8-byte Spill
	movq	%rdi, 40(%rsp)                  # 8-byte Spill
	movq	136(%rsp), %rdi
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %r13
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	movq	%r14, %rdx
	movq	%rbx, %rcx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	(%r14), %ebp
	movl	%ebp, %r12d
	imull	%r12d, %r12d
	movl	%ebp, %eax
	cltd
	idivl	(%rbx)
	movl	%eax, %r15d
	movq	128(%rsp), %rax
	movl	%r15d, (%rax)
	movl	%r15d, %ebx
	imull	%ebx, %ebx
	leaq	(,%r12,4), %r14
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	leaq	(,%rbx,4), %rdi
	callq	_Znam
	movq	%rax, %r14
	testl	%r15d, %r15d
	je	.LBB0_3
# %bb.1:                                # %.lr.ph.preheader
	cmpl	$1, %ebx
	adcl	$0, %ebx
	movq	%r14, %r15
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.2, %esi
	movq	%r13, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %r15
	decq	%rbx
	jne	.LBB0_2
.LBB0_3:                                # %.preheader52
	movq	%r14, 32(%rsp)                  # 8-byte Spill
	testl	%ebp, %ebp
	je	.LBB0_12
# %bb.4:                                # %.lr.ph55.preheader
	movl	%ebp, %r14d
	cmpl	$1, %r12d
	movl	%r12d, %ebp
	adcl	$0, %ebp
	movq	%rbp, %rbx
	movq	24(%rsp), %r15                  # 8-byte Reload
.LBB0_5:                                # %.lr.ph55
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.3, %esi
	movq	%r13, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %r15
	decq	%rbx
	jne	.LBB0_5
# %bb.6:                                # %.preheader51
	testl	%r14d, %r14d
	je	.LBB0_12
# %bb.7:
	movq	16(%rsp), %r15                  # 8-byte Reload
.LBB0_8:                                # %.lr.ph57
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.3, %esi
	movq	%r13, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %r15
	decq	%rbp
	jne	.LBB0_8
# %bb.9:                                # %.preheader
	testl	%r14d, %r14d
	je	.LBB0_12
# %bb.10:                               # %.lr.ph59.preheader
	cmpl	$1, %r12d
	adcl	$0, %r12d
	movq	8(%rsp), %r15                   # 8-byte Reload
.LBB0_11:                               # %.lr.ph59
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.3, %esi
	movq	%r13, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %r15
	decq	%r12
	jne	.LBB0_11
.LBB0_12:                               # %._crit_edge
	movq	%r13, %rdi
	callq	fclose
	movq	40(%rsp), %rax                  # 8-byte Reload
	movq	24(%rsp), %rcx                  # 8-byte Reload
	movq	%rcx, (%rax)
	movq	48(%rsp), %rax                  # 8-byte Reload
	movq	16(%rsp), %rcx                  # 8-byte Reload
	movq	%rcx, (%rax)
	movq	56(%rsp), %rax                  # 8-byte Reload
	movq	8(%rsp), %rcx                   # 8-byte Reload
	movq	%rcx, (%rax)
	movq	64(%rsp), %rax                  # 8-byte Reload
	movq	32(%rsp), %rcx                  # 8-byte Reload
	movq	%rcx, (%rax)
	addq	$72, %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_end0:
	.size	_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc, .Lfunc_end0-_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc
	.cfi_endproc
                                        # -- End function
	.globl	_Z5WritePfS_S_iiPKc             # -- Begin function _Z5WritePfS_S_iiPKc
	.type	_Z5WritePfS_S_iiPKc,@function
_Z5WritePfS_S_iiPKc:                    # @_Z5WritePfS_S_iiPKc
	.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	%r8d, %r15d
	movl	%ecx, %ebp
	movq	%rdx, %r14
	movq	%rsi, %r12
	movq	%rdi, %r13
	movl	$.L.str.4, %esi
	movq	%r9, %rdi
	callq	fopen
	movq	%rax, %rbx
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	movl	%ebp, %edx
	movl	%r15d, %ecx
	xorl	%eax, %eax
	callq	fprintf
	imull	%ebp, %r15d
	leal	-1(%r15), %eax
	movl	%eax, 8(%rsp)                   # 4-byte Spill
	movl	%eax, %ebp
	movq	%r15, 16(%rsp)                  # 8-byte Spill
	cmpl	$2, %r15d
	jl	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%r15d, %r15d
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r13,%r15,4), %xmm0
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	incq	%r15
	cmpq	%r15, %rbp
	jne	.LBB1_2
.LBB1_3:                                # %._crit_edge
	movslq	8(%rsp), %r15                   # 4-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r13,%r15,4), %xmm0
	movl	$.L.str.5, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movq	16(%rsp), %r13                  # 8-byte Reload
	cmpl	$1, %r13d
	jle	.LBB1_4
# %bb.9:                                # %.lr.ph43.preheader
	movq	%r15, 8(%rsp)                   # 8-byte Spill
	xorl	%r15d, %r15d
.LBB1_10:                               # %.lr.ph43
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r12,%r15,4), %xmm0
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	incq	%r15
	cmpq	%r15, %rbp
	jne	.LBB1_10
# %bb.6:                                # %._crit_edge44
	movq	8(%rsp), %rax                   # 8-byte Reload
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r12,%rax,4), %xmm0
	movq	%rax, %r12
	movl	$.L.str.5, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	cmpl	$2, %r13d
	jl	.LBB1_5
# %bb.7:                                # %.lr.ph47.preheader
	xorl	%r15d, %r15d
.LBB1_8:                                # %.lr.ph47
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r15,4), %xmm0
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	incq	%r15
	cmpq	%r15, %rbp
	jne	.LBB1_8
	jmp	.LBB1_5
.LBB1_4:                                # %._crit_edge44.thread
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r12,%r15,4), %xmm0
	movl	$.L.str.5, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movq	%r15, %r12
.LBB1_5:                                # %._crit_edge48
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r12,4), %xmm0
	movl	$.L.str.5, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movq	%rbx, %rdi
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.Lfunc_end1:
	.size	_Z5WritePfS_S_iiPKc, .Lfunc_end1-_Z5WritePfS_S_iiPKc
	.cfi_endproc
                                        # -- End function
	.globl	_Z10funcionCPUPfS_S_S_S_S_iiiPi # -- Begin function _Z10funcionCPUPfS_S_S_S_S_iiiPi
	.type	_Z10funcionCPUPfS_S_S_S_S_iiiPi,@function
_Z10funcionCPUPfS_S_S_S_S_iiiPi:        # @_Z10funcionCPUPfS_S_S_S_S_iiiPi
	.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
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$0, 56(%rsp)
	je	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader
	movq	%rdi, %r13
	movl	56(%rsp), %eax
                                        # kill: def $eax killed $eax def $rax
	imull	%eax, %eax
	cmpl	$1, %eax
	adcl	$0, %eax
	movq	%rax, -16(%rsp)                 # 8-byte Spill
	xorl	%r11d, %r11d
	movq	%r9, -8(%rsp)                   # 8-byte Spill
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%r11d, %eax
	movq	%rsi, %r9
	movq	%rdx, %rdi
	cltd
	movl	56(%rsp), %r12d
	idivl	%r12d
	movl	%edx, %ebp
	movq	%rcx, %rsi
	movl	%eax, %ebx
	movl	%edx, %eax
	cltd
	movl	64(%rsp), %ecx
	idivl	%ecx
	movl	%eax, %r14d
	movl	%ebx, %eax
	cltd
	idivl	%ecx
	movl	%eax, %r15d
	movl	72(%rsp), %r10d
	imull	%r10d, %eax
	addl	%r14d, %eax
	cltq
	movq	80(%rsp), %rdx
	movl	(%rdx,%rax,4), %eax
	cltd
	idivl	%r10d
	subl	%r14d, %edx
	subl	%r15d, %eax
	imull	%ecx, %edx
	addl	%ebp, %edx
	imull	%ecx, %eax
	addl	%ebx, %eax
	movq	%rsi, %rcx
	imull	%r12d, %eax
	addl	%edx, %eax
	movq	%rdi, %rdx
	movq	%r9, %rsi
	cltq
	movss	(%r13,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rcx,%r11,4)
	movss	(%r9,%rax,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%r8,%r11,4)
	movss	(%rdi,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movq	-8(%rsp), %r9                   # 8-byte Reload
	movss	%xmm0, (%r9,%r11,4)
	incq	%r11
	cmpq	%r11, -16(%rsp)                 # 8-byte Folded Reload
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	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_end2:
	.size	_Z10funcionCPUPfS_S_S_S_S_iiiPi, .Lfunc_end2-_Z10funcionCPUPfS_S_S_S_S_iiiPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__kernelGPUPfS_S_S_S_S_iiiPi # -- Begin function _Z24__device_stub__kernelGPUPfS_S_S_S_S_iiiPi
	.type	_Z24__device_stub__kernelGPUPfS_S_S_S_S_iiiPi,@function
_Z24__device_stub__kernelGPUPfS_S_S_S_S_iiiPi: # @_Z24__device_stub__kernelGPUPfS_S_S_S_S_iiiPi
	.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	$176, %rsp
	.cfi_def_cfa_offset 224
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	16(%rsp), %r8
	movq	%r9, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	224(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	232(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	240(%rsp), %rax
	movq	%rax, 64(%rbx)
	leaq	248(%rsp), %rax
	movq	%rax, 72(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z9kernelGPUPfS_S_S_S_S_iiiPi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$192, %rsp
	.cfi_adjust_cfa_offset -192
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z24__device_stub__kernelGPUPfS_S_S_S_S_iiiPi, .Lfunc_end3-_Z24__device_stub__kernelGPUPfS_S_S_S_S_iiiPi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI4_0:
	.byte	105                             # 0x69
	.byte	109                             # 0x6d
	.byte	103                             # 0x67
	.byte	49                              # 0x31
	.byte	48                              # 0x30
	.byte	48                              # 0x30
	.byte	120                             # 0x78
	.byte	49                              # 0x31
	.byte	48                              # 0x30
	.byte	48                              # 0x30
	.byte	67                              # 0x43
	.byte	80                              # 0x50
	.byte	85                              # 0x55
	.byte	46                              # 0x2e
	.byte	116                             # 0x74
	.byte	120                             # 0x78
.LCPI4_1:
	.byte	116                             # 0x74
	.byte	0                               # 0x0
	.byte	0                               # 0x0
	.byte	0                               # 0x0
	.byte	105                             # 0x69
	.byte	109                             # 0x6d
	.byte	103                             # 0x67
	.byte	49                              # 0x31
	.byte	48                              # 0x30
	.byte	48                              # 0x30
	.byte	120                             # 0x78
	.byte	49                              # 0x31
	.byte	48                              # 0x30
	.byte	48                              # 0x30
	.byte	71                              # 0x47
	.byte	80                              # 0x50
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI4_2:
	.quad	0x408f400000000000              # double 1000
.LCPI4_3:
	.quad	0x412e848000000000              # double 1.0E+6
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI4_4:
	.long	0x3b800000                      # float 0.00390625
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:                                # %.critedge
	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	$248, %rsp
	.cfi_def_cfa_offset 304
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movabsq	$3564652088609172841, %rax      # imm = 0x3178303031676D69
	leaq	196(%rsp), %r12
	movq	%rax, -20(%r12)
	movl	$1949184048, -12(%r12)          # imm = 0x742E3030
	movw	$29816, -8(%r12)                # imm = 0x7478
	movl	$0, -6(%r12)
	movw	$0, -2(%r12)
	movaps	.LCPI4_0(%rip), %xmm0           # xmm0 = [105,109,103,49,48,48,120,49,48,48,67,80,85,46,116,120]
	movups	%xmm0, (%r12)
	movaps	.LCPI4_1(%rip), %xmm0           # xmm0 = [116,0,0,0,105,109,103,49,48,48,120,49,48,48,71,80]
	movups	%xmm0, 16(%r12)
	leaq	216(%rsp), %rcx
	movabsq	$500237086293, %rax             # imm = 0x7478742E55
	movq	%rax, 12(%rcx)
	leaq	176(%rsp), %rax
	leaq	76(%rsp), %r10
	leaq	144(%rsp), %rdi
	leaq	136(%rsp), %rsi
	leaq	128(%rsp), %rdx
	leaq	8(%rsp), %rbx
	leaq	12(%rsp), %r8
	leaq	152(%rsp), %r9
	movq	%rbx, %rcx
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	callq	_Z4ReadPPfS0_S0_PiS1_PS1_S1_PKc
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	(%rbx), %r15d
	movq	%rbx, %rbp
	imull	%r15d, %r15d
	shlq	$2, %r15
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %rbx
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r14
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r15
	callq	clock
	movq	%rax, %r13
	leaq	144(%rsp), %rax
	movq	(%rax), %rdi
	movq	%rdi, 80(%rsp)                  # 8-byte Spill
	leaq	136(%rsp), %rax
	movq	(%rax), %rsi
	movq	%rsi, 88(%rsp)                  # 8-byte Spill
	leaq	128(%rsp), %rax
	movq	(%rax), %rdx
	movq	%rdx, 120(%rsp)                 # 8-byte Spill
	movl	(%rbp), %eax
	leaq	12(%rsp), %rcx
	movl	(%rcx), %r10d
	leaq	76(%rsp), %rcx
	movl	(%rcx), %ebp
	leaq	152(%rsp), %rcx
	movq	(%rcx), %r11
	movq	%r11, 24(%rsp)                  # 8-byte Spill
	movq	%rbx, %rcx
	movq	%r14, %r8
	movq	%r15, %r9
	pushq	%r11
	.cfi_adjust_cfa_offset 8
	pushq	%rbp
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	callq	_Z10funcionCPUPfS_S_S_S_S_iiiPi
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	callq	clock
	subq	%r13, %rax
	cvtsi2sd	%rax, %xmm0
	mulsd	.LCPI4_2(%rip), %xmm0
	divsd	.LCPI4_3(%rip), %xmm0
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$12, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r13
	movl	$.L.str.7, %esi
	movl	$4, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r13), %rax
	movq	-24(%rax), %rdi
	addq	%r13, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r13, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	leaq	8(%rsp), %r13
	movl	(%r13), %ecx
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	%ecx, %r8d
	movq	%r12, %r9
	callq	_Z5WritePfS_S_iiPKc
	movq	%rbx, %rdi
	callq	_ZdaPv
	movq	%r14, %rdi
	callq	_ZdaPv
	movq	%r15, %rdi
	callq	_ZdaPv
	movl	(%r13), %ebx
	movq	%r13, %r15
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebx, %xmm0
	mulss	%xmm0, %xmm0
	mulss	.LCPI4_4(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r12d
	imull	%ebx, %ebx
	shlq	$2, %rbx
	leaq	104(%rsp), %r14
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movl	(%r13), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	leaq	96(%rsp), %r13
	movq	%r13, %rdi
	callq	hipMalloc
	movl	(%r15), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	leaq	56(%rsp), %rdi
	callq	hipMalloc
	movq	%rbp, 16(%rsp)                  # 8-byte Spill
	movl	%ebp, %ebx
	imull	%ebx, %ebx
	shlq	$2, %rbx
	leaq	112(%rsp), %rbp
	movq	%rbp, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movl	(%r15), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movq	80(%rsp), %rsi                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	movq	120(%rsp), %r13                 # 8-byte Reload
	movl	(%r15), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movq	88(%rsp), %rsi                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	56(%rsp), %rax
	movq	(%rax), %rdi
	movl	(%r15), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbp), %rdi
	movq	24(%rsp), %rsi                  # 8-byte Reload
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	(%r15), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	leaq	48(%rsp), %rdi
	callq	hipMalloc
	movl	(%r15), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	leaq	40(%rsp), %rdi
	callq	hipMalloc
	movl	(%r15), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	leaq	32(%rsp), %rdi
	callq	hipMalloc
	leaq	160(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	leaq	64(%rsp), %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	btsq	$32, %r12
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$256, %rdx                      # imm = 0x100
	movq	%r12, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_2
# %bb.1:
	movq	104(%rsp), %rdi
	movq	96(%rsp), %rsi
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rcx
	movq	40(%rsp), %r8
	movq	32(%rsp), %r9
	movl	8(%rsp), %eax
	movl	12(%rsp), %r10d
	pushq	112(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	24(%rsp)                        # 8-byte Folded Reload
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	callq	_Z24__device_stub__kernelGPUPfS_S_S_S_S_iiiPi
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
.LBB4_2:
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	64(%rsp), %rdi
	callq	hipEventSynchronize
	movq	160(%rsp), %rsi
	movq	64(%rsp), %rdx
	leaq	172(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$12, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtss2sd	(%rbx), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.7, %esi
	movl	$4, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	8(%rsp), %r14d
	imull	%r14d, %r14d
	shlq	$2, %r14
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %r12
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %rbp
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %rbx
	movq	48(%rsp), %rsi
	movq	%r12, %rdi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	40(%rsp), %rsi
	movl	8(%rsp), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movq	%rbp, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rsi
	movl	8(%rsp), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	8(%rsp), %ecx
	movq	%r12, %rdi
	movq	%rbp, %rsi
	movq	%rbx, %rdx
	movl	%ecx, %r8d
	leaq	216(%rsp), %r9
	callq	_Z5WritePfS_S_iiPKc
	movq	104(%rsp), %rdi
	callq	hipFree
	movq	96(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	112(%rsp), %rdi
	callq	hipFree
	movq	80(%rsp), %rdi                  # 8-byte Reload
	testq	%rdi, %rdi
	je	.LBB4_4
# %bb.3:
	callq	_ZdaPv
.LBB4_4:
	movq	88(%rsp), %rdi                  # 8-byte Reload
	testq	%rdi, %rdi
	je	.LBB4_6
# %bb.5:
	callq	_ZdaPv
.LBB4_6:
	testq	%r13, %r13
	je	.LBB4_8
# %bb.7:
	movq	%r13, %rdi
	callq	_ZdaPv
.LBB4_8:
	movq	%r12, %rdi
	callq	_ZdaPv
	movq	%rbp, %rdi
	callq	_ZdaPv
	movq	%rbx, %rdi
	callq	_ZdaPv
	cmpq	$0, 24(%rsp)                    # 8-byte Folded Reload
	je	.LBB4_10
# %bb.9:
	movq	24(%rsp), %rdi                  # 8-byte Reload
	callq	_ZdaPv
.LBB4_10:
	xorl	%eax, %eax
	addq	$248, %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_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9kernelGPUPfS_S_S_S_S_iiiPi, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"r"
	.size	.L.str, 2

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

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

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

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

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

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

	.type	.L.str.6,@object                # @.str.6
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.6:
	.asciz	"Tiempo CPU: "
	.size	.L.str.6, 13

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"[ms]"
	.size	.L.str.7, 5

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Tiempo GPU: "
	.size	.L.str.8, 13

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9kernelGPUPfS_S_S_S_S_iiiPi"
	.size	.L__unnamed_1, 30

	.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__kernelGPUPfS_S_S_S_S_iiiPi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9kernelGPUPfS_S_S_S_S_iiiPi
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9kernelGPUPfS_S_S_S_S_iiiPi ; -- Begin function _Z9kernelGPUPfS_S_S_S_S_iiiPi
	.globl	_Z9kernelGPUPfS_S_S_S_S_iiiPi
	.p2align	8
	.type	_Z9kernelGPUPfS_S_S_S_S_iiiPi,@function
_Z9kernelGPUPfS_S_S_S_S_iiiPi:          ; @_Z9kernelGPUPfS_S_S_S_S_iiiPi
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x54
	s_load_b128 s[4:7], s[0:1], 0x30
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mul_i32 s2, s4, s4
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_cmp_gt_i32_e32 vcc_lo, s2, v1
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_ashr_i32 s2, s4, 31
	v_ashrrev_i32_e32 v2, 31, v1
	s_add_i32 s3, s4, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_xor_b32 s3, s3, s2
	v_add_nc_u32_e32 v4, v1, v2
	v_cvt_f32_u32_e32 v0, s3
	s_sub_i32 s7, 0, s3
	v_xor_b32_e32 v6, s2, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_xor_b32_e32 v4, v4, v2
	v_rcp_iflag_f32_e32 v0, v0
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v0, v0
	v_mul_lo_u32 v3, s7, v0
	s_ashr_i32 s7, s5, 31
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s8, s5, s7
	s_xor_b32 s8, s8, s7
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_sub_i32 s2, 0, s8
	v_mul_hi_u32 v3, v0, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v0, v3
	v_mul_hi_u32 v0, v4, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v3, v0, s3
	v_sub_nc_u32_e32 v3, v4, v3
	v_add_nc_u32_e32 v4, 1, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v5, s3, v3
	v_cmp_le_u32_e32 vcc_lo, s3, v3
	v_dual_cndmask_b32 v0, v0, v4 :: v_dual_cndmask_b32 v3, v3, v5
	v_cvt_f32_u32_e32 v4, s8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v5, 1, v0
	v_cmp_le_u32_e32 vcc_lo, s3, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_rcp_iflag_f32_e32 v4, v4
	v_cndmask_b32_e32 v0, v0, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_xor_b32_e32 v0, v0, v6
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v3, 0x4f7ffffe, v4
	v_sub_nc_u32_e32 v0, v0, v6
	v_cvt_u32_f32_e32 v3, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v4, v0, s4
	v_mul_lo_u32 v5, s2, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v6, v1, v4
	v_ashrrev_i32_e32 v4, 31, v0
	v_mul_hi_u32 v5, v3, v5
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_ashrrev_i32_e32 v7, 31, v6
	v_add_nc_u32_e32 v8, v0, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_nc_u32_e32 v9, v6, v7
	v_add_nc_u32_e32 v3, v3, v5
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v5, v8, v4
	v_xor_b32_e32 v4, s7, v4
	v_xor_b32_e32 v8, v9, v7
	v_xor_b32_e32 v7, s7, v7
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_mul_hi_u32 v9, v5, v3
	v_mul_hi_u32 v3, v8, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v10, v9, s8
	v_mul_lo_u32 v11, v3, s8
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v5, v5, v10
	v_add_nc_u32_e32 v10, 1, v9
	v_sub_nc_u32_e32 v8, v8, v11
	v_add_nc_u32_e32 v11, 1, v3
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cmp_le_u32_e32 vcc_lo, s8, v5
	v_subrev_nc_u32_e32 v12, s8, v8
	v_cmp_le_u32_e64 s2, s8, v8
	v_cndmask_b32_e32 v9, v9, v10, vcc_lo
	v_subrev_nc_u32_e32 v10, s8, v5
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v3, v3, v11, s2
	v_cndmask_b32_e64 v8, v8, v12, s2
	v_dual_cndmask_b32 v5, v5, v10 :: v_dual_add_nc_u32 v10, 1, v9
	s_load_b64 s[2:3], s[0:1], 0x40
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v11, 1, v3
	v_cmp_le_u32_e32 vcc_lo, s8, v5
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v5, v9, v10, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s8, v8
	v_xor_b32_e32 v5, v5, v4
	v_cndmask_b32_e32 v3, v3, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v8, v5, v4
	v_xor_b32_e32 v3, v3, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v3, v3, v7
	v_mad_u64_u32 v[4:5], null, v8, s6, v[3:4]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, s2, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s3, v5, vcc_lo
	s_ashr_i32 s2, s6, 31
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_add_i32 s3, s6, s2
	global_load_b32 v4, v[4:5], off
	s_xor_b32 s3, s3, s2
	v_cvt_f32_u32_e32 v5, s3
	s_sub_i32 s7, 0, s3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v5, v5
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v5, 0x4f7ffffe, v5
	v_cvt_u32_f32_e32 v5, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v7, s7, v5
	v_mul_hi_u32 v7, v5, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v5, v5, v7
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v9, 31, v4
	v_add_nc_u32_e32 v10, v4, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_xor_b32_e32 v7, v10, v9
	v_xor_b32_e32 v9, s2, v9
	v_mul_hi_u32 v5, v7, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v10, v5, s3
	v_sub_nc_u32_e32 v7, v7, v10
	v_add_nc_u32_e32 v10, 1, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_subrev_nc_u32_e32 v11, s3, v7
	v_cmp_le_u32_e32 vcc_lo, s3, v7
	v_cndmask_b32_e32 v5, v5, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_cndmask_b32 v7, v7, v11 :: v_dual_add_nc_u32 v10, 1, v5
	v_cmp_le_u32_e32 vcc_lo, s3, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v5, v5, v10, vcc_lo
	v_xor_b32_e32 v5, v5, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v5, v5, v9
	v_mul_lo_u32 v7, v5, s6
	v_sub_nc_u32_e32 v8, v5, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v7, v4, v7
	v_mad_u64_u32 v[4:5], null, v8, s5, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v0, v7, v3
	v_mul_lo_u32 v3, v4, s4
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v0, v0, s5
	s_clause 0x1
	s_load_b256 s[4:11], s[0:1], 0x0
	s_load_b128 s[0:3], s[0:1], 0x20
	v_add3_u32 v3, v0, v6, v3
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v4, vcc_lo
	global_load_b32 v9, v[5:6], off
	v_add_co_u32 v5, vcc_lo, s10, v0
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v1, vcc_lo
	v_add_co_u32 v7, vcc_lo, s6, v3
	v_add_co_ci_u32_e32 v8, vcc_lo, s7, v4, vcc_lo
	s_waitcnt vmcnt(0)
	global_store_b32 v[5:6], v9, off
	global_load_b32 v7, v[7:8], off
	v_add_co_u32 v5, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v1, vcc_lo
	v_add_co_u32 v2, vcc_lo, s8, v3
	v_add_co_ci_u32_e32 v3, vcc_lo, s9, v4, vcc_lo
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	s_waitcnt vmcnt(0)
	global_store_b32 v[5:6], v7, off
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9kernelGPUPfS_S_S_S_S_iiiPi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 328
		.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 13
		.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	_Z9kernelGPUPfS_S_S_S_S_iiiPi, .Lfunc_end0-_Z9kernelGPUPfS_S_S_S_S_iiiPi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1036
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; 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
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .offset:         48
        .size:           4
        .value_kind:     by_value
      - .offset:         52
        .size:           4
        .value_kind:     by_value
      - .offset:         56
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         64
        .size:           8
        .value_kind:     global_buffer
      - .offset:         72
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         76
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         80
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         84
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         86
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         88
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         90
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         92
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         94
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         112
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         120
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         128
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         136
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 328
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9kernelGPUPfS_S_S_S_S_iiiPi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9kernelGPUPfS_S_S_S_S_iiiPi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     13
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
