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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define MAX_NAME 256 /* tamanho maximo para nome de arquivo */
#define PI 3.14159265359

double **matrizpesos;

struct param{
	int totalthreads;
	int linhas;
	int colunas;
	int tamanho; //se a divisao nao for inteira aqui vai o mais 1
	int sobra; //resto da divisao que vamos distribuir
	int raio; //distancia para considerar os pixels
};

void InicializaMatrizPesos(int raio);
double **AlocaMatrizDouble(int lin, int col);
double **LiberaMatrizDouble(int lin, int col, double **mat);
int **AlocaMatriz(int lin, int col);
int **LiberaMatriz(int lin, int col, int **mat);

__global__ void filtra(int **cudaOldimage, int **cudaNewimage, double **cudaMatrizPesos, param parameters){
	int linhai, linhaf, deslocamento, meutam, index;

	index = threadIdx.x + blockIdx.x * blockDim.x; //index global da thread
	meutam = parameters.tamanho;
	deslocamento = 0;

	if (parameters.sobra > 0){
		if (index < parameters.sobra){
			meutam++;
		}
		else {
			deslocamento = parameters.sobra;
		}
	}
	linhai = (meutam)* index + deslocamento;
	if (index == parameters.totalthreads - 1){
		linhaf = parameters.linhas - 1;
	}
	else {
		linhaf = (meutam)+linhai - 1;
	}
	//printf("Eu sou a thread %d fico com: linha %d a %d\n", index, linhai, linhaf);

	//tratamento_normal(linhai, linhaf);
	int dls, dli, dce, dcd;
	int r, g, b, nr, ng, nb;
	int l;
	int c;
	int lin_mat_pes, col_mat_pes;
	double acumular, acumulag, acumulab;
	for (l = linhai; l <= linhaf; l++){
		if ((l - parameters.raio) < 0){
			dls = parameters.raio - l;
		}
		else dls = 0;
		if ((l + parameters.raio) >= parameters.linhas){
			dli = l + parameters.raio - (parameters.linhas - 1);
		}
		else dli = 0;
		//printf("Linha: %d ... dls(%d) e dli(%d)\n", l, dls, dli);
		for (c = 0; c < parameters.colunas; c++){
			acumular = 0;
			acumulag = 0;
			acumulab = 0;
			if ((c - parameters.raio) < 0){
				dce = parameters.raio - c;
			}
			else dce = 0;
			if ((c + parameters.raio) >= parameters.colunas){
				dcd = c + parameters.raio - (parameters.colunas - 1);
			}
			else dcd = 0;
			for (lin_mat_pes = dls; lin_mat_pes < (parameters.raio * 2 + 1 - dli); lin_mat_pes++){
				for (col_mat_pes = dce; col_mat_pes < (parameters.raio * 2 + 1 - dcd); col_mat_pes++){
					r = cudaOldimage[l - parameters.raio + lin_mat_pes][c - parameters.raio + col_mat_pes] / 1000000;
					g = (cudaOldimage[l - parameters.raio + lin_mat_pes][c - parameters.raio + col_mat_pes] - r * 1000000) / 1000;;
					b = cudaOldimage[l - parameters.raio + lin_mat_pes][c - parameters.raio + col_mat_pes] - r * 1000000 - g * 1000;
					acumular += (r * cudaMatrizPesos[lin_mat_pes][col_mat_pes]);
					acumulag += (g * cudaMatrizPesos[lin_mat_pes][col_mat_pes]);
					acumulab += (b * cudaMatrizPesos[lin_mat_pes][col_mat_pes]);
				}
			}
			nr = acumular;
			ng = acumulag;
			nb = acumulab;
			cudaNewimage[l][c] = nr * 1000000 + ng * 1000 + nb;
		}
	}

}

int main() {
	FILE *arqin;
	FILE *arqout;
	char narqin[MAX_NAME] = "c:\\temp\\reddead.ppm";
	char narqout[MAX_NAME] = "c:\\temp\\reddead2.ppm";
	char key[128];
	int i, j, max, r, g, b; //auxiliares
	int Blocks = 1;
	int ThreadsPerBlock = 1;

	struct param parameters;
	cudaError_t cudaStatus;

	parameters.totalthreads = Blocks * ThreadsPerBlock;

	printf("Qual raio?\n");
	scanf("%d", &parameters.raio);

	printf("Arquivo de entrada: %s\n", narqin);
	arqin = fopen(narqin, "r");

	if (arqin == NULL) {
		printf("Erro na abertura do arquivo %s\n", narqin);
		return 1;
	}

	printf("Arquivo de saida: %s\n", narqout);
	arqout = fopen(narqout, "w");

	if (arqout == NULL) {
		printf("Erro na abertura do arquivo %s\n", narqin);
		return 1;
	}

	fscanf(arqin, "%s", key);//leio cabealho
	fprintf(arqout, "%s\n", key);//j escrevo o cabealho no novo arquivo
	printf("Arquivo tipo: %s \n", key);
	fscanf(arqin, "%d %d %d", &parameters.colunas, &parameters.linhas, &max);//leio mais dados do cabealho
	fprintf(arqout, "%d %d \n%d", parameters.colunas, parameters.linhas, max);//j escrevo esses dados no novo arquivo
	printf("Colunas = %d \nLinhas = %d \n", parameters.colunas, parameters.linhas);

	//vamos definir o tamanho para cada um
	parameters.tamanho = parameters.linhas / parameters.totalthreads;
	if ((parameters.linhas % parameters.totalthreads) > 0){
		parameters.sobra = parameters.linhas % parameters.totalthreads;
	}
	else {
		parameters.sobra = 0;
	}

	printf("Tamanho %d\n", parameters.tamanho);

	//por enquanto nao vamos aceitar imagem com apenas uma linha
	if (parameters.linhas < parameters.totalthreads){
		printf("Mais threads do que dados %s\n", narqin);
		return 0;
	}
	
	int **oldimage = AlocaMatriz(parameters.linhas, parameters.colunas);
	int **newimage = AlocaMatriz(parameters.linhas, parameters.colunas);
	matrizpesos = AlocaMatrizDouble(parameters.raio * 2 + 1, parameters.raio * 2 + 1);
	InicializaMatrizPesos(parameters.raio);
	
	for (i = 0; i <= parameters.linhas - 1; i++)
		for (j = 0; j <= parameters.colunas - 1; j++) {
		fscanf(arqin, " %d %d %d ", &r, &g, &b);
		//printf("RGB: %d %d %d \n", r, g, b);
		oldimage[i][j] = r * 1000000 + g * 1000 + b;
		/*
		rgb = oldimage[i][j];
		nr = rgb/1000000;
		ng = (rgb-r*1000000)/1000;
		nb = rgb-r*1000000-g*1000;
		if ((nr != r) || (ng != g) || (nb != b)) printf("errooou");
		printf("Valor: %d\n", rgb);
		printf("Valor R: %d\n", r);
		printf("Valor G: %d\n", g);
		printf("Valor B: %d\n", b);
		*/
		}

	// aloca a memria no device
	int size_m_int = parameters.linhas*parameters.colunas*sizeof(int);	// tamanho da memria que ser aolocado para as matrizes
	int size_m_double = (parameters.raio * 2 + 1) * (parameters.raio * 2 + 1) * sizeof(double);	// tamanho da memria que ser aolocado para a matriz de pesos
	int **doldimage, **dnewimage;
	double **dmatrizpesos;

	printf("1...alocando doldimage na GPU...");
	cudaStatus = cudaMalloc((void**)&doldimage, size_m_int);
	if (cudaStatus != cudaSuccess) {
		printf("cudaMalloc failed!");
		return 1;
	}
	printf("2...alocando dnewimage na GPU...");
	cudaStatus = cudaMalloc((void**)&dnewimage, size_m_int);
	if (cudaStatus != cudaSuccess) {
		printf("cudaMalloc failed!");
		return 1;
	}
	printf("3...alocando dmatrizpesos na GPU...");
	cudaStatus = cudaMalloc((void**)&dmatrizpesos, size_m_double);
	if (cudaStatus != cudaSuccess) {
		printf("cudaMalloc failed!");
		return 1;
	}

	// copia as matrizes do host para o device
	printf("4...copiando oldimage para GPU...");
	cudaStatus = cudaMemcpy(doldimage, oldimage, size_m_int, cudaMemcpyHostToDevice);
	if (cudaStatus != cudaSuccess) {
		printf("cudaMemcpy failed!");
		return 1;
	}
	printf("5...copiando matrizpesos para GPU...");
	cudaStatus = cudaMemcpy(dmatrizpesos, matrizpesos, size_m_double, cudaMemcpyHostToDevice);
	if (cudaStatus != cudaSuccess) {
		printf("cudaMemcpy failed!");
		return 1;
	}

	//executa o kernel
	printf("6...rodando kernel...");
	filtra<<<Blocks, ThreadsPerBlock>>>(doldimage, dnewimage, dmatrizpesos, parameters);

	// Check for any errors launching the kernel
	cudaStatus = cudaGetLastError();
	if (cudaStatus != cudaSuccess) {
		printf("addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus));
		return 1;
	}

	// cudaDeviceSynchronize waits for the kernel to finish, and returns
	// any errors encountered during the launch.
	printf("7...sincronizando com device...");
	cudaStatus = cudaDeviceSynchronize();
	if (cudaStatus != cudaSuccess) {
		printf("cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
		return 1;
	}

	//copia matriz resultante da GPU para a CPU
	printf("8...copiando dnewimage da GPU para processador...");
	cudaStatus = cudaMemcpy(newimage, dnewimage, size_m_int, cudaMemcpyDeviceToHost);
	if (cudaStatus != cudaSuccess) {
		printf("cudaMemcpy failed!");
		return 1;
	}

	//escrever novo arquivo    
	printf("9...escrevendo nova imagem...");
	for (i = 0; i <= parameters.linhas - 1; i++){
		fprintf(arqout, "\n");
		for (j = 0; j <= parameters.colunas - 1; j++) {
			r = newimage[i][j] / 1000000;
			g = (newimage[i][j] - r * 1000000) / 1000;
			b = newimage[i][j] - r * 1000000 - g * 1000;
			fprintf(arqout, "%d %d %d ", r, g, b);
		}
	}

	//    for (i = 0; i <= linhas - 1; i++) for (j = 0; j <= colunas - 1; j++) printf("RGB: %d %d %d \n", newimage[i][j*3], newimage[i][j*3+1], newimage[i][j*3+2]);

	printf("10...liberando matrizes...");
	LiberaMatriz(parameters.linhas, parameters.colunas, oldimage);
	LiberaMatriz(parameters.linhas, parameters.colunas, newimage);
	LiberaMatrizDouble(parameters.raio * 2 + 1, parameters.raio * 2 + 1, matrizpesos);
	cudaFree(doldimage);
	cudaFree(dnewimage);
	cudaFree(dmatrizpesos);

	fclose(arqin);
	fclose(arqout);

	printf("Fim programa.\n");
	return 0;
}

void InicializaMatrizPesos(int raio){
	int i, j;
	double e, g;
	double somapesos = 0;
	float sigma = raio;
	for (i = 0; i < sigma * 2 + 1; i++){
		//printf("\n");
		for (j = 0; j < raio * 2 + 1; j++){
			e = pow((float)exp(1.0), ((-1)*(pow((i - sigma), 2) + pow((j - sigma), 2)) / (2 * pow(sigma, 2))));
			//printf("P(%d,%d)\n", i, j);
			//printf("E = %.4f - PARTEDECIMA = %.4f\n", e, partedecima);
			g = e / (2 * PI*pow(sigma, 2));
			matrizpesos[i][j] = g;
			somapesos += g;
			//printf("P(%d,%d) = %.4f ;", i, j, g);
		}
	}
	for (i = 0; i < sigma * 2 + 1; i++){
		//printf("de novo \n");
		for (j = 0; j < raio * 2 + 1; j++){
			matrizpesos[i][j] = matrizpesos[i][j] / somapesos;
			//printf("P(%d,%d) = %.4f ;", i, j, matrizpesos[i][j]);
		}
	}
	//printf("somapesos = %.5f\n", somapesos);
}

int **AlocaMatriz(int lin, int col){
	int **mat;  /* ponteiro para a matriz */
	int i;    /* variavel auxiliar      */
	if (lin < 1 || col < 1) { /* verifica parametros recebidos */
		printf("** Erro: Parametro invalido **\n");
		return(NULL);
	}
	/* aloca as linhas da matriz */
	mat = (int **)calloc(lin, sizeof(int *));
	if (mat == NULL) {
		printf("** Erro: Memoria Insuficiente **");
		return(NULL);
	}
	/* aloca as colunas da matriz */
	for (i = 0; i < lin; i++){
		mat[i] = (int*)calloc(col, sizeof(int));
		if (mat[i] == NULL) {
			printf("** Erro: Memoria Insuficiente **");
			return(NULL);
		}
	}
	return(mat); /* retorna o ponteiro para a matriz */
}

int **LiberaMatriz(int lin, int col, int **mat){
	int i;  /* variavel auxiliar */
	if (mat == NULL) return(NULL);
	if (lin < 1 || col < 1){  /* verifica parametros recebidos */
		printf("** Erro: Parametro invalido **\n");
		return(mat);
	}
	for (i = 0; i<lin; i++) free(mat[i]); /* libera as linhas da matriz */
	free(mat);      /* libera a matriz */
	return(NULL); /* retorna um ponteiro nulo */
}

double **AlocaMatrizDouble(int lin, int col){
	double **mat;  /* ponteiro para a matriz */
	int i;    /* variavel auxiliar      */
	if (lin < 1 || col < 1) { /* verifica parametros recebidos */
		printf("** Erro: Parametro invalido **\n");
		return(NULL);
	}
	/* aloca as linhas da matriz */
	mat = (double **)calloc(lin, sizeof(double *));
	if (mat == NULL) {
		printf("** Erro: Memoria Insuficiente **");
		return(NULL);
	}
	/* aloca as colunas da matriz */
	for (i = 0; i < lin; i++){
		mat[i] = (double*)calloc(col, sizeof(double));
		if (mat[i] == NULL) {
			printf("** Erro: Memoria Insuficiente **");
			return(NULL);
		}
	}
	return(mat); /* retorna o ponteiro para a matriz */
}

double **LiberaMatrizDouble(int lin, int col, double **mat){
	int i;  /* variavel auxiliar */
	if (mat == NULL) return(NULL);
	if (lin < 1 || col < 1){  /* verifica parametros recebidos */
		printf("** Erro: Parametro invalido **\n");
		return(mat);
	}
	for (i = 0; i<lin; i++) free(mat[i]); /* libera as linhas da matriz */
	free(mat);      /* libera a matriz */
	return(NULL); /* retorna um ponteiro nulo */
}
	.file	"tmpxft_0037e13b_00000000-6_kernel.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z21InicializaMatrizPesosi
	.type	_Z21InicializaMatrizPesosi, @function
_Z21InicializaMatrizPesosi:
.LFB2028:
	.cfi_startproc
	endbr64
	cvtsi2ssl	%edi, %xmm3
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	xorps	%xmm4, %xmm4
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movaps	%xmm3, %xmm6
	leal	(%rdi,%rdi), %ebx
	addss	%xmm3, %xmm6
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	addss	.LC1(%rip), %xmm6
.L3:
	cvtsi2ssl	%r12d, %xmm5
	comiss	%xmm5, %xmm6
	jbe	.L13
	leaq	0(,%r12,8), %r13
	xorl	%ebp, %ebp
.L7:
	movq	matrizpesos(%rip), %r14
	cmpl	%ebp, %ebx
	jl	.L16
	cvtsi2ssl	%ebp, %xmm0
	movaps	%xmm5, %xmm1
	cvtss2sd	%xmm3, %xmm2
	movsd	%xmm4, 24(%rsp)
	subss	%xmm3, %xmm1
	mulsd	%xmm2, %xmm2
	movss	%xmm6, 20(%rsp)
	movss	%xmm5, 16(%rsp)
	movss	%xmm3, 12(%rsp)
	subss	%xmm3, %xmm0
	cvtss2sd	%xmm1, %xmm1
	mulsd	%xmm1, %xmm1
	movsd	%xmm2, (%rsp)
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm0, %xmm0
	addsd	%xmm0, %xmm1
	movaps	%xmm2, %xmm0
	xorps	.LC2(%rip), %xmm1
	addsd	%xmm2, %xmm0
	divsd	%xmm0, %xmm1
	movsd	.LC3(%rip), %xmm0
	call	pow@PLT
	movsd	(%rsp), %xmm2
	movq	(%r14,%r13), %rax
	mulsd	.LC4(%rip), %xmm2
	movsd	24(%rsp), %xmm4
	movss	20(%rsp), %xmm6
	movss	16(%rsp), %xmm5
	movss	12(%rsp), %xmm3
	divsd	%xmm2, %xmm0
	movsd	%xmm0, (%rax,%rbp,8)
	addsd	%xmm0, %xmm4
	incq	%rbp
	jmp	.L7
.L16:
	incq	%r12
	jmp	.L3
.L13:
	movq	matrizpesos(%rip), %rsi
	xorl	%eax, %eax
.L8:
	cvtsi2ssl	%eax, %xmm0
	comiss	%xmm0, %xmm6
	jbe	.L17
	xorl	%edx, %edx
.L10:
	cmpl	%edx, %ebx
	jl	.L18
	movq	(%rsi,%rax,8), %rcx
	leaq	(%rcx,%rdx,8), %rcx
	incq	%rdx
	movsd	(%rcx), %xmm0
	divsd	%xmm4, %xmm0
	movsd	%xmm0, (%rcx)
	jmp	.L10
.L18:
	incq	%rax
	jmp	.L8
.L17:
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	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
.LFE2028:
	.size	_Z21InicializaMatrizPesosi, .-_Z21InicializaMatrizPesosi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC5:
	.string	"** Erro: Parametro invalido **\n"
.LC6:
	.string	"** Erro: Memoria Insuficiente **"
	.text
	.globl	_Z11AlocaMatrizii
	.type	_Z11AlocaMatrizii, @function
_Z11AlocaMatrizii:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	pushq	%rcx
	.cfi_def_cfa_offset 48
	testl	%edi, %edi
	jle	.L27
	movslq	%esi, %rbp
	testl	%ebp, %ebp
	jg	.L20
.L27:
	leaq	.LC5(%rip), %rsi
	jmp	.L34
.L20:
	movl	%edi, %r12d
	movl	$8, %esi
	movslq	%edi, %rdi
	xorl	%r13d, %r13d
	call	calloc@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L23
.L25:
	leaq	.LC6(%rip), %rsi
.L34:
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
	jmp	.L19
.L35:
	incq	%r13
	cmpl	%r13d, %r12d
	jle	.L19
.L23:
	movl	$4, %esi
	movq	%rbp, %rdi
	call	calloc@PLT
	movq	%rax, (%rbx,%r13,8)
	testq	%rax, %rax
	jne	.L35
	jmp	.L25
.L19:
	popq	%rdx
	.cfi_def_cfa_offset 40
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z11AlocaMatrizii, .-_Z11AlocaMatrizii
	.globl	_Z12LiberaMatriziiPPi
	.type	_Z12LiberaMatriziiPPi, @function
_Z12LiberaMatriziiPPi:
.LFB2030:
	.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
	testq	%rdx, %rdx
	je	.L37
	movl	%edi, %r12d
	movq	%rdx, %rbx
	testl	%edi, %edi
	jle	.L42
	xorl	%ebp, %ebp
	testl	%esi, %esi
	jg	.L38
.L42:
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L40
.L38:
	movq	(%rbx,%rbp,8), %rdi
	incq	%rbp
	call	free@PLT
	cmpl	%ebp, %r12d
	jg	.L38
	movq	%rbx, %rdi
	call	free@PLT
.L37:
	xorl	%ebx, %ebx
.L40:
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z12LiberaMatriziiPPi, .-_Z12LiberaMatriziiPPi
	.globl	_Z17AlocaMatrizDoubleii
	.type	_Z17AlocaMatrizDoubleii, @function
_Z17AlocaMatrizDoubleii:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	pushq	%rcx
	.cfi_def_cfa_offset 48
	testl	%edi, %edi
	jle	.L58
	movslq	%esi, %rbp
	testl	%ebp, %ebp
	jg	.L51
.L58:
	leaq	.LC5(%rip), %rsi
	jmp	.L65
.L51:
	movl	%edi, %r12d
	movl	$8, %esi
	movslq	%edi, %rdi
	xorl	%r13d, %r13d
	call	calloc@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L54
.L56:
	leaq	.LC6(%rip), %rsi
.L65:
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
	jmp	.L50
.L66:
	incq	%r13
	cmpl	%r13d, %r12d
	jle	.L50
.L54:
	movl	$8, %esi
	movq	%rbp, %rdi
	call	calloc@PLT
	movq	%rax, (%rbx,%r13,8)
	testq	%rax, %rax
	jne	.L66
	jmp	.L56
.L50:
	popq	%rdx
	.cfi_def_cfa_offset 40
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z17AlocaMatrizDoubleii, .-_Z17AlocaMatrizDoubleii
	.globl	_Z18LiberaMatrizDoubleiiPPd
	.type	_Z18LiberaMatrizDoubleiiPPd, @function
_Z18LiberaMatrizDoubleiiPPd:
.LFB2032:
	.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
	testq	%rdx, %rdx
	je	.L68
	movl	%edi, %r12d
	movq	%rdx, %rbx
	testl	%edi, %edi
	jle	.L73
	xorl	%ebp, %ebp
	testl	%esi, %esi
	jg	.L69
.L73:
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L71
.L69:
	movq	(%rbx,%rbp,8), %rdi
	incq	%rbp
	call	free@PLT
	cmpl	%ebp, %r12d
	jg	.L69
	movq	%rbx, %rdi
	call	free@PLT
.L68:
	xorl	%ebx, %ebx
.L71:
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z18LiberaMatrizDoubleiiPPd, .-_Z18LiberaMatrizDoubleiiPPd
	.globl	_Z38__device_stub__Z6filtraPPiS0_PPd5paramPPiS0_PPdR5param
	.type	_Z38__device_stub__Z6filtraPPiS0_PPd5paramPPiS0_PPdR5param, @function
_Z38__device_stub__Z6filtraPPiS0_PPd5paramPPiS0_PPdR5param:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movq	%rcx, 128(%rsp)
	leaq	48(%rsp), %rcx
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movl	$1, 64(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L81
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z6filtraPPiS0_PPd5param(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L81:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L83
	call	__stack_chk_fail@PLT
.L83:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z38__device_stub__Z6filtraPPiS0_PPd5paramPPiS0_PPdR5param, .-_Z38__device_stub__Z6filtraPPiS0_PPd5paramPPiS0_PPdR5param
	.globl	_Z6filtraPPiS0_PPd5param
	.type	_Z6filtraPPiS0_PPd5param, @function
_Z6filtraPPiS0_PPd5param:
.LFB2058:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	16(%rsp), %rcx
	call	_Z38__device_stub__Z6filtraPPiS0_PPd5paramPPiS0_PPdR5param
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z6filtraPPiS0_PPd5param, .-_Z6filtraPPiS0_PPd5param
	.section	.rodata.str1.1
.LC7:
	.string	"Qual raio?\n"
.LC8:
	.string	"%d"
.LC9:
	.string	"Arquivo de entrada: %s\n"
.LC10:
	.string	"r"
.LC11:
	.string	"Erro na abertura do arquivo %s\n"
.LC12:
	.string	"Arquivo de saida: %s\n"
.LC13:
	.string	"w"
.LC14:
	.string	"%s"
.LC15:
	.string	"%s\n"
.LC16:
	.string	"Arquivo tipo: %s \n"
.LC17:
	.string	"%d %d %d"
.LC18:
	.string	"%d %d \n%d"
.LC19:
	.string	"Colunas = %d \nLinhas = %d \n"
.LC20:
	.string	"Tamanho %d\n"
.LC21:
	.string	"Mais threads do que dados %s\n"
.LC22:
	.string	" %d %d %d "
.LC23:
	.string	"1...alocando doldimage na GPU..."
.LC24:
	.string	"cudaMalloc failed!"
.LC25:
	.string	"2...alocando dnewimage na GPU..."
.LC26:
	.string	"3...alocando dmatrizpesos na GPU..."
.LC27:
	.string	"4...copiando oldimage para GPU..."
.LC28:
	.string	"cudaMemcpy failed!"
.LC29:
	.string	"5...copiando matrizpesos para GPU..."
.LC30:
	.string	"6...rodando kernel..."
.LC31:
	.string	"addKernel launch failed: %s\n"
.LC32:
	.string	"7...sincronizando com device..."
.LC33:
	.string	"cudaDeviceSynchronize returned error code %d after launching addKernel!\n"
.LC34:
	.string	"8...copiando dnewimage da GPU para processador..."
.LC35:
	.string	"9...escrevendo nova imagem..."
.LC36:
	.string	"\n"
.LC37:
	.string	"%d %d %d "
.LC38:
	.string	"10...liberando matrizes..."
.LC39:
	.string	"Fim programa.\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$56, %ecx
	movabsq	$3342903911519642994, %rdx
	movabsq	$3631134287671354738, %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movabsq	$6660944131392289379, %rbx
	subq	$776, %rsp
	.cfi_def_cfa_offset 832
	movq	%fs:40, %rax
	movq	%rax, 760(%rsp)
	movabsq	$6660944131392289379, %rax
	leaq	280(%rsp), %rdi
	movq	%rdx, 256(%rsp)
	xorl	%edx, %edx
	movq	%rsi, 512(%rsp)
	leaq	.LC7(%rip), %rsi
	movq	%rdx, 528(%rsp)
	movq	%rbx, 504(%rsp)
	leaq	248(%rsp), %rbx
	movq	$7172208, 264(%rsp)
	movq	$1836085294, 520(%rsp)
	movq	%rax, 248(%rsp)
	xorl	%eax, %eax
	movq	%rax, 272(%rsp)
	xorl	%eax, %eax
	rep stosl
	leaq	536(%rsp), %rdi
	movl	$56, %ecx
	movl	$1, 72(%rsp)
	rep stosl
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	92(%rsp), %rsi
	leaq	.LC8(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	movq	%rbx, %rdx
	leaq	.LC9(%rip), %rsi
	call	__printf_chk@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rbx, %rdi
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L88
.L90:
	movq	%rbx, %rdx
	leaq	.LC11(%rip), %rsi
	jmp	.L115
.L88:
	leaq	504(%rsp), %rbp
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %r13
	movq	%rbp, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rbp, %rdi
	call	fopen@PLT
	movq	%rax, %r12
	testq	%rax, %rax
	je	.L90
	leaq	120(%rsp), %rbp
	leaq	.LC14(%rip), %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	movq	%rbp, %rdx
	call	__isoc23_fscanf@PLT
	movq	%rbp, %rcx
	movl	$2, %esi
	movq	%r12, %rdi
	leaq	.LC15(%rip), %rdx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	%rbp, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC16(%rip), %rsi
	call	__printf_chk@PLT
	leaq	76(%rsp), %rcx
	movq	%r13, %rdi
	xorl	%eax, %eax
	leaq	80(%rsp), %rdx
	leaq	8(%rsp), %r8
	leaq	.LC17(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movl	8(%rsp), %r9d
	movl	80(%rsp), %ecx
	xorl	%eax, %eax
	movl	76(%rsp), %r8d
	leaq	.LC18(%rip), %rdx
	movl	$2, %esi
	movq	%r12, %rdi
	call	__fprintf_chk@PLT
	movl	76(%rsp), %ecx
	movl	80(%rsp), %edx
	xorl	%eax, %eax
	leaq	.LC19(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	76(%rsp), %eax
	xorl	%ecx, %ecx
	movl	$2, %edi
	leaq	.LC20(%rip), %rsi
	cltd
	idivl	72(%rsp)
	testl	%edx, %edx
	movl	%eax, 84(%rsp)
	cmovs	%ecx, %edx
	movl	%edx, 88(%rsp)
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	76(%rsp), %edi
	cmpl	72(%rsp), %edi
	jge	.L91
	movq	%rbx, %rdx
	leaq	.LC21(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L92
.L91:
	movl	80(%rsp), %esi
	xorl	%ebx, %ebx
	call	_Z11AlocaMatrizii
	movl	80(%rsp), %esi
	movl	76(%rsp), %edi
	movq	%rax, %r15
	call	_Z11AlocaMatrizii
	movq	%rax, %r14
	movl	92(%rsp), %eax
	leal	1(%rax,%rax), %edi
	movl	%edi, %esi
	call	_Z17AlocaMatrizDoubleii
	movl	92(%rsp), %edi
	movq	%rax, matrizpesos(%rip)
	call	_Z21InicializaMatrizPesosi
.L93:
	movl	76(%rsp), %eax
	cmpl	%ebx, %eax
	jle	.L116
	xorl	%ebp, %ebp
.L95:
	cmpl	%ebp, 80(%rsp)
	jle	.L117
	leaq	16(%rsp), %rcx
	leaq	12(%rsp), %rdx
	movq	%r13, %rdi
	xorl	%eax, %eax
	leaq	20(%rsp), %r8
	leaq	.LC22(%rip), %rsi
	call	__isoc23_fscanf@PLT
	imull	$1000000, 12(%rsp), %eax
	movq	(%r15,%rbx,8), %rdx
	imull	$1000, 16(%rsp), %ecx
	addl	%ecx, %eax
	addl	20(%rsp), %eax
	movl	%eax, (%rdx,%rbp,4)
	incq	%rbp
	jmp	.L95
.L117:
	incq	%rbx
	jmp	.L93
.L116:
	imull	80(%rsp), %eax
	leaq	.LC23(%rip), %rsi
	movl	$2, %edi
	movl	92(%rsp), %ebp
	leal	0(,%rax,4), %ebx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movslq	%ebx, %rbx
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L96
.L97:
	leaq	.LC24(%rip), %rsi
	jmp	.L114
.L96:
	leaq	.LC25(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	32(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	jne	.L97
	leal	1(%rbp,%rbp), %ebp
	leaq	.LC26(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	imull	%ebp, %ebp
	leaq	40(%rsp), %rdi
	sall	$3, %ebp
	movslq	%ebp, %rbp
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	jne	.L97
	leaq	.LC27(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	24(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r15, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L98
.L100:
	leaq	.LC28(%rip), %rsi
.L114:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L89:
	movl	$1, %eax
	jmp	.L87
.L98:
	leaq	.LC29(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	matrizpesos(%rip), %rsi
	movq	40(%rsp), %rdi
	movq	%rbp, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L100
	leaq	.LC30(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movl	$1, 68(%rsp)
	movq	%rdi, %rdx
	movq	%rdi, 60(%rsp)
	movq	%rdi, 48(%rsp)
	movl	$1, 56(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L101
	movups	72(%rsp), %xmm0
	movq	88(%rsp), %rax
	leaq	96(%rsp), %rcx
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	movq	%rax, 112(%rsp)
	movups	%xmm0, 96(%rsp)
	call	_Z38__device_stub__Z6filtraPPiS0_PPd5paramPPiS0_PPdR5param
.L101:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L102
	call	cudaGetErrorString@PLT
	leaq	.LC31(%rip), %rsi
	movq	%rax, %rdx
.L115:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L89
.L102:
	leaq	.LC32(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %edx
	testl	%eax, %eax
	je	.L103
	leaq	.LC33(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L89
.L103:
	leaq	.LC34(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	32(%rsp), %rsi
	movq	%rbx, %rdx
	movq	%r14, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L100
	leaq	.LC35(%rip), %rsi
	movl	$2, %edi
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
.L104:
	cmpl	%ebx, 76(%rsp)
	jle	.L118
	leaq	.LC36(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	movq	%r12, %rdi
	call	__fprintf_chk@PLT
.L105:
	cmpl	%ebp, 80(%rsp)
	jle	.L119
	movq	(%r14,%rbx,8), %rax
	movl	$1000000, %ecx
	movl	$1000, %edi
	leaq	(%rax,%rbp,4), %rsi
	incq	%rbp
	movl	(%rsi), %eax
	cltd
	idivl	%ecx
	imull	$-1000000, %eax, %r9d
	movl	%eax, 12(%rsp)
	movl	%eax, %ecx
	movl	(%rsi), %eax
	addl	%r9d, %eax
	cltd
	idivl	%edi
	leaq	.LC37(%rip), %rdx
	movq	%r12, %rdi
	movl	%eax, 16(%rsp)
	movl	%eax, %r8d
	imull	$-1000, %eax, %eax
	addl	(%rsi), %r9d
	movl	$2, %esi
	addl	%eax, %r9d
	xorl	%eax, %eax
	movl	%r9d, 20(%rsp)
	call	__fprintf_chk@PLT
	jmp	.L105
.L119:
	incq	%rbx
	jmp	.L104
.L118:
	leaq	.LC38(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	80(%rsp), %esi
	movl	76(%rsp), %edi
	movq	%r15, %rdx
	call	_Z12LiberaMatriziiPPi
	movl	80(%rsp), %esi
	movl	76(%rsp), %edi
	movq	%r14, %rdx
	call	_Z12LiberaMatriziiPPi
	movl	92(%rsp), %eax
	movq	matrizpesos(%rip), %rdx
	leal	1(%rax,%rax), %edi
	movl	%edi, %esi
	call	_Z18LiberaMatrizDoubleiiPPd
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r13, %rdi
	call	fclose@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	leaq	.LC39(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L92:
	xorl	%eax, %eax
.L87:
	movq	760(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L108
	call	__stack_chk_fail@PLT
.L108:
	addq	$776, %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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC40:
	.string	"_Z6filtraPPiS0_PPd5param"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC40(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6filtraPPiS0_PPd5param(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2060:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	matrizpesos
	.bss
	.align 8
	.type	matrizpesos, @object
	.size	matrizpesos, 8
matrizpesos:
	.zero	8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	1065353216
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.long	0
	.long	-2147483648
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	-2147483648
	.long	1074118410
	.align 8
.LC4:
	.long	1413754602
	.long	1075388923
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include "hip/hip_runtime.h"


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define MAX_NAME 256 /* tamanho maximo para nome de arquivo */
#define PI 3.14159265359

double **matrizpesos;

struct param{
	int totalthreads;
	int linhas;
	int colunas;
	int tamanho; //se a divisao nao for inteira aqui vai o mais 1
	int sobra; //resto da divisao que vamos distribuir
	int raio; //distancia para considerar os pixels
};

void InicializaMatrizPesos(int raio);
double **AlocaMatrizDouble(int lin, int col);
double **LiberaMatrizDouble(int lin, int col, double **mat);
int **AlocaMatriz(int lin, int col);
int **LiberaMatriz(int lin, int col, int **mat);

__global__ void filtra(int **cudaOldimage, int **cudaNewimage, double **cudaMatrizPesos, param parameters){
	int linhai, linhaf, deslocamento, meutam, index;

	index = threadIdx.x + blockIdx.x * blockDim.x; //index global da thread
	meutam = parameters.tamanho;
	deslocamento = 0;

	if (parameters.sobra > 0){
		if (index < parameters.sobra){
			meutam++;
		}
		else {
			deslocamento = parameters.sobra;
		}
	}
	linhai = (meutam)* index + deslocamento;
	if (index == parameters.totalthreads - 1){
		linhaf = parameters.linhas - 1;
	}
	else {
		linhaf = (meutam)+linhai - 1;
	}
	//printf("Eu sou a thread %d fico com: linha %d a %d\n", index, linhai, linhaf);

	//tratamento_normal(linhai, linhaf);
	int dls, dli, dce, dcd;
	int r, g, b, nr, ng, nb;
	int l;
	int c;
	int lin_mat_pes, col_mat_pes;
	double acumular, acumulag, acumulab;
	for (l = linhai; l <= linhaf; l++){
		if ((l - parameters.raio) < 0){
			dls = parameters.raio - l;
		}
		else dls = 0;
		if ((l + parameters.raio) >= parameters.linhas){
			dli = l + parameters.raio - (parameters.linhas - 1);
		}
		else dli = 0;
		//printf("Linha: %d ... dls(%d) e dli(%d)\n", l, dls, dli);
		for (c = 0; c < parameters.colunas; c++){
			acumular = 0;
			acumulag = 0;
			acumulab = 0;
			if ((c - parameters.raio) < 0){
				dce = parameters.raio - c;
			}
			else dce = 0;
			if ((c + parameters.raio) >= parameters.colunas){
				dcd = c + parameters.raio - (parameters.colunas - 1);
			}
			else dcd = 0;
			for (lin_mat_pes = dls; lin_mat_pes < (parameters.raio * 2 + 1 - dli); lin_mat_pes++){
				for (col_mat_pes = dce; col_mat_pes < (parameters.raio * 2 + 1 - dcd); col_mat_pes++){
					r = cudaOldimage[l - parameters.raio + lin_mat_pes][c - parameters.raio + col_mat_pes] / 1000000;
					g = (cudaOldimage[l - parameters.raio + lin_mat_pes][c - parameters.raio + col_mat_pes] - r * 1000000) / 1000;;
					b = cudaOldimage[l - parameters.raio + lin_mat_pes][c - parameters.raio + col_mat_pes] - r * 1000000 - g * 1000;
					acumular += (r * cudaMatrizPesos[lin_mat_pes][col_mat_pes]);
					acumulag += (g * cudaMatrizPesos[lin_mat_pes][col_mat_pes]);
					acumulab += (b * cudaMatrizPesos[lin_mat_pes][col_mat_pes]);
				}
			}
			nr = acumular;
			ng = acumulag;
			nb = acumulab;
			cudaNewimage[l][c] = nr * 1000000 + ng * 1000 + nb;
		}
	}

}

int main() {
	FILE *arqin;
	FILE *arqout;
	char narqin[MAX_NAME] = "c:\\temp\\reddead.ppm";
	char narqout[MAX_NAME] = "c:\\temp\\reddead2.ppm";
	char key[128];
	int i, j, max, r, g, b; //auxiliares
	int Blocks = 1;
	int ThreadsPerBlock = 1;

	struct param parameters;
	hipError_t cudaStatus;

	parameters.totalthreads = Blocks * ThreadsPerBlock;

	printf("Qual raio?\n");
	scanf("%d", &parameters.raio);

	printf("Arquivo de entrada: %s\n", narqin);
	arqin = fopen(narqin, "r");

	if (arqin == NULL) {
		printf("Erro na abertura do arquivo %s\n", narqin);
		return 1;
	}

	printf("Arquivo de saida: %s\n", narqout);
	arqout = fopen(narqout, "w");

	if (arqout == NULL) {
		printf("Erro na abertura do arquivo %s\n", narqin);
		return 1;
	}

	fscanf(arqin, "%s", key);//leio cabealho
	fprintf(arqout, "%s\n", key);//j escrevo o cabealho no novo arquivo
	printf("Arquivo tipo: %s \n", key);
	fscanf(arqin, "%d %d %d", &parameters.colunas, &parameters.linhas, &max);//leio mais dados do cabealho
	fprintf(arqout, "%d %d \n%d", parameters.colunas, parameters.linhas, max);//j escrevo esses dados no novo arquivo
	printf("Colunas = %d \nLinhas = %d \n", parameters.colunas, parameters.linhas);

	//vamos definir o tamanho para cada um
	parameters.tamanho = parameters.linhas / parameters.totalthreads;
	if ((parameters.linhas % parameters.totalthreads) > 0){
		parameters.sobra = parameters.linhas % parameters.totalthreads;
	}
	else {
		parameters.sobra = 0;
	}

	printf("Tamanho %d\n", parameters.tamanho);

	//por enquanto nao vamos aceitar imagem com apenas uma linha
	if (parameters.linhas < parameters.totalthreads){
		printf("Mais threads do que dados %s\n", narqin);
		return 0;
	}
	
	int **oldimage = AlocaMatriz(parameters.linhas, parameters.colunas);
	int **newimage = AlocaMatriz(parameters.linhas, parameters.colunas);
	matrizpesos = AlocaMatrizDouble(parameters.raio * 2 + 1, parameters.raio * 2 + 1);
	InicializaMatrizPesos(parameters.raio);
	
	for (i = 0; i <= parameters.linhas - 1; i++)
		for (j = 0; j <= parameters.colunas - 1; j++) {
		fscanf(arqin, " %d %d %d ", &r, &g, &b);
		//printf("RGB: %d %d %d \n", r, g, b);
		oldimage[i][j] = r * 1000000 + g * 1000 + b;
		/*
		rgb = oldimage[i][j];
		nr = rgb/1000000;
		ng = (rgb-r*1000000)/1000;
		nb = rgb-r*1000000-g*1000;
		if ((nr != r) || (ng != g) || (nb != b)) printf("errooou");
		printf("Valor: %d\n", rgb);
		printf("Valor R: %d\n", r);
		printf("Valor G: %d\n", g);
		printf("Valor B: %d\n", b);
		*/
		}

	// aloca a memria no device
	int size_m_int = parameters.linhas*parameters.colunas*sizeof(int);	// tamanho da memria que ser aolocado para as matrizes
	int size_m_double = (parameters.raio * 2 + 1) * (parameters.raio * 2 + 1) * sizeof(double);	// tamanho da memria que ser aolocado para a matriz de pesos
	int **doldimage, **dnewimage;
	double **dmatrizpesos;

	printf("1...alocando doldimage na GPU...");
	cudaStatus = hipMalloc((void**)&doldimage, size_m_int);
	if (cudaStatus != hipSuccess) {
		printf("hipMalloc failed!");
		return 1;
	}
	printf("2...alocando dnewimage na GPU...");
	cudaStatus = hipMalloc((void**)&dnewimage, size_m_int);
	if (cudaStatus != hipSuccess) {
		printf("hipMalloc failed!");
		return 1;
	}
	printf("3...alocando dmatrizpesos na GPU...");
	cudaStatus = hipMalloc((void**)&dmatrizpesos, size_m_double);
	if (cudaStatus != hipSuccess) {
		printf("hipMalloc failed!");
		return 1;
	}

	// copia as matrizes do host para o device
	printf("4...copiando oldimage para GPU...");
	cudaStatus = hipMemcpy(doldimage, oldimage, size_m_int, hipMemcpyHostToDevice);
	if (cudaStatus != hipSuccess) {
		printf("hipMemcpy failed!");
		return 1;
	}
	printf("5...copiando matrizpesos para GPU...");
	cudaStatus = hipMemcpy(dmatrizpesos, matrizpesos, size_m_double, hipMemcpyHostToDevice);
	if (cudaStatus != hipSuccess) {
		printf("hipMemcpy failed!");
		return 1;
	}

	//executa o kernel
	printf("6...rodando kernel...");
	filtra<<<Blocks, ThreadsPerBlock>>>(doldimage, dnewimage, dmatrizpesos, parameters);

	// Check for any errors launching the kernel
	cudaStatus = hipGetLastError();
	if (cudaStatus != hipSuccess) {
		printf("addKernel launch failed: %s\n", hipGetErrorString(cudaStatus));
		return 1;
	}

	// cudaDeviceSynchronize waits for the kernel to finish, and returns
	// any errors encountered during the launch.
	printf("7...sincronizando com device...");
	cudaStatus = hipDeviceSynchronize();
	if (cudaStatus != hipSuccess) {
		printf("hipDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
		return 1;
	}

	//copia matriz resultante da GPU para a CPU
	printf("8...copiando dnewimage da GPU para processador...");
	cudaStatus = hipMemcpy(newimage, dnewimage, size_m_int, hipMemcpyDeviceToHost);
	if (cudaStatus != hipSuccess) {
		printf("hipMemcpy failed!");
		return 1;
	}

	//escrever novo arquivo    
	printf("9...escrevendo nova imagem...");
	for (i = 0; i <= parameters.linhas - 1; i++){
		fprintf(arqout, "\n");
		for (j = 0; j <= parameters.colunas - 1; j++) {
			r = newimage[i][j] / 1000000;
			g = (newimage[i][j] - r * 1000000) / 1000;
			b = newimage[i][j] - r * 1000000 - g * 1000;
			fprintf(arqout, "%d %d %d ", r, g, b);
		}
	}

	//    for (i = 0; i <= linhas - 1; i++) for (j = 0; j <= colunas - 1; j++) printf("RGB: %d %d %d \n", newimage[i][j*3], newimage[i][j*3+1], newimage[i][j*3+2]);

	printf("10...liberando matrizes...");
	LiberaMatriz(parameters.linhas, parameters.colunas, oldimage);
	LiberaMatriz(parameters.linhas, parameters.colunas, newimage);
	LiberaMatrizDouble(parameters.raio * 2 + 1, parameters.raio * 2 + 1, matrizpesos);
	hipFree(doldimage);
	hipFree(dnewimage);
	hipFree(dmatrizpesos);

	fclose(arqin);
	fclose(arqout);

	printf("Fim programa.\n");
	return 0;
}

void InicializaMatrizPesos(int raio){
	int i, j;
	double e, g;
	double somapesos = 0;
	float sigma = raio;
	for (i = 0; i < sigma * 2 + 1; i++){
		//printf("\n");
		for (j = 0; j < raio * 2 + 1; j++){
			e = pow((float)exp(1.0), ((-1)*(pow((i - sigma), 2) + pow((j - sigma), 2)) / (2 * pow(sigma, 2))));
			//printf("P(%d,%d)\n", i, j);
			//printf("E = %.4f - PARTEDECIMA = %.4f\n", e, partedecima);
			g = e / (2 * PI*pow(sigma, 2));
			matrizpesos[i][j] = g;
			somapesos += g;
			//printf("P(%d,%d) = %.4f ;", i, j, g);
		}
	}
	for (i = 0; i < sigma * 2 + 1; i++){
		//printf("de novo \n");
		for (j = 0; j < raio * 2 + 1; j++){
			matrizpesos[i][j] = matrizpesos[i][j] / somapesos;
			//printf("P(%d,%d) = %.4f ;", i, j, matrizpesos[i][j]);
		}
	}
	//printf("somapesos = %.5f\n", somapesos);
}

int **AlocaMatriz(int lin, int col){
	int **mat;  /* ponteiro para a matriz */
	int i;    /* variavel auxiliar      */
	if (lin < 1 || col < 1) { /* verifica parametros recebidos */
		printf("** Erro: Parametro invalido **\n");
		return(NULL);
	}
	/* aloca as linhas da matriz */
	mat = (int **)calloc(lin, sizeof(int *));
	if (mat == NULL) {
		printf("** Erro: Memoria Insuficiente **");
		return(NULL);
	}
	/* aloca as colunas da matriz */
	for (i = 0; i < lin; i++){
		mat[i] = (int*)calloc(col, sizeof(int));
		if (mat[i] == NULL) {
			printf("** Erro: Memoria Insuficiente **");
			return(NULL);
		}
	}
	return(mat); /* retorna o ponteiro para a matriz */
}

int **LiberaMatriz(int lin, int col, int **mat){
	int i;  /* variavel auxiliar */
	if (mat == NULL) return(NULL);
	if (lin < 1 || col < 1){  /* verifica parametros recebidos */
		printf("** Erro: Parametro invalido **\n");
		return(mat);
	}
	for (i = 0; i<lin; i++) free(mat[i]); /* libera as linhas da matriz */
	free(mat);      /* libera a matriz */
	return(NULL); /* retorna um ponteiro nulo */
}

double **AlocaMatrizDouble(int lin, int col){
	double **mat;  /* ponteiro para a matriz */
	int i;    /* variavel auxiliar      */
	if (lin < 1 || col < 1) { /* verifica parametros recebidos */
		printf("** Erro: Parametro invalido **\n");
		return(NULL);
	}
	/* aloca as linhas da matriz */
	mat = (double **)calloc(lin, sizeof(double *));
	if (mat == NULL) {
		printf("** Erro: Memoria Insuficiente **");
		return(NULL);
	}
	/* aloca as colunas da matriz */
	for (i = 0; i < lin; i++){
		mat[i] = (double*)calloc(col, sizeof(double));
		if (mat[i] == NULL) {
			printf("** Erro: Memoria Insuficiente **");
			return(NULL);
		}
	}
	return(mat); /* retorna o ponteiro para a matriz */
}

double **LiberaMatrizDouble(int lin, int col, double **mat){
	int i;  /* variavel auxiliar */
	if (mat == NULL) return(NULL);
	if (lin < 1 || col < 1){  /* verifica parametros recebidos */
		printf("** Erro: Parametro invalido **\n");
		return(mat);
	}
	for (i = 0; i<lin; i++) free(mat[i]); /* libera as linhas da matriz */
	free(mat);      /* libera a matriz */
	return(NULL); /* retorna um ponteiro nulo */
}
	.text
	.file	"kernel.hip"
	.globl	_Z21__device_stub__filtraPPiS0_PPd5param # -- Begin function _Z21__device_stub__filtraPPiS0_PPd5param
	.type	_Z21__device_stub__filtraPPiS0_PPd5param,@function
_Z21__device_stub__filtraPPiS0_PPd5param: # @_Z21__device_stub__filtraPPiS0_PPd5param
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	160(%rsp), %rax
	movq	%rax, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z6filtraPPiS0_PPd5param, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z21__device_stub__filtraPPiS0_PPd5param, .Lfunc_end0-_Z21__device_stub__filtraPPiS0_PPd5param
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$776, %rsp                      # imm = 0x308
	.cfi_def_cfa_offset 832
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	128(%rsp), %rbx
	movl	$.L__const.main.narqin, %esi
	movl	$256, %edx                      # imm = 0x100
	movq	%rbx, %rdi
	callq	memcpy@PLT
	leaq	512(%rsp), %rdi
	movl	$.L__const.main.narqout, %esi
	movl	$256, %edx                      # imm = 0x100
	callq	memcpy@PLT
	leaq	44(%rsp), %r14
	movl	$1, -20(%r14)
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.L.str.1, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	$.L.str.2, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_4
# %bb.1:
	movq	%rax, %rbx
	leaq	512(%rsp), %r14
	movl	$.L.str.5, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.6, %esi
	movq	%r14, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_4
# %bb.2:
	movq	%rax, %r14
	leaq	384(%rsp), %r15
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$.L.str.8, %esi
	movq	%r14, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$.L.str.9, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	leaq	32(%rsp), %rdx
	leaq	28(%rsp), %r15
	leaq	124(%rsp), %r12
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	movq	%r15, %rcx
	movq	%r12, %r8
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	(%r15), %ecx
	movl	4(%r15), %edx
	movl	(%r12), %r8d
	movl	$.L.str.11, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	(%r15), %edx
	movl	4(%r15), %esi
	movl	$.L.str.12, %edi
	xorl	%eax, %eax
	callq	printf
	movl	(%r15), %eax
	cltd
	idivl	-4(%r15)
	movl	%eax, 8(%r15)
	testl	%edx, %edx
	movl	$0, %ecx
	cmovgl	%edx, %ecx
	movl	%ecx, 12(%r15)
	movl	$.L.str.13, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	movl	(%r15), %edi
	cmpl	-4(%r15), %edi
	jge	.LBB1_6
# %bb.3:
	xorl	%ebp, %ebp
	leaq	128(%rsp), %rsi
	movl	$.L.str.14, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_19
.LBB1_4:
	leaq	128(%rsp), %rsi
	movl	$.L.str.4, %edi
.LBB1_5:
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_18
.LBB1_6:
	movq	%r14, 112(%rsp)                 # 8-byte Spill
	movq	%rbx, 104(%rsp)                 # 8-byte Spill
	movl	32(%rsp), %esi
	callq	_Z11AlocaMatrizii
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	movl	28(%rsp), %edi
	movl	32(%rsp), %esi
	callq	_Z11AlocaMatrizii
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	movl	44(%rsp), %eax
	leal	1(,%rax,2), %edi
	movl	%edi, %esi
	callq	_Z17AlocaMatrizDoubleii
	movq	%rax, matrizpesos(%rip)
	movl	44(%rsp), %edi
	callq	_Z21InicializaMatrizPesosi
	movl	28(%rsp), %eax
	movl	32(%rsp), %r14d
	testl	%eax, %eax
	jle	.LBB1_13
# %bb.7:                                # %.preheader.preheader
	leaq	60(%rsp), %rdx
	leaq	56(%rsp), %r12
	leaq	52(%rsp), %rbx
	xorl	%r13d, %r13d
	movq	72(%rsp), %rbp                  # 8-byte Reload
.LBB1_8:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_10 Depth 2
	testl	%r14d, %r14d
	jle	.LBB1_12
# %bb.9:                                # %.lr.ph
                                        #   in Loop: Header=BB1_8 Depth=1
	xorl	%r15d, %r15d
.LBB1_10:                               #   Parent Loop BB1_8 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$.L.str.15, %esi
	movq	104(%rsp), %rdi                 # 8-byte Reload
	movq	%rdx, %r14
	movq	%r12, %rcx
	movq	%rbx, %r8
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movq	%r14, %rdx
	imull	$1000000, 60(%rsp), %eax        # imm = 0xF4240
	imull	$1000, 56(%rsp), %esi           # imm = 0x3E8
	addl	%eax, %esi
	addl	52(%rsp), %esi
	movq	(%rbp,%r13,8), %rax
	movl	%esi, (%rax,%r15,4)
	incq	%r15
	movslq	32(%rsp), %r14
	cmpq	%r14, %r15
	jl	.LBB1_10
# %bb.11:                               # %._crit_edge.loopexit
                                        #   in Loop: Header=BB1_8 Depth=1
	movl	28(%rsp), %eax
.LBB1_12:                               # %._crit_edge
                                        #   in Loop: Header=BB1_8 Depth=1
	incq	%r13
	movslq	%eax, %rsi
	cmpq	%rsi, %r13
	jl	.LBB1_8
.LBB1_13:                               # %._crit_edge88
	imull	%eax, %r14d
	shll	$2, %r14d
	movl	44(%rsp), %ebx
	movl	$.L.str.16, %edi
	xorl	%eax, %eax
	callq	printf
	movslq	%r14d, %r13
	leaq	96(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_16
# %bb.14:
	movl	$.L.str.18, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	88(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_16
# %bb.15:
	leal	1(,%rbx,2), %ebx
	imull	%ebx, %ebx
	shll	$3, %ebx
	movl	$.L.str.19, %edi
	xorl	%eax, %eax
	callq	printf
	movslq	%ebx, %r12
	leaq	80(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB1_20
.LBB1_16:
	movl	$.L.str.17, %edi
.LBB1_17:
	xorl	%eax, %eax
	callq	printf
.LBB1_18:
	movl	$1, %ebp
.LBB1_19:
	movl	%ebp, %eax
	addq	$776, %rsp                      # imm = 0x308
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_20:
	.cfi_def_cfa_offset 832
	movl	$.L.str.20, %edi
	xorl	%eax, %eax
	callq	printf
	movq	96(%rsp), %rdi
	movl	$1, %ebp
	movq	72(%rsp), %rsi                  # 8-byte Reload
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_22
# %bb.21:
	movl	$.L.str.22, %edi
	xorl	%eax, %eax
	callq	printf
	movq	80(%rsp), %rdi
	movq	matrizpesos(%rip), %rsi
	movl	$1, %ebp
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB1_23
.LBB1_22:
	movl	$.L.str.21, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_19
.LBB1_23:
	movl	$.L.str.23, %edi
	xorl	%eax, %eax
	callq	printf
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_25
# %bb.24:
	movq	96(%rsp), %rdi
	movq	88(%rsp), %rsi
	movq	80(%rsp), %rdx
	movq	40(%rsp), %rax
	movq	%rax, 16(%rsp)
	movups	24(%rsp), %xmm0
	movups	%xmm0, (%rsp)
	callq	_Z21__device_stub__filtraPPiS0_PPd5param
.LBB1_25:
	callq	hipGetLastError
	testl	%eax, %eax
	movq	64(%rsp), %rbx                  # 8-byte Reload
	je	.LBB1_27
# %bb.26:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.24, %edi
	movq	%rax, %rsi
	jmp	.LBB1_5
.LBB1_27:
	movl	$.L.str.25, %edi
	xorl	%eax, %eax
	callq	printf
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	je	.LBB1_29
# %bb.28:
	movl	$.L.str.26, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_18
.LBB1_29:
	movl	$.L.str.27, %edi
	xorl	%eax, %eax
	callq	printf
	movq	88(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB1_31
# %bb.30:
	movl	$.L.str.21, %edi
	jmp	.LBB1_17
.LBB1_31:
	xorl	%ebp, %ebp
	movl	$.L.str.28, %edi
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, 28(%rsp)
	movq	112(%rsp), %r14                 # 8-byte Reload
	jle	.LBB1_37
# %bb.32:                               # %.lr.ph97.preheader
	xorl	%r12d, %r12d
	movq	64(%rsp), %r15                  # 8-byte Reload
.LBB1_33:                               # %.lr.ph97
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_35 Depth 2
	movl	$10, %edi
	movq	%r14, %rsi
	callq	fputc@PLT
	cmpl	$0, 32(%rsp)
	jle	.LBB1_36
# %bb.34:                               # %.lr.ph92
                                        #   in Loop: Header=BB1_33 Depth=1
	xorl	%ebx, %ebx
.LBB1_35:                               #   Parent Loop BB1_33 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	(%r15,%r12,8), %rax
	movslq	(%rax,%rbx,4), %rcx
	imulq	$1125899907, %rcx, %rdx         # imm = 0x431BDE83
	movq	%rdx, %rcx
	shrq	$63, %rcx
	sarq	$50, %rdx
	addl	%ecx, %edx
	movl	%edx, 60(%rsp)
	imull	$-1000000, %edx, %esi           # imm = 0xFFF0BDC0
	movl	(%rax,%rbx,4), %ecx
	addl	%esi, %ecx
	movslq	%ecx, %rcx
	imulq	$274877907, %rcx, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdi
	shrq	$63, %rdi
	sarq	$38, %rcx
	addl	%edi, %ecx
	movl	%ecx, 56(%rsp)
	addl	(%rax,%rbx,4), %esi
	imull	$-1000, %ecx, %r8d              # imm = 0xFC18
	addl	%esi, %r8d
	movl	%r8d, 52(%rsp)
	movl	$.L.str.30, %esi
	movq	%r14, %rdi
                                        # kill: def $edx killed $edx killed $rdx
                                        # kill: def $ecx killed $ecx killed $rcx
	xorl	%eax, %eax
	callq	fprintf
	incq	%rbx
	movslq	32(%rsp), %rax
	cmpq	%rax, %rbx
	jl	.LBB1_35
.LBB1_36:                               # %._crit_edge93
                                        #   in Loop: Header=BB1_33 Depth=1
	incq	%r12
	movslq	28(%rsp), %rax
	cmpq	%rax, %r12
	jl	.LBB1_33
.LBB1_37:                               # %._crit_edge98
	movl	$.L.str.31, %edi
	xorl	%eax, %eax
	callq	printf
	movl	28(%rsp), %edi
	movl	32(%rsp), %esi
	movq	72(%rsp), %rdx                  # 8-byte Reload
	callq	_Z12LiberaMatriziiPPi
	movl	28(%rsp), %edi
	movl	32(%rsp), %esi
	movq	64(%rsp), %rdx                  # 8-byte Reload
	callq	_Z12LiberaMatriziiPPi
	movl	44(%rsp), %eax
	leal	1(,%rax,2), %edi
	movq	matrizpesos(%rip), %rdx
	movl	%edi, %esi
	callq	_Z18LiberaMatrizDoubleiiPPd
	movq	96(%rsp), %rdi
	callq	hipFree
	movq	88(%rsp), %rdi
	callq	hipFree
	movq	80(%rsp), %rdi
	callq	hipFree
	movq	104(%rsp), %rdi                 # 8-byte Reload
	callq	fclose
	movq	%r14, %rdi
	callq	fclose
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	jmp	.LBB1_19
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z11AlocaMatrizii               # -- Begin function _Z11AlocaMatrizii
	.type	_Z11AlocaMatrizii,@function
_Z11AlocaMatrizii:                      # @_Z11AlocaMatrizii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	testl	%edi, %edi
	jle	.LBB2_2
# %bb.1:
	movl	%esi, %ebp
	testl	%esi, %esi
	jle	.LBB2_2
# %bb.3:
	movl	%edi, %r14d
	movl	$8, %esi
	movq	%r14, %rdi
	callq	calloc
	testq	%rax, %rax
	je	.LBB2_7
# %bb.4:                                # %.lr.ph
	movq	%rax, %rbx
	movl	%ebp, %r15d
	xorl	%r12d, %r12d
.LBB2_6:                                # =>This Inner Loop Header: Depth=1
	movl	$4, %esi
	movq	%r15, %rdi
	callq	calloc
	movq	%rax, (%rbx,%r12,8)
	testq	%rax, %rax
	je	.LBB2_7
# %bb.5:                                #   in Loop: Header=BB2_6 Depth=1
	incq	%r12
	cmpq	%r12, %r14
	jne	.LBB2_6
	jmp	.LBB2_8
.LBB2_2:
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	xorl	%ebx, %ebx
	jmp	.LBB2_8
.LBB2_7:
	xorl	%ebx, %ebx
	movl	$.L.str.34, %edi
	xorl	%eax, %eax
	callq	printf
.LBB2_8:                                # %.loopexit
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z11AlocaMatrizii, .Lfunc_end2-_Z11AlocaMatrizii
	.cfi_endproc
                                        # -- End function
	.globl	_Z17AlocaMatrizDoubleii         # -- Begin function _Z17AlocaMatrizDoubleii
	.type	_Z17AlocaMatrizDoubleii,@function
_Z17AlocaMatrizDoubleii:                # @_Z17AlocaMatrizDoubleii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	testl	%edi, %edi
	jle	.LBB3_2
# %bb.1:
	movl	%esi, %ebp
	testl	%esi, %esi
	jle	.LBB3_2
# %bb.3:
	movl	%edi, %r14d
	movl	$8, %esi
	movq	%r14, %rdi
	callq	calloc
	testq	%rax, %rax
	je	.LBB3_7
# %bb.4:                                # %.lr.ph
	movq	%rax, %rbx
	movl	%ebp, %r15d
	xorl	%r12d, %r12d
.LBB3_6:                                # =>This Inner Loop Header: Depth=1
	movl	$8, %esi
	movq	%r15, %rdi
	callq	calloc
	movq	%rax, (%rbx,%r12,8)
	testq	%rax, %rax
	je	.LBB3_7
# %bb.5:                                #   in Loop: Header=BB3_6 Depth=1
	incq	%r12
	cmpq	%r12, %r14
	jne	.LBB3_6
	jmp	.LBB3_8
.LBB3_2:
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	xorl	%ebx, %ebx
	jmp	.LBB3_8
.LBB3_7:
	xorl	%ebx, %ebx
	movl	$.L.str.34, %edi
	xorl	%eax, %eax
	callq	printf
.LBB3_8:                                # %.loopexit
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z17AlocaMatrizDoubleii, .Lfunc_end3-_Z17AlocaMatrizDoubleii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z21InicializaMatrizPesosi
.LCPI4_0:
	.long	0x3f800000                      # float 1
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI4_1:
	.quad	0x401921fb54442eea              # double 6.2831853071800001
.LCPI4_3:
	.quad	0x4005bf0a80000000              # double 2.7182817459106445
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI4_2:
	.quad	0x8000000000000000              # double -0
	.quad	0x8000000000000000              # double -0
	.text
	.globl	_Z21InicializaMatrizPesosi
	.type	_Z21InicializaMatrizPesosi,@function
_Z21InicializaMatrizPesosi:             # @_Z21InicializaMatrizPesosi
	.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	$48, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	cvtsi2ss	%edi, %xmm3
	movaps	%xmm3, %xmm1
	addss	%xmm3, %xmm1
	addss	.LCPI4_0(%rip), %xmm1
	xorps	%xmm0, %xmm0
	movss	%xmm1, 8(%rsp)                  # 4-byte Spill
	ucomiss	%xmm0, %xmm1
	jbe	.LBB4_12
# %bb.1:                                # %.preheader40.lr.ph
	movl	%edi, %ebx
	leal	(%rbx,%rbx), %r14d
	cvtss2sd	%xmm3, %xmm4
	mulsd	%xmm4, %xmm4
	movapd	%xmm4, %xmm5
	addsd	%xmm4, %xmm5
	mulsd	.LCPI4_1(%rip), %xmm4
	xorl	%r15d, %r15d
	testl	%r14d, %r14d
	movl	$0, %r12d
	cmovgl	%r14d, %r12d
	orl	$1, %r12d
	xorpd	%xmm2, %xmm2
	movapd	.LCPI4_2(%rip), %xmm6           # xmm6 = [-0.0E+0,-0.0E+0]
	movsd	.LCPI4_3(%rip), %xmm7           # xmm7 = mem[0],zero
	movss	%xmm3, 12(%rsp)                 # 4-byte Spill
	movsd	%xmm4, 24(%rsp)                 # 8-byte Spill
	movsd	%xmm5, 16(%rsp)                 # 8-byte Spill
.LBB4_2:                                # %.preheader40
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_4 Depth 2
	testl	%ebx, %ebx
	js	.LBB4_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB4_2 Depth=1
	subss	%xmm3, %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm0, %xmm0
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	xorl	%r13d, %r13d
.LBB4_4:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	%xmm2, 40(%rsp)                 # 8-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r13d, %xmm0
	subss	%xmm3, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	%xmm0, %xmm1
	mulsd	%xmm1, %xmm1
	addsd	32(%rsp), %xmm1                 # 8-byte Folded Reload
	xorpd	%xmm6, %xmm1
	divsd	%xmm5, %xmm1
	movapd	%xmm7, %xmm0
	callq	pow
	movsd	.LCPI4_3(%rip), %xmm7           # xmm7 = mem[0],zero
	movapd	.LCPI4_2(%rip), %xmm6           # xmm6 = [-0.0E+0,-0.0E+0]
	movsd	16(%rsp), %xmm5                 # 8-byte Reload
                                        # xmm5 = mem[0],zero
	movsd	24(%rsp), %xmm4                 # 8-byte Reload
                                        # xmm4 = mem[0],zero
	movss	12(%rsp), %xmm3                 # 4-byte Reload
                                        # xmm3 = mem[0],zero,zero,zero
	movsd	40(%rsp), %xmm2                 # 8-byte Reload
                                        # xmm2 = mem[0],zero
	divsd	%xmm4, %xmm0
	movq	matrizpesos(%rip), %rax
	movq	(%rax,%r15,8), %rax
	movsd	%xmm0, (%rax,%r13,8)
	addsd	%xmm0, %xmm2
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB4_4
.LBB4_5:                                # %._crit_edge
                                        #   in Loop: Header=BB4_2 Depth=1
	incq	%r15
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r15d, %xmm0
	movss	8(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	ja	.LBB4_2
# %bb.6:                                # %.preheader39
	xorps	%xmm0, %xmm0
	movss	8(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jbe	.LBB4_12
# %bb.7:                                # %.preheader.lr.ph
	movq	matrizpesos(%rip), %rax
	xorl	%ecx, %ecx
	testl	%r14d, %r14d
	cmovlel	%ecx, %r14d
	orl	$1, %r14d
	movss	8(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
.LBB4_8:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_10 Depth 2
	testl	%ebx, %ebx
	js	.LBB4_11
# %bb.9:                                # %.lr.ph50
                                        #   in Loop: Header=BB4_8 Depth=1
	movq	(%rax,%rcx,8), %rdx
	xorl	%esi, %esi
.LBB4_10:                               #   Parent Loop BB4_8 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rdx,%rsi,8), %xmm0            # xmm0 = mem[0],zero
	divsd	%xmm2, %xmm0
	movsd	%xmm0, (%rdx,%rsi,8)
	incq	%rsi
	cmpq	%rsi, %r14
	jne	.LBB4_10
.LBB4_11:                               # %._crit_edge51
                                        #   in Loop: Header=BB4_8 Depth=1
	incq	%rcx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ecx, %xmm0
	ucomiss	%xmm0, %xmm1
	ja	.LBB4_8
.LBB4_12:                               # %._crit_edge53
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z21InicializaMatrizPesosi, .Lfunc_end4-_Z21InicializaMatrizPesosi
	.cfi_endproc
                                        # -- End function
	.globl	_Z12LiberaMatriziiPPi           # -- Begin function _Z12LiberaMatriziiPPi
	.type	_Z12LiberaMatriziiPPi,@function
_Z12LiberaMatriziiPPi:                  # @_Z12LiberaMatriziiPPi
	.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
	testq	%rdx, %rdx
	je	.LBB5_6
# %bb.1:
	movq	%rdx, %rbx
	testl	%edi, %edi
	jle	.LBB5_8
# %bb.2:
	testl	%esi, %esi
	jle	.LBB5_8
# %bb.3:                                # %.preheader.preheader
	movl	%edi, %r14d
	xorl	%r15d, %r15d
.LBB5_4:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx,%r15,8), %rdi
	callq	free
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB5_4
# %bb.5:
	movq	%rbx, %rdi
	callq	free
.LBB5_6:
	xorl	%ebx, %ebx
	jmp	.LBB5_7
.LBB5_8:
	movl	$.Lstr.5, %edi
	callq	puts@PLT
.LBB5_7:
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z12LiberaMatriziiPPi, .Lfunc_end5-_Z12LiberaMatriziiPPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z18LiberaMatrizDoubleiiPPd     # -- Begin function _Z18LiberaMatrizDoubleiiPPd
	.type	_Z18LiberaMatrizDoubleiiPPd,@function
_Z18LiberaMatrizDoubleiiPPd:            # @_Z18LiberaMatrizDoubleiiPPd
	.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
	testq	%rdx, %rdx
	je	.LBB6_6
# %bb.1:
	movq	%rdx, %rbx
	testl	%edi, %edi
	jle	.LBB6_8
# %bb.2:
	testl	%esi, %esi
	jle	.LBB6_8
# %bb.3:                                # %.preheader.preheader
	movl	%edi, %r14d
	xorl	%r15d, %r15d
.LBB6_4:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx,%r15,8), %rdi
	callq	free
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB6_4
# %bb.5:
	movq	%rbx, %rdi
	callq	free
.LBB6_6:
	xorl	%ebx, %ebx
	jmp	.LBB6_7
.LBB6_8:
	movl	$.Lstr.5, %edi
	callq	puts@PLT
.LBB6_7:
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z18LiberaMatrizDoubleiiPPd, .Lfunc_end6-_Z18LiberaMatrizDoubleiiPPd
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6filtraPPiS0_PPd5param, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	matrizpesos,@object             # @matrizpesos
	.bss
	.globl	matrizpesos
	.p2align	3, 0x0
matrizpesos:
	.quad	0
	.size	matrizpesos, 8

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

	.type	.L__const.main.narqin,@object   # @__const.main.narqin
	.p2align	4, 0x0
.L__const.main.narqin:
	.asciz	"c:\\temp\\reddead.ppm\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
	.size	.L__const.main.narqin, 256

	.type	.L__const.main.narqout,@object  # @__const.main.narqout
	.p2align	4, 0x0
.L__const.main.narqout:
	.asciz	"c:\\temp\\reddead2.ppm\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
	.size	.L__const.main.narqout, 256

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Arquivo de entrada: %s\n"
	.size	.L.str.2, 24

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Erro na abertura do arquivo %s\n"
	.size	.L.str.4, 32

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Arquivo de saida: %s\n"
	.size	.L.str.5, 22

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%s"
	.size	.L.str.7, 3

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

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Arquivo tipo: %s \n"
	.size	.L.str.9, 19

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"%d %d %d"
	.size	.L.str.10, 9

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

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Colunas = %d \nLinhas = %d \n"
	.size	.L.str.12, 28

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

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Mais threads do que dados %s\n"
	.size	.L.str.14, 30

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

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"1...alocando doldimage na GPU..."
	.size	.L.str.16, 33

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

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"2...alocando dnewimage na GPU..."
	.size	.L.str.18, 33

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"3...alocando dmatrizpesos na GPU..."
	.size	.L.str.19, 36

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"4...copiando oldimage para GPU..."
	.size	.L.str.20, 34

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

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"5...copiando matrizpesos para GPU..."
	.size	.L.str.22, 37

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"6...rodando kernel..."
	.size	.L.str.23, 22

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

	.type	.L.str.25,@object               # @.str.25
.L.str.25:
	.asciz	"7...sincronizando com device..."
	.size	.L.str.25, 32

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

	.type	.L.str.27,@object               # @.str.27
.L.str.27:
	.asciz	"8...copiando dnewimage da GPU para processador..."
	.size	.L.str.27, 50

	.type	.L.str.28,@object               # @.str.28
.L.str.28:
	.asciz	"9...escrevendo nova imagem..."
	.size	.L.str.28, 30

	.type	.L.str.30,@object               # @.str.30
.L.str.30:
	.asciz	"%d %d %d "
	.size	.L.str.30, 10

	.type	.L.str.31,@object               # @.str.31
.L.str.31:
	.asciz	"10...liberando matrizes..."
	.size	.L.str.31, 27

	.type	.L.str.34,@object               # @.str.34
.L.str.34:
	.asciz	"** Erro: Memoria Insuficiente **"
	.size	.L.str.34, 33

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6filtraPPiS0_PPd5param"
	.size	.L__unnamed_1, 25

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

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Qual raio?"
	.size	.Lstr, 11

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Fim programa."
	.size	.Lstr.1, 14

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"** Erro: Parametro invalido **"
	.size	.Lstr.5, 31

	.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 _Z21__device_stub__filtraPPiS0_PPd5param
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6filtraPPiS0_PPd5param
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6filtraPPiS0_PPd5param ; -- Begin function _Z6filtraPPiS0_PPd5param
	.globl	_Z6filtraPPiS0_PPd5param
	.p2align	8
	.type	_Z6filtraPPiS0_PPd5param,@function
_Z6filtraPPiS0_PPd5param:               ; @_Z6filtraPPiS0_PPd5param
; %bb.0:
	s_clause 0x2
	s_load_b32 s8, s[0:1], 0x3c
	s_load_b64 s[2:3], s[0:1], 0x28
	s_load_b128 s[4:7], s[0:1], 0x18
	s_mov_b32 s13, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s8, s8, 0xffff
	s_cmp_gt_i32 s2, 0
	v_mad_u64_u32 v[2:3], null, s15, s8, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_cmp_gt_i32_e32 vcc_lo, s2, v2
	v_cndmask_b32_e64 v0, s2, 0, vcc_lo
	s_cselect_b32 s2, -1, 0
	s_and_b32 vcc_lo, s2, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e64 v4, null, s7, 0, vcc_lo
	v_cndmask_b32_e64 v3, 0, v0, s2
	s_add_i32 s2, s4, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[0:1], null, v4, v2, v[3:4]
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v0, vcc_lo
	v_cmp_eq_u32_e32 vcc_lo, s2, v2
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v14, v1, s5, vcc_lo
	v_cmpx_lt_i32_e64 v0, v14
	s_cbranch_execz .LBB0_13
; %bb.1:                                ; %.lr.ph142
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[14:15], s[0:1], 0x10
	s_cmp_gt_i32 s6, 0
	s_mov_b32 s7, 0
	s_cselect_b32 s1, -1, 0
	s_lshl_b32 s0, s3, 1
	s_sub_i32 s4, 0, s3
	s_or_b32 s2, s0, 1
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
                                        ;       Child Loop BB0_6 Depth 3
                                        ;         Child Loop BB0_8 Depth 4
	s_and_not1_b32 vcc_lo, exec_lo, s1
	s_cbranch_vccnz .LBB0_12
; %bb.3:                                ; %.lr.ph137
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_ashrrev_i32_e32 v1, 31, v0
	v_add_nc_u32_e32 v3, s3, v0
	v_subrev_nc_u32_e32 v15, s3, v0
	v_sub_nc_u32_e32 v5, s3, v0
	s_mov_b32 s12, 0
	v_lshlrev_b64 v[1:2], 3, v[0:1]
	v_xad_u32 v4, v3, -1, s5
	v_ashrrev_i32_e32 v6, 31, v15
	s_mov_b32 s20, s3
	s_mov_b32 s21, s4
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s10, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s11, v2, vcc_lo
	v_cmp_le_i32_e32 vcc_lo, s5, v3
	v_and_b32_e32 v16, v6, v5
	global_load_b64 v[1:2], v[1:2], off
	v_cndmask_b32_e32 v3, 0, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v17, s2, v3
	v_cmp_lt_i32_e64 s0, v16, v17
.LBB0_4:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_6 Depth 3
                                        ;         Child Loop BB0_8 Depth 4
	v_mov_b32_e32 v3, 0
	v_mov_b32_e32 v4, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mov_b32 v6, v4 :: v_dual_mov_b32 v5, v3
	v_dual_mov_b32 v8, v4 :: v_dual_mov_b32 v7, v3
	s_and_saveexec_b32 s22, s0
	s_cbranch_execz .LBB0_11
; %bb.5:                                ; %.preheader.lr.ph
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_max_i32 s16, s21, 0
	s_sub_i32 s23, s12, s3
	s_add_i32 s18, s16, s20
	s_add_i32 s25, s12, s3
	s_mov_b32 s17, s13
	s_ashr_i32 s19, s18, 31
	s_sub_i32 s24, s3, s12
	s_ashr_i32 s23, s23, 31
	s_not_b32 s26, s25
	s_lshl_b64 s[16:17], s[16:17], 2
	s_lshl_b64 s[18:19], s[18:19], 3
	s_and_b32 s23, s23, s24
	s_add_i32 s24, s6, s26
	v_mov_b32_e32 v3, 0
	s_cmp_ge_i32 s25, s6
	v_dual_mov_b32 v4, 0 :: v_dual_mov_b32 v9, v16
	s_cselect_b32 s24, s24, 0
	s_mov_b32 s26, 0
	s_add_i32 s24, s24, s2
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mov_b32 v6, v4 :: v_dual_mov_b32 v5, v3
	v_dual_mov_b32 v8, v4 :: v_dual_mov_b32 v7, v3
	s_cmp_lt_i32 s23, s24
	s_cselect_b32 s25, -1, 0
.LBB0_6:                                ; %.preheader
                                        ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_4 Depth=2
                                        ; =>    This Loop Header: Depth=3
                                        ;         Child Loop BB0_8 Depth 4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s25
	s_cbranch_vccnz .LBB0_9
; %bb.7:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_6 Depth=3
	v_add_nc_u32_e32 v11, v9, v15
	v_ashrrev_i32_e32 v10, 31, v9
	s_mov_b32 s27, s23
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v12, 31, v11
	v_lshlrev_b64 v[18:19], 3, v[9:10]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[10:11], 3, v[11:12]
	v_add_co_u32 v12, vcc_lo, s14, v18
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v13, vcc_lo, s15, v19, vcc_lo
	v_add_co_u32 v10, vcc_lo, s8, v10
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v11, vcc_lo, s9, v11, vcc_lo
	global_load_b64 v[12:13], v[12:13], off
	global_load_b64 v[18:19], v[10:11], off
	s_waitcnt vmcnt(1)
	v_add_co_u32 v10, vcc_lo, v12, s18
	v_add_co_ci_u32_e32 v11, vcc_lo, s19, v13, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_co_u32 v12, vcc_lo, v18, s16
	v_add_co_ci_u32_e32 v13, vcc_lo, s17, v19, vcc_lo
.LBB0_8:                                ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_4 Depth=2
                                        ;       Parent Loop BB0_6 Depth=3
                                        ; =>      This Inner Loop Header: Depth=4
	global_load_b32 v20, v[12:13], off
	global_load_b64 v[18:19], v[10:11], off
	v_add_co_u32 v10, vcc_lo, v10, 8
	v_add_co_ci_u32_e32 v11, vcc_lo, 0, v11, vcc_lo
	v_add_co_u32 v12, vcc_lo, v12, 4
	v_add_co_ci_u32_e32 v13, vcc_lo, 0, v13, vcc_lo
	s_add_i32 s27, s27, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_cmp_lt_i32 s27, s24
	s_waitcnt vmcnt(1)
	v_mul_hi_i32 v21, 0x431bde83, v20
	v_lshrrev_b32_e32 v22, 31, v21
	v_ashrrev_i32_e32 v21, 18, v21
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v21, v21, v22
	v_mad_i32_i24 v20, 0xfff0bdc0, v21, v20
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_i32 v22, 0x10624dd3, v20
	v_lshrrev_b32_e32 v23, 31, v22
	v_ashrrev_i32_e32 v22, 6, v22
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v22, v22, v23
	v_mad_i32_i24 v24, 0xfffffc18, v22, v20
	v_cvt_f64_i32_e32 v[20:21], v21
	v_cvt_f64_i32_e32 v[22:23], v22
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cvt_f64_i32_e32 v[24:25], v24
	s_waitcnt vmcnt(0)
	v_fma_f64 v[7:8], v[18:19], v[20:21], v[7:8]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fma_f64 v[5:6], v[18:19], v[22:23], v[5:6]
	v_fma_f64 v[3:4], v[18:19], v[24:25], v[3:4]
	s_cbranch_scc1 .LBB0_8
.LBB0_9:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_6 Depth=3
	v_add_nc_u32_e32 v9, 1, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_ge_i32_e32 vcc_lo, v9, v17
	s_or_b32 s26, vcc_lo, s26
	s_and_not1_b32 exec_lo, exec_lo, s26
	s_cbranch_execnz .LBB0_6
; %bb.10:                               ; %Flow178
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s26
.LBB0_11:                               ; %Flow179
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_or_b32 exec_lo, exec_lo, s22
	v_cvt_i32_f64_e32 v7, v[7:8]
	s_delay_alu instid0(VALU_DEP_3)
	v_cvt_i32_f64_e32 v5, v[5:6]
	v_cvt_i32_f64_e32 v6, v[3:4]
	s_lshl_b64 s[16:17], s[12:13], 2
	s_add_i32 s12, s12, 1
	s_waitcnt vmcnt(0)
	v_add_co_u32 v3, vcc_lo, v1, s16
	v_add_co_ci_u32_e32 v4, vcc_lo, s17, v2, vcc_lo
	s_add_i32 s21, s21, 1
	s_add_i32 s20, s20, -1
	s_cmp_lg_u32 s12, s6
	v_mul_lo_u32 v7, 0xf4240, v7
	v_mul_lo_u32 v5, 0x3e8, v5
	s_delay_alu instid0(VALU_DEP_1)
	v_add3_u32 v5, v5, v7, v6
	global_store_b32 v[3:4], v5, off
	s_cbranch_scc1 .LBB0_4
.LBB0_12:                               ; %._crit_edge138
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_add_nc_u32_e32 v0, 1, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_ge_i32_e32 vcc_lo, v0, v14
	s_or_b32 s7, vcc_lo, s7
	s_and_not1_b32 exec_lo, exec_lo, s7
	s_cbranch_execnz .LBB0_2
.LBB0_13:                               ; %._crit_edge143
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6filtraPPiS0_PPd5param
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 304
		.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 26
		.amdhsa_next_free_sgpr 28
		.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	_Z6filtraPPiS0_PPd5param, .Lfunc_end0-_Z6filtraPPiS0_PPd5param
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 944
; NumSgprs: 30
; NumVgprs: 26
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 3
; VGPRBlocks: 3
; NumSGPRsForWavesPerEU: 30
; NumVGPRsForWavesPerEU: 26
; Occupancy: 16
; WaveLimiterHint : 1
; 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
      - .offset:         24
        .size:           24
        .value_kind:     by_value
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         52
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         60
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         62
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         64
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         66
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         68
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         70
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         112
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 304
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6filtraPPiS0_PPd5param
    .private_segment_fixed_size: 0
    .sgpr_count:     30
    .sgpr_spill_count: 0
    .symbol:         _Z6filtraPPiS0_PPd5param.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     26
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
