// File: /workspace/github_c_makefile_star2_O2/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
movl %r8d, %r13d
testl %edx, %edx
sete %al
testl %r9d, %r9d
sete %r8b
xorl %ebp, %ebp
orb %al, %r8b
jne 0x3f2e
movl %r9d, %r15d
movq %rdi, 0x50(%rsp)
movq %rcx, 0x8(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x28(%rsp)
leal (%r15,%rdx), %ebp
movslq %r13d, %rbx
leaq (,%rbx,8), %rdi
callq 0x21c0
movq %rbx, %r11
movq %rax, %rbx
movslq %ebp, %rax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
testl %r11d, %r11d
movl $0x0, %r14d
movl %r13d, 0x4(%rsp)
cmovgl %r13d, %r14d
movq %r11, 0x20(%rsp)
cmpq %r12, %r14
je 0x3a55
movq 0x18(%rsp), %rdi
callq 0x21c0
movq 0x20(%rsp), %r11
movq %rax, (%rbx,%r12,8)
incq %r12
jmp 0x3a38
xorl %eax, %eax
movq 0x28(%rsp), %r8
testl %r8d, %r8d
movl $0x0, %ecx
cmovgl %r8d, %ecx
movq %rcx, 0x48(%rsp)
movslq %r8d, %rsi
testl %r15d, %r15d
cmovlel %eax, %r15d
movq 0x38(%rsp), %r10
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %r12
cmpq %r14, %rax
je 0x3acb
xorl %ecx, %ecx
cmpq %rcx, 0x48(%rsp)
je 0x3aa8
movq (%r10,%rax,8), %rdx
movb (%rdx,%rcx), %dl
movq (%rbx,%rax,8), %r9
movb %dl, (%r9,%rcx)
incq %rcx
jmp 0x3a8d
xorl %ecx, %ecx
cmpq %rcx, %r15
je 0x3ac6
movq (%r12,%rax,8), %rdx
movb (%rdx,%rcx), %dl
movq (%rbx,%rax,8), %r9
addq %rsi, %r9
movb %dl, (%rcx,%r9)
incq %rcx
jmp 0x3aaa
incq %rax
jmp 0x3a86
movl 0x4(%rsp), %eax
cmpl %r8d, %eax
movl %r8d, %ecx
cmovll %eax, %ecx
xorl %r12d, %r12d
testl %ecx, %ecx
cmovlel %r12d, %ecx
movq %rcx, 0x58(%rsp)
movl %r8d, %r8d
movl %eax, %eax
movq %rax, 0x8(%rsp)
pushq $0x1
popq %rax
movq %rax, 0x40(%rsp)
movq %rsi, 0x10(%rsp)
movq %r8, 0x30(%rsp)
cmpl %ebp, %r12d
movl %ebp, %eax
cmovgl %r12d, %eax
movq %rax, 0x60(%rsp)
cmpq 0x58(%rsp), %r12
je 0x3c82
movq %r12, %r15
cmpq %r8, %r15
je 0x3bb9
movq %r12, %rax
movq 0x8(%rsp), %rdx
cmpq %rax, %rdx
je 0x3ba3
movq (%rbx,%rax,8), %rcx
cmpb $0x0, (%rcx,%r15)
jne 0x3b44
incq %rax
jmp 0x3b2f
movl %eax, %eax
cmpq %r12, %rax
je 0x3b5b
movq (%rbx,%rax,8), %rcx
movq (%rbx,%r12,8), %rdx
movq %rdx, (%rbx,%rax,8)
movq %rcx, (%rbx,%r12,8)
cmpq %r12, %r15
je 0x3ba3
movl %r15d, %edi
movl %r12d, %esi
movq %rbx, %rdx
movl 0x4(%rsp), %r13d
movl %r13d, %ecx
movl %ebp, %r8d
callq 0x2b55
movl %r15d, %edi
movl %r12d, %esi
movq 0x38(%rsp), %rdx
movl %r13d, %ecx
movl %ebp, %r8d
callq 0x2b55
movq 0x30(%rsp), %r8
movq 0x20(%rsp), %r11
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rbx,%r12,8), %r13
movb (%r13,%r12), %al
incq %r15
testb %al, %al
je 0x3b1e
jmp 0x3bca
movq (%rbx,%r12,8), %r13
movb (%r13,%r12), %al
testb %al, %al
je 0x3c82
movzbl %al, %edi
callq 0x2433
movzbl %al, %eax
shll $0x8, %eax
movq %r12, %rcx
movq 0x40(%rsp), %r15
movq 0x60(%rsp), %rdi
cmpq %rcx, %rdi
je 0x3c07
movzbl (%r13,%rcx), %edx
leaq 0x13419(%rip), %rsi     # 0x17010
addq %rax, %rsi
movb (%rdx,%rsi), %dl
movb %dl, (%r13,%rcx)
incq %rcx
jmp 0x3be5
movq %r15, %rax
movl 0x4(%rsp), %r8d
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %r11
cmpl %r8d, %eax
jge 0x3c6d
movq (%rbx,%rax,8), %rcx
cmpb $0x0, (%rcx,%r12)
je 0x3c68
movq %r12, %rdx
leal 0x1(%rdx), %r9d
cmpl %r9d, %ebp
jle 0x3c63
movzbl 0x1(%r13,%rdx), %r9d
testq %r9, %r9
je 0x3c5e
movzbl (%rcx,%r12), %r10d
shll $0x8, %r10d
addq 0x2c38b(%rip), %r10     # 0x2ffe0
movb (%r9,%r10), %r9b
xorb %r9b, 0x1(%rcx,%rdx)
incq %rdx
jmp 0x3c31
movb $0x0, (%rcx,%r12)
incq %rax
jmp 0x3c1e
incq %r12
incq %r15
movq %r15, 0x40(%rsp)
movq 0x30(%rsp), %r8
jmp 0x3b02
movl 0x4(%rsp), %eax
cmpl %eax, %ebp
cmovll %ebp, %eax
movslq %eax, %rcx
movq 0x28(%rsp), %rax
cmpl %ecx, %eax
movq %rcx, 0x30(%rsp)
cmovlel %ecx, %eax
movq %rax, 0x28(%rsp)
leaq (%rbx,%rsi,8), %r12
cmpq 0x30(%rsp), %rsi
jge 0x3de2
leaq 0x1(%rsi), %rax
movq %rax, 0x8(%rsp)
cltq
movq %rax, 0x10(%rsp)
movq %rsi, %r15
cmpq %rdi, %r15
jge 0x3d2e
xorl %eax, %eax
leaq (%rsi,%rax), %rcx
cmpq %r11, %rcx
jge 0x3d1c
movq (%r12,%rax,8), %rcx
cmpb $0x0, (%rcx,%r15)
jne 0x3ce4
incq %rax
jmp 0x3ccb
testq %rax, %rax
je 0x3cf5
movq (%rbx,%rsi,8), %rdx
movq %rdx, (%r12,%rax,8)
movq %rcx, (%rbx,%rsi,8)
cmpq %rsi, %r15
je 0x3d1c
movl %r15d, %edi
movq %rbx, %rdx
movl 0x4(%rsp), %ecx
movl %ebp, %r8d
movq %rsi, %r13
callq 0x2b55
movq 0x20(%rsp), %r11
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movq (%rbx,%rsi,8), %r13
movb (%r13,%rsi), %al
incq %r15
testb %al, %al
je 0x3cc4
jmp 0x3d3f
movq (%rbx,%rsi,8), %r13
movb (%r13,%rsi), %al
testb %al, %al
je 0x3de9
movzbl %al, %edi
movq %rsi, %r15
callq 0x2433
movq 0x20(%rsp), %r11
movq 0x18(%rsp), %rdi
movq %r15, %r8
movzbl %al, %eax
shll $0x8, %eax
movq %r15, %rcx
movq 0x10(%rsp), %r10
cmpq %rdi, %rcx
jge 0x3d87
movzbl (%r13,%rcx), %edx
leaq 0x13299(%rip), %rsi     # 0x17010
addq %rax, %rsi
movb (%rdx,%rsi), %dl
movb %dl, (%r13,%rcx)
incq %rcx
jmp 0x3d65
movq %r10, %rax
cmpq %r11, %rax
jge 0x3dd4
movq (%rbx,%rax,8), %rcx
cmpb $0x0, (%rcx,%r8)
je 0x3dcf
movq %r10, %rdx
cmpq %rdi, %rdx
jge 0x3dca
movzbl (%r13,%rdx), %esi
testq %rsi, %rsi
je 0x3dc5
movzbl (%rcx,%r8), %r9d
shll $0x8, %r9d
addq 0x2c223(%rip), %r9      # 0x2ffe0
movb (%rsi,%r9), %sil
xorb %sil, (%rcx,%rdx)
incq %rdx
jmp 0x3d9d
movb $0x0, (%rcx,%r8)
incq %rax
jmp 0x3d8a
addq $0x8, %r12
movq 0x8(%rsp), %rsi
jmp 0x3ca6
movq 0x28(%rsp), %rax
movl %eax, %esi
movl %ebp, %r15d
movq %rsi, 0x10(%rsp)
subl %esi, %r15d
callq 0x21c0
movq 0x38(%rsp), %r11
movq %rax, %r12
xorl %ecx, %ecx
testl %r15d, %r15d
movl $0x0, %eax
movl %r15d, 0x8(%rsp)
cmovgl %r15d, %eax
movq 0x50(%rsp), %r15
leaq 0x131f0(%rip), %r13     # 0x17010
cmpq %rax, %rcx
je 0x3e3e
xorl %edx, %edx
cmpq %rdx, %r14
je 0x3e39
movq (%r15,%rdx,8), %rsi
movb $0x0, (%rsi,%rcx)
incq %rdx
jmp 0x3e27
incq %rcx
jmp 0x3e20
xorl %ecx, %ecx
testl %ebp, %ebp
movl $0x0, %edx
cmovgl %ebp, %edx
movl 0x10(%rsp), %esi
cmpq %rax, %rcx
je 0x3f04
xorl %edi, %edi
cmpq %rdi, %rdx
je 0x3e68
movb $0x0, (%r12,%rdi)
incq %rdi
jmp 0x3e59
movl %ecx, %edi
notl %edi
addl %ebp, %edi
movslq %edi, %rdi
movb $0x1, (%r12,%rdi)
movq %rsi, %rdi
testl %edi, %edi
jle 0x3eb6
leaq -0x1(%rdi), %r8
cmpl %edi, %ebp
jle 0x3eb1
movzbl (%r12,%rdi), %r9d
testq %r9, %r9
je 0x3eac
movq (%rbx,%r8,8), %r10
movzbl (%r10,%rdi), %r10d
testq %r10, %r10
je 0x3eac
shll $0x8, %r9d
addq %r13, %r9
movb (%r10,%r9), %r9b
xorb %r9b, (%r12,%r8)
incq %rdi
jmp 0x3e81
movq %r8, %rdi
jmp 0x3e79
xorl %edi, %edi
cmpq 0x48(%rsp), %rdi
je 0x3efc
xorl %r8d, %r8d
cmpq %r8, %r14
je 0x3ef7
movzbl (%r12,%rdi), %r9d
testq %r9, %r9
je 0x3ef2
movq (%r11,%r8,8), %r10
movzbl (%r10,%rdi), %r10d
testq %r10, %r10
je 0x3ef2
shll $0x8, %r9d
addq %r13, %r9
movb (%r10,%r9), %r9b
movq (%r15,%r8,8), %r10
xorb %r9b, (%r10,%rcx)
incq %r8
jmp 0x3ec2
incq %rdi
jmp 0x3eb8
incq %rcx
jmp 0x3e4e
xorl %r15d, %r15d
movl 0x8(%rsp), %ebp
cmpq %r15, %r14
je 0x3f1e
movq (%rbx,%r15,8), %rdi
callq 0x2030
incq %r15
jmp 0x3f0b
movq %rbx, %rdi
callq 0x2030
movq %r12, %rdi
callq 0x2030
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq