// File: /workspace/github_c_makefile_star2_O1/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, %r13d
testl %ecx, %ecx
sete %al
testl %r8d, %r8d
sete %cl
xorl %r15d, %r15d
orb %al, %cl
jne 0x37aa
movl %edx, %r14d
movq %rsi, %rbx
movl %r8d, 0x20(%rsp)
movq %rdi, 0x48(%rsp)
movslq %edx, %r15
leaq (,%r15,8), %rdi
callq 0x21d0
movq %rax, %rbp
movslq %r13d, %rax
movq %rax, 0x40(%rsp)
movl %r14d, %eax
movq %rax, 0x8(%rsp)
movl %r13d, %r12d
movq %r15, 0x38(%rsp)
testl %r15d, %r15d
movl %r13d, %r15d
jle 0x3564
xorl %r13d, %r13d
movq 0x40(%rsp), %rdi
callq 0x21d0
movq %rax, (%rbp,%r13,8)
testl %r15d, %r15d
jle 0x355a
movq (%rbx,%r13,8), %rcx
xorl %edx, %edx
movb (%rcx,%rdx), %sil
movb %sil, (%rax,%rdx)
incq %rdx
cmpq %rdx, %r12
jne 0x354a
incq %r13
cmpq 0x8(%rsp), %r13
jne 0x3530
movl 0x20(%rsp), %ecx
cmpl %r15d, %ecx
cmovll %ecx, %r15d
testl %r15d, %r15d
jle 0x373e
movl %r15d, 0x2c(%rsp)
movl %r15d, %eax
movq %rax, 0x50(%rsp)
movslq %ecx, %rcx
movl $0x1, %eax
movq %rax, 0x30(%rsp)
xorl %r9d, %r9d
leaq 0x15a74(%rip), %rdi     # 0x19010
movq %rbp, %r8
xorl %r15d, %r15d
movq 0x8(%rsp), %r13
movq %rbp, 0x60(%rsp)
movl %r14d, 0x14(%rsp)
movq %rbx, 0x18(%rsp)
movq %r9, 0x20(%rsp)
negq %r9
movb $0x1, %r11b
movq %r15, %r10
xorl %eax, %eax
movq (%r8,%rax,8), %rdx
cmpb $0x0, (%rdx,%r10)
jne 0x35e5
leaq (%r15,%rax), %rdx
incq %rdx
incq %rax
cmpq %rcx, %rdx
jl 0x35c6
jmp 0x3668
testq %rax, %rax
je 0x360c
cmpq 0x38(%rsp), %r15
jge 0x360c
leal (%r9,%rax), %edx
cmpl %r14d, %edx
jge 0x360c
movq (%r8,%rax,8), %rdx
movq (%rbp,%r15,8), %rsi
movq %rsi, (%r8,%rax,8)
movq %rdx, (%rbp,%r15,8)
cmpq %r15, %r10
je 0x3668
testl %r14d, %r14d
setg %al
andb %r11b, %al
cmpb $0x1, %al
jne 0x3668
xorl %edx, %edx
movq (%rbp,%rdx,8), %rsi
movb (%rsi,%r10), %r11b
movb (%rsi,%r15), %r13b
movb %r13b, (%rsi,%r10)
movq 0x8(%rsp), %r13
movb %r11b, (%rsi,%r15)
incq %rdx
cmpq %rdx, %r13
jne 0x3620
testb %al, %al
je 0x3668
xorl %eax, %eax
movq (%rbx,%rax,8), %rdx
movb (%rdx,%r10), %sil
movb (%rdx,%r15), %r11b
movb %r11b, (%rdx,%r10)
movq (%rbx,%rax,8), %rdx
movb %sil, (%rdx,%r15)
incq %rax
cmpq %rax, %r13
jne 0x3648
movq (%rbp,%r15,8), %rax
cmpb $0x0, (%rax,%r15)
jne 0x3686
incq %r10
cmpq 0x40(%rsp), %r10
setl %r11b
jl 0x35c4
movq (%rbp,%r15,8), %r11
movzbl (%r11,%r15), %ebx
testq %rbx, %rbx
je 0x374d
leaq 0x1(%r15), %rax
movq %rax, 0x58(%rsp)
cmpq 0x38(%rsp), %rax
jge 0x3702
movq 0x30(%rsp), %rdx
movq (%rbp,%rdx,8), %rax
movzbl (%rax,%r15), %ebp
testq %rbp, %rbp
je 0x36f0
movq %r15, %r13
movzbl (%rax,%r13), %r9d
movl %ebx, %r10d
shll $0x8, %r10d
addq %rdi, %r10
movzbl (%r11,%r13), %r14d
movl %ebp, %esi
shll $0x8, %esi
addq %rdi, %rsi
movb (%r14,%rsi), %sil
xorb (%r9,%r10), %sil
movb %sil, (%rax,%r13)
incq %r13
cmpq %r13, %r12
jne 0x36c0
incq %rdx
movq 0x8(%rsp), %r13
cmpq %r13, %rdx
movq 0x60(%rsp), %rbp
jne 0x36ae
testq %rbx, %rbx
je 0x3748
incq 0x30(%rsp)
addq $0x8, %r8
movq 0x20(%rsp), %r9
decq %r9
movq 0x58(%rsp), %rax
movq %rax, %r15
cmpq 0x50(%rsp), %rax
movl 0x14(%rsp), %r14d
movq 0x18(%rsp), %rbx
jne 0x35b6
movl 0x2c(%rsp), %eax
movl %eax, %r15d
jmp 0x3752
xorl %r15d, %r15d
movq 0x8(%rsp), %r13
jmp 0x3752
movl 0x14(%rsp), %r14d
movq 0x18(%rsp), %rbx
testl %r15d, %r15d
movq 0x48(%rsp), %r8
je 0x3788
movl %r15d, %eax
xorl %ecx, %ecx
testl %r14d, %r14d
jle 0x3780
xorl %edx, %edx
movq (%rbx,%rdx,8), %rsi
movb (%rsi,%rcx), %sil
movq (%r8,%rdx,8), %rdi
movb %sil, (%rdi,%rcx)
incq %rdx
cmpq %rdx, %r13
jne 0x3768
incq %rcx
cmpq %rax, %rcx
jne 0x3761
testl %r14d, %r14d
jle 0x37a2
xorl %r14d, %r14d
movq (%rbp,%r14,8), %rdi
callq 0x2030
incq %r14
cmpq %r14, %r13
jne 0x3790
movq %rbp, %rdi
callq 0x2030
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq