// File: /workspace/github_cpp_makefile_star2_O1/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 0x1871c
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 0xf0f90(%rip), %rsi     # 0x1090ec
movq %r15, %rdi
callq 0x158c0
testl %eax, %eax
je 0x181ae
leaq 0xf0f75(%rip), %rsi     # 0x1090e4
movq %r15, %rdi
callq 0x158c0
testl %eax, %eax
je 0x182aa
leaq 0xf0f72(%rip), %rsi     # 0x1090f8
movq %r15, %rdi
callq 0x158c0
testl %eax, %eax
je 0x184cd
leaq 0xf100a(%rip), %rdi     # 0x1091a7
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xc5782
jmp 0x1871e
leal -0x2(%r13), %eax
movl %eax, (%r14)
leaq 0x10(%r12), %rax
movq %rax, (%rbx)
movq 0x10(%r12), %rdi
callq 0x157e0
movsd %xmm0, (%rsp)
leal -0x3(%r13), %eax
movl %eax, (%r14)
leaq 0x18(%r12), %rax
movq %rax, (%rbx)
movq 0x18(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x10(%rsp)
leal -0x4(%r13), %eax
movl %eax, (%r14)
leaq 0x20(%r12), %rax
movq %rax, (%rbx)
movq 0x20(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x8(%rsp)
leal -0x5(%r13), %eax
movl %eax, (%r14)
leaq 0x28(%r12), %rax
movq %rax, (%rbx)
movq 0x28(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x18(%rsp)
leal -0x6(%r13), %eax
movl %eax, (%r14)
leaq 0x30(%r12), %rax
movq %rax, (%rbx)
movq 0x30(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x20(%rsp)
addl $-0x7, %r13d
movl %r13d, (%r14)
leaq 0x38(%r12), %rax
movq %rax, (%rbx)
movq 0x38(%r12), %rdi
callq 0x157e0
movaps %xmm0, %xmm5
leaq 0x78(%rsp), %rdi
movsd (%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
movsd 0x20(%rsp), %xmm4
callq 0x8652c
movl $0x40, %edi
callq 0x15610
movq %rax, %rbx
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x32d00
jmp 0x184be
leal -0x2(%r13), %eax
movl %eax, (%r14)
leaq 0x10(%r12), %rax
movq %rax, (%rbx)
movq 0x10(%r12), %rdi
callq 0x157e0
movsd %xmm0, (%rsp)
leal -0x3(%r13), %eax
movl %eax, (%r14)
leaq 0x18(%r12), %rax
movq %rax, (%rbx)
movq 0x18(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x10(%rsp)
leal -0x4(%r13), %eax
movl %eax, (%r14)
leaq 0x20(%r12), %rax
movq %rax, (%rbx)
movq 0x20(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x8(%rsp)
leal -0x5(%r13), %eax
movl %eax, (%r14)
leaq 0x28(%r12), %rax
movq %rax, (%rbx)
movq 0x28(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x18(%rsp)
leal -0x6(%r13), %eax
movl %eax, (%r14)
leaq 0x30(%r12), %rax
movq %rax, (%rbx)
movq 0x30(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x20(%rsp)
leal -0x7(%r13), %eax
movl %eax, (%r14)
leaq 0x38(%r12), %rax
movq %rax, (%rbx)
movq 0x38(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x58(%rsp)
leal -0x8(%r13), %eax
movl %eax, (%r14)
leaq 0x40(%r12), %rax
movq %rax, (%rbx)
movq 0x40(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x50(%rsp)
leal -0x9(%r13), %eax
movl %eax, (%r14)
leaq 0x48(%r12), %rax
movq %rax, (%rbx)
movq 0x48(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x48(%rsp)
leal -0xa(%r13), %eax
movl %eax, (%r14)
leaq 0x50(%r12), %rax
movq %rax, (%rbx)
movq 0x50(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x40(%rsp)
leal -0xb(%r13), %eax
movl %eax, (%r14)
leaq 0x58(%r12), %rax
movq %rax, (%rbx)
movq 0x58(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x38(%rsp)
leal -0xc(%r13), %eax
movl %eax, (%r14)
leaq 0x60(%r12), %rax
movq %rax, (%rbx)
movq 0x60(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x30(%rsp)
addl $-0xd, %r13d
movl %r13d, (%r14)
leaq 0x68(%r12), %rax
movq %rax, (%rbx)
movq 0x68(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x28(%rsp)
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movsd (%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
callq 0x9d282
leaq 0x110(%rsp), %r14
movq %r14, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
callq 0x9dd1a
leaq 0xf8(%rsp), %r15
movq %r15, %rdi
movsd 0x50(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
callq 0x9dd1a
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 0x85130
movl $0x88, %edi
callq 0x15610
movq %rax, %rbx
leaq 0x78(%rsp), %rsi
movq %rax, %rdi
callq 0x32d6c
leaq 0x78(%rsp), %rdi
callq 0x872e4
jmp 0x1871e
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 0xc2368
movq %r15, %rdi
xorl %esi, %esi
callq 0x15a20
movl $0xd0, %edi
callq 0x15610
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xaa3ac
movq %r15, %rdi
movq %r12, %rsi
callq 0xb28ae
testl %eax, %eax
je 0x1865c
cmpl $0x0, 0x1568a1(%rip)    # 0x16edcc
je 0x18670
leaq 0xf106e(%rip), %rdi     # 0x1095a6
movq %r12, %rsi
xorl %eax, %eax
callq 0x15080
leaq 0x78(%rsp), %rdi
callq 0xc23ca
leaq 0xf1066(%rip), %rdi     # 0x1095b9
movb $0x1, %al
callq 0x15080
movl 0xc0(%r15), %esi
movl 0xc4(%r15), %edx
leaq 0xf1061(%rip), %rdi     # 0x1095d0
xorl %eax, %eax
callq 0x15080
movsd 0xb0(%r15), %xmm1
leaq 0x1567c2(%rip), %rax    # 0x16ed48
movsd (%rax), %xmm2
movapd 0xf0aee(%rip), %xmm0    # 0x109080
xorpd %xmm2, %xmm0
movsd 0xf0a72(%rip), %xmm3    # 0x109010
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 0xf101f(%rip), %rdi     # 0x1095e6
movb $0x1, %al
callq 0x15080
movq %r15, %rdi
callq 0xab1fe
leaq 0xf1019(%rip), %rdi     # 0x1095f6
movl %eax, %esi
xorl %eax, %eax
callq 0x15080
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xaaff4
movsd (%r12), %xmm0
leaq 0xf1007(%rip), %rdi     # 0x10960a
movb $0x1, %al
callq 0x15080
movsd 0x8(%r12), %xmm0
leaq 0xf1002(%rip), %rdi     # 0x10961a
movb $0x1, %al
callq 0x15080
movq %r15, %rdi
callq 0xab148
leaq 0xf0ffc(%rip), %rdi     # 0x10962a
movb $0x1, %al
callq 0x15080
movq %r15, %rdi
callq 0xab198
leaq 0xf0ff5(%rip), %rdi     # 0x109639
movb $0x1, %al
callq 0x15080
movq 0x15590e(%rip), %rax    # 0x16df60
movq (%rax), %rdi
callq 0x15760
jmp 0x18670
leaq 0xf0f27(%rip), %rdi     # 0x10958a
xorl %r15d, %r15d
movq %r12, %rsi
xorl %eax, %eax
callq 0xc5782
testq %r15, %r15
je 0x1871c
movq $0x0, (%rsp)
movl (%r14), %ebp
leal -0x1(%rbp), %eax
movl %eax, (%r14)
movq (%rbx), %r12
leaq 0x8(%r12), %rax
movq %rax, (%rbx)
movq 0x8(%r12), %r13
leaq 0xf0a64(%rip), %rsi     # 0x109105
movq %r13, %rdi
callq 0x158c0
testl %eax, %eax
je 0x18758
leaq 0xf0a67(%rip), %rsi     # 0x10911f
movq %r13, %rdi
callq 0x158c0
testl %eax, %eax
je 0x18733
leaq 0xf0a43(%rip), %rsi     # 0x10910e
movq %r13, %rdi
callq 0x158c0
testl %eax, %eax
je 0x1873a
leaq 0xf0a38(%rip), %rsi     # 0x109116
movq %r13, %rdi
callq 0x158c0
testl %eax, %eax
je 0x18741
leaq 0xf0a34(%rip), %rsi     # 0x109125
movq %r13, %rdi
callq 0x158c0
testl %eax, %eax
je 0x18748
leaq 0xf0a26(%rip), %rsi     # 0x10912a
movq %r13, %rdi
callq 0x158c0
testl %eax, %eax
je 0x1874f
leaq 0xf0a1f(%rip), %rdi     # 0x109136
jmp 0x1892d
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
jmp 0x18754
movl $0x2, %eax
jmp 0x18754
movl $0x3, %eax
jmp 0x18754
movl $0x4, %eax
jmp 0x18754
movl $0x5, %eax
movq %rax, (%rsp)
leal -0x2(%rbp), %eax
movl %eax, (%r14)
leaq 0x10(%r12), %rax
movq %rax, (%rbx)
movq 0x10(%r12), %r13
leaq 0x106e14(%rip), %rsi    # 0x11f586
movq %r13, %rdi
callq 0x158c0
testl %eax, %eax
je 0x18810
leaq 0xf09da(%rip), %rsi     # 0x109163
movq %r13, %rdi
callq 0x158c0
testl %eax, %eax
je 0x1881a
leaq 0xf09c5(%rip), %rsi     # 0x109165
movq %r13, %rdi
callq 0x158c0
testl %eax, %eax
je 0x18824
movb (%r13), %sil
testb %sil, %sil
sete %al
je 0x187f0
leaq 0x1(%r13), %rcx
movabsq $0x680000000000, %rdx   # imm = 0x680000000000
movsbl %sil, %edi
addl $-0x30, %edi
cmpl $0xa, %edi
jb 0x187e2
cmpb $0x2e, %sil
ja 0x187f0
movzbl %sil, %esi
btq %rsi, %rdx
jae 0x187f0
movb (%rcx), %sil
incq %rcx
testb %sil, %sil
sete %al
jne 0x187c6
testb $0x1, %al
je 0x18926
movq %r13, %rdi
callq 0x157e0
movsd %xmm0, 0x10(%rsp)
movl $0x0, 0x8(%rsp)
jmp 0x18835
movl $0x2, 0x8(%rsp)
jmp 0x1882c
movl $0x3, 0x8(%rsp)
jmp 0x1882c
movl $0x4, 0x8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
leal -0x3(%rbp), %eax
movl %eax, (%r14)
leaq 0x18(%r12), %rax
movq %rax, (%rbx)
movq 0x18(%r12), %r13
leaq 0xfc52d(%rip), %rsi     # 0x114d7c
movq %r13, %rdi
callq 0x158c0
testl %eax, %eax
je 0x188b6
movb (%r13), %sil
testb %sil, %sil
sete %al
je 0x1889f
leaq 0x1(%r13), %rcx
movabsq $0x680000000000, %rdx   # imm = 0x680000000000
movsbl %sil, %edi
addl $-0x30, %edi
cmpl $0xa, %edi
jb 0x18891
cmpb $0x2e, %sil
ja 0x1889f
movzbl %sil, %esi
btq %rsi, %rdx
jae 0x1889f
movb (%rcx), %sil
incq %rcx
testb %sil, %sil
sete %al
jne 0x18875
testb $0x1, %al
je 0x1891d
movq %r13, %rdi
callq 0x157e0
movsd %xmm0, 0x18(%rsp)
xorl %r13d, %r13d
jmp 0x188c5
movl $0x1, %r13d
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
addl $-0x4, %ebp
movl %ebp, (%r14)
leaq 0x20(%r12), %rax
movq %rax, (%rbx)
movq 0x20(%r12), %rdi
callq 0x157e0
movsd %xmm0, 0x20(%rsp)
movl $0x38, %edi
callq 0x15610
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
movl 0x8(%rsp), %ecx
movl %r13d, %r8d
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
callq 0x335ea
jmp 0x1871e
leaq 0xf0864(%rip), %rdi     # 0x109188
jmp 0x1892d
leaq 0xf083a(%rip), %rdi     # 0x109167
xorl %ebx, %ebx
movq %r13, %rsi
jmp 0x181a2
movq %rax, %r14
movl $0x38, %esi
movq %rbx, %rdi
jmp 0x1894f
movq %rax, %r14
movl $0xd0, %esi
movq %r15, %rdi
callq 0x15620
jmp 0x18981
movq %rax, %r14
movl $0x88, %esi
jmp 0x1896a
jmp 0x18974
movq %rax, %r14
movl $0x40, %esi
movq %rbx, %rdi
callq 0x15620
jmp 0x18977
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x872e4
movq %r14, %rdi
callq 0x15ae0