// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::SubdivideFace(gaps::R3MeshFace*)
R3MeshFace *R3Mesh::
SubdivideFace(R3MeshFace *f)
{
  // Find vertices/edges bounding face
  R3MeshVertex *v0 = VertexOnFace(f, 0);
  R3MeshEdge *e0 = EdgeOnFace(f, v0, RN_CCW);
  R3MeshVertex *v1 = VertexAcrossEdge(e0, v0);
  R3MeshEdge *e1 = EdgeOnFace(f, v1, RN_CCW);
  R3MeshVertex *v2 = VertexAcrossEdge(e1, v1);
  R3MeshEdge *e2 = EdgeOnFace(f, v2, RN_CCW);
  int m = FaceMaterial(f);
  int s = FaceSegment(f);
  int c = FaceCategory(f);

  // Delete face
  DeleteFace(f);

  // Subdivide edges
  R3MeshVertex *ve0 = SubdivideEdge(e0);
  R3MeshVertex *ve1 = SubdivideEdge(e1);
  R3MeshVertex *ve2 = SubdivideEdge(e2);

  // Create new faces
  R3MeshFace *f1 = CreateFace(v0, ve0, ve2);  
  R3MeshFace *f2 = CreateFace(v1, ve1, ve0);  
  R3MeshFace *f3 = CreateFace(v2, ve2, ve1);  
  R3MeshFace *f4 = CreateFace(ve0, ve1, ve2);  

  // Set face materials
  SetFaceMaterial(f1, m);
  SetFaceMaterial(f2, m);
  SetFaceMaterial(f3, m);
  SetFaceMaterial(f4, m);

  // Set face segments
  SetFaceSegment(f1, s);
  SetFaceSegment(f2, s);
  SetFaceSegment(f3, s);
  SetFaceSegment(f4, s);

  // Set face categorys
  SetFaceCategory(f1, c);
  SetFaceCategory(f2, c);
  SetFaceCategory(f3, c);
  SetFaceCategory(f4, c);

  // Return interior face
  return f4;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x8(%rsi), %r15
movq 0x20(%rsi), %r12
movq 0x8(%r12), %r13
cmpq %r15, %r13
jne 0x16a02
movq 0x10(%r12), %r13
cmpq %r13, %r15
je 0x16a17
cmpq %r13, 0x10(%rsi)
je 0x16a1e
cmpq %r13, 0x18(%rsi)
je 0x16a25
xorl %ebp, %ebp
jmp 0x16a2e
movl $0x20, %eax
jmp 0x16a2a
movl $0x28, %eax
jmp 0x16a2a
movl $0x30, %eax
movq (%rsi,%rax), %rbp
movq 0x8(%rbp), %rax
cmpq %r13, %rax
jne 0x16a3b
movq 0x10(%rbp), %rax
cmpq %rax, %r15
movq %rax, 0x20(%rsp)
je 0x16a56
cmpq %rax, 0x10(%rsi)
je 0x16a5d
cmpq %rax, 0x18(%rsi)
je 0x16a64
xorl %r14d, %r14d
jmp 0x16a6d
movl $0x20, %eax
jmp 0x16a69
movl $0x28, %eax
jmp 0x16a69
movl $0x30, %eax
movq (%rsi,%rax), %r14
movl 0x98(%rsi), %eax
movl %eax, 0xc(%rsp)
movl 0x9c(%rsi), %eax
movl %eax, 0x10(%rsp)
movl 0xa0(%rsi), %eax
movl %eax, 0x14(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x70(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0xc8(%rax)
movq %rax, %r12
movq %rax, 0x18(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
movq %rbp, %rsi
callq *0xc8(%rax)
movq %rax, %rbp
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0xc8(%rax)
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq *0x48(%rax)
movq %rax, %r15
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
callq *0x48(%rax)
movq %rax, %r13
movq (%rbx), %rax
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq *0x48(%rax)
movq %rax, %r12
movq (%rbx), %rax
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq *0x48(%rax)
movl 0xc(%rsp), %ecx
movl %ecx, 0x98(%r15)
movl %ecx, 0x98(%r13)
movl %ecx, 0x98(%r12)
movl %ecx, 0x98(%rax)
movl 0x10(%rsp), %ecx
movl %ecx, 0x9c(%r15)
movl %ecx, 0x9c(%r13)
movl %ecx, 0x9c(%r12)
movl %ecx, 0x9c(%rax)
movl 0x14(%rsp), %ecx
movl %ecx, 0xa0(%r15)
movl %ecx, 0xa0(%r13)
movl %ecx, 0xa0(%r12)
movl %ecx, 0xa0(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop