// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelObject.cpp
// Function: gaps::R3SurfelObject::BestOrientedBBox(int) const
R3OrientedBox R3SurfelObject::
BestOrientedBBox(int originator) const
{
  // Return best OBB (or an empty box if there is none)
  RNScalar best_confidence = -FLT_MAX;
  R3OrientedBox best_obb = R3null_oriented_box;
  for (int i = 0; i < properties.NEntries(); i++) {
    R3SurfelObjectProperty *property = properties.Kth(i);
    if (property->Type() != R3_SURFEL_OBJECT_AMODAL_OBB_PROPERTY) continue;
    if (property->NOperands() != 20) continue;
    int orig = (int) (property->Operand(16) + 0.5);
    if (orig != originator) continue;
    RNScalar confidence = property->Operand(15);
    if (confidence > best_confidence) {
      R3Point centroid(property->Operand(0), property->Operand(1), property->Operand(2));
      R3Vector axis1(property->Operand(3), property->Operand(4), property->Operand(5));
      R3Vector axis2(property->Operand(6), property->Operand(7), property->Operand(8));
      // R3Vector axis3(property->Operand(9), property->Operand(10), property->Operand(11));
      RNScalar radius1 = property->Operand(12);
      RNScalar radius2 = property->Operand(13);
      RNScalar radius3 = property->Operand(14);
      best_obb.Reset(centroid, axis1, axis2, radius1, radius2, radius3);
      best_confidence = confidence;
    }
  }

  // Return best obb
  return best_obb;
}

// Assembly:
subq $0x158, %rsp            # imm = 0x158
movq %rdi, 0x90(%rsp)
movq %rdi, %rax
movq %rax, 0x98(%rsp)
movq %rdi, 0x150(%rsp)
movq %rsi, 0x148(%rsp)
movl %edx, 0x144(%rsp)
movq 0x148(%rsp), %rax
movq %rax, 0xa0(%rsp)
movsd 0x18a05f(%rip), %xmm0   # 0x1a4188
movsd %xmm0, 0x138(%rsp)
movb $0x0, 0x137(%rsp)
leaq 0x1e2f8f(%rip), %rsi    # 0x1fd0d0
callq 0xc7980
movl $0x0, 0x130(%rsp)
movq 0xa0(%rsp), %rdi
movl 0x130(%rsp), %eax
movl %eax, 0x88(%rsp)
addq $0x30, %rdi
callq 0x16d50
movl %eax, 0x8c(%rsp)
jmp 0x1a179
movl 0x88(%rsp), %eax
movl 0x8c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x1a4e7
movq 0xa0(%rsp), %rdi
addq $0x30, %rdi
movl 0x130(%rsp), %esi
callq 0x1bcb0
movq %rax, 0x80(%rsp)
jmp 0x1a1b1
movq 0x80(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rdi
callq 0x1bc50
movl %eax, 0x7c(%rsp)
jmp 0x1a1d4
movl 0x7c(%rsp), %eax
cmpl $0x2, %eax
je 0x1a208
jmp 0x1a4d1
movq 0x90(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x128(%rsp)
movl %eax, 0x124(%rsp)
callq 0x1bd00
jmp 0x1a516
movq 0x118(%rsp), %rdi
callq 0x1bcd0
movl %eax, 0x78(%rsp)
jmp 0x1a21b
movl 0x78(%rsp), %eax
cmpl $0x14, %eax
je 0x1a229
jmp 0x1a4d1
movq 0x118(%rsp), %rdi
movl $0x10, %esi
callq 0x1bce0
movsd %xmm0, 0x70(%rsp)
jmp 0x1a243
movsd 0x70(%rsp), %xmm0
movsd 0x189f07(%rip), %xmm1   # 0x1a4158
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x114(%rsp)
movl 0x114(%rsp), %eax
cmpl 0x144(%rsp), %eax
je 0x1a275
jmp 0x1a4d1
movq 0x118(%rsp), %rdi
movl $0xf, %esi
callq 0x1bce0
movsd %xmm0, 0x68(%rsp)
jmp 0x1a28f
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
movsd 0x108(%rsp), %xmm0
ucomisd 0x138(%rsp), %xmm0
jbe 0x1a4cf
movq 0x118(%rsp), %rdi
xorl %esi, %esi
callq 0x1bce0
movsd %xmm0, 0x60(%rsp)
jmp 0x1a2cd
movq 0x118(%rsp), %rdi
movl $0x1, %esi
callq 0x1bce0
movsd %xmm0, 0x58(%rsp)
jmp 0x1a2e7
movq 0x118(%rsp), %rdi
movl $0x2, %esi
callq 0x1bce0
movsd %xmm0, 0x50(%rsp)
jmp 0x1a301
movsd 0x50(%rsp), %xmm2
movsd 0x58(%rsp), %xmm1
movsd 0x60(%rsp), %xmm0
leaq 0xf0(%rsp), %rdi
callq 0xf8350
jmp 0x1a322
movq 0x118(%rsp), %rdi
movl $0x3, %esi
callq 0x1bce0
movsd %xmm0, 0x48(%rsp)
jmp 0x1a33c
movq 0x118(%rsp), %rdi
movl $0x4, %esi
callq 0x1bce0
movsd %xmm0, 0x40(%rsp)
jmp 0x1a356
movq 0x118(%rsp), %rdi
movl $0x5, %esi
callq 0x1bce0
movsd %xmm0, 0x38(%rsp)
jmp 0x1a370
movsd 0x38(%rsp), %xmm2
movsd 0x40(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
leaq 0xd8(%rsp), %rdi
callq 0xf94b0
jmp 0x1a391
movq 0x118(%rsp), %rdi
movl $0x6, %esi
callq 0x1bce0
movsd %xmm0, 0x30(%rsp)
jmp 0x1a3ab
movq 0x118(%rsp), %rdi
movl $0x7, %esi
callq 0x1bce0
movsd %xmm0, 0x28(%rsp)
jmp 0x1a3c5
movq 0x118(%rsp), %rdi
movl $0x8, %esi
callq 0x1bce0
movsd %xmm0, 0x20(%rsp)
jmp 0x1a3df
movsd 0x20(%rsp), %xmm2
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm0
leaq 0xc0(%rsp), %rdi
callq 0xf94b0
jmp 0x1a400
movq 0x118(%rsp), %rdi
movl $0xc, %esi
callq 0x1bce0
movsd %xmm0, 0x18(%rsp)
jmp 0x1a41a
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movq 0x118(%rsp), %rdi
movl $0xd, %esi
callq 0x1bce0
movsd %xmm0, 0x10(%rsp)
jmp 0x1a443
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
movq 0x118(%rsp), %rdi
movl $0xe, %esi
callq 0x1bce0
movsd %xmm0, 0x8(%rsp)
jmp 0x1a46c
movq 0x90(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
movsd 0xb8(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm1
movsd 0xa8(%rsp), %xmm2
leaq 0xf0(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
leaq 0xc0(%rsp), %rcx
callq 0xc98d0
jmp 0x1a4bd
movsd 0x108(%rsp), %xmm0
movsd %xmm0, 0x138(%rsp)
jmp 0x1a4d1
movl 0x130(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x130(%rsp)
jmp 0x1a151
movb $0x1, 0x137(%rsp)
testb $0x1, 0x137(%rsp)
jne 0x1a506
movq 0x90(%rsp), %rdi
callq 0x1bd00
movq 0x98(%rsp), %rax
addq $0x158, %rsp            # imm = 0x158
retq
movq 0x128(%rsp), %rdi
callq 0x13970
nopw %cs:(%rax,%rax)