// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
testl %ecx, %ecx
jle 0x3768
movl %ecx, %ebp
movslq %edx, %r15
leaq (,%r15,8), %rdi
movl %edx, 0x4(%rsp)
movq %rsi, 0x10(%rsp)
callq 0x21d0
movq %rax, %r14
movl %ebp, %eax
imull 0x4(%rsp), %eax
movslq %eax, %rdi
callq 0x21d0
movq 0x10(%rsp), %r8
movl 0x4(%rsp), %r11d
movl %ebp, %ebx
movq %r14, %rbp
movl %r11d, %r10d
movq %r15, 0x40(%rsp)
testl %r15d, %r15d
jle 0x3618
xorl %r9d, %r9d
movq %rax, %rcx
movq %r9, %rdx
imulq %rbx, %rdx
addq %rax, %rdx
movq %rdx, (%rbp,%r9,8)
movq (%r8,%r9,8), %rdx
xorl %esi, %esi
movb (%rdx,%rsi), %dil
movb %dil, (%rcx,%rsi)
incq %rsi
cmpq %rsi, %rbx
jne 0x35fd
incq %r9
addq %rbx, %rcx
cmpq %r10, %r9
jne 0x35e8
movq %rax, 0x28(%rsp)
xorl %r13d, %r13d
movl $0x1, %eax
movq %rax, 0x18(%rsp)
leaq 0x159df(%rip), %r14     # 0x19010
xorl %eax, %eax
movq %rbp, 0x20(%rsp)
movq %r10, 0x30(%rsp)
movl %r11d, %edx
subl %eax, %edx
jle 0x366b
movslq %eax, %r15
leal 0x1(%rax), %edi
leaq (,%r15,8), %rcx
addq %rbp, %rcx
xorl %r12d, %r12d
movq (%rcx,%r12,8), %rsi
cmpb $0x0, (%rsi,%r13)
jne 0x3672
incq %r12
cmpl %r12d, %edx
jne 0x3658
movl %eax, %ecx
jmp 0x3753
movq %rdi, 0x8(%rsp)
testl %r12d, %r12d
je 0x368a
movq (%rbp,%r15,8), %rax
movq %rsi, (%rbp,%r15,8)
movq %rax, (%rcx,%r12,8)
movq (%rbp,%r15,8), %rbp
movzbl (%rbp,%r13), %edi
callq 0x2534
movq 0x8(%rsp), %rcx
addl %r12d, %ecx
movl 0x4(%rsp), %r11d
cmpl %r11d, %ecx
jge 0x3716
movl 0x8(%rsp), %edx
addq %r12, %rdx
movzbl %al, %eax
leaq 0x1(%r13), %rcx
movslq %edx, %rdx
shll $0x8, %eax
cmpq %rbx, %rcx
setae %r8b
movq 0x20(%rsp), %rsi
movq (%rsi,%rdx,8), %rsi
movzbl (%rsi,%r13), %edi
testq %rdi, %rdi
sete %r9b
orb %r8b, %r9b
jne 0x370c
leaq (%rax,%r14), %r8
movzbl (%rdi,%r8), %edi
shll $0x8, %edi
movq 0x18(%rsp), %r8
movzbl (%rbp,%r8), %r9d
leaq (%rdi,%r14), %r10
movb (%r9,%r10), %r9b
xorb %r9b, (%rsi,%r8)
incq %r8
cmpq %r8, %rbx
jne 0x36f2
incq %rdx
cmpq 0x40(%rsp), %rdx
jl 0x36c0
testl %r11d, %r11d
movq 0x10(%rsp), %rsi
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %r10
jle 0x3744
xorl %eax, %eax
movq (%rsi,%rax,8), %rcx
movb (%rcx,%r13), %cl
movq (%rdi,%rax,8), %rdx
movb %cl, (%rdx,%r15)
incq %rax
cmpq %rax, %r10
jne 0x372c
movq 0x8(%rsp), %rcx
cmpl %r11d, %ecx
movq 0x20(%rsp), %rbp
je 0x376c
incq %r13
incq 0x18(%rsp)
movl %ecx, %eax
cmpq %rbx, %r13
jne 0x363d
jmp 0x376f
xorl %eax, %eax
jmp 0x3787
movl %r11d, %ecx
movq %rcx, %rbx
movq 0x28(%rsp), %rdi
callq 0x2030
movq %rbp, %rdi
callq 0x2030
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq