// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelUtils.cpp
// Function: gaps::GetObjectOBBProperty(gaps::R3SurfelObject*, gaps::R3OrientedBox*, double*, int*)
R3SurfelObjectProperty *
GetObjectOBBProperty(R3SurfelObject *object,
  R3OrientedBox *obb, RNScalar *confidence, int *originator)
{
  // Constants for OBB property
  static const int property_type = R3_SURFEL_OBJECT_AMODAL_OBB_PROPERTY;
  static const int noperands = 20;

  // Get object property
  R3SurfelObjectProperty *property = object->FindObjectProperty(property_type);
  if (!property) return NULL;

  // Check property operands
  if (property->NOperands() != noperands) return NULL;

  // Extract obb
  if (obb) {
    R3Point center(property->Operand(0), property->Operand(1), property->Operand(2));
    R3Vector axis0(property->Operand(3), property->Operand(4), property->Operand(5));
    R3Vector axis1(property->Operand(6), property->Operand(7), property->Operand(8));
    // R3Vector axis2(property->Operand(9), property->Operand(10), property->Operand(11));
    RNScalar radius0 = property->Operand(12);
    RNScalar radius1 = property->Operand(13);
    RNScalar radius2 = property->Operand(14);
    obb->Reset(center, axis0, axis1, radius0, radius1, radius2);
  }

  // Extract confidence and originator
  if (confidence) *confidence = property->Operand(15);
  if (originator) *originator = (int) (property->Operand(16) + 0.5);

  // Return property
  return property;
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xb8(%rsp)
movq %rsi, 0xb0(%rsp)
movq %rdx, 0xa8(%rsp)
movq %rcx, 0xa0(%rsp)
movq 0xb8(%rsp), %rdi
movl $0x2, %esi
callq 0x19a40
movq %rax, 0x98(%rsp)
cmpq $0x0, 0x98(%rsp)
jne 0x3734d
movq $0x0, 0xc0(%rsp)
jmp 0x3757d
movq 0x98(%rsp), %rdi
callq 0x1bcd0
cmpl $0x14, %eax
je 0x37370
movq $0x0, 0xc0(%rsp)
jmp 0x3757d
cmpq $0x0, 0xb0(%rsp)
je 0x3750d
movq 0x98(%rsp), %rdi
xorl %esi, %esi
callq 0x1bce0
movsd %xmm0, 0x10(%rsp)
movq 0x98(%rsp), %rdi
movl $0x1, %esi
callq 0x1bce0
movsd %xmm0, 0x8(%rsp)
movq 0x98(%rsp), %rdi
movl $0x2, %esi
callq 0x1bce0
movsd 0x8(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x10(%rsp), %xmm0
leaq 0x80(%rsp), %rdi
callq 0xf8350
movq 0x98(%rsp), %rdi
movl $0x3, %esi
callq 0x1bce0
movsd %xmm0, 0x20(%rsp)
movq 0x98(%rsp), %rdi
movl $0x4, %esi
callq 0x1bce0
movsd %xmm0, 0x18(%rsp)
movq 0x98(%rsp), %rdi
movl $0x5, %esi
callq 0x1bce0
movsd 0x18(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x20(%rsp), %xmm0
leaq 0x68(%rsp), %rdi
callq 0xf94b0
movq 0x98(%rsp), %rdi
movl $0x6, %esi
callq 0x1bce0
movsd %xmm0, 0x30(%rsp)
movq 0x98(%rsp), %rdi
movl $0x7, %esi
callq 0x1bce0
movsd %xmm0, 0x28(%rsp)
movq 0x98(%rsp), %rdi
movl $0x8, %esi
callq 0x1bce0
movsd 0x28(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x30(%rsp), %xmm0
leaq 0x50(%rsp), %rdi
callq 0xf94b0
movq 0x98(%rsp), %rdi
movl $0xc, %esi
callq 0x1bce0
movsd %xmm0, 0x48(%rsp)
movq 0x98(%rsp), %rdi
movl $0xd, %esi
callq 0x1bce0
movsd %xmm0, 0x40(%rsp)
movq 0x98(%rsp), %rdi
movl $0xe, %esi
callq 0x1bce0
movsd %xmm0, 0x38(%rsp)
movq 0xb0(%rsp), %rdi
movsd 0x48(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
movq (%rdi), %rax
leaq 0x80(%rsp), %rsi
leaq 0x68(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq *0x268(%rax)
cmpq $0x0, 0xa8(%rsp)
je 0x37536
movq 0x98(%rsp), %rdi
movl $0xf, %esi
callq 0x1bce0
movq 0xa8(%rsp), %rax
movsd %xmm0, (%rax)
cmpq $0x0, 0xa0(%rsp)
je 0x3756d
movq 0x98(%rsp), %rdi
movl $0x10, %esi
callq 0x1bce0
movsd 0x16cbfd(%rip), %xmm1   # 0x1a4158
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, (%rax)
movq 0x98(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
addq $0xc8, %rsp
retq
nopl (%rax)