// File: /workspace/github_c_makefile_star2_O1/cbouilla[P]AES-attacks-finder/Algebre.c
// Function: Intersection_tmp
int Intersection_tmp(unsigned char **dst, unsigned char **mat1, int b1, unsigned char **mat2, int a, int b2)
{
	/* A améliorer */
	if (b1==0 || b2==0) return 0;
	int b=b1+b2,i;
	unsigned char **m=malloc(a*sizeof(unsigned char *));
	for (i = 0; i < a; i++) m[i]=malloc(b*sizeof(unsigned char)); 
	for (i = 0; i < a; i++)
	{
		int j;
		for (j = 0; j < b1; j++) m[i][j]=mat1[i][j];
		for (j = 0; j < b2; j++) m[i][j+b1]=mat2[i][j];	
	}
	for (i = 0; i < min(a,b1); i++)
	{
		int k1;
		for (k1 = i; k1 < b1; k1++)
		{
			int k2;
			for (k2 = i; k2 < a; k2++)
			{
				if (m[k2][k1])
				{
					if (k2!=i) echangeligne(k2,i,m,a,b);
					if (k1!=i)
					{
						echangecolonne(k1,i,m,a,b);
						echangecolonne(k1,i,mat1,a,b);
					}
					break;
				}
			}
			if (m[i][i]) break;
		}
		if (!m[i][i]) break;
		else
		{
			unsigned char invp=Inverse(m[i][i]);
			int j;
			for (j = i; j < b; j++) m[i][j]=Multiply(invp,m[i][j]);
			for (j = i+1; j < a; j++)
			{
				if (m[j][i])
				{
					int k;
					for (k = i+1; k < b; k++) if (m[i][k]) m[j][k]^=Multiply(m[j][i],m[i][k]);
					m[j][i]=0;
				}
			}
		}	
	}
	for (i = b1; i < min(a,b); i++)
	{
		int k1;
		for (k1 = i; k1 < b; k1++)
		{
			int k2;
			for (k2 = i; k2 < a; k2++)
			{
				if (m[k2][k1])
				{
					if (k2!=i) echangeligne(k2,i,m,a,b);
					if (k1!=i) echangecolonne(k1,i,m,a,b);
					break;
				}
			}
			if (m[i][i]) break;
		}
		if (!m[i][i]) break;
		else
		{
			unsigned char invp=Inverse(m[i][i]);
			int j;
			for (j = i; j < b; j++) m[i][j]=Multiply(invp,m[i][j]);
			for (j = i+1; j < a; j++)
			{
				if (m[j][i])
				{
					int k;
					for (k = i+1; k < b; k++) if (m[i][k]) m[j][k]^=Multiply(m[j][i],m[i][k]);
					m[j][i]=0;
				}
			}
		}	
	}
	int b3=b-i,j;
	unsigned char *coef=malloc(b*sizeof(unsigned char));
	for (i = 0; i < b3; i++) for (j = 0; j < a; j++) dst[j][i]=0;	
	for (i = 0; i < b3; i++)
	{
		for (j = 0; j < b; j++) coef[j]=0;
		coef[b-1-i]=1;
		for (j = b-b3-1; j >=0; j--)
		{
			int k;
			for (k = j+1; k < b; k++) if (coef[k] && m[j][k]) coef[j]^=Multiply(coef[k],m[j][k]); // 34 % du temps passé ici
		}
		for (j = 0; j < b1; j++)
		{
			int k;
			for (k = 0; k < a; k++) if (coef[j] && mat1[k][j]) dst[k][i]^=Multiply(coef[j],mat1[k][j]); // 19 % du temps passé ici
		}
	}
	for (i = 0; i < a; i++) free(m[i]);
	free(m);
	free(coef);
	return b3;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, %r12d
testl %edx, %edx
sete %dl
testl %r9d, %r9d
sete %r10b
xorl %eax, %eax
orb %dl, %r10b
jne 0x44b3
movq %rcx, 0x8(%rsp)
movq %rdi, 0x60(%rsp)
movq %rsi, 0x48(%rsp)
movq %r9, 0x50(%rsp)
leal (%r9,%r12), %ebp
movslq %r8d, %r15
leaq (,%r15,8), %rdi
movl %r8d, %ebx
callq 0x21d0
movq %rax, %r10
movslq %ebp, %r13
movl %ebx, 0x4(%rsp)
movl %ebx, %ebx
testl %r15d, %r15d
movq %rax, 0x20(%rsp)
jle 0x3f15
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x21d0
movq 0x20(%rsp), %r10
movq %rax, (%r10,%r14,8)
incq %r14
cmpq %r14, %rbx
jne 0x3efc
movq %r13, 0x28(%rsp)
movl %r12d, %r8d
movq 0x50(%rsp), %r14
movl %r14d, %r13d
cmpl $0x0, 0x4(%rsp)
movq 0x48(%rsp), %r11
jle 0x3f84
movslq %r12d, %rax
xorl %ecx, %ecx
movq 0x8(%rsp), %r9
testl %r12d, %r12d
jle 0x3f5a
movq (%r10,%rcx,8), %rdx
xorl %esi, %esi
movq (%r11,%rcx,8), %rdi
movb (%rdi,%rsi), %dil
movb %dil, (%rdx,%rsi)
incq %rsi
cmpq %rsi, %r8
jne 0x3f46
testl %r14d, %r14d
jle 0x3f7c
movq (%r10,%rcx,8), %rdx
addq %rax, %rdx
xorl %esi, %esi
movq (%r9,%rcx,8), %rdi
movb (%rdi,%rsi), %dil
movb %dil, (%rdx,%rsi)
incq %rsi
cmpq %rsi, %r13
jne 0x3f68
incq %rcx
cmpq %rbx, %rcx
jne 0x3f3b
movq %r13, 0x40(%rsp)
movq %r8, 0x70(%rsp)
movl 0x4(%rsp), %r9d
cmpl %r12d, %r9d
movq %r12, 0x30(%rsp)
movl %r12d, %eax
cmovll %r9d, %eax
testl %eax, %eax
jle 0x4156
movl %eax, %eax
movq %rax, 0x58(%rsp)
movslq 0x30(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x1, %eax
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
movq %r10, %r14
movq %r13, %rax
movq 0x18(%rsp), %r12
xorl %ecx, %ecx
movq (%r14,%rcx,8), %rdx
cmpb $0x0, (%rdx,%rax)
jne 0x3ff0
leaq (%rcx,%r13), %rdx
incq %rdx
incq %rcx
cmpq %r15, %rdx
jl 0x3fd5
jmp 0x4066
testq %rcx, %rcx
je 0x4005
movq (%r14,%rcx,8), %rdx
movq (%r10,%r13,8), %rsi
movq %rsi, (%r14,%rcx,8)
movq %rdx, (%r10,%r13,8)
cmpq %r13, %rax
je 0x4066
movq 0x28(%rsp), %rcx
cmpq %rcx, %r13
setl %dl
cmpq %rcx, %rax
setl %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x4066
xorl %edx, %edx
movq (%r10,%rdx,8), %rsi
movb (%rsi,%rax), %dil
movb (%rsi,%r13), %r8b
movb %r8b, (%rsi,%rax)
movb %dil, (%rsi,%r13)
incq %rdx
cmpq %rdx, %rbx
jne 0x4024
testb %cl, %cl
je 0x4066
xorl %ecx, %ecx
movq (%r11,%rcx,8), %rdx
movb (%rdx,%rax), %sil
movb (%rdx,%r13), %dil
movb %dil, (%rdx,%rax)
movq (%r11,%rcx,8), %rdx
movb %sil, (%rdx,%r13)
incq %rcx
cmpq %rcx, %rbx
jne 0x4046
movq (%r10,%r13,8), %rcx
cmpb $0x0, (%rcx,%r13)
jne 0x407d
incq %rax
cmpq %r12, %rax
jl 0x3fd3
movq (%r10,%r13,8), %r12
movb (%r12,%r13), %al
testb %al, %al
je 0x4156
movb %al, 0x8(%rsp)
movzbl %al, %edi
callq 0x2537
movq 0x28(%rsp), %rdi
cmpq %rdi, %r13
leaq 0x14f68(%rip), %r8      # 0x19010
jge 0x40cb
movzbl %al, %eax
shll $0x8, %eax
movq %r13, %rcx
movzbl (%r12,%rcx), %edx
leaq (%rax,%r8), %rsi
movb (%rdx,%rsi), %dl
movb %dl, (%r12,%rcx)
incq %rcx
cmpq %rdi, %rcx
jl 0x40b3
leaq 0x1(%r13), %rax
cmpq %r15, %rax
movl 0x4(%rsp), %r9d
movq 0x20(%rsp), %r10
movq 0x48(%rsp), %r11
jge 0x4138
movq 0x10(%rsp), %rcx
movq (%r10,%rcx,8), %rdx
cmpb $0x0, (%rdx,%r13)
je 0x4130
cmpq 0x28(%rsp), %rax
jge 0x412b
movq %r13, %rsi
movzbl 0x1(%r12,%rsi), %edi
testq %rdi, %rdi
je 0x4121
movzbl (%rdx,%r13), %r8d
shll $0x8, %r8d
addq 0x2dec8(%rip), %r8      # 0x31fe0
movb (%rdi,%r8), %dil
xorb %dil, 0x1(%rdx,%rsi)
incq %rsi
leal 0x1(%rsi), %edi
cmpl %edi, %ebp
jg 0x40fd
movb $0x0, (%rdx,%r13)
incq %rcx
cmpq %rbx, %rcx
jne 0x40e8
cmpb $0x0, 0x8(%rsp)
je 0x4156
incq 0x10(%rsp)
addq $0x8, %r14
movq %rax, %r13
cmpq 0x58(%rsp), %rax
jne 0x3fcb
cmpl %r9d, %ebp
movl %r9d, %ecx
cmovll %ebp, %ecx
movq 0x30(%rsp), %rax
movl %eax, %r13d
movl %ecx, 0x3c(%rsp)
cmpl %eax, %ecx
movq 0x28(%rsp), %rdi
jle 0x4324
movq 0x30(%rsp), %rax
movslq %eax, %r13
leaq (%r10,%r13,8), %r11
leal 0x1(%rax), %ecx
movq 0x50(%rsp), %rax
decl %eax
movq %rax, 0x8(%rsp)
movl %ecx, 0x58(%rsp)
movslq %ecx, %rax
movq %rax, 0x18(%rsp)
leaq 0x1(%r13), %rax
movq %rax, 0x10(%rsp)
movslq %eax, %r14
movb $0x1, %cl
movq %r13, %rax
xorl %edx, %edx
movq (%r11,%rdx,8), %rsi
cmpb $0x0, (%rsi,%rax)
jne 0x41cd
leaq (%rdx,%r13), %rsi
incq %rsi
incq %rdx
cmpq %r15, %rsi
jl 0x41b2
jmp 0x4215
testq %rdx, %rdx
je 0x41de
movq (%r10,%r13,8), %r8
movq %r8, (%r11,%rdx,8)
movq %rsi, (%r10,%r13,8)
testl %r9d, %r9d
setle %dl
cmpq %r13, %rax
sete %sil
notb %cl
orb %dl, %cl
orb %sil, %cl
testb $0x1, %cl
jne 0x4215
xorl %ecx, %ecx
movq (%r10,%rcx,8), %rdx
movb (%rdx,%rax), %sil
movb (%rdx,%r13), %r8b
movb %r8b, (%rdx,%rax)
movb %sil, (%rdx,%r13)
incq %rcx
cmpq %rcx, %rbx
jne 0x41f9
movq (%r10,%r13,8), %rcx
cmpb $0x0, (%rcx,%r13)
jne 0x422b
incq %rax
cmpq %rdi, %rax
setl %cl
jl 0x41b0
movq (%r10,%r13,8), %r12
movb (%r12,%r13), %al
testb %al, %al
je 0x4324
movq %r11, 0x68(%rsp)
movb %al, 0x3(%rsp)
movzbl %al, %edi
callq 0x2537
movzbl %al, %eax
leaq (%r12,%r13), %rcx
shll $0x8, %eax
xorl %edx, %edx
movq 0x40(%rsp), %r8
leaq 0x14dac(%rip), %r9      # 0x19010
movzbl (%rcx,%rdx), %esi
leaq (%rax,%r9), %rdi
movb (%rsi,%rdi), %sil
movb %sil, (%rcx,%rdx)
incq %rdx
cmpl %edx, %r8d
jne 0x4264
cmpq %r15, 0x10(%rsp)
movl 0x4(%rsp), %r9d
movq 0x20(%rsp), %r10
movq 0x28(%rsp), %rdi
movq 0x68(%rsp), %r11
jge 0x42f0
addq 0x18(%rsp), %r12
movq (%r10,%r14,8), %rax
cmpb $0x0, (%rax,%r13)
je 0x42e8
cmpq %rdi, 0x10(%rsp)
jge 0x42e3
movq 0x18(%rsp), %rcx
addq %rax, %rcx
xorl %edx, %edx
movzbl (%r12,%rdx), %esi
testq %rsi, %rsi
je 0x42da
movzbl (%rax,%r13), %r8d
shll $0x8, %r8d
addq 0x2dd0e(%rip), %r8      # 0x31fe0
movb (%rsi,%r8), %sil
xorb %sil, (%rcx,%rdx)
incq %rdx
cmpl %edx, 0x8(%rsp)
jne 0x42b8
movb $0x0, (%rax,%r13)
incq %r14
cmpq %r15, %r14
jl 0x429c
cmpb $0x0, 0x3(%rsp)
je 0x4324
addq $0x8, %r11
decq 0x40(%rsp)
movl 0x58(%rsp), %ecx
incl %ecx
decq 0x8(%rsp)
movq 0x10(%rsp), %rax
movq %rax, %r13
cmpl %eax, 0x3c(%rsp)
jne 0x4193
movl 0x3c(%rsp), %eax
movl %eax, %r13d
callq 0x21d0
movl 0x4(%rsp), %r8d
movq %rax, %r15
movl %ebp, %esi
subl %r13d, %esi
movl %esi, %eax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %r11
jle 0x4367
xorl %eax, %eax
testl %r8d, %r8d
jle 0x435d
xorl %ecx, %ecx
movq (%r11,%rcx,8), %rdx
movb $0x0, (%rdx,%rax)
incq %rcx
cmpq %rcx, %rbx
jne 0x434d
incq %rax
cmpq 0x8(%rsp), %rax
jne 0x4346
movl %esi, 0x40(%rsp)
testl %esi, %esi
movq 0x20(%rsp), %rdi
movq 0x48(%rsp), %r10
jle 0x4484
movq 0x30(%rsp), %rax
movq 0x50(%rsp), %rcx
addl %ecx, %eax
decl %eax
incq %rax
movq %rax, 0x18(%rsp)
movl %r13d, %eax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x14c6b(%rip), %r12     # 0x19010
testl %ebp, %ebp
jle 0x43cc
movq %r15, %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x2120
movq 0x60(%rsp), %r11
movq 0x48(%rsp), %r10
movq 0x20(%rsp), %rdi
movl 0x4(%rsp), %r8d
movl %r14d, %eax
notl %eax
addl %ebp, %eax
cltq
movb $0x1, (%r15,%rax)
movq 0x10(%rsp), %rax
testl %r13d, %r13d
jle 0x4427
movq %rax, %rcx
decq %rax
cmpq 0x28(%rsp), %rcx
jge 0x4421
movq %rcx, %rdx
movzbl (%r15,%rdx), %esi
testq %rsi, %rsi
je 0x441a
movq (%rdi,%rax,8), %r9
movzbl (%r9,%rdx), %r9d
testq %r9, %r9
je 0x441a
shll $0x8, %esi
addq %r12, %rsi
movb (%r9,%rsi), %sil
xorb %sil, (%r15,%rax)
incq %rdx
cmpl %edx, %ebp
jg 0x43f4
cmpq $0x1, %rcx
jg 0x43e4
cmpl $0x0, 0x30(%rsp)
jle 0x4476
xorl %eax, %eax
testl %r8d, %r8d
jle 0x446c
movzbl (%r15,%rax), %ecx
xorl %edx, %edx
testq %rcx, %rcx
je 0x4464
movq (%r10,%rdx,8), %rsi
movzbl (%rsi,%rax), %esi
testq %rsi, %rsi
je 0x4464
movl %ecx, %r9d
shll $0x8, %r9d
addq %r12, %r9
movb (%rsi,%r9), %sil
movq (%r11,%rdx,8), %r9
xorb %sil, (%r9,%r14)
incq %rdx
cmpq %rdx, %rbx
jne 0x443c
incq %rax
cmpq 0x70(%rsp), %rax
jne 0x4430
incq %r14
cmpq 0x8(%rsp), %r14
jne 0x43a5
testl %r8d, %r8d
jle 0x44a2
xorl %r14d, %r14d
movq (%rdi,%r14,8), %rdi
callq 0x2030
movq 0x20(%rsp), %rdi
incq %r14
cmpq %r14, %rbx
jne 0x448c
callq 0x2030
movq %r15, %rdi
callq 0x2030
movl 0x40(%rsp), %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq