// File: MarkCBell[P]twister/./twister/kernel/twister.cpp
// Function: rectangle::drill()
void rectangle::drill()
{
	output_debugging("drill", 2);
	
	manifold *M = sq[0]->home;
	
	// First find out if we need a new layer.
	bool need_new_layer = false;
	for (int i = 0; i < length; i++)
		if (! sq[i]->get_status())
		{
			need_new_layer = true;
			break;
		}
	
	if ((M->marked_points[front] == half_twisted) || (M->marked_points[back] == half_twisted))
		need_new_layer = true;
	
	if (need_new_layer) M->insert_layer();
	
	for (int i = 0; i < length; i++)
		sq[i]->set_status(false);
	
	M->marked_points[front] = drilled;
	M->marked_points[back] = drilled;
	
	// Convert each child cube to a gadget.
	std::vector<cube*> new_cubes;
	for (int i = 0; i < length; i++)
		new_cubes.push_back(convert_cube_to_gadget(sq[i], upright[i]));
	
	// Gadget pups can't get horizontal gluing information from their parents.
	// So we must provide it now.
	for (int i = 0; i < length - 1; i++)
	{
		int j = i + 1;
		// Glue pup_gadgets together.
		tetra *current_top_back = new_cubes[i]->get_tetra(low, left)->get_child();
		tetra *next_top_front = new_cubes[j]->get_tetra(top, left)->get_child();
		tetra *current_bottom_back = new_cubes[i]->get_tetra(low, right)->get_child();
		tetra *next_bottom_front = new_cubes[j]->get_tetra(top, right)->get_child();
		
		// (*1*) Gadgets were designed so this was true. :)
		current_top_back->gluesym(next_top_front, 0, perm(0,1,3,2));
		current_bottom_back->gluesym(next_bottom_front, 0, perm(0,1,3,2));
		
		glue_cubes(new_cubes[i], new_cubes[j], upright[i], upright[j]);
	}
	
	for (int i = 0; i < length; i++)
		delete new_cubes[i];
	
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x3560
movq -0xd8(%rbp), %rdx
leaq 0xb57c(%rip), %rsi      # 0x275d4
leaq -0x28(%rbp), %rdi
callq 0x4e10
jmp 0x1c063
leaq -0x28(%rbp), %rdi
movl $0x2, %esi
callq 0x4c10
jmp 0x1c073
leaq -0x28(%rbp), %rdi
callq 0x35f8
leaq -0x29(%rbp), %rdi
callq 0x3360
movq -0xe0(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x38(%rax), %rax
movq %rax, -0x48(%rbp)
movb $0x0, -0x49(%rbp)
movl $0x0, -0x50(%rbp)
movq -0xe0(%rbp), %rcx
movl -0x50(%rbp), %eax
cmpl (%rcx), %eax
jge 0x1c114
movq -0xe0(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x211c0
testb $0x1, %al
jne 0x1c107
movb $0x1, -0x49(%rbp)
jmp 0x1c114
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1c0f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x35f8
leaq -0x29(%rbp), %rdi
callq 0x3360
jmp 0x1c56d
jmp 0x1c109
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x1c0a6
movq -0xe0(%rbp), %rax
movq -0x48(%rbp), %rdi
addq $0x58, %rdi
movslq 0x18(%rax), %rsi
callq 0x9af0
cmpl $0x2, (%rax)
je 0x1c14e
movq -0xe0(%rbp), %rax
movq -0x48(%rbp), %rdi
addq $0x58, %rdi
movslq 0x1c(%rax), %rsi
callq 0x9af0
cmpl $0x2, (%rax)
jne 0x1c152
movb $0x1, -0x49(%rbp)
testb $0x1, -0x49(%rbp)
je 0x1c161
movq -0x48(%rbp), %rdi
callq 0x1b770
movl $0x0, -0x54(%rbp)
movq -0xe0(%rbp), %rcx
movl -0x54(%rbp), %eax
cmpl (%rcx), %eax
jge 0x1c19b
movq -0xe0(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %esi, %esi
callq 0x9b30
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1c168
movq -0xe0(%rbp), %rax
movq -0x48(%rbp), %rdi
addq $0x58, %rdi
movslq 0x18(%rax), %rsi
callq 0x9af0
movq %rax, %rcx
movq -0xe0(%rbp), %rax
movl $0x1, (%rcx)
movq -0x48(%rbp), %rdi
addq $0x58, %rdi
movslq 0x1c(%rax), %rsi
callq 0x9af0
movl $0x1, (%rax)
leaq -0x70(%rbp), %rdi
callq 0x9080
movl $0x0, -0x74(%rbp)
movq -0xe0(%rbp), %rcx
movl -0x74(%rbp), %eax
cmpl (%rcx), %eax
jge 0x1c265
movq -0xe0(%rbp), %rax
movslq -0x74(%rbp), %rcx
movq 0x8(%rax), %rdx
movq 0x10(%rax), %rax
movq (%rdx,%rcx,8), %rdi
movzbl (%rax,%rcx), %esi
andl $0x1, %esi
callq 0x183c0
movq %rax, -0xe8(%rbp)
jmp 0x1c224
movq -0xe8(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x8cd0
jmp 0x1c23e
jmp 0x1c240
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x1c1ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x9540
jmp 0x1c56d
movl $0x0, -0x84(%rbp)
movq -0xe0(%rbp), %rcx
movl -0x84(%rbp), %eax
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1c4fc
movl -0x84(%rbp), %eax
incl %eax
movl %eax, -0x88(%rbp)
movslq -0x84(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x8d20
movq (%rax), %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x20bc0
movq %rax, -0xf0(%rbp)
jmp 0x1c2bf
movq -0xf0(%rbp), %rdi
callq 0x20e60
movq %rax, -0xf8(%rbp)
jmp 0x1c2d4
movq -0xf8(%rbp), %rax
movq %rax, -0x90(%rbp)
movslq -0x88(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x8d20
movq (%rax), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x20bc0
movq %rax, -0x100(%rbp)
jmp 0x1c307
movq -0x100(%rbp), %rdi
callq 0x20e60
movq %rax, -0x108(%rbp)
jmp 0x1c31c
movq -0x108(%rbp), %rax
movq %rax, -0x98(%rbp)
movslq -0x84(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x8d20
movq (%rax), %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x20bc0
movq %rax, -0x110(%rbp)
jmp 0x1c355
movq -0x110(%rbp), %rdi
callq 0x20e60
movq %rax, -0x118(%rbp)
jmp 0x1c36a
movq -0x118(%rbp), %rax
movq %rax, -0xa0(%rbp)
movslq -0x88(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x8d20
movq (%rax), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x20bc0
movq %rax, -0x120(%rbp)
jmp 0x1c3a0
movq -0x120(%rbp), %rdi
callq 0x20e60
movq %rax, -0x128(%rbp)
jmp 0x1c3b5
movq -0x128(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x3, %ecx
movl $0x2, %r8d
callq 0x9cc0
jmp 0x1c3ff
movq -0x130(%rbp), %rsi
movq -0x138(%rbp), %rdi
xorl %edx, %edx
leaq -0xb8(%rbp), %rcx
callq 0x17390
jmp 0x1c41d
movq -0xa0(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0xc8(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x3, %ecx
movl $0x2, %r8d
callq 0x9cc0
jmp 0x1c459
movq -0x140(%rbp), %rsi
movq -0x148(%rbp), %rdi
xorl %edx, %edx
leaq -0xc8(%rbp), %rcx
callq 0x17390
jmp 0x1c477
movslq -0x84(%rbp), %rsi
leaq -0x70(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x8d20
movq -0x158(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x150(%rbp)
movslq -0x88(%rbp), %rsi
callq 0x8d20
movq -0x150(%rbp), %rdi
movq %rax, %rcx
movq -0xe0(%rbp), %rax
movq (%rcx), %rsi
movq 0x10(%rax), %rax
movslq -0x84(%rbp), %rdx
movslq -0x88(%rbp), %rcx
movzbl (%rax,%rdx), %edx
andl $0x1, %edx
movzbl (%rax,%rcx), %ecx
andl $0x1, %ecx
callq 0x18150
jmp 0x1c4e6
jmp 0x1c4e8
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x1c26f
movl $0x0, -0xcc(%rbp)
movq -0xe0(%rbp), %rcx
movl -0xcc(%rbp), %eax
cmpl (%rcx), %eax
jge 0x1c55b
movslq -0xcc(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x8d20
movq (%rax), %rax
movq %rax, -0x160(%rbp)
cmpq $0x0, %rax
je 0x1c548
movq -0x160(%rbp), %rdi
movl $0x40, %esi
callq 0x3310
jmp 0x1c54a
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x1c506
leaq -0x70(%rbp), %rdi
callq 0x9540
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x3550
nopw %cs:(%rax,%rax)