// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movq %rdi, %r13
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x7223(%rip), %rsi      # 0x1782a
leaq 0x7228(%rip), %rdx      # 0x17836
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x86fe
movq %r14, %rdi
movl $0x2, %esi
callq 0x4209
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x1063f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3220
cmpq $0x0, 0x8(%r13)
je 0x10865
movq 0x58(%r13), %rdi
movq 0x60(%r13), %rdx
subq %rdi, %rdx
movq %rdx, %rax
shrq $0x2, %rax
testl %eax, %eax
jle 0x10674
movabsq $0x1fffffffc, %rax      # imm = 0x1FFFFFFFC
andq %rax, %rdx
xorl %esi, %esi
callq 0x3160
movq 0x40(%r13), %rax
movq 0x48(%r13), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
testl %ecx, %ecx
jle 0x1069f
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
movq (%rax,%rdx,8), %rsi
movb $0x1, 0x32(%rsi)
incq %rdx
cmpq %rdx, %rcx
jne 0x1068f
incl 0x38(%r13)
movq 0x40(%r13), %rax
movq 0x48(%r13), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
testl %ecx, %ecx
jle 0x107e8
xorl %ebx, %ebx
movq (%rax,%rbx,8), %r12
movl $0x40, %edi
callq 0x3210
movq %rax, %r15
movl 0x38(%r13), %edx
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rcx
callq 0xe2a6
movq %r13, %r14
movq (%r12), %r13
movq (%r15), %rbp
movq %rsp, %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x2, %ecx
movl $0x3, %r8d
callq 0x8630
movq %r13, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movq %rsp, %rcx
callq 0xe02c
movq 0x18(%r12), %r13
movq 0x18(%r15), %rbp
movq %rsp, %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x2, %ecx
movl $0x3, %r8d
callq 0x8630
movq %r13, %rdi
movq %rbp, %rsi
movl $0x2, %edx
movq %rsp, %rcx
callq 0xe02c
movq (%r12), %r13
movq 0x10(%r15), %rbp
movq %rsp, %rdi
xorl %esi, %esi
movl $0x3, %edx
movl $0x2, %ecx
movl $0x1, %r8d
callq 0x8630
movq %r13, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movq %rsp, %rcx
callq 0xde78
movq 0x18(%r12), %r12
movq 0x28(%r15), %r13
movq %rsp, %rdi
movq %rdi, %rbp
xorl %esi, %esi
movl $0x1, %edx
movl $0x3, %ecx
movl $0x2, %r8d
callq 0x8630
movq %r12, %rdi
movq %r13, %rsi
movl $0x2, %edx
movq %rbp, %rcx
callq 0xde78
movl $0x40, %esi
movq %r15, %rdi
callq 0x3220
incq %rbx
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbx
movq %r14, %r13
jl 0x106bc
movq 0x8(%r13), %r14
movl 0x90(%r14), %eax
cmpl 0x38(%r13), %eax
jne 0x10865
movq %rsp, %r15
xorl %ebx, %ebx
xorl %ebp, %ebp
cmpq $0x0, 0x10(%r14,%rbx)
je 0x10816
incl %ebp
addq $0x8, %rbx
cmpq $0x20, %rbx
jne 0x10800
jmp 0x10854
movq 0x80(%r14), %rax
movq 0x10(%rax,%rbx), %rcx
testq %rcx, %rcx
je 0x10808
cmpl $0x0, 0x90(%rcx)
jne 0x10808
movq 0x88(%rcx), %rsi
testq %rsi, %rsi
je 0x10808
movups 0x30(%rax,%rbx,2), %xmm0
movaps %xmm0, (%rsp)
movq %r14, %rdi
movl %ebp, %edx
movq %r15, %rcx
callq 0xde78
jmp 0x10808
movq 0x8(%r14), %r14
movl 0x90(%r14), %eax
cmpl 0x38(%r13), %eax
je 0x107fc
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x1089b
movq 0x28(%rsp), %rsi
incq %rsi
jmp 0x10896
movq %rax, %rbx
movl $0x40, %esi
movq %r15, %rdi
callq 0x3220
movq %rbx, %rdi
callq 0x33e0
nop