// File: /workspace/github_c_makefile_star2_O0/cbouilla[P]AES-attacks-finder/Algebre.c
// Function: Base
int Base(unsigned char ** __restrict dst, unsigned char ** __restrict const mat, const int a, const int b) // Met dans dst une famille libre contenue dans la liste de vecteurs mat. Renvoi le nombre de colone de dst.
{
	if (b>0)
	{
		unsigned char ** __restrict m=malloc(a*sizeof(unsigned char *));
		unsigned char * __restrict espace=malloc(a*b*sizeof(unsigned char));
		
		{
			int i;
			for (i = 0; i < a; i++)
			{
				m[i]=espace+i*b;
				int j;
				for (j = 0; j < b; j++) m[i][j]=mat[i][j];
			}
		}
		
		int dim = 0;
		int pivot_c;
		for (pivot_c = 0; pivot_c < b; pivot_c++)
		{
			int new_pivot_l;
			for (new_pivot_l = dim; new_pivot_l < a; new_pivot_l++)
			{
				if (m[new_pivot_l][pivot_c])
				{
					if (new_pivot_l!=dim)
					{
						unsigned char *tmp = m[dim];
						m[dim]=m[new_pivot_l];
						m[new_pivot_l]=tmp;
					}

					int ligne;
					unsigned char * __restrict ligne_pivot = m[dim];
					const unsigned char invp = Inverse(ligne_pivot[pivot_c]);
					for (ligne = new_pivot_l+1; ligne < a; ligne++) // on fait le pivot de Gauss
					{
						if (m[ligne][pivot_c])
						{
							int colonne;
							unsigned char * __restrict ligne_need_update = m[ligne];
							const unsigned char coeff = Multiply(invp,ligne_need_update[pivot_c]);
							for (colonne = pivot_c+1; colonne < b; colonne++)
							{
								//m[ligne][colonne]=Multiply(m[dim][pivot_c],m[ligne][colonne]) ^ Multiply(m[ligne][pivot_c],m[dim][colonne]);
								ligne_need_update[colonne]^=Multiply(coeff,ligne_pivot[colonne]);
							}
						}
					}
					for (ligne = 0; ligne < a; ligne++) dst[ligne][dim]=mat[ligne][pivot_c];
					dim++;
					if (dim != a) break;
					else
					{
						free(espace);
						free(m);
						return dim;
					}
				}
			}
		}
		free(espace);
		free(m);
		return dim;	
	}
	else return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x3eec
movslq -0x1c(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
movslq %eax, %rdi
shlq $0x0, %rdi
callq 0x21c0
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3cd3
movq -0x30(%rbp), %rdx
movl -0x34(%rbp), %eax
imull -0x20(%rbp), %eax
cltq
addq %rax, %rdx
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x3cc6
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x3c8d
jmp 0x3cc8
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3c62
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x3ed2
movl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3ec2
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x40(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3eb2
movl -0x44(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0x3d59
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x50(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movslq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %edi
callq 0x24c0
movb %al, -0x61(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3e45
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x40(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3e35
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
movzbl -0x61(%rbp), %eax
movl %eax, %ecx
leaq 0x21247(%rip), %rax     # 0x25010
shlq $0x8, %rcx
addq %rcx, %rax
movq -0x70(%rbp), %rcx
movslq -0x40(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movb (%rax,%rcx), %al
movb %al, -0x71(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x3e33
movzbl -0x71(%rbp), %eax
movl %eax, %ecx
leaq 0x21210(%rip), %rax     # 0x25010
shlq $0x8, %rcx
addq %rcx, %rax
movq -0x60(%rbp), %rcx
movslq -0x68(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movzbl (%rax,%rcx), %esi
movq -0x70(%rbp), %rax
movslq -0x68(%rbp), %rcx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x3deb
jmp 0x3e35
jmp 0x3e37
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x3d86
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3e85
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x40(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x3e4c
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
je 0x3e98
jmp 0x3ec2
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x28(%rbp), %rdi
callq 0x2030
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ef3
jmp 0x3eb4
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x3cf3
jmp 0x3ec4
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3ce1
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x28(%rbp), %rdi
callq 0x2030
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ef3
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop