// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: ParseConstraint(int&, char**&)
R3SurfelConstraint *
ParseConstraint(int& argc, char **& argv)
{
  // Check arguments
  if (argc == 0) return NULL;

  // Check constraint type
  argc--; argv++;
  const char *constraint_type = *argv;
  if (!strcmp(constraint_type, "BoundingBox")) {
    // Read bounding box coordinates
    argc--; argv++; double x1 = atof(*argv);
    argc--; argv++; double y1 = atof(*argv);
    argc--; argv++; double z1 = atof(*argv);
    argc--; argv++; double x2 = atof(*argv);
    argc--; argv++; double y2 = atof(*argv);
    argc--; argv++; double z2 = atof(*argv);
    R3Box box(x1, y1, z1, x2, y2, z2);
    R3SurfelBoxConstraint *constraint = new R3SurfelBoxConstraint(box);
    return constraint;
  }
  else if (!strcmp(constraint_type, "OrientedBoundingBox")) {
    // Read bounding box coordinates
    argc--; argv++; double cx = atof(*argv);
    argc--; argv++; double cy = atof(*argv);
    argc--; argv++; double cz = atof(*argv);
    argc--; argv++; double ax1 = atof(*argv);
    argc--; argv++; double ay1 = atof(*argv);
    argc--; argv++; double az1 = atof(*argv);
    argc--; argv++; double ax2 = atof(*argv);
    argc--; argv++; double ay2 = atof(*argv);
    argc--; argv++; double az2 = atof(*argv);
    argc--; argv++; double r1 = atof(*argv);
    argc--; argv++; double r2 = atof(*argv);
    argc--; argv++; double r3 = atof(*argv);
    R3Point center(cx, cy, cz);
    R3Vector axis1(ax1, ay1, az1);
    R3Vector axis2(ax2, ay2, az2);
    R3OrientedBox obb(center, axis1, axis2, r1, r2, r3);
    R3SurfelOrientedBoxConstraint *constraint = new R3SurfelOrientedBoxConstraint(obb);
    return constraint;
  }
  else if (!strcmp(constraint_type, "OverheadGrid")) {
    // Read overhead grid
    argc--; argv++; const char *overhead_grid_name = *argv;
    R2Grid *overhead_grid = ReadGrid(overhead_grid_name);
    if (!overhead_grid) return NULL;

    // Parse comparison type
    argc--; argv++; const char *comparison_type_string = *argv;
    int comparison_type = 0;
    if (!strcmp(comparison_type_string, "NotEqual")) comparison_type = R3_SURFEL_CONSTRAINT_NOT_EQUAL;
    else if (!strcmp(comparison_type_string, "Equal")) comparison_type = R3_SURFEL_CONSTRAINT_EQUAL;
    else if (!strcmp(comparison_type_string, "Greater")) comparison_type = R3_SURFEL_CONSTRAINT_GREATER;
    else if (!strcmp(comparison_type_string, "GreaterOrEqual")) comparison_type = R3_SURFEL_CONSTRAINT_GREATER_OR_EQUAL;
    else if (!strcmp(comparison_type_string, "Less")) comparison_type = R3_SURFEL_CONSTRAINT_LESS;
    else if (!strcmp(comparison_type_string, "LessOrEqual")) comparison_type = R3_SURFEL_CONSTRAINT_LESS_OR_EQUAL;
    else { RNFail("Unrecognized constraint comparison type: %s\n", comparison_type_string); return NULL; }

    // Parse surfel operand
    argc--; argv++; const char *surfel_operand_string = *argv;
    RNScalar surfel_operand_value = 0;
    int surfel_operand_type = R3_SURFEL_CONSTRAINT_OPERAND;
    if (!strcmp(surfel_operand_string, "X")) surfel_operand_type = R3_SURFEL_CONSTRAINT_X;
    else if (!strcmp(surfel_operand_string, "Y")) surfel_operand_type = R3_SURFEL_CONSTRAINT_Y;
    else if (!strcmp(surfel_operand_string, "Z")) surfel_operand_type = R3_SURFEL_CONSTRAINT_Z;
    else if (CheckForNumber(surfel_operand_string)) surfel_operand_value = atof(surfel_operand_string); 
    else { RNFail("Unrecognized surfel operand: %s\n", surfel_operand_string); return NULL; }
  
    // Parse grid operand
    argc--; argv++; const char *grid_operand_string = *argv;
    RNScalar grid_operand_value = 0;
    int grid_operand_type = R3_SURFEL_CONSTRAINT_OPERAND;
    if (!strcmp(grid_operand_string, "Value")) grid_operand_type = R3_SURFEL_CONSTRAINT_VALUE;
    else if (CheckForNumber(grid_operand_string)) grid_operand_value = atof(grid_operand_string); 
    else { RNFail("Unrecognized grid operand: %s\n", grid_operand_string); return NULL; }

    // Parse epsilon
    argc--; argv++; double epsilon = atof(*argv);

    // Create constraint
    R3SurfelOverheadGridConstraint *constraint = new R3SurfelOverheadGridConstraint(
      overhead_grid, comparison_type, 
      surfel_operand_type, grid_operand_type, 
      surfel_operand_value, grid_operand_value, 
      epsilon);
    return constraint;
  }

  // Did not recognize constraint type
  RNFail("Unrecognized constraint type: %s\n", constraint_type); 
  return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movl (%rdi), %r13d
testl %r13d, %r13d
je 0x17919
movq %rsi, %rbx
movq %rdi, %r14
leal -0x1(%r13), %eax
movl %eax, (%rdi)
movq (%rsi), %r12
leaq 0x8(%r12), %rax
movq %rax, (%rsi)
movq 0x8(%r12), %r15
leaq 0xd480a(%rip), %rsi     # 0xec0d8
movq %r15, %rdi
callq 0x158e0
testl %eax, %eax
je 0x17920
leaq 0xd47ef(%rip), %rsi     # 0xec0d0
movq %r15, %rdi
callq 0x158e0
testl %eax, %eax
je 0x17a1a
leaq 0xd47ec(%rip), %rsi     # 0xec0e4
movq %r15, %rdi
callq 0x158e0
testl %eax, %eax
je 0x17c3d
leaq 0xd4880(%rip), %rdi     # 0xec18f
xorl %ebx, %ebx
movq %r15, %rsi
jmp 0x17eb8
xorl %ebx, %ebx
jmp 0x17ebf
leal -0x2(%r13), %eax
movl %eax, (%r14)
leaq 0x10(%r12), %rax
movq %rax, (%rbx)
movq 0x10(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x20(%rsp)
leal -0x3(%r13), %eax
movl %eax, (%r14)
leaq 0x18(%r12), %rax
movq %rax, (%rbx)
movq 0x18(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x8(%rsp)
leal -0x4(%r13), %eax
movl %eax, (%r14)
leaq 0x20(%r12), %rax
movq %rax, (%rbx)
movq 0x20(%r12), %rdi
callq 0x157d0
movsd %xmm0, (%rsp)
leal -0x5(%r13), %eax
movl %eax, (%r14)
leaq 0x28(%r12), %rax
movq %rax, (%rbx)
movq 0x28(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x18(%rsp)
leal -0x6(%r13), %eax
movl %eax, (%r14)
leaq 0x30(%r12), %rax
movq %rax, (%rbx)
movq 0x30(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x10(%rsp)
addl $-0x7, %r13d
movl %r13d, (%r14)
leaq 0x38(%r12), %rax
movq %rax, (%rbx)
movq 0x38(%r12), %rdi
callq 0x157d0
movaps %xmm0, %xmm5
leaq 0x78(%rsp), %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movsd (%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
movsd 0x10(%rsp), %xmm4
callq 0x79a9e
pushq $0x40
popq %rdi
callq 0x15620
movq %rax, %rbx
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x2f528
jmp 0x17c2e
leal -0x2(%r13), %eax
movl %eax, (%r14)
leaq 0x10(%r12), %rax
movq %rax, (%rbx)
movq 0x10(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x20(%rsp)
leal -0x3(%r13), %eax
movl %eax, (%r14)
leaq 0x18(%r12), %rax
movq %rax, (%rbx)
movq 0x18(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x8(%rsp)
leal -0x4(%r13), %eax
movl %eax, (%r14)
leaq 0x20(%r12), %rax
movq %rax, (%rbx)
movq 0x20(%r12), %rdi
callq 0x157d0
movsd %xmm0, (%rsp)
leal -0x5(%r13), %eax
movl %eax, (%r14)
leaq 0x28(%r12), %rax
movq %rax, (%rbx)
movq 0x28(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x18(%rsp)
leal -0x6(%r13), %eax
movl %eax, (%r14)
leaq 0x30(%r12), %rax
movq %rax, (%rbx)
movq 0x30(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x10(%rsp)
leal -0x7(%r13), %eax
movl %eax, (%r14)
leaq 0x38(%r12), %rax
movq %rax, (%rbx)
movq 0x38(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x58(%rsp)
leal -0x8(%r13), %eax
movl %eax, (%r14)
leaq 0x40(%r12), %rax
movq %rax, (%rbx)
movq 0x40(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x50(%rsp)
leal -0x9(%r13), %eax
movl %eax, (%r14)
leaq 0x48(%r12), %rax
movq %rax, (%rbx)
movq 0x48(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x48(%rsp)
leal -0xa(%r13), %eax
movl %eax, (%r14)
leaq 0x50(%r12), %rax
movq %rax, (%rbx)
movq 0x50(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x40(%rsp)
leal -0xb(%r13), %eax
movl %eax, (%r14)
leaq 0x58(%r12), %rax
movq %rax, (%rbx)
movq 0x58(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x38(%rsp)
leal -0xc(%r13), %eax
movl %eax, (%r14)
leaq 0x60(%r12), %rax
movq %rax, (%rbx)
movq 0x60(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x30(%rsp)
addl $-0xd, %r13d
movl %r13d, (%r14)
leaq 0x68(%r12), %rax
movq %rax, (%rbx)
movq 0x68(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x28(%rsp)
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movsd (%rsp), %xmm2
callq 0x8ded4
leaq 0x110(%rsp), %r14
movq %r14, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
callq 0x8e694
leaq 0xf8(%rsp), %r15
movq %r15, %rdi
movsd 0x50(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
callq 0x8e694
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
movsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
callq 0x78802
movl $0x88, %edi
callq 0x15620
movq %rax, %rbx
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x2f592
leaq 0x78(%rsp), %rdi
callq 0x7a6c6
jmp 0x17ebf
addl $-0x2, %r13d
movl %r13d, (%r14)
leaq 0x10(%r12), %rax
movq %rax, (%rbx)
movq 0x10(%r12), %r12
leaq 0x78(%rsp), %r15
movq %r15, %rdi
callq 0xaf4d6
movq %r15, %rdi
callq 0x1d806
movl $0xd0, %edi
callq 0x15620
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x99878
movq %r15, %rdi
movq %r12, %rsi
callq 0xa11ce
testl %eax, %eax
je 0x17e1c
cmpl $0x0, 0x142143(%rip)    # 0x159ddc
je 0x17d86
leaq 0xd48e8(%rip), %rdi     # 0xec58e
movq %r12, %rsi
xorl %eax, %eax
callq 0x15080
leaq 0x78(%rsp), %rdi
callq 0xaf510
leaq 0xd48e0(%rip), %rdi     # 0xec5a1
movb $0x1, %al
callq 0x15080
movl 0xc0(%r15), %esi
movl 0xc4(%r15), %edx
leaq 0xd48db(%rip), %rdi     # 0xec5b8
xorl %eax, %eax
callq 0x15080
movq %r15, %rdi
callq 0x1d80e
leaq 0xd48db(%rip), %rdi     # 0xec5ce
movb $0x1, %al
callq 0x15080
movq %r15, %rdi
callq 0x9a5d8
leaq 0xd48d5(%rip), %rdi     # 0xec5de
movl %eax, %esi
xorl %eax, %eax
callq 0x15080
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x9a3e4
movsd (%r12), %xmm0
leaq 0xd48c3(%rip), %rdi     # 0xec5f2
movb $0x1, %al
callq 0x15080
movsd 0x8(%r12), %xmm0
leaq 0xd48be(%rip), %rdi     # 0xec602
movb $0x1, %al
callq 0x15080
movq %r15, %rdi
callq 0x9a526
leaq 0xd48b8(%rip), %rdi     # 0xec612
movb $0x1, %al
callq 0x15080
movq %r15, %rdi
callq 0x9a574
leaq 0xd48b1(%rip), %rdi     # 0xec621
movb $0x1, %al
callq 0x15080
movq 0x141202(%rip), %rax    # 0x158f80
movq (%rax), %rdi
callq 0x15750
movl (%r14), %r13d
leal -0x1(%r13), %eax
movl %eax, (%r14)
movq (%rbx), %rbp
leaq 0x8(%rbp), %rax
movq %rax, (%rbx)
movq 0x8(%rbp), %r12
leaq 0xd434c(%rip), %rsi     # 0xec0f1
movq %r12, %rdi
callq 0x158e0
testl %eax, %eax
je 0x17e28
leaq 0xd4353(%rip), %rsi     # 0xec10b
movq %r12, %rdi
callq 0x158e0
testl %eax, %eax
je 0x17e2c
leaq 0xd432f(%rip), %rsi     # 0xec0fa
movq %r12, %rdi
callq 0x158e0
testl %eax, %eax
je 0x17e30
leaq 0xd4324(%rip), %rsi     # 0xec102
movq %r12, %rdi
callq 0x158e0
testl %eax, %eax
je 0x17e34
leaq 0xd4320(%rip), %rsi     # 0xec111
movq %r12, %rdi
callq 0x158e0
testl %eax, %eax
je 0x17e38
leaq 0xd4312(%rip), %rsi     # 0xec116
movq %r12, %rdi
callq 0x158e0
testl %eax, %eax
je 0x17e3c
leaq 0xd430b(%rip), %rdi     # 0xec122
jmp 0x17eb3
leaq 0xd474f(%rip), %rdi     # 0xec572
jmp 0x17eb3
xorl %ecx, %ecx
jmp 0x17e3f
pushq $0x1
jmp 0x17e3e
pushq $0x2
jmp 0x17e3e
pushq $0x3
jmp 0x17e3e
pushq $0x4
jmp 0x17e3e
pushq $0x5
popq %rcx
leal -0x2(%r13), %eax
movl %eax, (%r14)
leaq 0x10(%rbp), %rax
movq %rax, (%rbx)
movq 0x10(%rbp), %r12
movzbl (%r12), %eax
cmpl $0x5a, %eax
movl %ecx, 0x20(%rsp)
je 0x17e81
cmpl $0x59, %eax
je 0x17e75
cmpl $0x58, %eax
jne 0x17e89
cmpb $0x0, 0x1(%r12)
jne 0x17e89
pushq $0x2
jmp 0x17ed6
cmpb $0x0, 0x1(%r12)
jne 0x17e89
pushq $0x3
jmp 0x17ed6
cmpb $0x0, 0x1(%r12)
je 0x17ed4
movq %r12, %rdi
callq 0x17fea
testl %eax, %eax
je 0x17eac
movq %r12, %rdi
callq 0x157d0
movsd %xmm0, 0x8(%rsp)
movl $0x0, (%rsp)
jmp 0x17ee3
leaq 0xd429c(%rip), %rdi     # 0xec14f
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0xb2096
movq %rbx, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x4
popq %rax
movl %eax, (%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %r12
leal -0x3(%r13), %eax
movl %eax, (%r14)
leaq 0x18(%rbp), %rax
movq %rax, (%rbx)
movq 0x18(%rbp), %r13
leaq 0xdfd5d(%rip), %rsi     # 0xf7c5c
movq %r13, %rdi
callq 0x158e0
testl %eax, %eax
je 0x17f2a
movq %r13, %rdi
callq 0x17fea
testl %eax, %eax
je 0x17f8b
movq %r13, %rdi
callq 0x157d0
movsd %xmm0, 0x10(%rsp)
xorl %r13d, %r13d
jmp 0x17f37
pushq $0x1
popq %r13
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
addl $-0x4, %r12d
movl %r12d, (%r14)
leaq 0x20(%rbp), %rax
movq %rax, (%rbx)
movq 0x20(%rbp), %rdi
callq 0x157d0
movsd %xmm0, 0x18(%rsp)
pushq $0x38
popq %rdi
callq 0x15620
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
movl 0x20(%rsp), %edx
movl (%rsp), %ecx
movl %r13d, %r8d
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
callq 0x2fcb8
jmp 0x17ebf
leaq 0xd41de(%rip), %rdi     # 0xec170
xorl %ebx, %ebx
movq %r13, %rsi
jmp 0x17eb8
movq %rax, %r14
pushq $0x38
popq %rsi
movq %rbx, %rdi
jmp 0x17fb2
movq %rax, %r14
movl $0xd0, %esi
movq %r15, %rdi
callq 0x15630
jmp 0x17fe2
movq %rax, %r14
movl $0x88, %esi
jmp 0x17fcb
jmp 0x17fd5
movq %rax, %r14
pushq $0x40
popq %rsi
movq %rbx, %rdi
callq 0x15630
jmp 0x17fd8
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x7a6c6
movq %r14, %rdi
callq 0x15af0