// File: /workspace/github_c_makefile_star2_O3/cbouilla[P]AES-attacks-finder/Algebre.c
// Function: BaseSpeciale
int BaseSpeciale(unsigned char **dst, unsigned char **mat, int a, int b, int Known)
{
	if (b==0) return 0;
	if (Known==0) return 0;
	unsigned char **m=malloc(a*sizeof(unsigned char *));
	int i;
	for (i = 0; i < a; i++)
	{
		m[i]=malloc(b*sizeof(unsigned char));
		int j;
		for (j = 0; j < b; j++) m[i][j]=mat[i][j];
	}
	for (i = 0; i < min(Known,b); i++)
	{
		int k1;
		for (k1 = i; k1 < b; k1++)
		{
			int k2;
			for (k2 = i; k2 < Known; k2++)
			{
				if (m[k2][k1]!=0)
				{
					if (k2!=i) echangeligne(k2,i,m,a,b);
					if (k1!=i)
					{
						echangecolonne(k1,i,m,a,b);
						echangecolonne(k1,i,mat,a,b);
					}
					break;
				}
			}
			if (m[i][i]!=0) break;
		}
		unsigned char p=m[i][i];
		if (p==0) break;
		else
		{
			int j;
			for (j = i+1; j < a; j++)
			{
				unsigned char c=m[j][i];
				if (c!=0)
				{
					int k;
					for (k = i; k < b; k++) m[j][k]=Multiply(p,m[j][k])^Multiply(c,m[i][k]);
				}
			}
		}	
	}
	int tmp=i;
	for (i = 0; i < tmp; i++)
	{
		int j;
		for (j = 0; j < a; j++) dst[j][i]=mat[j][i];
	}
	for (i = 0; i < a; i++) free(m[i]);
	free(m);
	return tmp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %ebp
testl %ecx, %ecx
sete %al
testl %r8d, %r8d
sete %cl
xorl %r13d, %r13d
orb %al, %cl
jne 0x3a4a
movl %edx, %ebx
movq %rsi, %r15
movl %r8d, 0x8(%rsp)
movq %rdi, 0x30(%rsp)
movslq %edx, %r13
leaq (,%r13,8), %rdi
callq 0x21d0
movq %rax, %r12
movslq %ebp, %rax
movq %rax, 0x28(%rsp)
movl %ebx, %r14d
movl %ebp, %eax
movq %rax, 0x20(%rsp)
movq %r13, 0x48(%rsp)
testl %r13d, %r13d
movl %ebx, %r13d
movl %ebp, %ebx
jle 0x3836
xorl %ebp, %ebp
movq 0x28(%rsp), %rdi
callq 0x21d0
movq 0x20(%rsp), %rdi
movq %rax, (%r12,%rbp,8)
testl %ebx, %ebx
jle 0x382e
movq (%r15,%rbp,8), %rcx
xorl %edx, %edx
movb (%rcx,%rdx), %sil
movb %sil, (%rax,%rdx)
incq %rdx
cmpq %rdx, %rdi
jne 0x381e
incq %rbp
cmpq %r14, %rbp
jne 0x3801
movl 0x8(%rsp), %ecx
cmpl %ebx, %ecx
cmovll %ecx, %ebx
testl %ebx, %ebx
movl %r13d, 0x4(%rsp)
jle 0x3a24
movl %ebx, 0x14(%rsp)
movl %ebx, %eax
movq %rax, 0x40(%rsp)
movslq %ecx, %rcx
movl $0x1, %eax
movq %rax, 0x18(%rsp)
xorl %esi, %esi
movq %r12, %r8
xorl %r10d, %r10d
movq %r12, 0x60(%rsp)
movq %r14, 0x58(%rsp)
movq %r15, 0x38(%rsp)
movq %rsi, 0x8(%rsp)
negq %rsi
movq %r10, %r11
movq 0x48(%rsp), %rdi
xorl %eax, %eax
movq (%r8,%rax,8), %rdx
cmpb $0x0, (%rdx,%r11)
jne 0x38a9
leaq (%r10,%rax), %rdx
incq %rdx
incq %rax
cmpq %rcx, %rdx
jl 0x388d
jmp 0x391b
testq %rax, %rax
je 0x38cb
cmpq %rdi, %r10
jge 0x38cb
leal (%rsi,%rax), %edx
cmpl %r13d, %edx
jge 0x38cb
movq (%r8,%rax,8), %rdx
movq (%r12,%r10,8), %r9
movq %r9, (%r8,%rax,8)
movq %rdx, (%r12,%r10,8)
testl %r13d, %r13d
setle %al
cmpq %r10, %r11
sete %dl
orb %al, %dl
jne 0x391b
xorl %eax, %eax
movq (%r12,%rax,8), %rdx
movb (%rdx,%r11), %r9b
movb (%rdx,%r10), %bpl
movb %bpl, (%rdx,%r11)
movb %r9b, (%rdx,%r10)
incq %rax
cmpq %rax, %r14
jne 0x38dd
xorl %eax, %eax
movq (%r15,%rax,8), %rdx
movb (%rdx,%r11), %r9b
movb (%rdx,%r10), %bpl
movb %bpl, (%rdx,%r11)
movq (%r15,%rax,8), %rdx
movb %r9b, (%rdx,%r10)
incq %rax
cmpq %rax, %r14
jne 0x38fb
movq (%r12,%r10,8), %rax
movzbl (%rax,%r10), %ebx
testq %rbx, %rbx
jne 0x3937
incq %r11
cmpq 0x28(%rsp), %r11
jl 0x388b
testq %rbx, %rbx
je 0x39e6
leaq 0x1(%r10), %rdx
movq %rdx, 0x50(%rsp)
cmpq %rdi, %rdx
jge 0x39b4
movq 0x18(%rsp), %r11
movq (%r12,%r11,8), %rbp
movzbl (%rbp,%r10), %edi
testq %rdi, %rdi
movq 0x20(%rsp), %r14
leaq 0x156a4(%rip), %r15     # 0x19010
je 0x39a2
movq %r10, %r9
movzbl (%rbp,%r9), %r13d
movl %ebx, %edx
shll $0x8, %edx
addq %r15, %rdx
movzbl (%rax,%r9), %r12d
movl %edi, %esi
shll $0x8, %esi
addq %r15, %rsi
movb (%r12,%rsi), %sil
xorb (%r13,%rdx), %sil
movb %sil, (%rbp,%r9)
incq %r9
cmpq %r9, %r14
jne 0x3971
incq %r11
movq 0x58(%rsp), %r14
cmpq %r14, %r11
movq 0x60(%rsp), %r12
jne 0x3953
incq 0x18(%rsp)
addq $0x8, %r8
movq 0x8(%rsp), %rsi
decq %rsi
movq 0x50(%rsp), %r10
cmpq 0x40(%rsp), %r10
movl 0x4(%rsp), %r13d
movq 0x38(%rsp), %r15
jne 0x387b
movl 0x14(%rsp), %r8d
jmp 0x39e9
movl %r10d, %r8d
testl %r8d, %r8d
movq 0x30(%rsp), %r9
je 0x3a24
movl %r8d, %eax
xorl %ecx, %ecx
testl %r13d, %r13d
jle 0x3a17
xorl %edx, %edx
movq (%r15,%rdx,8), %rsi
movb (%rsi,%rcx), %sil
movq (%r9,%rdx,8), %rdi
movb %sil, (%rdi,%rcx)
incq %rdx
cmpq %rdx, %r14
jne 0x39ff
incq %rcx
cmpq %rax, %rcx
jne 0x39f8
movl %r8d, %r13d
jmp 0x3a27
xorl %r13d, %r13d
cmpl $0x0, 0x4(%rsp)
jle 0x3a42
xorl %r15d, %r15d
movq (%r12,%r15,8), %rdi
callq 0x2030
incq %r15
cmpq %r15, %r14
jne 0x3a31
movq %r12, %rdi
callq 0x2030
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq