#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define SEC_AS_NANO 1000000000.0

struct _matriz
{
	int n;
	int m;
	int **cont;
}; typedef struct _matriz Matriz;

Matriz *criarMatriz(int n, int m)
{
	Matriz *mat = (Matriz*) malloc(sizeof(Matriz));

	mat->n = n;
	mat->m = m;
	mat->cont = (int**) malloc(n * sizeof(int*));
	for(int i = 0; i < n; i++)
		mat->cont[i] = (int*) malloc(m * sizeof(int));

	return mat;
}

void liberarMatriz(Matriz *m)
{
	for(int i = 0; i < m->n; i++)
		free(m->cont[i]);
	free(m->cont);
	free(m);
}

Matriz *gerarMatriz(int n, int m)
{
	Matriz *mat = criarMatriz(n, m);
	
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			{
				mat->cont[i][j] = rand() % 100;
			}

	return mat;
}

void printarMatriz(Matriz *mat)
{
	for(int i = 0; i < mat->n; i++)
	{
		for(int j = 0; j < mat->m; j++)
			printf("%d ", mat->cont[i][j]);
		printf("\n");
	}
}

void multiplicarMatrizes(Matriz *a, Matriz *b, Matriz *c)
{
	for(int i = 0; i < a->n; i++)
		for(int j = 0; j < b->m; j++)
		{
			c->cont[i][j] = 0;
			for(int k = 0; k < a->m; k++)
				c->cont[i][j] += a->cont[i][k] * b->cont[k][j];
		}
}

Matriz *lerMatriz(char *nome, int n, int m)
{
	Matriz *mat = criarMatriz(n, m);

	FILE *f = fopen(nome, "r");

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			fscanf(f, " %d", &(mat->cont[i][j]));

	fclose(f);

	return mat;
}

void salvarMatriz(Matriz *mat)
{
	static int i = 0;

	char nome[100];
	sprintf(nome, "%d-%dx%d.txt", i, mat->n, mat->m);

	FILE *f = fopen(nome, "w");

	for(int i = 0; i < mat->n; i++)
	{
		for(int j = 0; j < mat->m; j++)
			fprintf(f, "%d ", mat->cont[i][j]);
		fprintf(f, "\n");
	}

	fclose(f);
	i++;
}

struct _input
{
	Matriz *a;
	Matriz *b;
	Matriz *c;
	short int salvar;
}; typedef struct _input Input;

Input *lerInput(int argc, char **argv)
{
	if(argc >= 6)
	{
		Input *i = (Input *) malloc(sizeof(Input));
		i->salvar = 0;

		int n1, m1, n2, m2;
		char op;

		op = argv[1][0];
		
		sscanf(argv[2], " %d", &n1);
		sscanf(argv[3], " %d", &m1);
		sscanf(argv[4], " %d", &n2);
		sscanf(argv[5], " %d", &m2);
	
		if(m1 == n2)
		{
			Matriz *a, *b, *c;		
			
			switch(op)
			{
				case 'g':
					srand(time(NULL));
					a = gerarMatriz(n1, m1);
					b = gerarMatriz(n2, m2);
					if(argc == 7 && argv[6][0] == 's')
						i->salvar = 1;
					break;
				case 'f':
					a = lerMatriz(argv[6], n1, m1);
					b = lerMatriz(argv[7], n2, m2);
					break;
				default:
					return 0;
			}
			c = criarMatriz(n1, m2);

			i->a = a;
			i->b = b;
			i->c = c;

			return i;
		}
		else
			printf("Incompatible Matrices!\n");
	}
	else
		printf("Invalid arguments!\n");

	return NULL;
}

double medirTempoInput(Input **i, int argc, char **argv, Input *ler(int, char**))
{
	timespec ini, fim;
	clock_gettime(CLOCK_REALTIME, &ini);
	*i = ler(argc, argv);
	clock_gettime(CLOCK_REALTIME, &fim);

	double iniSec = ini.tv_sec + ini.tv_nsec / SEC_AS_NANO;
	double fimSec = fim.tv_sec + fim.tv_nsec / SEC_AS_NANO;	

	return (fimSec - iniSec);
}

double medirTempoExecMul(Input *i)
{
	timespec ini, fim;
	clock_gettime(CLOCK_REALTIME, &ini);
	multiplicarMatrizes(i->a, i->b, i->c);
	clock_gettime(CLOCK_REALTIME, &fim);

	double iniSec = ini.tv_sec + ini.tv_nsec / SEC_AS_NANO;
	double fimSec = fim.tv_sec + fim.tv_nsec / SEC_AS_NANO;	

	return (fimSec - iniSec);
}

void salvarELiberarMatrizes(Input *i)
{	
	if(i->salvar)
	{
		salvarMatriz(i->a);
		salvarMatriz(i->b);
	}
	salvarMatriz(i->c);

	liberarMatriz(i->a);
	liberarMatriz(i->b);
	liberarMatriz(i->c);
	free(i);
}

int verificarArgumentos(int argc, char **argv)
{
	if(argc < 6)
	{
		printf("Not enough arguments\n"
			"#  SOURCE: f for files, g for generation\n"
			"#  LINSA: matrix A lines\n"
			"#  COLSA: matrix A columns\n"
			"#  LINSB: matrix B lines\n"
			"#  COLSB: matrix B columns\n"
			"#  FILEA: matrix A file\n"
			"#  FILEB: matrix B file\n"
			"#  SAV (opcional): saves generated matrices A and B"
			"##  ./bin f LA CA LB CB FILEA FILEB\n"
			"##  ./bin g LA CA LB CB SAV\n");
		return 0;
	}
	else
	{
		if(argv[1][0] != 'f' && argv[1][0] != 'g')
		{
			printf("Invalid source argument, try using g or f\n");
			return 0;
		}

		int aux;
		for(int i = 2; i < 6; i++)
			if(!sscanf(argv[i], "%d", &aux))
			{
				printf("%d is not a number, type matrices A and B dimensions\n", (i - 1));
				return 0;
			}

		if(argv[1][0] == 'g')
			if(argc == 7)
				if(argv[6][0] != 's')
				{
					printf("Add 's' to save matrices A and B\n");
					return 0;
				}

		if(argv[1][0] == 'f')
		{
			FILE *f;
			if((f = fopen(argv[6], "r")) == NULL)
			{
				printf("Matrix A file does not exist\n");
				return 0;
			}
			else
				fclose(f);
			if((f = fopen(argv[7], "r")) == NULL)
			{
				printf("Matrix B file does not exist\n");
				return 0;
			}
			else
				fclose(f);
		}
		
	}

	return 1;
}

int main(int argc, char ** argv)
{
	if(verificarArgumentos(argc, argv))
	{
		Input *i;
		printf("Creation time: %lf\n", medirTempoInput(&i, argc, argv, &lerInput));
		printf("Execution time: %lf\n", medirTempoExecMul(i));
		salvarELiberarMatrizes(i);
	}

	return 0;
}

	.file	"tmpxft_003520e4_00000000-6_matrix.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2042:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2042:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z11criarMatrizii
	.type	_Z11criarMatrizii, @function
_Z11criarMatrizii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edi, %r12d
	movl	$16, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movslq	%esi, %rbx
	call	malloc@PLT
	movslq	%r12d, %rdi
	movl	%ebx, 4(%rax)
	salq	$3, %rdi
	movq	%rax, %rbp
	salq	$2, %rbx
	movl	%r12d, (%rax)
	call	malloc@PLT
	movq	%rax, 8(%rbp)
	movq	%rax, %r14
.L3:
	cmpl	%r13d, %r12d
	jle	.L7
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rax, (%r14,%r13,8)
	incq	%r13
	jmp	.L3
.L7:
	popq	%rbx
	.cfi_def_cfa_offset 40
	movq	%rbp, %rax
	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
.LFE2027:
	.size	_Z11criarMatrizii, .-_Z11criarMatrizii
	.globl	_Z13liberarMatrizP7_matriz
	.type	_Z13liberarMatrizP7_matriz, @function
_Z13liberarMatrizP7_matriz:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 32
.L9:
	movq	8(%rbx), %rdi
	cmpl	%ebp, (%rbx)
	jle	.L12
	movq	(%rdi,%rbp,8), %rdi
	incq	%rbp
	call	free@PLT
	jmp	.L9
.L12:
	call	free@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	free@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z13liberarMatrizP7_matriz, .-_Z13liberarMatrizP7_matriz
	.globl	_Z11gerarMatrizii
	.type	_Z11gerarMatrizii, @function
_Z11gerarMatrizii:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$100, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	%edi, 12(%rsp)
	call	_Z11criarMatrizii
	movq	%rax, %rbx
.L14:
	cmpl	%r12d, 12(%rsp)
	jle	.L13
	leaq	0(,%r12,8), %r13
	xorl	%ebp, %ebp
.L17:
	cmpl	%ebp, %r14d
	jle	.L19
	call	rand@PLT
	movq	8(%rbx), %rdx
	movq	(%rdx,%r13), %rsi
	cltd
	idivl	%r15d
	movl	%edx, (%rsi,%rbp,4)
	incq	%rbp
	jmp	.L17
.L19:
	incq	%r12
	jmp	.L14
.L13:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z11gerarMatrizii, .-_Z11gerarMatrizii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d "
.LC1:
	.string	"\n"
	.text
	.globl	_Z13printarMatrizP7_matriz
	.type	_Z13printarMatrizP7_matriz, @function
_Z13printarMatrizP7_matriz:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %r14
	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
	movq	%rdi, %rbx
.L21:
	cmpl	%r12d, (%rbx)
	jle	.L20
	leaq	0(,%r12,8), %r13
	xorl	%ebp, %ebp
.L24:
	cmpl	%ebp, 4(%rbx)
	jle	.L26
	movq	8(%rbx), %rax
	movq	%r14, %rsi
	movl	$2, %edi
	movq	(%rax,%r13), %rax
	movl	(%rax,%rbp,4), %edx
	xorl	%eax, %eax
	incq	%rbp
	call	__printf_chk@PLT
	jmp	.L24
.L26:
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%r12
	call	__printf_chk@PLT
	jmp	.L21
.L20:
	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
.LFE2030:
	.size	_Z13printarMatrizP7_matriz, .-_Z13printarMatrizP7_matriz
	.globl	_Z19multiplicarMatrizesP7_matrizS0_S0_
	.type	_Z19multiplicarMatrizesP7_matrizS0_S0_, @function
_Z19multiplicarMatrizesP7_matrizS0_S0_:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	%rdi, %rax
	movq	%rdx, %r8
	movq	%rsi, %rdi
	xorl	%esi, %esi
.L35:
	cmpl	%esi, (%rax)
	jle	.L42
	leaq	0(,%rsi,8), %r11
	xorl	%ecx, %ecx
	cmpl	%ecx, 4(%rdi)
	jg	.L40
	incq	%rsi
	jmp	.L35
.L42:
	ret
.L40:
	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
.L31:
	movq	8(%r8), %rdx
	leaq	0(,%rcx,4), %rbx
	xorl	%r9d, %r9d
	movq	(%rdx,%r11), %rbp
	xorl	%edx, %edx
	addq	%rbx, %rbp
.L29:
	movl	%r9d, 0(%rbp)
	cmpl	%edx, 4(%rax)
	jle	.L43
	movq	8(%rax), %r10
	movq	8(%rdi), %r12
	movq	(%r10,%r11), %r10
	movq	(%r12,%rdx,8), %r12
	movl	(%r10,%rdx,4), %r10d
	imull	(%r12,%rbx), %r10d
	incq	%rdx
	addl	%r10d, %r9d
	jmp	.L29
.L43:
	incq	%rcx
.L33:
	cmpl	%ecx, 4(%rdi)
	jg	.L31
	incq	%rsi
	cmpl	%esi, (%rax)
	jle	.L27
	leaq	0(,%rsi,8), %r11
	xorl	%ecx, %ecx
	jmp	.L33
.L27:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z19multiplicarMatrizesP7_matrizS0_S0_, .-_Z19multiplicarMatrizesP7_matrizS0_S0_
	.section	.rodata.str1.1
.LC2:
	.string	"r"
.LC3:
	.string	" %d"
	.text
	.globl	_Z9lerMatrizPcii
	.type	_Z9lerMatrizPcii, @function
_Z9lerMatrizPcii:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%esi, %r13d
	movl	%edx, %esi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	movl	%r13d, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	_Z11criarMatrizii
	movq	%rbp, %rdi
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rbx
	call	fopen@PLT
	movq	%rax, %rdi
.L45:
	cmpl	%r15d, %r13d
	jle	.L47
	leaq	0(,%r15,8), %rbp
	xorl	%r12d, %r12d
.L48:
	cmpl	%r12d, %r14d
	jle	.L50
	movq	8(%rbx), %rax
	leaq	.LC3(%rip), %rsi
	movq	%rdi, 8(%rsp)
	movq	(%rax,%rbp), %rax
	leaq	(%rax,%r12,4), %rdx
	xorl	%eax, %eax
	incq	%r12
	call	__isoc23_fscanf@PLT
	movq	8(%rsp), %rdi
	jmp	.L48
.L50:
	incq	%r15
	jmp	.L45
.L47:
	call	fclose@PLT
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z9lerMatrizPcii, .-_Z9lerMatrizPcii
	.section	.rodata.str1.1
.LC4:
	.string	"Incompatible Matrices!\n"
.LC5:
	.string	"Invalid arguments!\n"
	.text
	.globl	_Z8lerInputiPPc
	.type	_Z8lerInputiPPc, @function
_Z8lerInputiPPc:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	cmpl	$5, %edi
	jle	.L52
	movl	%edi, %r14d
	movl	$32, %edi
	movq	%rsi, %rbp
	call	malloc@PLT
	leaq	.LC3(%rip), %r12
	movq	16(%rbp), %rdi
	leaq	8(%rsp), %rdx
	movw	$0, 24(%rax)
	movq	%rax, %rbx
	movq	8(%rbp), %rax
	movq	%r12, %rsi
	movb	(%rax), %r13b
	xorl	%eax, %eax
	call	__isoc23_sscanf@PLT
	movq	24(%rbp), %rdi
	leaq	12(%rsp), %rdx
	xorl	%eax, %eax
	movq	%r12, %rsi
	call	__isoc23_sscanf@PLT
	movq	32(%rbp), %rdi
	leaq	16(%rsp), %rdx
	xorl	%eax, %eax
	movq	%r12, %rsi
	call	__isoc23_sscanf@PLT
	movq	40(%rbp), %rdi
	leaq	20(%rsp), %rdx
	xorl	%eax, %eax
	movq	%r12, %rsi
	call	__isoc23_sscanf@PLT
	movl	12(%rsp), %edx
	cmpl	16(%rsp), %edx
	jne	.L53
	cmpb	$102, %r13b
	je	.L54
	cmpb	$103, %r13b
	jne	.L62
	xorl	%edi, %edi
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	movl	12(%rsp), %esi
	movl	8(%rsp), %edi
	call	_Z11gerarMatrizii
	movl	20(%rsp), %esi
	movl	16(%rsp), %edi
	movq	%rax, %r13
	call	_Z11gerarMatrizii
	movq	%rax, %r12
	cmpl	$7, %r14d
	jne	.L57
	movq	48(%rbp), %rax
	cmpb	$115, (%rax)
	jne	.L57
	movw	$1, 24(%rbx)
	jmp	.L57
.L54:
	movq	48(%rbp), %rdi
	movl	8(%rsp), %esi
	call	_Z9lerMatrizPcii
	movq	56(%rbp), %rdi
	movl	20(%rsp), %edx
	movl	16(%rsp), %esi
	movq	%rax, %r13
	call	_Z9lerMatrizPcii
	movq	%rax, %r12
.L57:
	movl	20(%rsp), %esi
	movl	8(%rsp), %edi
	call	_Z11criarMatrizii
	movq	%r13, (%rbx)
	movq	%r12, 8(%rbx)
	movq	%rax, 16(%rbx)
	jmp	.L51
.L53:
	leaq	.LC4(%rip), %rsi
.L64:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L62:
	xorl	%ebx, %ebx
	jmp	.L51
.L52:
	leaq	.LC5(%rip), %rsi
	jmp	.L64
.L51:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L61
	call	__stack_chk_fail@PLT
.L61:
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	movq	%rbx, %rax
	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
.LFE2034:
	.size	_Z8lerInputiPPc, .-_Z8lerInputiPPc
	.section	.rodata.str1.1
.LC6:
	.string	"%d-%dx%d.txt"
.LC7:
	.string	"w"
	.text
	.globl	_Z12salvarMatrizP7_matriz
	.type	_Z12salvarMatrizP7_matriz, @function
_Z12salvarMatrizP7_matriz:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$100, %edx
	leaq	.LC6(%rip), %rcx
	movl	$2, %esi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC0(%rip), %r15
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movl	_ZZ12salvarMatrizP7_matrizE1i(%rip), %r8d
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rbp
	pushq	%rax
	.cfi_def_cfa_offset 184
	movl	4(%rdi), %eax
	pushq	%rax
	.cfi_def_cfa_offset 192
	movl	(%rdi), %r9d
	xorl	%eax, %eax
	movq	%rbp, %rdi
	call	__sprintf_chk@PLT
	popq	%rdx
	.cfi_def_cfa_offset 184
	movq	%rbp, %rdi
	popq	%rcx
	.cfi_def_cfa_offset 176
	leaq	.LC7(%rip), %rsi
	call	fopen@PLT
	movq	%rax, %rbp
.L66:
	cmpl	%r13d, (%rbx)
	jle	.L68
	leaq	0(,%r13,8), %r14
	xorl	%r12d, %r12d
.L69:
	cmpl	%r12d, 4(%rbx)
	jle	.L72
	movq	8(%rbx), %rax
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%rbp, %rdi
	movq	(%rax,%r14), %rax
	movl	(%rax,%r12,4), %ecx
	xorl	%eax, %eax
	incq	%r12
	call	__fprintf_chk@PLT
	jmp	.L69
.L72:
	leaq	.LC1(%rip), %rdx
	movq	%rbp, %rdi
	xorl	%eax, %eax
	incq	%r13
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L66
.L68:
	movq	%rbp, %rdi
	call	fclose@PLT
	incl	_ZZ12salvarMatrizP7_matrizE1i(%rip)
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L70
	call	__stack_chk_fail@PLT
.L70:
	addq	$120, %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
.LFE2033:
	.size	_Z12salvarMatrizP7_matriz, .-_Z12salvarMatrizP7_matriz
	.globl	_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E
	.type	_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E, @function
_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rcx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	xorl	%edi, %edi
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rsi
	call	clock_gettime@PLT
	movq	%r13, %rsi
	movl	%r12d, %edi
	call	*%rbp
	leaq	24(%rsp), %rsi
	xorl	%edi, %edi
	movq	%rax, (%rbx)
	call	clock_gettime@PLT
	cvtsi2sdq	32(%rsp), %xmm0
	movsd	.LC8(%rip), %xmm2
	cvtsi2sdq	24(%rsp), %xmm1
	divsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvtsi2sdq	16(%rsp), %xmm1
	divsd	%xmm2, %xmm1
	cvtsi2sdq	8(%rsp), %xmm2
	addsd	%xmm2, %xmm1
	subsd	%xmm1, %xmm0
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L74
	call	__stack_chk_fail@PLT
.L74:
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2035:
	.size	_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E, .-_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E
	.globl	_Z17medirTempoExecMulP6_input
	.type	_Z17medirTempoExecMulP6_input, @function
_Z17medirTempoExecMulP6_input:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	xorl	%edi, %edi
	subq	$48, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rsi
	call	clock_gettime@PLT
	movq	16(%rbx), %rdx
	movq	8(%rbx), %rsi
	movq	(%rbx), %rdi
	call	_Z19multiplicarMatrizesP7_matrizS0_S0_
	leaq	24(%rsp), %rsi
	xorl	%edi, %edi
	call	clock_gettime@PLT
	cvtsi2sdq	32(%rsp), %xmm0
	movsd	.LC8(%rip), %xmm2
	cvtsi2sdq	24(%rsp), %xmm1
	divsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvtsi2sdq	16(%rsp), %xmm1
	divsd	%xmm2, %xmm1
	cvtsi2sdq	8(%rsp), %xmm2
	addsd	%xmm2, %xmm1
	subsd	%xmm1, %xmm0
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L77
	call	__stack_chk_fail@PLT
.L77:
	addq	$48, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z17medirTempoExecMulP6_input, .-_Z17medirTempoExecMulP6_input
	.globl	_Z22salvarELiberarMatrizesP6_input
	.type	_Z22salvarELiberarMatrizesP6_input, @function
_Z22salvarELiberarMatrizesP6_input:
.LFB2037:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	cmpw	$0, 24(%rdi)
	movq	%rdi, %rbx
	je	.L80
	movq	(%rdi), %rdi
	call	_Z12salvarMatrizP7_matriz
	movq	8(%rbx), %rdi
	call	_Z12salvarMatrizP7_matriz
.L80:
	movq	16(%rbx), %rdi
	call	_Z12salvarMatrizP7_matriz
	movq	(%rbx), %rdi
	call	_Z13liberarMatrizP7_matriz
	movq	8(%rbx), %rdi
	call	_Z13liberarMatrizP7_matriz
	movq	16(%rbx), %rdi
	call	_Z13liberarMatrizP7_matriz
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	free@PLT
	.cfi_endproc
.LFE2037:
	.size	_Z22salvarELiberarMatrizesP6_input, .-_Z22salvarELiberarMatrizesP6_input
	.section	.rodata.str1.1
.LC9:
	.ascii	"Not enough arguments\n#  SOURCE: f for files, g for generati"
	.ascii	"on\n#  LINSA: m"
	.string	"atrix A lines\n#  COLSA: matrix A columns\n#  LINSB: matrix B lines\n#  COLSB: matrix B columns\n#  FILEA: matrix A file\n#  FILEB: matrix B file\n#  SAV (opcional): saves generated matrices A and B##  ./bin f LA CA LB CB FILEA FILEB\n##  ./bin g LA CA LB CB SAV\n"
.LC10:
	.string	"Invalid source argument, try using g or f\n"
.LC11:
	.string	"%d"
.LC12:
	.string	"%d is not a number, type matrices A and B dimensions\n"
.LC13:
	.string	"Add 's' to save matrices A and B\n"
.LC14:
	.string	"Matrix A file does not exist\n"
.LC15:
	.string	"Matrix B file does not exist\n"
	.text
	.globl	_Z19verificarArgumentosiPPc
	.type	_Z19verificarArgumentosiPPc, @function
_Z19verificarArgumentosiPPc:
.LFB2038:
	.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
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	cmpl	$5, %edi
	jg	.L83
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	jmp	.L99
.L83:
	movq	8(%rsi), %rax
	movq	%rsi, %rbx
	movl	%edi, %r12d
	movl	$2, %ebp
	leaq	.LC11(%rip), %r13
	leaq	.LC10(%rip), %rsi
	movb	(%rax), %al
	subl	$102, %eax
	cmpb	$1, %al
	ja	.L98
.L85:
	movq	(%rbx,%rbp,8), %rdi
	xorl	%eax, %eax
	leaq	4(%rsp), %rdx
	movq	%r13, %rsi
	call	__isoc23_sscanf@PLT
	testl	%eax, %eax
	jne	.L87
	leal	-1(%rbp), %edx
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L84
.L87:
	incq	%rbp
	cmpq	$6, %rbp
	jne	.L85
	movq	8(%rbx), %rax
	movb	(%rax), %al
	cmpb	$103, %al
	jne	.L88
	cmpl	$7, %r12d
	jne	.L89
	movq	48(%rbx), %rax
	leaq	.LC13(%rip), %rsi
	cmpb	$115, (%rax)
	je	.L89
	jmp	.L98
.L88:
	cmpb	$102, %al
	jne	.L89
	movq	48(%rbx), %rdi
	leaq	.LC2(%rip), %rbp
	movq	%rbp, %rsi
	call	fopen@PLT
	leaq	.LC14(%rip), %rsi
	movq	%rax, %rdi
	testq	%rax, %rax
	je	.L98
	call	fclose@PLT
	movq	56(%rbx), %rdi
	movq	%rbp, %rsi
	call	fopen@PLT
	movq	%rax, %rdi
	testq	%rax, %rax
	jne	.L91
	leaq	.LC15(%rip), %rsi
.L98:
	movl	$2, %edi
	xorl	%eax, %eax
.L99:
	call	__printf_chk@PLT
	jmp	.L84
.L91:
	call	fclose@PLT
.L89:
	movl	$1, %eax
	jmp	.L82
.L84:
	xorl	%eax, %eax
.L82:
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L93
	call	__stack_chk_fail@PLT
.L93:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2038:
	.size	_Z19verificarArgumentosiPPc, .-_Z19verificarArgumentosiPPc
	.section	.rodata.str1.1
.LC16:
	.string	"Creation time: %lf\n"
.LC17:
	.string	"Execution time: %lf\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2039:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	_Z19verificarArgumentosiPPc
	testl	%eax, %eax
	je	.L101
	leaq	_Z8lerInputiPPc(%rip), %rcx
	movq	%rbp, %rdx
	movl	%ebx, %esi
	movq	%rsp, %rdi
	call	_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	movq	(%rsp), %rbx
	movq	%rbx, %rdi
	call	_Z17medirTempoExecMulP6_input
	movl	$2, %edi
	leaq	.LC17(%rip), %rsi
	movb	$1, %al
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	_Z22salvarELiberarMatrizesP6_input
.L101:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L102
	call	__stack_chk_fail@PLT
.L102:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2039:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2065:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2065:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.local	_ZZ12salvarMatrizP7_matrizE1i
	.comm	_ZZ12salvarMatrizP7_matrizE1i,4,4
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC8:
	.long	0
	.long	1104006501
	.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 <time.h>

#define SEC_AS_NANO 1000000000.0

struct _matriz
{
	int n;
	int m;
	int **cont;
}; typedef struct _matriz Matriz;

Matriz *criarMatriz(int n, int m)
{
	Matriz *mat = (Matriz*) malloc(sizeof(Matriz));

	mat->n = n;
	mat->m = m;
	mat->cont = (int**) malloc(n * sizeof(int*));
	for(int i = 0; i < n; i++)
		mat->cont[i] = (int*) malloc(m * sizeof(int));

	return mat;
}

void liberarMatriz(Matriz *m)
{
	for(int i = 0; i < m->n; i++)
		free(m->cont[i]);
	free(m->cont);
	free(m);
}

Matriz *gerarMatriz(int n, int m)
{
	Matriz *mat = criarMatriz(n, m);
	
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			{
				mat->cont[i][j] = rand() % 100;
			}

	return mat;
}

void printarMatriz(Matriz *mat)
{
	for(int i = 0; i < mat->n; i++)
	{
		for(int j = 0; j < mat->m; j++)
			printf("%d ", mat->cont[i][j]);
		printf("\n");
	}
}

void multiplicarMatrizes(Matriz *a, Matriz *b, Matriz *c)
{
	for(int i = 0; i < a->n; i++)
		for(int j = 0; j < b->m; j++)
		{
			c->cont[i][j] = 0;
			for(int k = 0; k < a->m; k++)
				c->cont[i][j] += a->cont[i][k] * b->cont[k][j];
		}
}

Matriz *lerMatriz(char *nome, int n, int m)
{
	Matriz *mat = criarMatriz(n, m);

	FILE *f = fopen(nome, "r");

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			fscanf(f, " %d", &(mat->cont[i][j]));

	fclose(f);

	return mat;
}

void salvarMatriz(Matriz *mat)
{
	static int i = 0;

	char nome[100];
	sprintf(nome, "%d-%dx%d.txt", i, mat->n, mat->m);

	FILE *f = fopen(nome, "w");

	for(int i = 0; i < mat->n; i++)
	{
		for(int j = 0; j < mat->m; j++)
			fprintf(f, "%d ", mat->cont[i][j]);
		fprintf(f, "\n");
	}

	fclose(f);
	i++;
}

struct _input
{
	Matriz *a;
	Matriz *b;
	Matriz *c;
	short int salvar;
}; typedef struct _input Input;

Input *lerInput(int argc, char **argv)
{
	if(argc >= 6)
	{
		Input *i = (Input *) malloc(sizeof(Input));
		i->salvar = 0;

		int n1, m1, n2, m2;
		char op;

		op = argv[1][0];
		
		sscanf(argv[2], " %d", &n1);
		sscanf(argv[3], " %d", &m1);
		sscanf(argv[4], " %d", &n2);
		sscanf(argv[5], " %d", &m2);
	
		if(m1 == n2)
		{
			Matriz *a, *b, *c;		
			
			switch(op)
			{
				case 'g':
					srand(time(NULL));
					a = gerarMatriz(n1, m1);
					b = gerarMatriz(n2, m2);
					if(argc == 7 && argv[6][0] == 's')
						i->salvar = 1;
					break;
				case 'f':
					a = lerMatriz(argv[6], n1, m1);
					b = lerMatriz(argv[7], n2, m2);
					break;
				default:
					return 0;
			}
			c = criarMatriz(n1, m2);

			i->a = a;
			i->b = b;
			i->c = c;

			return i;
		}
		else
			printf("Incompatible Matrices!\n");
	}
	else
		printf("Invalid arguments!\n");

	return NULL;
}

double medirTempoInput(Input **i, int argc, char **argv, Input *ler(int, char**))
{
	timespec ini, fim;
	clock_gettime(CLOCK_REALTIME, &ini);
	*i = ler(argc, argv);
	clock_gettime(CLOCK_REALTIME, &fim);

	double iniSec = ini.tv_sec + ini.tv_nsec / SEC_AS_NANO;
	double fimSec = fim.tv_sec + fim.tv_nsec / SEC_AS_NANO;	

	return (fimSec - iniSec);
}

double medirTempoExecMul(Input *i)
{
	timespec ini, fim;
	clock_gettime(CLOCK_REALTIME, &ini);
	multiplicarMatrizes(i->a, i->b, i->c);
	clock_gettime(CLOCK_REALTIME, &fim);

	double iniSec = ini.tv_sec + ini.tv_nsec / SEC_AS_NANO;
	double fimSec = fim.tv_sec + fim.tv_nsec / SEC_AS_NANO;	

	return (fimSec - iniSec);
}

void salvarELiberarMatrizes(Input *i)
{	
	if(i->salvar)
	{
		salvarMatriz(i->a);
		salvarMatriz(i->b);
	}
	salvarMatriz(i->c);

	liberarMatriz(i->a);
	liberarMatriz(i->b);
	liberarMatriz(i->c);
	free(i);
}

int verificarArgumentos(int argc, char **argv)
{
	if(argc < 6)
	{
		printf("Not enough arguments\n"
			"#  SOURCE: f for files, g for generation\n"
			"#  LINSA: matrix A lines\n"
			"#  COLSA: matrix A columns\n"
			"#  LINSB: matrix B lines\n"
			"#  COLSB: matrix B columns\n"
			"#  FILEA: matrix A file\n"
			"#  FILEB: matrix B file\n"
			"#  SAV (opcional): saves generated matrices A and B"
			"##  ./bin f LA CA LB CB FILEA FILEB\n"
			"##  ./bin g LA CA LB CB SAV\n");
		return 0;
	}
	else
	{
		if(argv[1][0] != 'f' && argv[1][0] != 'g')
		{
			printf("Invalid source argument, try using g or f\n");
			return 0;
		}

		int aux;
		for(int i = 2; i < 6; i++)
			if(!sscanf(argv[i], "%d", &aux))
			{
				printf("%d is not a number, type matrices A and B dimensions\n", (i - 1));
				return 0;
			}

		if(argv[1][0] == 'g')
			if(argc == 7)
				if(argv[6][0] != 's')
				{
					printf("Add 's' to save matrices A and B\n");
					return 0;
				}

		if(argv[1][0] == 'f')
		{
			FILE *f;
			if((f = fopen(argv[6], "r")) == NULL)
			{
				printf("Matrix A file does not exist\n");
				return 0;
			}
			else
				fclose(f);
			if((f = fopen(argv[7], "r")) == NULL)
			{
				printf("Matrix B file does not exist\n");
				return 0;
			}
			else
				fclose(f);
		}
		
	}

	return 1;
}

int main(int argc, char ** argv)
{
	if(verificarArgumentos(argc, argv))
	{
		Input *i;
		printf("Creation time: %lf\n", medirTempoInput(&i, argc, argv, &lerInput));
		printf("Execution time: %lf\n", medirTempoExecMul(i));
		salvarELiberarMatrizes(i);
	}

	return 0;
}

	.text
	.file	"matrix.hip"
	.globl	_Z11criarMatrizii               # -- Begin function _Z11criarMatrizii
	.type	_Z11criarMatrizii,@function
_Z11criarMatrizii:                      # @_Z11criarMatrizii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %r15d
	movl	%edi, %ebp
	movl	$16, %edi
	callq	malloc
	movq	%rax, %rbx
	movl	%ebp, (%rax)
	movl	%r15d, 4(%rax)
	movslq	%ebp, %r12
	leaq	(,%r12,8), %rdi
	callq	malloc
	movq	%rax, 8(%rbx)
	testl	%r12d, %r12d
	jle	.LBB0_3
# %bb.1:                                # %.lr.ph
	movq	%rax, %r14
	movslq	%r15d, %r15
	shlq	$2, %r15
	movl	%ebp, %r12d
	xorl	%r13d, %r13d
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, (%r14,%r13,8)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB0_2
.LBB0_3:                                # %._crit_edge
	movq	%rbx, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z11criarMatrizii, .Lfunc_end0-_Z11criarMatrizii
	.cfi_endproc
                                        # -- End function
	.globl	_Z13liberarMatrizP7_matriz      # -- Begin function _Z13liberarMatrizP7_matriz
	.type	_Z13liberarMatrizP7_matriz,@function
_Z13liberarMatrizP7_matriz:             # @_Z13liberarMatrizP7_matriz
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	cmpl	$0, (%rdi)
	jle	.LBB1_3
# %bb.1:                                # %.lr.ph
	xorl	%r14d, %r14d
.LBB1_2:                                # =>This Inner Loop Header: Depth=1
	movq	8(%rbx), %rax
	movq	(%rax,%r14,8), %rdi
	callq	free
	incq	%r14
	movslq	(%rbx), %rax
	cmpq	%rax, %r14
	jl	.LBB1_2
.LBB1_3:                                # %._crit_edge
	movq	8(%rbx), %rdi
	callq	free
	movq	%rbx, %rdi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	free                            # TAILCALL
.Lfunc_end1:
	.size	_Z13liberarMatrizP7_matriz, .Lfunc_end1-_Z13liberarMatrizP7_matriz
	.cfi_endproc
                                        # -- End function
	.globl	_Z11gerarMatrizii               # -- Begin function _Z11gerarMatrizii
	.type	_Z11gerarMatrizii,@function
_Z11gerarMatrizii:                      # @_Z11gerarMatrizii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebx
	movl	%edi, %ebp
	callq	_Z11criarMatrizii
	movq	%rax, %r14
	testl	%ebp, %ebp
	jle	.LBB2_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebp, %r15d
	movl	%ebx, %r12d
	xorl	%r13d, %r13d
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB2_5
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB2_2 Depth=1
	xorl	%ebp, %ebp
.LBB2_4:                                # %.lr.ph
                                        #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	subl	%ecx, %eax
	movq	8(%r14), %rcx
	movq	(%rcx,%r13,8), %rcx
	movl	%eax, (%rcx,%rbp,4)
	incq	%rbp
	cmpq	%rbp, %r12
	jne	.LBB2_4
.LBB2_5:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r13
	cmpq	%r15, %r13
	jne	.LBB2_2
.LBB2_6:                                # %._crit_edge14
	movq	%r14, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z11gerarMatrizii, .Lfunc_end2-_Z11gerarMatrizii
	.cfi_endproc
                                        # -- End function
	.globl	_Z13printarMatrizP7_matriz      # -- Begin function _Z13printarMatrizP7_matriz
	.type	_Z13printarMatrizP7_matriz,@function
_Z13printarMatrizP7_matriz:             # @_Z13printarMatrizP7_matriz
	.cfi_startproc
# %bb.0:
	cmpl	$0, (%rdi)
	jle	.LBB3_7
# %bb.1:                                # %.preheader.lr.ph
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	xorl	%r14d, %r14d
.LBB3_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
	cmpl	$0, 4(%rbx)
	jle	.LBB3_5
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB3_2 Depth=1
	xorl	%r15d, %r15d
.LBB3_4:                                # %.lr.ph
                                        #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	8(%rbx), %rax
	movq	(%rax,%r14,8), %rax
	movl	(%rax,%r15,4), %esi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	movslq	4(%rbx), %rax
	cmpq	%rax, %r15
	jl	.LBB3_4
.LBB3_5:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r14
	movslq	(%rbx), %rax
	cmpq	%rax, %r14
	jl	.LBB3_2
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB3_7:                                # %._crit_edge11
	retq
.Lfunc_end3:
	.size	_Z13printarMatrizP7_matriz, .Lfunc_end3-_Z13printarMatrizP7_matriz
	.cfi_endproc
                                        # -- End function
	.globl	_Z19multiplicarMatrizesP7_matrizS0_S0_ # -- Begin function _Z19multiplicarMatrizesP7_matrizS0_S0_
	.type	_Z19multiplicarMatrizesP7_matrizS0_S0_,@function
_Z19multiplicarMatrizesP7_matrizS0_S0_: # @_Z19multiplicarMatrizesP7_matrizS0_S0_
	.cfi_startproc
# %bb.0:
	movl	(%rdi), %ecx
	testl	%ecx, %ecx
	jle	.LBB4_11
# %bb.1:                                # %.preheader.lr.ph
	pushq	%rbp
	.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 %rbp, -16
	movl	4(%rsi), %r9d
	xorl	%eax, %eax
.LBB4_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_4 Depth 2
                                        #       Child Loop BB4_6 Depth 3
	testl	%r9d, %r9d
	jle	.LBB4_9
# %bb.3:                                # %.lr.ph24
                                        #   in Loop: Header=BB4_2 Depth=1
	movq	8(%rdx), %rcx
	movq	(%rcx,%rax,8), %rcx
	xorl	%r8d, %r8d
.LBB4_4:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB4_6 Depth 3
	movl	$0, (%rcx,%r8,4)
	cmpl	$0, 4(%rdi)
	jle	.LBB4_7
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB4_4 Depth=2
	movq	8(%rdi), %r9
	movq	(%r9,%rax,8), %r9
	movq	8(%rsi), %r10
	xorl	%r11d, %r11d
	xorl	%ebx, %ebx
.LBB4_6:                                #   Parent Loop BB4_2 Depth=1
                                        #     Parent Loop BB4_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movq	(%r10,%rbx,8), %r14
	movl	(%r14,%r8,4), %ebp
	imull	(%r9,%rbx,4), %ebp
	addl	%ebp, %r11d
	movl	%r11d, (%rcx,%r8,4)
	incq	%rbx
	movslq	4(%rdi), %r14
	cmpq	%r14, %rbx
	jl	.LBB4_6
.LBB4_7:                                # %._crit_edge
                                        #   in Loop: Header=BB4_4 Depth=2
	incq	%r8
	movslq	4(%rsi), %r9
	cmpq	%r9, %r8
	jl	.LBB4_4
# %bb.8:                                # %._crit_edge25.loopexit
                                        #   in Loop: Header=BB4_2 Depth=1
	movl	(%rdi), %ecx
.LBB4_9:                                # %._crit_edge25
                                        #   in Loop: Header=BB4_2 Depth=1
	incq	%rax
	movslq	%ecx, %r8
	cmpq	%r8, %rax
	jl	.LBB4_2
# %bb.10:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %rbp
.LBB4_11:                               # %._crit_edge27
	retq
.Lfunc_end4:
	.size	_Z19multiplicarMatrizesP7_matrizS0_S0_, .Lfunc_end4-_Z19multiplicarMatrizesP7_matrizS0_S0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z9lerMatrizPcii                # -- Begin function _Z9lerMatrizPcii
	.type	_Z9lerMatrizPcii,@function
_Z9lerMatrizPcii:                       # @_Z9lerMatrizPcii
	.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	%esi, %ebp
	movq	%rdi, %r15
	movl	%esi, %edi
	movl	%edx, 12(%rsp)                  # 4-byte Spill
	movl	%edx, %esi
	callq	_Z11criarMatrizii
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	$.L.str.2, %esi
	movq	%r15, %rdi
	callq	fopen
	movq	%rax, %r15
	testl	%ebp, %ebp
	jle	.LBB5_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebp, %r12d
	movl	12(%rsp), %r13d                 # 4-byte Reload
	shlq	$2, %r13
	xorl	%ebp, %ebp
.LBB5_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_4 Depth 2
	cmpl	$0, 12(%rsp)                    # 4-byte Folded Reload
	jle	.LBB5_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB5_2 Depth=1
	movq	16(%rsp), %rax                  # 8-byte Reload
	movq	8(%rax), %r14
	xorl	%ebx, %ebx
.LBB5_4:                                #   Parent Loop BB5_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	(%r14,%rbp,8), %rdx
	addq	%rbx, %rdx
	movl	$.L.str.3, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %rbx
	cmpq	%rbx, %r13
	jne	.LBB5_4
.LBB5_5:                                # %._crit_edge
                                        #   in Loop: Header=BB5_2 Depth=1
	incq	%rbp
	cmpq	%r12, %rbp
	jne	.LBB5_2
.LBB5_6:                                # %._crit_edge17
	movq	%r15, %rdi
	callq	fclose
	movq	16(%rsp), %rax                  # 8-byte Reload
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z9lerMatrizPcii, .Lfunc_end5-_Z9lerMatrizPcii
	.cfi_endproc
                                        # -- End function
	.globl	_Z12salvarMatrizP7_matriz       # -- Begin function _Z12salvarMatrizP7_matriz
	.type	_Z12salvarMatrizP7_matriz,@function
_Z12salvarMatrizP7_matriz:              # @_Z12salvarMatrizP7_matriz
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$104, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	_ZZ12salvarMatrizP7_matrizE1i(%rip), %edx
	movl	(%rdi), %ecx
	movl	4(%rdi), %r8d
	movq	%rsp, %r14
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	sprintf
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	callq	fopen
	movq	%rax, %r14
	cmpl	$0, (%rbx)
	jle	.LBB6_6
# %bb.1:                                # %.preheader.lr.ph
	xorl	%r15d, %r15d
.LBB6_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_4 Depth 2
	cmpl	$0, 4(%rbx)
	jle	.LBB6_5
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB6_2 Depth=1
	xorl	%r12d, %r12d
.LBB6_4:                                # %.lr.ph
                                        #   Parent Loop BB6_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	8(%rbx), %rax
	movq	(%rax,%r15,8), %rax
	movl	(%rax,%r12,4), %edx
	movl	$.L.str, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r12
	movslq	4(%rbx), %rax
	cmpq	%rax, %r12
	jl	.LBB6_4
.LBB6_5:                                # %._crit_edge
                                        #   in Loop: Header=BB6_2 Depth=1
	movl	$10, %edi
	movq	%r14, %rsi
	callq	fputc@PLT
	incq	%r15
	movslq	(%rbx), %rax
	cmpq	%rax, %r15
	jl	.LBB6_2
.LBB6_6:                                # %._crit_edge16
	movq	%r14, %rdi
	callq	fclose
	incl	_ZZ12salvarMatrizP7_matrizE1i(%rip)
	addq	$104, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z12salvarMatrizP7_matriz, .Lfunc_end6-_Z12salvarMatrizP7_matriz
	.cfi_endproc
                                        # -- End function
	.globl	_Z8lerInputiPPc                 # -- Begin function _Z8lerInputiPPc
	.type	_Z8lerInputiPPc,@function
_Z8lerInputiPPc:                        # @_Z8lerInputiPPc
	.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
	cmpl	$6, %edi
	jl	.LBB7_10
# %bb.1:
	movq	%rsi, %r14
	movl	%edi, %ebp
	movl	$32, %edi
	callq	malloc
	movq	%rax, %rbx
	movw	$0, 24(%rax)
	movq	8(%r14), %rax
	movq	16(%r14), %rdi
	movzbl	(%rax), %r13d
	leaq	12(%rsp), %rdx
	movl	$.L.str.3, %esi
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movq	24(%r14), %rdi
	leaq	20(%rsp), %r15
	movl	$.L.str.3, %esi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movq	32(%r14), %rdi
	leaq	16(%rsp), %r12
	movl	$.L.str.3, %esi
	movq	%r12, %rdx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movq	40(%r14), %rdi
	leaq	8(%rsp), %rdx
	movl	$.L.str.3, %esi
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movl	(%r15), %edx
	cmpl	(%r12), %edx
	jne	.LBB7_9
# %bb.2:
	cmpl	$102, %r13d
	je	.LBB7_7
# %bb.3:
	cmpl	$103, %r13d
	jne	.LBB7_12
# %bb.4:
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movl	12(%rsp), %edi
	movl	20(%rsp), %esi
	callq	_Z11gerarMatrizii
	movq	%rax, %r15
	movl	16(%rsp), %edi
	movl	8(%rsp), %esi
	callq	_Z11gerarMatrizii
	movq	%rax, %r12
	cmpl	$7, %ebp
	jne	.LBB7_8
# %bb.5:
	movq	48(%r14), %rax
	cmpb	$115, (%rax)
	jne	.LBB7_8
# %bb.6:
	movw	$1, 24(%rbx)
	jmp	.LBB7_8
.LBB7_10:
	movl	$.Lstr, %edi
	jmp	.LBB7_11
.LBB7_9:
	movl	$.Lstr.1, %edi
.LBB7_11:
	callq	puts@PLT
.LBB7_12:
	xorl	%ebx, %ebx
.LBB7_13:
	movq	%rbx, %rax
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB7_7:
	.cfi_def_cfa_offset 80
	movq	48(%r14), %rdi
	movl	12(%rsp), %esi
	callq	_Z9lerMatrizPcii
	movq	%rax, %r15
	movq	56(%r14), %rdi
	movl	16(%rsp), %esi
	movl	8(%rsp), %edx
	callq	_Z9lerMatrizPcii
	movq	%rax, %r12
.LBB7_8:
	movl	12(%rsp), %edi
	movl	8(%rsp), %esi
	callq	_Z11criarMatrizii
	movq	%r15, (%rbx)
	movq	%r12, 8(%rbx)
	movq	%rax, 16(%rbx)
	jmp	.LBB7_13
.Lfunc_end7:
	.size	_Z8lerInputiPPc, .Lfunc_end7-_Z8lerInputiPPc
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E
.LCPI8_0:
	.quad	0x41cdcd6500000000              # double 1.0E+9
	.text
	.globl	_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E
	.type	_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E,@function
_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E: # @_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E
	.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
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, %rbx
	movq	%rdx, %r14
	movl	%esi, %ebp
	movq	%rdi, %r15
	leaq	16(%rsp), %r12
	xorl	%edi, %edi
	movq	%r12, %rsi
	callq	clock_gettime
	movl	%ebp, %edi
	movq	%r14, %rsi
	callq	*%rbx
	movq	%rax, (%r15)
	movq	%rsp, %rbx
	xorl	%edi, %edi
	movq	%rbx, %rsi
	callq	clock_gettime
	cvtsi2sdq	(%r12), %xmm0
	cvtsi2sdq	8(%r12), %xmm1
	movsd	.LCPI8_0(%rip), %xmm2           # xmm2 = mem[0],zero
	divsd	%xmm2, %xmm1
	addsd	%xmm0, %xmm1
	cvtsi2sdq	(%rbx), %xmm3
	xorps	%xmm0, %xmm0
	cvtsi2sdq	8(%rbx), %xmm0
	divsd	%xmm2, %xmm0
	addsd	%xmm3, %xmm0
	subsd	%xmm1, %xmm0
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	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_end8:
	.size	_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E, .Lfunc_end8-_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z17medirTempoExecMulP6_input
.LCPI9_0:
	.quad	0x41cdcd6500000000              # double 1.0E+9
	.text
	.globl	_Z17medirTempoExecMulP6_input
	.type	_Z17medirTempoExecMulP6_input,@function
_Z17medirTempoExecMulP6_input:          # @_Z17medirTempoExecMulP6_input
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$40, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	leaq	24(%rsp), %r14
	xorl	%edi, %edi
	movq	%r14, %rsi
	callq	clock_gettime
	movq	(%rbx), %rdi
	movq	8(%rbx), %rsi
	movq	16(%rbx), %rdx
	callq	_Z19multiplicarMatrizesP7_matrizS0_S0_
	leaq	8(%rsp), %rbx
	xorl	%edi, %edi
	movq	%rbx, %rsi
	callq	clock_gettime
	cvtsi2sdq	(%r14), %xmm0
	cvtsi2sdq	8(%r14), %xmm1
	movsd	.LCPI9_0(%rip), %xmm2           # xmm2 = mem[0],zero
	divsd	%xmm2, %xmm1
	addsd	%xmm0, %xmm1
	cvtsi2sdq	(%rbx), %xmm3
	xorps	%xmm0, %xmm0
	cvtsi2sdq	8(%rbx), %xmm0
	divsd	%xmm2, %xmm0
	addsd	%xmm3, %xmm0
	subsd	%xmm1, %xmm0
	addq	$40, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end9:
	.size	_Z17medirTempoExecMulP6_input, .Lfunc_end9-_Z17medirTempoExecMulP6_input
	.cfi_endproc
                                        # -- End function
	.globl	_Z22salvarELiberarMatrizesP6_input # -- Begin function _Z22salvarELiberarMatrizesP6_input
	.type	_Z22salvarELiberarMatrizesP6_input,@function
_Z22salvarELiberarMatrizesP6_input:     # @_Z22salvarELiberarMatrizesP6_input
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	cmpw	$0, 24(%rdi)
	je	.LBB10_2
# %bb.1:
	movq	(%rbx), %rdi
	callq	_Z12salvarMatrizP7_matriz
	movq	8(%rbx), %rdi
	callq	_Z12salvarMatrizP7_matriz
.LBB10_2:
	movq	16(%rbx), %rdi
	callq	_Z12salvarMatrizP7_matriz
	movq	(%rbx), %rdi
	callq	_Z13liberarMatrizP7_matriz
	movq	8(%rbx), %rdi
	callq	_Z13liberarMatrizP7_matriz
	movq	16(%rbx), %rdi
	callq	_Z13liberarMatrizP7_matriz
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	free                            # TAILCALL
.Lfunc_end10:
	.size	_Z22salvarELiberarMatrizesP6_input, .Lfunc_end10-_Z22salvarELiberarMatrizesP6_input
	.cfi_endproc
                                        # -- End function
	.globl	_Z19verificarArgumentosiPPc     # -- Begin function _Z19verificarArgumentosiPPc
	.type	_Z19verificarArgumentosiPPc,@function
_Z19verificarArgumentosiPPc:            # @_Z19verificarArgumentosiPPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$5, %edi
	jg	.LBB11_2
# %bb.1:
	movl	$.Lstr.6, %edi
	jmp	.LBB11_17
.LBB11_2:
	movq	%rsi, %rbx
	movq	8(%rsi), %rax
	movb	(%rax), %al
	andb	$-2, %al
	cmpb	$102, %al
	jne	.LBB11_3
# %bb.4:
	movl	%edi, %ebp
	leaq	4(%rsp), %r15
	xorl	%r14d, %r14d
.LBB11_5:                               # =>This Inner Loop Header: Depth=1
	movq	16(%rbx,%r14,8), %rdi
	movl	$.L.str.10, %esi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	testl	%eax, %eax
	je	.LBB11_6
# %bb.7:                                #   in Loop: Header=BB11_5 Depth=1
	incq	%r14
	cmpq	$4, %r14
	jne	.LBB11_5
# %bb.8:                                # %.critedge
	movq	8(%rbx), %rax
	movb	(%rax), %al
	cmpl	$7, %ebp
	jne	.LBB11_12
# %bb.9:                                # %.critedge
	cmpb	$103, %al
	jne	.LBB11_12
# %bb.10:
	movq	48(%rbx), %rax
	cmpb	$115, (%rax)
	je	.LBB11_20
# %bb.11:
	movl	$.Lstr.4, %edi
	jmp	.LBB11_17
.LBB11_3:
	movl	$.Lstr.5, %edi
.LBB11_17:                              # %.critedge37.thread
	callq	puts@PLT
.LBB11_18:                              # %.critedge37.thread
	xorl	%eax, %eax
.LBB11_21:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB11_6:
	.cfi_def_cfa_offset 48
	incl	%r14d
	movl	$.L.str.11, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB11_18
.LBB11_12:
	cmpb	$102, %al
	jne	.LBB11_20
# %bb.13:
	movq	48(%rbx), %rdi
	movl	$.L.str.2, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB11_14
# %bb.15:
	movq	%rax, %rdi
	callq	fclose
	movq	56(%rbx), %rdi
	movl	$.L.str.2, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB11_16
# %bb.19:
	movq	%rax, %rdi
	callq	fclose
.LBB11_20:                              # %.thread
	movl	$1, %eax
	jmp	.LBB11_21
.LBB11_14:
	movl	$.Lstr.3, %edi
	jmp	.LBB11_17
.LBB11_16:
	movl	$.Lstr.2, %edi
	jmp	.LBB11_17
.Lfunc_end11:
	.size	_Z19verificarArgumentosiPPc, .Lfunc_end11-_Z19verificarArgumentosiPPc
	.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	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	callq	_Z19verificarArgumentosiPPc
	testl	%eax, %eax
	je	.LBB12_2
# %bb.1:
	leaq	8(%rsp), %r14
	movl	$_Z8lerInputiPPc, %ecx
	movq	%r14, %rdi
	movl	%ebp, %esi
	movq	%rbx, %rdx
	callq	_Z15medirTempoInputPP6_inputiPPcPFS0_iS3_E
	movl	$.L.str.15, %edi
	movb	$1, %al
	callq	printf
	movq	(%r14), %rbx
	movq	%rbx, %rdi
	callq	_Z17medirTempoExecMulP6_input
	movl	$.L.str.16, %edi
	movb	$1, %al
	callq	printf
	movq	%rbx, %rdi
	callq	_Z22salvarELiberarMatrizesP6_input
.LBB12_2:
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end12:
	.size	main, .Lfunc_end12-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%d "
	.size	.L.str, 4

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

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

	.type	_ZZ12salvarMatrizP7_matrizE1i,@object # @_ZZ12salvarMatrizP7_matrizE1i
	.local	_ZZ12salvarMatrizP7_matrizE1i
	.comm	_ZZ12salvarMatrizP7_matrizE1i,4,4
	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%d-%dx%d.txt"
	.size	.L.str.4, 13

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

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

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"%d is not a number, type matrices A and B dimensions\n"
	.size	.L.str.11, 54

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Creation time: %lf\n"
	.size	.L.str.15, 20

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"Execution time: %lf\n"
	.size	.L.str.16, 21

	.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	"Invalid arguments!"
	.size	.Lstr, 19

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Incompatible Matrices!"
	.size	.Lstr.1, 23

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Matrix B file does not exist"
	.size	.Lstr.2, 29

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Matrix A file does not exist"
	.size	.Lstr.3, 29

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Add 's' to save matrices A and B"
	.size	.Lstr.4, 33

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"Invalid source argument, try using g or f"
	.size	.Lstr.5, 42

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"Not enough arguments\n#  SOURCE: f for files, g for generation\n#  LINSA: matrix A lines\n#  COLSA: matrix A columns\n#  LINSB: matrix B lines\n#  COLSB: matrix B columns\n#  FILEA: matrix A file\n#  FILEB: matrix B file\n#  SAV (opcional): saves generated matrices A and B##  ./bin f LA CA LB CB FILEA FILEB\n##  ./bin g LA CA LB CB SAV"
	.size	.Lstr.6, 329

	.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 _Z8lerInputiPPc
	.addrsig_sym __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
