// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movl %esi, 0x14(%rsp)
movq %rdi, 0x18(%rsp)
leaq 0x5c8e(%rip), %rsi      # 0x11581
leaq 0xa8(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x3e82
leaq 0xa8(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x3d1a
leaq 0xa8(%rsp), %rdi
callq 0x3458
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x38(%rax), %rbx
cmpl $0x1, 0x10(%rbx)
jne 0xb96b
leaq 0x5c49(%rip), %rsi      # 0x11588
leaq 0x88(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x3e82
leaq 0x88(%rsp), %rdi
callq 0x3dec
leaq 0x88(%rsp), %rdi
callq 0x3458
cmpl $0x0, 0x38(%rbx)
je 0xb99b
leaq 0x5c37(%rip), %rsi      # 0x115af
leaq 0x68(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x3e82
leaq 0x68(%rsp), %rdi
callq 0x3dec
leaq 0x68(%rsp), %rdi
callq 0x3458
movq %rbx, 0x30(%rsp)
xorl %ebx, %ebx
pushq $0x3
popq %r15
pushq $0x2
popq %r14
pushq $-0x1
popq %r12
movq 0x18(%rsp), %rax
movslq (%rax), %rcx
cmpq %rcx, %rbx
jge 0xbbdc
movq %rbx, 0x28(%rsp)
movl $0xc0, %edi
callq 0x3240
movq %rax, %r13
andq $0x0, (%rsp)
movq %rax, %rdi
movq 0x30(%rsp), %rbp
movq %rbp, %rsi
movl %r14d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
movl %r12d, %r9d
callq 0xa3fa
movl $0xc0, %edi
callq 0x3240
andq $0x0, (%rsp)
movq %rax, %rbx
movq %rax, %rdi
movq %rbp, %rsi
movl %r14d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
movl %r12d, %r9d
callq 0xa3fa
movl $0xc0, %edi
callq 0x3240
andq $0x0, (%rsp)
movq %rax, 0x38(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
movl %r14d, %edx
movl %r14d, %r8d
movl %r15d, %r14d
movl %r15d, %ecx
movl %r8d, %ebp
movl %r12d, %r9d
callq 0xa3fa
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x14(%rsp), %ecx
movq 0x28(%rsp), %rdx
cmpb %cl, (%rax,%rdx)
movq %rbx, 0x20(%rsp)
leaq 0x40(%rsp), %r12
movq %r12, %rdi
jne 0xba85
xorl %esi, %esi
pushq $0x1
popq %rbx
movl %ebx, %edx
movl %r14d, %r15d
movl %r14d, %ecx
movl %ebp, %r14d
movl %ebp, %r8d
jmp 0xba98
xorl %esi, %esi
movl %r14d, %r15d
movl %r14d, %edx
movl %ebp, %r14d
movl %ebp, %ecx
pushq $0x1
popq %rbx
movl %ebx, %r8d
callq 0x6790
movq %r13, %rdi
movq 0x20(%rsp), %rbp
movq %rbp, %rsi
movl %r15d, %edx
movq %r12, %rcx
callq 0xa5d2
movq %r12, %rdi
movl %r15d, %esi
movl %ebx, %edx
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x6790
movq %rbp, %rdi
movq 0x38(%rsp), %rsi
movl %r15d, %edx
movq %r12, %rcx
callq 0xa5d2
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movl %ebx, %r8d
movq 0x28(%rsp), %rbx
movq (%rax,%rbx,8), %rax
cmpb $0x0, 0x14(%rsp)
movq %r12, %rbp
movq %r13, 0x50(%rsp)
je 0xbb4e
movq (%rax), %r12
movq %rbp, %rdi
movl %r8d, %esi
xorl %edx, %edx
movl %r14d, %ecx
movl %r15d, %r8d
callq 0x6790
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %rbp, %rcx
callq 0xa5d2
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rax
movq (%rax,%rbx,8), %rax
movq 0x18(%rax), %r13
movq 0x10(%rcx), %rax
cmpb $0x1, (%rax,%rbx)
jne 0xbb9d
movq %rbp, %rdi
movl %r14d, %esi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
movl %r15d, %r8d
jmp 0xbbb9
movq 0x10(%rax), %r12
movq %rbp, %rdi
movl %r15d, %esi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x6790
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %rbp, %rcx
callq 0xa5d2
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rax
movq (%rax,%rbx,8), %rax
movq 0x28(%rax), %r13
movq 0x10(%rcx), %rax
cmpb $0x1, (%rax,%rbx)
jne 0xbbaa
movq %rbp, %rdi
movl %r15d, %esi
xorl %edx, %edx
pushq $0x1
popq %rcx
movl %r14d, %r8d
jmp 0xbbb9
movq %rbp, %rdi
movl %r14d, %esi
xorl %edx, %edx
movl %r15d, %ecx
jmp 0xbbb5
movq %rbp, %rdi
movl %r15d, %esi
movl %r14d, %edx
xorl %ecx, %ecx
pushq $0x1
popq %r8
callq 0x6790
pushq $-0x1
popq %r12
movq 0x20(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rbp, %rcx
callq 0xa5d2
incq %rbx
jmp 0xb9ae
movzbl 0x14(%rsp), %eax
leal 0x1(%rax), %edx
movl %edx, 0x30(%rsp)
xorb $0x1, %al
movzbl %al, %edx
shll $0x4, %edx
movq %rdx, 0x60(%rsp)
leaq 0x18(%rdx), %rax
movq %rax, 0x58(%rsp)
xorl %r15d, %r15d
movq 0x38(%rsp), %r13
movslq %ecx, %rax
cmpq %rax, %r15
jge 0xbce8
leal (%r15,%rcx), %eax
decl %eax
cltd
idivl %ecx
movl %edx, 0x14(%rsp)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax,%r15,8), %rax
movq 0x60(%rsp), %rcx
movq (%rax,%rcx), %rax
movq 0x58(%rsp), %rcx
movq (%rax,%rcx), %r14
movq 0x28(%r14), %r12
movq 0x28(%r12), %rbx
movq %rbx, 0x28(%rsp)
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
pushq $0x1
popq %rcx
pushq $0x3
popq %r8
callq 0x6790
movq %rbx, %rdi
movq %r13, %rsi
movl 0x30(%rsp), %ebx
movl %ebx, %edx
movq %rbp, %rcx
callq 0xa5d2
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
cmpb $0x0, (%rax,%r15)
movq %r12, %rbp
cmovneq %r14, %rbp
movslq 0x14(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
movq 0x50(%rsp), %r13
cmovneq 0x20(%rsp), %r13
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
pushq $0x1
popq %rcx
pushq $0x3
popq %r8
callq 0x6790
movq %rbp, %rdi
movq %r13, %rsi
movl %ebx, %edx
leaq 0x40(%rsp), %rcx
callq 0xa5d2
incq %r15
movq 0x18(%rsp), %rax
movl (%rax), %ecx
movq 0x28(%rsp), %r13
movq %r12, 0x20(%rsp)
movq %r14, 0x50(%rsp)
jmp 0xbc06
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq 0x88(%rsp), %rdi
jmp 0xbd20
jmp 0xbd27
movq %rax, %r14
leaq 0x68(%rsp), %rdi
jmp 0xbd20
jmp 0xbd27
movq %rax, %r14
leaq 0xa8(%rsp), %rdi
callq 0x3458
jmp 0xbd58
movq %rax, %r14
jmp 0xbd58
movq %rax, %r14
movl $0xc0, %esi
movq 0x38(%rsp), %rdi
jmp 0xbd53
movq %rax, %r14
movl $0xc0, %esi
movq %rbx, %rdi
jmp 0xbd53
movq %rax, %r14
movl $0xc0, %esi
movq %r13, %rdi
callq 0x3250
movq %r14, %rdi
callq 0x33d0