// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
movq %rcx, %r13
movl %edx, %r15d
testl %edx, %edx
sete %dl
testl %r9d, %r9d
sete %cl
xorl %eax, %eax
orb %dl, %cl
jne 0x4743
movq %rsi, %r12
movq %rdi, 0x50(%rsp)
movq %r9, 0x18(%rsp)
leal (%r9,%r15), %eax
movq %rax, 0x30(%rsp)
movslq %r8d, %rbp
leaq (,%rbp,8), %rdi
movl %r8d, 0x8(%rsp)
callq 0x21d0
movl 0x8(%rsp), %r10d
movq %rax, %r11
movl %r10d, %ebx
testl %ebp, %ebp
movq %rax, 0x40(%rsp)
jle 0x421d
movslq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
movq 0x28(%rsp), %rdi
callq 0x21d0
movq 0x40(%rsp), %r11
movq %rax, (%r11,%r14,8)
incq %r14
cmpq %r14, %rbx
jne 0x419e
movl 0x8(%rsp), %r10d
testl %r10d, %r10d
jle 0x421d
movslq %r15d, %rax
movl %r15d, %ecx
movl 0x18(%rsp), %edx
xorl %esi, %esi
testl %r15d, %r15d
jle 0x41ef
movq (%r11,%rsi,8), %rdi
xorl %r8d, %r8d
movq (%r12,%rsi,8), %r9
movb (%r9,%r8), %r9b
movb %r9b, (%rdi,%r8)
incq %r8
cmpq %r8, %rcx
jne 0x41db
cmpl $0x0, 0x18(%rsp)
jle 0x4215
movq (%r11,%rsi,8), %rdi
addq %rax, %rdi
xorl %r8d, %r8d
movq (%r13,%rsi,8), %r9
movb (%r9,%r8), %r9b
movb %r9b, (%rdi,%r8)
incq %r8
cmpq %r8, %rdx
jne 0x4200
incq %rsi
cmpq %rbx, %rsi
jne 0x41cf
cmpl %r15d, %r10d
movq %r15, 0x48(%rsp)
movl %r15d, %eax
cmovll %r10d, %eax
testl %eax, %eax
movq 0x18(%rsp), %r9
jle 0x43d7
movslq 0x30(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movl %eax, %eax
movq %rax, 0x38(%rsp)
movslq 0x48(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0x1, %eax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movq %r11, %r14
movq %rax, %r13
xorl %ecx, %ecx
movq (%r14,%rcx,8), %rdx
cmpb $0x0, (%rdx,%rax)
jne 0x4283
leaq (%rcx,%r13), %rdx
incq %rdx
incq %rcx
cmpq %rbp, %rdx
jl 0x4268
jmp 0x42f8
testq %rcx, %rcx
je 0x4298
movq (%r14,%rcx,8), %rdx
movq (%r11,%r13,8), %rsi
movq %rsi, (%r14,%rcx,8)
movq %rdx, (%r11,%r13,8)
movq 0x20(%rsp), %rsi
cmpq %rsi, %r13
setge %cl
cmpq %r13, %rax
sete %dl
cmpq %rsi, %rax
setge %sil
orb %cl, %sil
orb %dl, %sil
jne 0x42f8
xorl %ecx, %ecx
movq (%r11,%rcx,8), %rdx
movb (%rdx,%rax), %sil
movb (%rdx,%r13), %dil
movb %dil, (%rdx,%rax)
movb %sil, (%rdx,%r13)
incq %rcx
cmpq %rcx, %rbx
jne 0x42ba
xorl %ecx, %ecx
movq (%r12,%rcx,8), %rdx
movb (%rdx,%rax), %sil
movb (%rdx,%r13), %dil
movb %dil, (%rdx,%rax)
movq (%r12,%rcx,8), %rdx
movb %sil, (%rdx,%r13)
incq %rcx
cmpq %rcx, %rbx
jne 0x42d8
movq (%r11,%r13,8), %r15
movb (%r15,%r13), %cl
testb %cl, %cl
jne 0x4312
incq %rax
cmpq 0x28(%rsp), %rax
jl 0x4266
testb %cl, %cl
je 0x43d7
movzbl %cl, %edi
callq 0x2534
movq 0x20(%rsp), %rdi
cmpq %rdi, %r13
leaq 0x14cdf(%rip), %r8      # 0x19010
jge 0x4354
movzbl %al, %eax
shll $0x8, %eax
movq %r13, %rcx
movzbl (%r15,%rcx), %edx
leaq (%rax,%r8), %rsi
movb (%rdx,%rsi), %dl
movb %dl, (%r15,%rcx)
incq %rcx
cmpq %rdi, %rcx
jl 0x433c
leaq 0x1(%r13), %rax
cmpq %rbp, %rax
movl 0x8(%rsp), %r10d
movq 0x40(%rsp), %r11
movq 0x18(%rsp), %r9
jge 0x43c3
movq 0x10(%rsp), %rcx
movq (%r11,%rcx,8), %rdx
cmpb $0x0, (%rdx,%r13)
je 0x43bb
cmpq 0x20(%rsp), %rax
jge 0x43b6
movq %r13, %rsi
movzbl 0x1(%r15,%rsi), %edi
testq %rdi, %rdi
je 0x43aa
movzbl (%rdx,%r13), %r8d
shll $0x8, %r8d
addq 0x2dc3f(%rip), %r8      # 0x31fe0
movb (%rdi,%r8), %dil
xorb %dil, 0x1(%rdx,%rsi)
incq %rsi
leal 0x1(%rsi), %edi
cmpl %edi, 0x30(%rsp)
jg 0x4386
movb $0x0, (%rdx,%r13)
incq %rcx
cmpq %rbx, %rcx
jne 0x4371
incq 0x10(%rsp)
addq $0x8, %r14
cmpq 0x38(%rsp), %rax
jne 0x4263
movq 0x30(%rsp), %r14
cmpl %r10d, %r14d
movl %r10d, %eax
cmovll %r14d, %eax
movq 0x48(%rsp), %rcx
cmpl %ecx, %eax
jle 0x4592
movl %eax, 0x10(%rsp)
movslq %ecx, %rdx
movslq %r14d, %rdi
leaq (%r11,%rdx,8), %r13
movl %r9d, %eax
movq %rax, 0x38(%rsp)
leal 0x1(%rcx), %eax
decl %r9d
movq %rdi, 0x58(%rsp)
movq %rdx, %r14
movl %eax, 0xc(%rsp)
cltq
movq %rax, 0x20(%rsp)
leaq 0x1(%rdx), %rax
movq %rax, 0x28(%rsp)
cltq
movq %rax, 0x60(%rsp)
movq %rdx, %rax
xorl %ecx, %ecx
movq (%r13,%rcx,8), %rdx
cmpb $0x0, (%rdx,%rax)
jne 0x4453
leaq (%r14,%rcx), %rdx
incq %rdx
incq %rcx
cmpq %rbp, %rdx
jl 0x4437
jmp 0x4493
testq %rcx, %rcx
je 0x4465
movq (%r11,%r14,8), %rsi
movq %rsi, (%r13,%rcx,8)
movq %rdx, (%r11,%r14,8)
testl %r10d, %r10d
setle %cl
cmpq %r14, %rax
sete %dl
orb %cl, %dl
jne 0x4493
xorl %ecx, %ecx
movq (%r11,%rcx,8), %rdx
movb (%rdx,%rax), %sil
movb (%rdx,%r14), %r8b
movb %r8b, (%rdx,%rax)
movb %sil, (%rdx,%r14)
incq %rcx
cmpq %rcx, %rbx
jne 0x4477
movq (%r11,%r14,8), %r15
movb (%r15,%r14), %cl
testb %cl, %cl
jne 0x44a7
incq %rax
cmpq %rdi, %rax
jl 0x4435
testb %cl, %cl
je 0x459a
movq %r9, 0x18(%rsp)
movzbl %cl, %edi
callq 0x2534
movzbl %al, %eax
leaq (%r15,%r14), %rcx
shll $0x8, %eax
xorl %edx, %edx
movq 0x38(%rsp), %r8
leaq 0x14b3c(%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 0x44d4
movq 0x28(%rsp), %rdx
cmpq %rbp, %rdx
movq 0x40(%rsp), %r11
movq 0x18(%rsp), %r9
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %r10
jge 0x4565
addq 0x20(%rsp), %r15
movq (%r11,%r10,8), %rax
cmpb $0x0, (%rax,%r14)
je 0x455d
cmpq %rdi, %rdx
jge 0x4553
movq 0x20(%rsp), %rcx
addq %rax, %rcx
xorl %edx, %edx
movzbl (%r15,%rdx), %esi
testq %rsi, %rsi
je 0x454b
movzbl (%rax,%r14), %r8d
shll $0x8, %r8d
addq 0x2da9d(%rip), %r8      # 0x31fe0
movb (%rsi,%r8), %sil
xorb %sil, (%rcx,%rdx)
incq %rdx
cmpl %edx, %r9d
jne 0x4529
movb $0x0, (%rax,%r14)
movq 0x28(%rsp), %rdx
incq %r10
cmpq %rbp, %r10
jl 0x450f
addq $0x8, %r13
decq 0x38(%rsp)
movl 0xc(%rsp), %eax
incl %eax
decq %r9
cmpl %edx, 0x10(%rsp)
movl 0x8(%rsp), %r10d
jne 0x4414
movq 0x30(%rsp), %r14
movl 0x10(%rsp), %r13d
jmp 0x45a2
movslq %r14d, %rdi
movl %ecx, %r13d
jmp 0x45a2
movl %r14d, %r13d
movq 0x30(%rsp), %r14
movq %rdi, %r15
callq 0x21d0
movq %rax, %rbp
movl %r14d, %eax
movl %r13d, 0x10(%rsp)
subl %r13d, %eax
movl %eax, 0xc(%rsp)
movl 0x8(%rsp), %r8d
movq 0x40(%rsp), %rdi
movq 0x50(%rsp), %r10
jle 0x4714
movq %r14, %r11
movl 0xc(%rsp), %esi
movl %esi, %r9d
xorl %eax, %eax
testl %r8d, %r8d
jle 0x45f4
xorl %ecx, %ecx
movq (%r10,%rcx,8), %rdx
movb $0x0, (%rdx,%rax)
incq %rcx
cmpq %rcx, %rbx
jne 0x45e4
incq %rax
cmpq %r9, %rax
jne 0x45dd
movq %r9, 0x20(%rsp)
testl %esi, %esi
jle 0x4714
leal -0x1(%r11), %eax
incq %rax
movq %rax, 0x38(%rsp)
movl 0x10(%rsp), %eax
movq %rax, 0x18(%rsp)
movl 0x48(%rsp), %eax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
leaq 0x149df(%rip), %r13     # 0x19010
testl %r11d, %r11d
jle 0x4659
movq %rbp, %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
callq 0x2120
movq 0x30(%rsp), %r11
movq 0x50(%rsp), %r10
movq 0x40(%rsp), %rdi
movl 0x8(%rsp), %r8d
movl %r14d, %eax
notl %eax
addl %r11d, %eax
cltq
movb $0x1, (%rbp,%rax)
movq 0x18(%rsp), %rax
cmpl $0x0, 0x10(%rsp)
jle 0x46b7
movq %rax, %rcx
decq %rax
cmpq %r15, %rcx
jge 0x46b1
movq %rcx, %rdx
movzbl (%rbp,%rdx), %esi
testq %rsi, %rsi
je 0x46a9
movq (%rdi,%rax,8), %r9
movzbl (%r9,%rdx), %r9d
testq %r9, %r9
je 0x46a9
shll $0x8, %esi
addq %r13, %rsi
movb (%r9,%rsi), %sil
xorb %sil, (%rbp,%rax)
incq %rdx
cmpl %edx, %r11d
jg 0x4682
cmpq $0x1, %rcx
jg 0x4674
cmpl $0x0, 0x48(%rsp)
jle 0x4706
xorl %eax, %eax
testl %r8d, %r8d
jle 0x46fc
movzbl (%rbp,%rax), %ecx
xorl %edx, %edx
testq %rcx, %rcx
je 0x46f4
movq (%r12,%rdx,8), %rsi
movzbl (%rsi,%rax), %esi
testq %rsi, %rsi
je 0x46f4
movl %ecx, %r9d
shll $0x8, %r9d
addq %r13, %r9
movb (%rsi,%r9), %sil
movq (%r10,%rdx,8), %r9
xorb %sil, (%r9,%r14)
incq %rdx
cmpq %rdx, %rbx
jne 0x46cc
incq %rax
cmpq 0x28(%rsp), %rax
jne 0x46c0
incq %r14
cmpq 0x20(%rsp), %r14
jne 0x4631
testl %r8d, %r8d
jle 0x4732
xorl %r14d, %r14d
movq (%rdi,%r14,8), %rdi
callq 0x2030
movq 0x40(%rsp), %rdi
incq %r14
cmpq %r14, %rbx
jne 0x471c
callq 0x2030
movq %rbp, %rdi
callq 0x2030
movl 0xc(%rsp), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq