// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movl %ecx, %ebp
testl %ecx, %ecx
sete %al
testl %r8d, %r8d
sete %cl
xorl %r14d, %r14d
orb %al, %cl
jne 0x3360
movq %rsi, %r13
movl %r8d, 0x8(%rsp)
movq %rdi, 0x30(%rsp)
movslq %edx, %rax
movq %rax, 0x20(%rsp)
leaq (,%rax,8), %rdi
movl %edx, (%rsp)
callq 0x21c0
movq %rax, %rbx
movslq %ebp, %r12
xorl %r14d, %r14d
testl %ebp, %ebp
movl $0x0, %r15d
movl %ebp, 0x4(%rsp)
cmovgl %ebp, %r15d
cmpl $0x0, 0x20(%rsp)
movl $0x0, %ebp
cmovgl (%rsp), %ebp
cmpq %rbp, %r14
je 0x31a2
movq %r12, %rdi
callq 0x21c0
movq %rax, (%rbx,%r14,8)
xorl %ecx, %ecx
cmpq %rcx, %r15
je 0x319d
movq (%r13,%r14,8), %rdx
movb (%rdx,%rcx), %dl
movb %dl, (%rax,%rcx)
incq %rcx
jmp 0x3188
incq %r14
jmp 0x3175
movq %rbp, 0x28(%rsp)
movq %r13, 0x18(%rsp)
movl 0x4(%rsp), %r12d
movl 0x8(%rsp), %ecx
cmpl %r12d, %ecx
movl %r12d, %eax
cmovll %ecx, %eax
xorl %r14d, %r14d
testl %eax, %eax
cmovlel %r14d, %eax
movq %rax, 0x10(%rsp)
movl %r12d, %edi
movl %ecx, %r13d
leaq 0x13e37(%rip), %r15     # 0x17010
movq %rdi, 0x8(%rsp)
cmpl %r14d, %r12d
movl %r14d, %ebp
cmovgl %r12d, %ebp
cmpq 0x10(%rsp), %r14
je 0x3300
movq %r14, %r12
movl (%rsp), %ecx
cmpq %rdi, %r12
je 0x3289
movq %r14, %rax
cmpq %rax, %r13
je 0x3274
movq (%rbx,%rax,8), %rdx
cmpb $0x0, (%rdx,%r12)
jne 0x321a
incq %rax
jmp 0x3205
movl %eax, %esi
cmpq %r14, %rsi
je 0x323c
cmpq 0x20(%rsp), %r14
jge 0x323c
cmpl %ecx, %eax
jge 0x323c
movq (%rbx,%rsi,8), %rax
movq (%rbx,%r14,8), %rdx
movq %rdx, (%rbx,%rsi,8)
movq %rax, (%rbx,%r14,8)
cmpq %r14, %r12
je 0x3274
movl %r12d, %edi
movl %r14d, %esi
movq %rbx, %rdx
movl 0x4(%rsp), %r8d
callq 0x2b55
movl %r12d, %edi
movl %r14d, %esi
movq 0x18(%rsp), %rdx
movl (%rsp), %ecx
movl 0x4(%rsp), %r8d
callq 0x2b55
movq 0x8(%rsp), %rdi
movl (%rsp), %ecx
movq (%rbx,%r14,8), %rax
movb (%rax,%r14), %dl
incq %r12
testb %dl, %dl
je 0x31f9
jmp 0x3295
movq (%rbx,%r14,8), %rax
movb (%rax,%r14), %dl
testb %dl, %dl
je 0x330a
movzbl %dl, %ecx
shll $0x8, %ecx
addq %r15, %rcx
movq %r14, %r8
movl 0x4(%rsp), %r12d
leaq 0x1(%r8), %rdx
cmpl (%rsp), %edx
jge 0x32f3
movq 0x8(%rbx,%r8,8), %rsi
movzbl (%rsi,%r14), %edi
movq %rdx, %r8
testq %rdi, %rdi
je 0x32a6
movq %r14, %r8
cmpq %r8, %rbp
je 0x32ee
movzbl (%rsi,%r8), %r9d
movzbl (%rax,%r8), %r10d
movl %edi, %r11d
shll $0x8, %r11d
addq %r15, %r11
movb (%r10,%r11), %r10b
xorb (%r9,%rcx), %r10b
movb %r10b, (%rsi,%r8)
incq %r8
jmp 0x32c4
movq %rdx, %r8
jmp 0x32a6
incq %r14
movq 0x8(%rsp), %rdi
jmp 0x31de
movq 0x10(%rsp), %r9
movl %r9d, %r14d
jmp 0x330d
movl %r14d, %r9d
xorl %eax, %eax
movq 0x18(%rsp), %rdi
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %r12
cmpq %r9, %rax
je 0x3342
xorl %ecx, %ecx
cmpq %rcx, %r12
je 0x333d
movq (%rdi,%rcx,8), %rdx
movb (%rdx,%rax), %dl
movq (%r8,%rcx,8), %rsi
movb %dl, (%rsi,%rax)
incq %rcx
jmp 0x3325
incq %rax
jmp 0x331e
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x3358
movq (%rbx,%r15,8), %rdi
callq 0x2030
incq %r15
jmp 0x3345
movq %rbx, %rdi
callq 0x2030
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq