// File: /workspace/github_cpp_makefile_star2_O2/MarkCBell[P]twister/./twister/kernel/twister.cpp
// Function: manifold::insert_layer()
void manifold::insert_layer()
{
	output_debugging("insert_layer", 2);
	
	if (!last_tetra)  // Empty manifold?
		return;
	
	// Reset the layer flags on cubes and marked points.
	for (int i = 0; i < int(marked_points.size()); i++)
		marked_points[i] = standard;
	
	for (int i = 0; i < int(cubes.size()); i++)
		cubes[i]->set_status(true);
	
	num_layers++;
	
	// Duplicate layer #0.
	for (int i = 0; i < int(cubes.size()); i++)
	{
		cube *C = cubes[i];
		cube *C2 = new cube(*this, num_layers, C);
		
		C->get_tetra(top, left)->subbedby(C2->get_tetra(top, left), 1, perm(0,1,2,3));
		C->get_tetra(top, right)->subbedby(C2->get_tetra(top, right), 2, perm(0,1,2,3));
		
		C->get_tetra(top, left)->gluesym(C2->get_tetra(low, left), 1, perm(0,3,2,1));
		C->get_tetra(top, right)->gluesym(C2->get_tetra(low, right), 2, perm(0,1,3,2));
		
		delete C2;
	}
	
	// Glue the tetra in layer #L together and subbedby the top most faces in.
	for (tetra *current = last_tetra; current->get_layer() == num_layers; current = current->get_prev())
		for (int i = 0; i < 4; i++)
			if (current->get_gluedto(i) == NULL)
			{
				tetra *myparent = current->get_parent();
				tetra *myuncle = myparent->get_gluedto(i);
				
				if ((myuncle != NULL) && (myuncle->get_layer() == 0))
				{
					tetra *mycousin = myuncle->get_child();
					if (mycousin != NULL) 
						current->gluesym(mycousin, i, myparent->get_gluing(i));
				}
			}
	
	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r13
leaq 0x4fd8(%rip), %rsi      # 0x117c2
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x3e82
leaq 0x28(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x3d1a
leaq 0x28(%rsp), %rdi
callq 0x3458
cmpq $0x0, 0x8(%r13)
je 0xca1c
leaq 0x8(%r13), %r14
movq 0x58(%r13), %rax
movq 0x60(%r13), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
cmpq %rdx, %rcx
je 0xc843
andl $0x0, (%rax,%rdx,4)
incq %rdx
jmp 0xc835
movq 0x40(%r13), %rax
movq 0x48(%r13), %rcx
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
xorl %esi, %esi
testl %edx, %edx
cmovlel %esi, %edx
cmpq %rsi, %rdx
je 0xc86e
movq (%rax,%rsi,8), %rdi
movb $0x1, 0x32(%rdi)
incq %rsi
jmp 0xc85c
incl 0x38(%r13)
xorl %edx, %edx
pushq $0x40
popq %rdi
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rdx
jge 0xc9a7
movq %rdx, 0x20(%rsp)
movq (%rax,%rdx,8), %rbx
callq 0x3240
movq %rax, %r15
movl 0x38(%r13), %edx
movq %rax, %rdi
movq %r13, %rsi
movq %rbx, %rcx
callq 0xa926
movq (%rbx), %rbp
movq (%r15), %r12
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
pushq $0x2
popq %rcx
pushq $0x3
popq %r8
callq 0x6790
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
leaq 0x10(%rsp), %rcx
callq 0xa734
movq 0x18(%rbx), %r12
movq 0x18(%r15), %rax
movq %rax, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
pushq $0x2
popq %rbp
movl %ebp, %ecx
pushq $0x3
popq %r8
callq 0x6790
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
leaq 0x10(%rsp), %rbp
movq %rbp, %rcx
callq 0xa734
movq (%rbx), %r12
movq 0x10(%r15), %rax
movq %rax, 0x8(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
pushq $0x3
popq %rdx
pushq $0x2
popq %rcx
pushq $0x1
popq %rbp
movl %ebp, %r8d
callq 0x6790
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
leaq 0x10(%rsp), %rbp
movq %rbp, %rcx
callq 0xa5d2
movq 0x18(%rbx), %rbx
movq 0x28(%r15), %r12
movq %rbp, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
pushq $0x3
popq %rcx
pushq $0x2
popq %rbp
movl %ebp, %r8d
callq 0x6790
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
leaq 0x10(%rsp), %rcx
callq 0xa5d2
movq %r15, %rdi
pushq $0x40
popq %rbx
movq %rbx, %rsi
callq 0x3250
movq 0x20(%rsp), %rdx
incq %rdx
movq 0x40(%r13), %rax
movq 0x48(%r13), %rcx
movq %rbx, %rdi
jmp 0xc877
leaq 0x10(%rsp), %rbx
movq (%r14), %r14
movl 0x90(%r14), %eax
cmpl 0x38(%r13), %eax
jne 0xca1c
xorl %r15d, %r15d
cmpq $0x4, %r15
je 0xca16
cmpq $0x0, 0x10(%r14,%r15,8)
je 0xc9d2
incq %r15
jmp 0xc9bf
movq 0x80(%r14), %rsi
movq 0x10(%rsi,%r15,8), %rax
testq %rax, %rax
je 0xc9cd
cmpl $0x0, 0x90(%rax)
jne 0xc9cd
movq 0x88(%rax), %r12
testq %r12, %r12
je 0xc9cd
movq %rbx, %rdi
movl %r15d, %edx
callq 0xf05e
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
movq %rbx, %rcx
callq 0xa5d2
jmp 0xc9cd
addq $0x8, %r14
jmp 0xc9ac
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3458
jmp 0xca4d
movq %rax, %rbx
jmp 0xca4d
movq %rax, %rbx
pushq $0x40
popq %rsi
movq %r15, %rdi
callq 0x3250
movq %rbx, %rdi
callq 0x33d0
nop