// File: tomfunkhouser[P]gaps/apps/scn2scn/scn2scn.cpp
// Function: main
int main(int argc, char **argv)
{
  // Parse program arguments
  if (!ParseArgs(argc, argv)) exit(1);

  // Read scene
  R3Scene *scene = ReadScene(input_name);
  if (!scene) exit(-1);

  // Read categories
  if (input_categories_name) {
    if (!ReadCategories(scene, input_categories_name)) exit(-1);
  }

  // Read lights
  if (input_lights_name) {
    if (!ReadLights(scene, input_lights_name)) exit(-1);
  }

  // Remove unselected nodes
  if (select_nodes_in_subtree_name || select_nodes_in_grid_filename || !select_nodes_in_bbox.IsEmpty()) {
    if (!RemoveNodes(scene)) exit(-1);
  }

  // Transform scene
  if (!xform.IsIdentity()) {
    R3SceneNode *root = scene->Root();
    R3Affine tmp = R3identity_affine;
    tmp.Transform(xform);
    tmp.Transform(root->Transformation());
    root->SetTransformation(tmp);
  }

  // Apply processing operations
  if (remove_references) scene->RemoveReferences();
  if (remove_hierarchy) scene->RemoveHierarchy();
  if (remove_transformations) scene->RemoveTransformations();
  if (max_edge_length > 0) scene->SubdivideTriangles(max_edge_length);

  // Write scene
  if (!WriteScene(scene, output_name)) exit(-1);

  // Return success 
  return 0;
}

// Assembly:
subq $0x158, %rsp            # imm = 0x158
movl $0x0, 0x154(%rsp)
movl %edi, 0x150(%rsp)
movq %rsi, 0x148(%rsp)
movl 0x150(%rsp), %edi
movq 0x148(%rsp), %rsi
callq 0x282a0
cmpl $0x0, %eax
jne 0x28074
movl $0x1, %edi
callq 0x23c00
movq 0x2143e5(%rip), %rdi    # 0x23c460
callq 0x29110
movq %rax, 0x140(%rsp)
cmpq $0x0, 0x140(%rsp)
jne 0x2809d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x23c00
cmpq $0x0, 0x2143c3(%rip)    # 0x23c468
je 0x280cc
movq 0x140(%rsp), %rdi
movq 0x2143b2(%rip), %rsi    # 0x23c468
callq 0x29300
cmpl $0x0, %eax
jne 0x280ca
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x23c00
jmp 0x280cc
cmpq $0x0, 0x21439c(%rip)    # 0x23c470
je 0x280fb
movq 0x140(%rsp), %rdi
movq 0x21438b(%rip), %rsi    # 0x23c470
callq 0x29390
cmpl $0x0, %eax
jne 0x280f9
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x23c00
jmp 0x280fb
cmpq $0x0, 0x214375(%rip)    # 0x23c478
jne 0x28120
cmpq $0x0, 0x214373(%rip)    # 0x23c480
jne 0x28120
leaq 0x214202(%rip), %rdi    # 0x23c318
callq 0x2a3b0
cmpl $0x0, %eax
jne 0x2813e
movq 0x140(%rsp), %rdi
callq 0x29440
cmpl $0x0, %eax
jne 0x2813c
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x23c00
jmp 0x2813e
leaq 0x21420b(%rip), %rdi    # 0x23c350
callq 0xc0c80
cmpl $0x0, %eax
jne 0x281f3
movq 0x140(%rsp), %rdi
callq 0x2a470
movq %rax, 0x138(%rsp)
leaq 0x216fc1(%rip), %rsi    # 0x23f130
leaq 0x28(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x2a480
movq 0x10(%rsp), %rdi
leaq 0x2141c6(%rip), %rsi    # 0x23c350
callq 0xc0e40
jmp 0x28191
movq 0x138(%rsp), %rdi
callq 0x2a530
movq %rax, 0x8(%rsp)
jmp 0x281a5
movq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdi
callq 0xc0e40
jmp 0x281b6
movq 0x138(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x567f0
jmp 0x281ca
leaq 0x28(%rsp), %rdi
callq 0xc0b70
jmp 0x281f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
leaq 0x28(%rsp), %rdi
callq 0xc0b70
jmp 0x28288
cmpl $0x0, 0x21428e(%rip)    # 0x23c488
je 0x28209
movq 0x140(%rsp), %rdi
callq 0x2c0a0
cmpl $0x0, 0x21427c(%rip)    # 0x23c48c
je 0x2821f
movq 0x140(%rsp), %rdi
callq 0x2c280
cmpl $0x0, 0x21426a(%rip)    # 0x23c490
je 0x28235
movq 0x140(%rsp), %rdi
callq 0x2c480
movsd 0x21425b(%rip), %xmm0   # 0x23c498
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2825b
movq 0x140(%rsp), %rdi
movsd 0x214242(%rip), %xmm0   # 0x23c498
callq 0x2c690
movq 0x140(%rsp), %rdi
movq 0x214236(%rip), %rsi    # 0x23c4a0
callq 0x29520
cmpl $0x0, %eax
jne 0x2827e
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x23c00
xorl %eax, %eax
addq $0x158, %rsp            # imm = 0x158
retq
movq 0x20(%rsp), %rdi
callq 0x24210
nopw %cs:(%rax,%rax)