// File: /workspace/github_cpp_makefile_star2_O3/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 0x7167(%rip), %rsi      # 0x1786a
leaq 0x716c(%rip), %rdx      # 0x17876
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x892e
movq %r14, %rdi
movl $0x2, %esi
callq 0x4229
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x1073b
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3220
cmpq $0x0, 0x8(%r13)
je 0x1097c
movq 0x58(%r13), %rdi
movq 0x60(%r13), %rdx
subq %rdi, %rdx
movq %rdx, %rax
shrq $0x2, %rax
testl %eax, %eax
jle 0x10770
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 0x108f5
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
movb $0x1, 0x32(%rdi)
incq %rsi
cmpq %rsi, %rdx
jne 0x10791
leaq 0x38(%r13), %r12
movl 0x38(%r13), %edx
incl %edx
movl %edx, 0x38(%r13)
testl %ecx, %ecx
jle 0x10903
movq %r12, 0x10(%rsp)
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 0xe452
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 0x8860
movq %r13, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movq %rsp, %rcx
callq 0xe200
movq 0x18(%r12), %r13
movq 0x18(%r15), %rbp
movq %rsp, %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x2, %ecx
movl $0x3, %r8d
callq 0x8860
movq %r13, %rdi
movq %rbp, %rsi
movl $0x2, %edx
movq %rsp, %rcx
callq 0xe200
movq (%r12), %r13
movq 0x10(%r15), %rbp
movq %rsp, %rdi
xorl %esi, %esi
movl $0x3, %edx
movl $0x2, %ecx
movl $0x1, %r8d
callq 0x8860
movq %r13, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movq %rsp, %rcx
callq 0xe04e
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 0x8860
movq %r12, %rdi
movq %r13, %rsi
movl $0x2, %edx
movq %rbp, %rcx
callq 0xe04e
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 0x107be
movq 0x10(%rsp), %r12
movl (%r12), %edx
jmp 0x10903
leaq 0x38(%r13), %r12
movl 0x38(%r13), %edx
incl %edx
movl %edx, 0x38(%r13)
movq 0x8(%r13), %rbx
cmpl %edx, 0x90(%rbx)
jne 0x1097c
movq %rsp, %r14
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq $0x0, 0x10(%rbx,%r15)
je 0x1092d
incl %ebp
addq $0x8, %r15
cmpq $0x20, %r15
jne 0x10917
jmp 0x1096c
movq 0x80(%rbx), %rax
movq 0x10(%rax,%r15), %rcx
testq %rcx, %rcx
je 0x1091f
cmpl $0x0, 0x90(%rcx)
jne 0x1091f
movq 0x88(%rcx), %rsi
testq %rsi, %rsi
je 0x1091f
movups 0x30(%rax,%r15,2), %xmm0
movaps %xmm0, (%rsp)
movq %rbx, %rdi
movl %ebp, %edx
movq %r14, %rcx
callq 0xe04e
jmp 0x1091f
movq 0x8(%rbx), %rbx
movl 0x90(%rbx), %eax
cmpl (%r12), %eax
je 0x10912
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 0x109b2
movq 0x28(%rsp), %rsi
incq %rsi
jmp 0x109ad
movq %rax, %rbx
movl $0x40, %esi
movq %r15, %rdi
callq 0x3220
movq %rbx, %rdi
callq 0x33e0