// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelScene.cpp
// Function: gaps::WriteOffFile(gaps::R3SurfelObject*, char const*)
static int 
WriteOffFile(R3SurfelObject *object, const char *filename)
{
  // Get pointset
  R3SurfelPointSet *pointset = object->PointSet();
  if (!pointset) return 0;

  // Create mesh
  R3Mesh mesh;
  for (int i = 0; i < pointset->NPoints(); i++) {
    R3SurfelPoint *point = pointset->Point(i);
    R3Point position = point->Position();
    R3Point position1 = position; position1[0] -= 1E-3;
    R3Point position2 = position; position2[0] += 1E-3;
    R3Point position3 = position; position3[1] += 1E-3;
    R3MeshVertex *v1 = mesh.CreateVertex(position1);
    R3MeshVertex *v2 = mesh.CreateVertex(position2);
    R3MeshVertex *v3 = mesh.CreateVertex(position3);
    mesh.CreateFace(v1, v2, v3);
  }

  // Delete pointset
  delete pointset;

  // Write mesh
  if (!mesh.WriteFile(filename)) return 0;

  // Return succes
  return 1;
}

// Assembly:
subq $0x238, %rsp            # imm = 0x238
movq %rdi, 0x228(%rsp)
movq %rsi, 0x220(%rsp)
movq 0x228(%rsp), %rdi
xorl %esi, %esi
xorps %xmm0, %xmm0
callq 0x19ad0
movq %rax, 0x218(%rsp)
cmpq $0x0, 0x218(%rsp)
jne 0x302ac
movl $0x0, 0x234(%rsp)
jmp 0x30526
leaq 0xe0(%rsp), %rdi
callq 0x98410
movl $0x0, 0xdc(%rsp)
movl 0xdc(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x218(%rsp), %rdi
callq 0x18700
movl %eax, 0x40(%rsp)
jmp 0x302e2
movl 0x3c(%rsp), %eax
movl 0x40(%rsp), %ecx
cmpl %ecx, %eax
jge 0x304af
movq 0x218(%rsp), %rdi
movl 0xdc(%rsp), %esi
callq 0x18710
movq %rax, 0x30(%rsp)
jmp 0x3030d
movq 0x30(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x18730
jmp 0x30331
leaq 0x90(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0xf8390
jmp 0x30348
leaq 0x90(%rsp), %rdi
xorl %esi, %esi
callq 0x1bde0
movsd (%rax), %xmm0
movsd 0x174045(%rip), %xmm1   # 0x1a43a8
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
leaq 0x78(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0xf8390
jmp 0x3037f
leaq 0x78(%rsp), %rdi
xorl %esi, %esi
callq 0x1bde0
movsd (%rax), %xmm0
movsd 0x174019(%rip), %xmm1   # 0x1a43b0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
leaq 0x60(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0xf8390
jmp 0x303b3
leaq 0x60(%rsp), %rdi
movl $0x1, %esi
callq 0x1bde0
movsd (%rax), %xmm0
movsd 0x173fe2(%rip), %xmm1   # 0x1a43b0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
xorl %eax, %eax
movl %eax, %edx
leaq 0xe0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x9e9f0
movq %rax, 0x28(%rsp)
jmp 0x303f6
movq 0x28(%rsp), %rax
movq %rax, 0x58(%rsp)
xorl %eax, %eax
movl %eax, %edx
leaq 0xe0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x9e9f0
movq %rax, 0x20(%rsp)
jmp 0x3041d
movq 0x20(%rsp), %rax
movq %rax, 0x50(%rsp)
xorl %eax, %eax
movl %eax, %edx
leaq 0xe0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x9e9f0
movq %rax, 0x18(%rsp)
jmp 0x30444
movq 0x18(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rcx
xorl %eax, %eax
movl %eax, %r8d
leaq 0xe0(%rsp), %rdi
callq 0x9efe0
jmp 0x30471
jmp 0x30473
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x302c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x99310
jmp 0x30535
movq 0x218(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x304cd
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x220(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0xb80f0
movl %eax, 0xc(%rsp)
jmp 0x304e8
movl 0xc(%rsp), %eax
cmpl $0x0, %eax
jne 0x30506
movl $0x0, 0x234(%rsp)
movl $0x1, 0x44(%rsp)
jmp 0x30519
movl $0x1, 0x234(%rsp)
movl $0x1, 0x44(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x99310
movl 0x234(%rsp), %eax
addq $0x238, %rsp            # imm = 0x238
retq
movq 0xd0(%rsp), %rdi
callq 0x13970
nopw %cs:(%rax,%rax)
nopl (%rax)