// File: MarkCBell[P]twister/./twister/kernel/twister.cpp
// Function: glue_cubes(cube*, cube*, bool, bool)
void glue_cubes(cube *c1, cube *c2, bool u1, bool u2)
{
	// Depending on the orientations of c1 and c2, glue some
	// vertical face of cube c1 to some vertical face of cube c2.
	int toface = u1 ? 1 : 0;
	perm howto = u1 ? perm(0,2,1,3) : perm(2,1,0,3);
	
	if (u1 && u2)
	{
		(c1->get_tetra(low, right))->gluesym(c2->get_tetra(low, left), toface, howto);
		(c1->get_tetra(top, right))->gluesym(c2->get_tetra(top, left), toface, howto);
	}
	else if (u1 && !u2)
	{
		(c1->get_tetra(low, right))->gluesym(c2->get_tetra(low, right), toface, howto);
		(c1->get_tetra(top, right))->gluesym(c2->get_tetra(mid, right), toface, howto);
	}
	else if (!u1 && u2)
	{
		(c1->get_tetra(mid, left))->gluesym(c2->get_tetra(low, left), toface, howto);
		(c1->get_tetra(top, left))->gluesym(c2->get_tetra(top, left), toface, howto);
	}
	else if (!u1 && !u2)
	{
		(c1->get_tetra(mid, left))->gluesym(c2->get_tetra(low, right), toface, howto);
		(c1->get_tetra(top, left))->gluesym(c2->get_tetra(mid, right), toface, howto);
	}
	
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %cl, %al
movb %dl, %cl
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %cl
movb %cl, -0x11(%rbp)
andb $0x1, %al
movb %al, -0x12(%rbp)
movb -0x11(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x18(%rbp)
testb $0x1, -0x11(%rbp)
je 0x181a5
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x1, %ecx
movl $0x3, %r8d
callq 0x9cc0
jmp 0x181c0
leaq -0x28(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %edx
xorl %ecx, %ecx
movl $0x3, %r8d
callq 0x9cc0
testb $0x1, -0x11(%rbp)
je 0x1823f
testb $0x1, -0x12(%rbp)
je 0x1823f
movq -0x8(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x20bc0
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x20bc0
movq -0x38(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %edx
leaq -0x28(%rbp), %rcx
callq 0x17390
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x20bc0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x20bc0
movq -0x30(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %edx
leaq -0x28(%rbp), %rcx
callq 0x17390
jmp 0x183ba
testb $0x1, -0x11(%rbp)
je 0x182c4
testb $0x1, -0x12(%rbp)
jne 0x182c4
movq -0x8(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x20bc0
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x20bc0
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %edx
leaq -0x28(%rbp), %rcx
callq 0x17390
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x20bc0
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x20bc0
movq -0x40(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %edx
leaq -0x28(%rbp), %rcx
callq 0x17390
jmp 0x183b8
testb $0x1, -0x11(%rbp)
jne 0x1833a
testb $0x1, -0x12(%rbp)
je 0x1833a
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x20bc0
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x20bc0
movq -0x58(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %edx
leaq -0x28(%rbp), %rcx
callq 0x17390
movq -0x8(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x20bc0
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x20bc0
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %edx
leaq -0x28(%rbp), %rcx
callq 0x17390
jmp 0x183b6
testb $0x1, -0x11(%rbp)
jne 0x183b4
testb $0x1, -0x12(%rbp)
jne 0x183b4
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x20bc0
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x20bc0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %edx
leaq -0x28(%rbp), %rcx
callq 0x17390
movq -0x8(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x20bc0
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x20bc0
movq -0x60(%rbp), %rdi
movq %rax, %rsi
movl -0x18(%rbp), %edx
leaq -0x28(%rbp), %rcx
callq 0x17390
jmp 0x183b6
jmp 0x183b8
jmp 0x183ba
addq $0x70, %rsp
popq %rbp
retq