// File: /workspace/github_cpp_makefile_star2_O3/MarkCBell[P]twister/./twister/kernel/twister.cpp
// Function: annulus::twohandle(bool)
void annulus::twohandle(bool is_above)
{
	output_debugging("handle", 2);
	
	manifold *M = sq[0]->home;
	
	if (M->get_manifold_type() == bundle)
		output_error("Cannot attach two-handles to a bundle.");
	
	if (M->get_num_layers() != 0)
		output_error("Handles must be attached before any twisting or drilling occurs.");
	
	tetra *far, *mid, *near;
	
	for(int i = 0; i < length; i++)
	{
		// Glue together a bunch of prisms and
		// attach them to the tops of the cubes.
		
		// construct three tetras
		far = new tetra(M, handle);
		mid = new tetra(M, handle);
		near = new tetra(M, handle);
		
		// Build the prism
		
		// XOR since up/down inverts uprightness
		far->gluesym(mid, 3, (upright[i] ^ is_above) ? perm(0,3,2,1) : perm(0,1,3,2));
		mid->gluesym(near, 3, perm(3,1,2,0));
		
		// Glue prism to the floor / ceiling
		if (is_above)
		{
			far->gluesym(sq[i]->topleft, 0, perm(1,0,2,3));
			mid->gluesym(sq[i]->topright, 0, (upright[i]) ? perm(2,1,0,3) : perm(2,0,3,1));
		}
		else
		{
			far->gluesym(sq[i]->lowleft, 0, perm(3,2,0,1));
			mid->gluesym(sq[i]->lowright, 0, (upright[i]) ? perm(3,0,1,2) : perm(3,2,0,1));
		}
	}
	
	// The next bit of code depends on the values of
	// "far", "mid", and "near" left over from the
	// end of the previous 'for' loop.
	
	tetra *farprev, *midprev, *nearprev;
	int toface = (is_above) ? 2 : 1;
	for (int i = 0; i < length; i++)
	{
		int prev = (i + length - 1) % length;
		
		// Play pass the pointer.
		farprev = far;
		midprev = mid;
		nearprev = near;
		
		far = (is_above) ? sq[i]->topleft->get_gluedto(1) : sq[i]->lowleft->get_gluedto(3);
		mid = far->get_gluedto(3);
		near = mid->get_gluedto(3);
		
		// Glue the prisms to each other.
		near->gluesym(nearprev, toface, perm(0,2,1,3));
		
		(upright[i] ? far : mid)->gluesym((upright[prev] ? midprev : farprev), toface, perm(0,2,1,3));
	}
	
	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %esi, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
leaq 0xa8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x7ffc(%rip), %rsi      # 0x17629
leaq 0x7ffb(%rip), %rdx      # 0x1762f
leaq 0x98(%rsp), %r14
movq %r14, %rdi
callq 0x892e
movq %r14, %rdi
movl $0x2, %esi
callq 0x4229
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0xf66e
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3220
movq 0x8(%rsp), %r14
movq 0x8(%r14), %rax
movq (%rax), %rax
movq 0x38(%rax), %rbx
cmpl $0x1, 0x10(%rbx)
jne 0xf6d2
leaq 0x88(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x7f99(%rip), %rsi      # 0x17630
leaq 0x7fb8(%rip), %rdx      # 0x17656
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x892e
movq %r14, %rdi
callq 0x43b0
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
movq 0x8(%rsp), %r14
je 0xf6d2
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3220
cmpl $0x0, 0x38(%rbx)
je 0xf720
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x7f6f(%rip), %rsi      # 0x17657
leaq 0x7fa8(%rip), %rdx      # 0x17697
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0x892e
movq %r14, %rdi
callq 0x43b0
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
movq 0x8(%rsp), %r14
je 0xf720
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3220
cmpl $0x0, (%r14)
jle 0xfa98
movq %rbx, 0x20(%rsp)
xorl %ebx, %ebx
movl $0xc0, %edi
callq 0x3210
movq %rax, %r15
movq $0x0, (%rsp)
movq %rax, %rdi
movq 0x20(%rsp), %r13
movq %r13, %rsi
movl $0x2, %edx
movl $0x3, %ecx
movl $0x2, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0xde5c
movl $0xc0, %edi
callq 0x3210
movq $0x0, (%rsp)
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r13, %rsi
movl $0x2, %edx
movl $0x3, %ecx
movl $0x2, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0xde5c
movl $0xc0, %edi
callq 0x3210
movq $0x0, (%rsp)
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
movl $0x2, %edx
movl $0x3, %ecx
movl $0x2, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0xde5c
movq 0x10(%r14), %rax
movl 0x18(%rsp), %ecx
cmpb %cl, (%rax,%rbx)
jne 0xf803
leaq 0x30(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x3, %ecx
movl $0x2, %r8d
jmp 0xf81d
leaq 0x30(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
movl $0x3, %edx
movl $0x2, %ecx
movl $0x1, %r8d
callq 0x8860
movq %r15, %rdi
movq 0x10(%rsp), %rbp
movq %rbp, %rsi
movl $0x3, %edx
movq %r13, %rcx
callq 0xe04e
movq %r13, %rdi
movl $0x3, %esi
movl $0x1, %edx
movl $0x2, %ecx
xorl %r8d, %r8d
callq 0x8860
movq %rbp, %rdi
movq %r12, 0x50(%rsp)
movq %r12, %rsi
movl $0x3, %edx
movq %r13, %rcx
callq 0xe04e
movq 0x8(%r14), %rax
movq (%rax,%rbx,8), %rax
cmpb $0x0, 0x18(%rsp)
je 0xf8d8
movq (%rax), %r12
movq %r13, %rdi
movl $0x1, %esi
xorl %edx, %edx
movl $0x2, %ecx
movl $0x3, %r8d
callq 0x8860
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0xe04e
movq 0x8(%r14), %rax
movq (%rax,%rbx,8), %rax
movq 0x18(%rax), %r12
movq 0x10(%r14), %rax
cmpb $0x1, (%rax,%rbx)
jne 0xf933
movq %r13, %rdi
movl $0x2, %esi
movl $0x1, %edx
xorl %ecx, %ecx
movl $0x3, %r8d
jmp 0xf959
movq 0x10(%rax), %r12
movq %r13, %rdi
movl $0x3, %esi
movl $0x2, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x8860
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0xe04e
movq 0x8(%r14), %rax
movq (%rax,%rbx,8), %rax
movq 0x28(%rax), %r12
movq 0x10(%r14), %rax
cmpb $0x1, (%rax,%rbx)
jne 0xf944
movq %r13, %rdi
movl $0x3, %esi
xorl %edx, %edx
movl $0x1, %ecx
movl $0x2, %r8d
jmp 0xf959
movq %r13, %rdi
movl $0x2, %esi
xorl %edx, %edx
movl $0x3, %ecx
jmp 0xf953
movq %r13, %rdi
movl $0x3, %esi
movl $0x2, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x8860
movq %r13, %rcx
movq 0x10(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xe04e
incq %rbx
movq 0x8(%rsp), %r14
movslq (%r14), %rcx
cmpq %rcx, %rbx
jl 0xf731
testl %ecx, %ecx
movq 0x50(%rsp), %r13
jle 0xfa98
movq %r15, %r12
movl 0x18(%rsp), %eax
movzbl %al, %edx
incl %edx
movl %edx, 0x2c(%rsp)
xorb $0x1, %al
movzbl %al, %edx
shll $0x4, %edx
movq %rdx, 0x48(%rsp)
leaq 0x18(%rdx), %rax
movq %rax, 0x40(%rsp)
xorl %ebx, %ebx
leal (%rbx,%rcx), %eax
decl %eax
cltd
idivl %ecx
movl %edx, 0x20(%rsp)
movq 0x8(%r14), %rax
movq (%rax,%rbx,8), %rax
movq 0x48(%rsp), %rcx
movq (%rax,%rcx), %rax
movq 0x40(%rsp), %rcx
movq (%rax,%rcx), %rbp
movq 0x28(%rbp), %r15
movq 0x28(%r15), %r14
movq %r14, 0x18(%rsp)
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x1, %ecx
movl $0x3, %r8d
callq 0x8860
movq %r14, %rdi
movq %r13, %rsi
movl 0x2c(%rsp), %r14d
movl %r14d, %edx
leaq 0x30(%rsp), %rcx
callq 0xe04e
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
cmpb $0x0, (%rax,%rbx)
movq %r15, %r13
cmovneq %rbp, %r13
movslq 0x20(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
cmovneq 0x10(%rsp), %r12
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x1, %ecx
movl $0x3, %r8d
callq 0x8860
movq %r13, %rdi
movq %r12, %rsi
movl %r14d, %edx
leaq 0x30(%rsp), %rcx
callq 0xe04e
incq %rbx
movq 0x8(%rsp), %rax
movslq (%rax), %rcx
movq %rbp, %r12
movq 0x8(%rsp), %r14
movq %r15, 0x10(%rsp)
movq 0x18(%rsp), %r13
cmpq %rcx, %rbx
jl 0xf9b9
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0xfb1e
movq 0x88(%rsp), %rsi
jmp 0xfaed
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0xfb1e
movq 0x68(%rsp), %rsi
jmp 0xfaed
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0xfb1e
movq 0xa8(%rsp), %rsi
incq %rsi
jmp 0xfb19
movq %rax, %rbx
movl $0xc0, %esi
movq %r15, %rdi
jmp 0xfb19
movq %rax, %rbx
movl $0xc0, %esi
movq 0x10(%rsp), %rdi
jmp 0xfb19
movq %rax, %rbx
movl $0xc0, %esi
movq %r12, %rdi
callq 0x3220
movq %rbx, %rdi
callq 0x33e0