// File: /workspace/github_cpp_makefile_star2_O3/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 0x1817a
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 0xeefc4(%rip), %rsi     # 0x1070ec
movq %r15, %rdi
callq 0x158b0
testl %eax, %eax
je 0x18181
leaq 0xeefa9(%rip), %rsi     # 0x1070e4
movq %r15, %rdi
callq 0x158b0
testl %eax, %eax
je 0x1827d
leaq 0xeefa6(%rip), %rsi     # 0x1070f8
movq %r15, %rdi
callq 0x158b0
testl %eax, %eax
je 0x184b0
leaq 0xef03a(%rip), %rdi     # 0x1071a3
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xc3e02
jmp 0x1849b
xorl %ebx, %ebx
jmp 0x1849b
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, 0x10(%rsp)
leal -0x6(%r13), %eax
movl %eax, (%r14)
leaq 0x30(%r12), %rax
movq %rax, (%rbx)
movq 0x30(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x18(%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 0x10(%rsp), %xmm3
movsd 0x18(%rsp), %xmm4
callq 0x85504
movl $0x40, %edi
callq 0x15610
movq %rax, %rbx
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x32830
jmp 0x18491
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, 0x10(%rsp)
leal -0x6(%r13), %eax
movl %eax, (%r14)
leaq 0x30(%r12), %rax
movq %rax, (%rbx)
movq 0x30(%r12), %rdi
callq 0x157d0
movsd %xmm0, 0x18(%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 0x9bed2
leaq 0x110(%rsp), %r14
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
callq 0x9c966
leaq 0xf8(%rsp), %r15
movq %r15, %rdi
movsd 0x50(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
callq 0x9c966
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 0x84118
movl $0x88, %edi
callq 0x15610
movq %rax, %rbx
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x3289c
leaq 0x78(%rsp), %rdi
callq 0x86284
movq %rbx, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
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 0xc0cf4
movq %r15, %rdi
xorl %esi, %esi
callq 0x15a10
movl $0xd0, %edi
callq 0x15610
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xa8e34
movq %r15, %rdi
movq %r12, %rsi
callq 0xb1252
testl %eax, %eax
je 0x186d0
cmpl $0x0, 0x1548ae(%rip)    # 0x16cdbc
je 0x1863d
leaq 0xef084(%rip), %rdi     # 0x10759f
movq %r12, %rsi
xorl %eax, %eax
callq 0x15080
leaq 0x78(%rsp), %rdi
callq 0xc0d56
leaq 0xef07c(%rip), %rdi     # 0x1075b2
movb $0x1, %al
callq 0x15080
movl 0xc0(%r15), %esi
movl 0xc4(%r15), %edx
leaq 0xef077(%rip), %rdi     # 0x1075c9
xorl %eax, %eax
callq 0x15080
movsd 0xb0(%r15), %xmm1
leaq 0x1547cf(%rip), %rax    # 0x16cd38
movsd (%rax), %xmm2
movapd 0xeeb0b(%rip), %xmm0    # 0x107080
xorpd %xmm2, %xmm0
movsd 0xeea8f(%rip), %xmm3    # 0x107010
divsd %xmm1, %xmm3
cmpnlesd %xmm1, %xmm0
movapd %xmm0, %xmm4
andpd %xmm3, %xmm4
cmpnlesd %xmm2, %xmm1
andpd %xmm3, %xmm1
andnpd %xmm1, %xmm0
orpd %xmm4, %xmm0
leaq 0xef035(%rip), %rdi     # 0x1075df
movb $0x1, %al
callq 0x15080
movq %r15, %rdi
callq 0xa9ca0
leaq 0xef02f(%rip), %rdi     # 0x1075ef
movl %eax, %esi
xorl %eax, %eax
callq 0x15080
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xa9a90
movsd (%r12), %xmm0
leaq 0xef01d(%rip), %rdi     # 0x107603
movb $0x1, %al
callq 0x15080
movsd 0x8(%r12), %xmm0
leaq 0xef018(%rip), %rdi     # 0x107613
movb $0x1, %al
callq 0x15080
movq %r15, %rdi
callq 0xa9bea
leaq 0xef012(%rip), %rdi     # 0x107623
movb $0x1, %al
callq 0x15080
movq %r15, %rdi
callq 0xa9c3a
leaq 0xef00b(%rip), %rdi     # 0x107632
movb $0x1, %al
callq 0x15080
movq 0x15392b(%rip), %rax    # 0x16bf60
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 0xeeaa9(%rip), %rsi     # 0x107105
movq %r12, %rdi
callq 0x158b0
testl %eax, %eax
je 0x186e1
leaq 0xeeab0(%rip), %rsi     # 0x10711f
movq %r12, %rdi
callq 0x158b0
testl %eax, %eax
je 0x186e6
leaq 0xeea8c(%rip), %rsi     # 0x10710e
movq %r12, %rdi
callq 0x158b0
testl %eax, %eax
je 0x186ee
leaq 0xeea81(%rip), %rsi     # 0x107116
movq %r12, %rdi
callq 0x158b0
testl %eax, %eax
je 0x186f6
leaq 0xeea7d(%rip), %rsi     # 0x107125
movq %r12, %rdi
callq 0x158b0
testl %eax, %eax
je 0x186fe
leaq 0xeea6f(%rip), %rsi     # 0x10712a
movq %r12, %rdi
callq 0x158b0
testl %eax, %eax
je 0x18706
leaq 0xeea68(%rip), %rdi     # 0x107136
jmp 0x186d7
leaq 0xeeeac(%rip), %rdi     # 0x107583
xorl %ebx, %ebx
movq %r12, %rsi
jmp 0x1816e
xorl %r8d, %r8d
jmp 0x1870c
movl $0x1, %r8d
jmp 0x1870c
movl $0x2, %r8d
jmp 0x1870c
movl $0x3, %r8d
jmp 0x1870c
movl $0x4, %r8d
jmp 0x1870c
movl $0x5, %r8d
leal -0x2(%r13), %eax
movl %eax, (%r14)
leaq 0x10(%rbp), %rax
movq %rax, (%rbx)
movq 0x10(%rbp), %rsi
movb (%rsi), %al
movzbl %al, %ecx
cmpl $0x58, %ecx
movl %r8d, 0x20(%rsp)
jg 0x18745
testl %ecx, %ecx
je 0x18793
cmpl $0x58, %ecx
jne 0x18764
cmpb $0x0, 0x1(%rsi)
jne 0x18764
movl $0x2, (%rsp)
jmp 0x187bf
cmpl $0x59, %ecx
je 0x1875e
cmpl $0x5a, %ecx
jne 0x18764
cmpb $0x0, 0x1(%rsi)
jne 0x18764
movl $0x4, (%rsp)
jmp 0x187bf
cmpb $0x0, 0x1(%rsi)
je 0x187b8
leaq 0x1(%rsi), %rcx
movabsq $0x680000000000, %rdx   # imm = 0x680000000000
movsbl %al, %edi
addl $-0x30, %edi
cmpl $0xa, %edi
jb 0x1878a
cmpb $0x2e, %al
ja 0x187aa
movzbl %al, %eax
btq %rax, %rdx
jae 0x187aa
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x18772
movq %rsi, %rdi
callq 0x157d0
movsd %xmm0, 0x8(%rsp)
movl $0x0, (%rsp)
jmp 0x187c8
leaq 0xee9b2(%rip), %rdi     # 0x107163
xorl %ebx, %ebx
jmp 0x1816e
movl $0x3, (%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 0xfa588(%rip), %rsi     # 0x112d6c
movq %r13, %rdi
callq 0x158b0
testl %eax, %eax
je 0x18843
movb (%r13), %cl
testb %cl, %cl
je 0x18830
leaq 0x1(%r13), %rax
movabsq $0x680000000000, %rdx   # imm = 0x680000000000
movsbl %cl, %esi
addl $-0x30, %esi
cmpl $0xa, %esi
jb 0x18827
cmpb $0x2e, %cl
ja 0x188a8
movzbl %cl, %ecx
btq %rcx, %rdx
jae 0x188a8
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x18806
movq %r13, %rdi
callq 0x157d0
movsd %xmm0, 0x10(%rsp)
xorl %r13d, %r13d
jmp 0x18852
movl $0x1, %r13d
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)
movl $0x38, %edi
callq 0x15610
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 0x3311a
jmp 0x1849b
leaq 0xee8d5(%rip), %rdi     # 0x107184
xorl %ebx, %ebx
movq %r13, %rsi
jmp 0x1816e
movq %rax, %r14
movl $0x38, %esi
movq %rbx, %rdi
jmp 0x188d1
movq %rax, %r14
movl $0xd0, %esi
movq %r15, %rdi
callq 0x15620
jmp 0x18903
movq %rax, %r14
movl $0x88, %esi
jmp 0x188ec
jmp 0x188f6
movq %rax, %r14
movl $0x40, %esi
movq %rbx, %rdi
callq 0x15620
jmp 0x188f9
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x86284
movq %r14, %rdi
callq 0x15ad0