// File: /workspace/github_cpp_makefile_star2_O1/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, %r13d
movq %rdi, 0x10(%rsp)
leaq 0xa8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x80a3(%rip), %rsi      # 0x175e9
leaq 0x80a2(%rip), %rdx      # 0x175ef
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
callq 0x86fe
movq %rbx, %rdi
movl $0x2, %esi
callq 0x4209
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0xf587
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3220
movq 0x10(%rsp), %rax
movq %rax, %r14
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x38(%rax), %rbx
cmpl $0x1, 0x10(%rbx)
movq %rbx, 0x28(%rsp)
jne 0xf5f8
leaq 0x88(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x8038(%rip), %rsi      # 0x175f0
leaq 0x8057(%rip), %rdx      # 0x17616
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x86fe
movq %rbx, %rdi
callq 0x4397
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
movq 0x10(%rsp), %r14
movq 0x28(%rsp), %rbx
je 0xf5f8
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3220
cmpl $0x0, 0x38(%rbx)
movq %r14, %rbx
je 0xf649
leaq 0x68(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x8006(%rip), %rsi      # 0x17617
leaq 0x803f(%rip), %rdx      # 0x17657
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0x86fe
movq %rbx, %rdi
callq 0x4397
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
movq 0x10(%rsp), %rbx
je 0xf649
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3220
cmpl $0x0, (%rbx)
jle 0xf8c3
movq $0x0, 0x20(%rsp)
movl %r13d, %r14d
movl %r13d, 0x30(%rsp)
movq %rbx, %r15
movl $0xc0, %edi
callq 0x3210
movq %rax, %r12
movq $0x0, (%rsp)
movq %rax, %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
movl $0x2, %edx
movl $0x3, %ecx
movl $0x2, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0xdc7c
movl $0xc0, %edi
callq 0x3210
movq $0x0, (%rsp)
movq %rax, %r13
movq %rax, %rdi
movq %rbx, %rsi
movl $0x2, %edx
movl $0x3, %ecx
movl $0x2, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0xdc7c
movl $0xc0, %edi
callq 0x3210
movq $0x0, (%rsp)
movq %rax, %rbp
movq %rax, %rdi
movq %rbx, %rsi
movl $0x2, %edx
movl $0x3, %ecx
movl $0x2, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0xdc7c
movq %r15, %rbx
movq 0x10(%r15), %rax
movl %r14d, %r15d
movq 0x20(%rsp), %rcx
cmpb %r15b, (%rax,%rcx)
movq %r13, 0x18(%rsp)
leaq 0x40(%rsp), %r13
movq %r13, %rdi
jne 0xf743
xorl %esi, %esi
movl $0x1, %edx
movl $0x3, %ecx
movl $0x2, %r8d
jmp 0xf755
xorl %esi, %esi
movl $0x3, %edx
movl $0x2, %ecx
movl $0x1, %r8d
callq 0x8630
movq %r12, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
movl $0x3, %edx
movq %r13, %rcx
callq 0xde78
movq %r13, %rdi
movl $0x3, %esi
movl $0x1, %edx
movl $0x2, %ecx
xorl %r8d, %r8d
callq 0x8630
movq %r14, %rdi
movq %rbp, %rsi
movl $0x3, %edx
movq %r13, %rcx
callq 0xde78
movq 0x8(%rbx), %rax
movq 0x20(%rsp), %r14
movq (%rax,%r14,8), %rax
testb %r15b, %r15b
je 0xf80f
movq (%rax), %r15
movq %r13, %rdi
movl $0x1, %esi
xorl %edx, %edx
movl $0x2, %ecx
movl $0x3, %r8d
callq 0x8630
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0xde78
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rax
movq 0x18(%rax), %r15
movq 0x10(%rbx), %rax
cmpb $0x1, (%rax,%r14)
jne 0xf86b
movq %r13, %rdi
movl $0x2, %esi
movl $0x1, %edx
xorl %ecx, %ecx
movl $0x3, %r8d
jmp 0xf891
movq 0x10(%rax), %r15
movq %r13, %rdi
movl $0x3, %esi
movl $0x2, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x8630
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0xde78
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rax
movq 0x28(%rax), %r15
movq 0x10(%rbx), %rax
cmpb $0x1, (%rax,%r14)
jne 0xf87c
movq %r13, %rdi
movl $0x3, %esi
xorl %edx, %edx
movl $0x1, %ecx
movl $0x2, %r8d
jmp 0xf891
movq %r13, %rdi
movl $0x2, %esi
xorl %edx, %edx
movl $0x3, %ecx
jmp 0xf88b
movq %r13, %rdi
movl $0x3, %esi
movl $0x2, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x8630
movq 0x18(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0xde78
incq %r14
movslq (%rbx), %rax
movq %r14, 0x20(%rsp)
cmpq %rax, %r14
movl 0x30(%rsp), %r14d
jl 0xf663
jmp 0xf8c6
movl %r13d, %r14d
movl (%rbx), %ecx
testl %ecx, %ecx
movq 0x18(%rsp), %rsi
jle 0xf9e2
movzbl %r14b, %eax
incl %eax
movl %eax, 0x3c(%rsp)
xorb $0x1, %r14b
movzbl %r14b, %edx
shll $0x4, %edx
movq %rdx, 0x30(%rsp)
leaq 0x18(%rdx), %rax
movq %rax, 0x50(%rsp)
xorl %r15d, %r15d
movq %rsi, 0x18(%rsp)
leal (%r15,%rcx), %eax
decl %eax
cltd
idivl %ecx
movl %edx, 0x28(%rsp)
movq 0x8(%rbx), %rax
movq (%rax,%r15,8), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx), %rax
movq 0x50(%rsp), %rcx
movq (%rax,%rcx), %r14
movq %rbp, %rbx
movq 0x28(%r14), %rbp
movq 0x28(%rbp), %r13
movq %r13, 0x20(%rsp)
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x1, %ecx
movl $0x3, %r8d
callq 0x8630
movq %r13, %rdi
movq %rbx, %rsi
movl 0x3c(%rsp), %r13d
movl %r13d, %edx
leaq 0x40(%rsp), %rcx
callq 0xde78
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
cmpb $0x0, (%rax,%r15)
movq %rbp, %rbx
cmovneq %r14, %rbx
movslq 0x28(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
cmovneq 0x18(%rsp), %r12
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x1, %ecx
movl $0x3, %r8d
callq 0x8630
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %edx
leaq 0x40(%rsp), %rcx
callq 0xde78
incq %r15
movq 0x10(%rsp), %rax
movslq (%rax), %rcx
movq %r14, %r12
movq 0x10(%rsp), %rbx
movq %rbp, %rsi
movq 0x20(%rsp), %rbp
cmpq %rcx, %r15
jl 0xf8fb
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0xfa66
movq 0x88(%rsp), %rsi
jmp 0xfa37
movq %rax, %r15
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0xfa66
movq 0x68(%rsp), %rsi
jmp 0xfa37
movq %rax, %r15
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0xfa66
movq 0xa8(%rsp), %rsi
incq %rsi
jmp 0xfa61
movq %rax, %r15
movl $0xc0, %esi
movq %r12, %rdi
jmp 0xfa61
movq %rax, %r15
movl $0xc0, %esi
movq %r13, %rdi
jmp 0xfa61
movq %rax, %r15
movl $0xc0, %esi
movq %rbp, %rdi
callq 0x3220
movq %r15, %rdi
callq 0x33e0