// File: /workspace/github_c_makefile_star2_O1/cbouilla[P]AES-attacks-finder/Algebre.c
// Function: DimensionBorne_tmp
int DimensionBorne_tmp(unsigned char ** __restrict m, const int a, const int b, const int borne) // calcul le rang de la matrice mat de taille a x b, ie la dimension de l'espace engendré par les b vecteurs colonnes.
{
	//PrintMat(m,a,b);
	//getchar();
	int dim = 0;
	const int dim_max = min(a-1,borne);
	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++) // on cherche un pivot sur la colonne
		{
			if (m[new_pivot_l][pivot_c]) // on en a trouvé un
			{
				if (dim!=dim_max)
				{
					if (new_pivot_l!=dim) // on echange les lignes
					{
						unsigned char * __restrict const tmp = m[dim];
						m[dim]=m[new_pivot_l];
						m[new_pivot_l]=tmp;
					}
							
					const unsigned char * const __restrict ligne_pivot = m[dim];
					int ligne;
					for (ligne = new_pivot_l+1; ligne < a; ligne++) // on fait le pivot de Gauss
					{
						if (m[ligne][pivot_c])
						{
							unsigned char * __restrict ligne_need_update = m[ligne];
							const unsigned char coeff = Multiply(Inverse(ligne_pivot[pivot_c]),ligne_need_update[pivot_c]);
							int colonne;
							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]);
							}
						}
					}
					dim++;
					break;
				}
				else return dim+1;
			}
		}
	}
	return dim;	
}

// Assembly:
leal -0x1(%rsi), %eax
cmpl %ecx, %eax
cmovll %eax, %ecx
testl %edx, %edx
jle 0x3032
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r13
movslq %esi, %rax
movq %rax, 0x30(%rsp)
movl %edx, %ebp
xorl %ebx, %ebx
movl $0x1, %r11d
xorl %eax, %eax
movl %ecx, 0xc(%rsp)
movq %rsi, 0x20(%rsp)
movb $0x1, %r15b
movl %esi, %r9d
subl %eax, %r9d
jle 0x301c
movslq %eax, %r14
leaq (,%r14,8), %rdx
addq %r13, %rdx
xorl %r8d, %r8d
movq (%rdx,%r8,8), %rdi
cmpb $0x0, (%rdi,%rbx)
jne 0x2f53
incq %r8
cmpl %r8d, %r9d
jne 0x2f3c
jmp 0x301c
cmpl %ecx, %eax
jne 0x2f66
leal 0x1(%rax), %edx
movl %edx, 0x8(%rsp)
xorl %r15d, %r15d
jmp 0x301c
movq %r11, 0x18(%rsp)
testl %r8d, %r8d
je 0x2f7e
movq (%r13,%r14,8), %rcx
movq %rdi, (%r13,%r14,8)
movq %rcx, (%rdx,%r8,8)
movl %eax, %edx
incl %eax
movq %rax, 0x10(%rsp)
addl %r8d, %edx
incl %edx
cmpl %esi, %edx
jge 0x3006
addq 0x10(%rsp), %r8
movq (%r13,%r14,8), %r12
leaq 0x1(%rbx), %rax
movq %rax, 0x28(%rsp)
movslq %r8d, %r15
movq (%r13,%r15,8), %r14
cmpb $0x0, (%r14,%rbx)
je 0x2ffc
movzbl (%r12,%rbx), %edi
callq 0x2537
leaq 0x1604d(%rip), %rdi     # 0x19010
cmpq %rbp, 0x28(%rsp)
jae 0x2ffc
movzbl (%r14,%rbx), %ecx
movzbl %al, %eax
shll $0x8, %eax
addq %rdi, %rax
movzbl (%rcx,%rax), %eax
shll $0x8, %eax
movq 0x18(%rsp), %rcx
movzbl (%r12,%rcx), %edx
leaq (%rax,%rdi), %rsi
movb (%rdx,%rsi), %dl
xorb %dl, (%r14,%rcx)
incq %rcx
cmpq %rcx, %rbp
jne 0x2fe4
incq %r15
cmpq 0x30(%rsp), %r15
jl 0x2fa6
movl 0xc(%rsp), %ecx
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r11
movq 0x10(%rsp), %rax
movb $0x1, %r15b
testb %r15b, %r15b
je 0x3035
incq %rbx
incq %r11
cmpq %rbp, %rbx
jne 0x2f1c
jmp 0x3039
xorl %eax, %eax
retq
movl 0x8(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq