// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, (%rsp)
leal -0x1(%rsi), %eax
cmpl %ecx, %eax
cmovll %eax, %ecx
testl %edx, %edx
jle 0x335d
movslq %esi, %rax
movq %rax, 0x30(%rsp)
movl %edx, %r13d
xorl %ebp, %ebp
movl $0x1, %r11d
leaq 0x15dba(%rip), %r14     # 0x19010
xorl %eax, %eax
movl %ecx, 0xc(%rsp)
movq %rsi, 0x18(%rsp)
movl %esi, %edi
subl %eax, %edi
jle 0x334c
movslq %eax, %r9
leal 0x1(%rax), %ebx
movq (%rsp), %rdx
leaq (%rdx,%r9,8), %r10
xorl %edx, %edx
movq (%r10,%rdx,8), %r8
cmpb $0x0, (%r8,%rbp)
jne 0x3292
incq %rdx
cmpl %edx, %edi
jne 0x327b
jmp 0x334c
cmpl %ecx, %eax
je 0x3361
testl %edx, %edx
je 0x32ae
movq (%rsp), %rdi
movq (%rdi,%r9,8), %rax
movq %r8, (%rdi,%r9,8)
movq %rax, (%r10,%rdx,8)
leal (%rbx,%rdx), %eax
cmpl %esi, %eax
jge 0x334a
movq %r11, 0x10(%rsp)
movq %rbx, 0x20(%rsp)
movl %ebx, %eax
addq %rdx, %rax
movq (%rsp), %rcx
movq (%rcx,%r9,8), %r12
leaq 0x1(%rbp), %rcx
movq %rcx, 0x28(%rsp)
movslq %eax, %r15
movq (%rsp), %rax
movq (%rax,%r15,8), %rbx
cmpb $0x0, (%rbx,%rbp)
je 0x332b
movzbl (%r12,%rbp), %edi
callq 0x2534
cmpq %r13, 0x28(%rsp)
jae 0x332b
movzbl (%rbx,%rbp), %ecx
movzbl %al, %eax
shll $0x8, %eax
addq %r14, %rax
movzbl (%rcx,%rax), %eax
shll $0x8, %eax
movq 0x10(%rsp), %rcx
movzbl (%r12,%rcx), %edx
leaq (%rax,%r14), %rsi
movb (%rdx,%rsi), %dl
xorb %dl, (%rbx,%rcx)
incq %rcx
cmpq %rcx, %r13
jne 0x3314
incq %r15
cmpq 0x30(%rsp), %r15
jl 0x32dc
movq 0x20(%rsp), %rax
movl 0xc(%rsp), %ecx
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %r11
jmp 0x334c
movl %ebx, %eax
incq %rbp
incq %r11
cmpq %r13, %rbp
jne 0x3261
jmp 0x3365
xorl %eax, %eax
jmp 0x3365
incl %ecx
movl %ecx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq