// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Draw.cpp
// Function: gaps::R3OrientedBox::Draw(gaps::RNFlags) const
void R3OrientedBox::
Draw(const R3DrawFlags draw_flags) const
{
    // Check if box is empty
    if (IsEmpty()) return;

    static R2Point texcoords[4] = {
	R2Point(0.0, 0.0),
	R2Point(1.0, 0.0),
	R2Point(1.0, 1.0),
	R2Point(0.0, 1.0)
    };
    static int surface_paths[6][4] = {
	{ 3, 0, 1, 2 },
	{ 4, 7, 6, 5 },
	{ 0, 4, 5, 1 },
	{ 7, 3, 2, 6 },
	{ 3, 7, 4, 0 },
        { 1, 5, 6, 2 }
    };
    static int outline_path[16] = {
	0, 1, 2, 3,
	0, 4, 5, 6,
	7, 4, 5, 1,
	2, 6, 7, 3
    };

    /* Get box corner points */
    R3Point corners[8];
    corners[0] = Corner(RN_NNN_OCTANT);
    corners[1] = Corner(RN_NNP_OCTANT);
    corners[2] = Corner(RN_NPP_OCTANT);
    corners[3] = Corner(RN_NPN_OCTANT);
    corners[4] = Corner(RN_PNN_OCTANT);
    corners[5] = Corner(RN_PNP_OCTANT);
    corners[6] = Corner(RN_PPP_OCTANT);
    corners[7] = Corner(RN_PPN_OCTANT);

    // Draw surface
    if (draw_flags[R3_SURFACES_DRAW_FLAG]) {
	for (int i = 0; i < 6; i++) {
	    R3BeginPolygon();
	    if (draw_flags[R3_SURFACE_NORMALS_DRAW_FLAG]) {
                RNScalar sign = (i < 3) ? 1.0 : -1.0;
                R3LoadNormal(sign * Axis(i%3));
            }
	    for (int j = 0; j < 4; j++) {
		if (draw_flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG]) 
		    R3LoadTextureCoords(texcoords[j]);
		R3LoadPoint(corners[surface_paths[i][j]]);
	    }
	    R3EndPolygon();
	}
    }

    // Draw edges
    if (draw_flags[R3_EDGES_DRAW_FLAG]) {
	R3BeginLine();
	for (int i = 0; i < 16; i++)
	    R3LoadPoint(corners[outline_path[i]]);
	R3EndLine();
    }    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %rbx
movq %rdi, %r12
callq 0x22b76
testl %eax, %eax
jne 0x3c613
movb 0x49f92e(%rip), %al     # 0x4dbd10
testb %al, %al
je 0x3c625
xorl %r14d, %r14d
leaq (%rsp,%r14), %rdi
addq $0x20, %rdi
callq 0x37b4a
addq $0x18, %r14
cmpq $0xc0, %r14
jne 0x3c3ed
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x221da
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x37e36
leaq 0x8(%rsp), %r15
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x221da
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x37e36
leaq 0x8(%rsp), %r15
pushq $0x3
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x221da
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x37e36
leaq 0x8(%rsp), %r15
pushq $0x2
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x221da
leaq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x37e36
leaq 0x8(%rsp), %r15
pushq $0x4
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x221da
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x37e36
leaq 0x8(%rsp), %r15
pushq $0x5
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x221da
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x37e36
leaq 0x8(%rsp), %r15
pushq $0x7
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x221da
leaq 0xb0(%rsp), %rdi
movq %r15, %rsi
callq 0x37e36
leaq 0x8(%rsp), %r14
pushq $0x6
popq %rdx
movq %r14, %rdi
movq %r12, %r15
movq %r12, %rsi
callq 0x221da
leaq 0xc8(%rsp), %rdi
movq %r14, %rsi
callq 0x37e36
testb $0x2, %bl
jne 0x3c556
testb $0x1, %bl
je 0x3c613
callq 0x21c38
xorl %ebx, %ebx
leaq 0x5d98f(%rip), %r14     # 0x99ec0
cmpq $0x40, %rbx
je 0x3c60e
movslq (%rbx,%r14), %rax
imulq $0x18, %rax, %rax
leaq (%rsp,%rax), %rdi
addq $0x20, %rdi
callq 0xe130
addq $0x4, %rbx
jmp 0x3c531
addq $0x20, %r15
leaq 0x5d8ff(%rip), %r13     # 0x99e60
xorl %ebp, %ebp
cmpq $0x6, %rbp
je 0x3c51a
callq 0x21c40
testb $0x20, %bl
je 0x3c5c0
movq %rbp, %rax
shlq $0x20, %rax
movabsq $-0x300000000, %rcx     # imm = 0xFFFFFFFD00000000
addq %rax, %rcx
xorl %edx, %edx
cmpq $0x3, %rbp
setb %dl
cmovbq %rax, %rcx
leaq 0x5d8b5(%rip), %rax     # 0x99e50
movsd (%rax,%rdx,8), %xmm0
sarq $0x20, %rcx
imulq $0x18, %rcx, %rsi
addq %r15, %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x38a02
movq %r14, %rdi
callq 0xe6e0
leaq 0x49f709(%rip), %r12    # 0x4dbcd0
xorl %r14d, %r14d
cmpq $0x4, %r14
je 0x3c5fd
btl $0x9, %ebx
jae 0x3c5de
movq %r12, %rdi
callq 0xe120
movslq (%r13,%r14,4), %rax
imulq $0x18, %rax, %rax
leaq (%rsp,%rax), %rdi
addq $0x20, %rdi
callq 0xe130
incq %r14
addq $0x10, %r12
jmp 0x3c5ca
callq 0xe5f0
incq %rbp
addq $0x10, %r13
jmp 0x3c563
callq 0xe5f0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x49f6e4(%rip), %rdi    # 0x4dbd10
callq 0xe840
testl %eax, %eax
je 0x3c3ea
leaq 0x49f690(%rip), %rdi    # 0x4dbcd0
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
callq 0x5f58c
leaq 0x49f68e(%rip), %rdi    # 0x4dbce0
movsd 0x569ae(%rip), %xmm0    # 0x93008
xorps %xmm1, %xmm1
callq 0x5f58c
leaq 0x49f687(%rip), %rdi    # 0x4dbcf0
movsd 0x56997(%rip), %xmm0    # 0x93008
movaps %xmm0, %xmm1
callq 0x5f58c
leaq 0x49f680(%rip), %rdi    # 0x4dbd00
movsd 0x56980(%rip), %xmm1    # 0x93008
xorps %xmm0, %xmm0
callq 0x5f58c
leaq 0x49f679(%rip), %rdi    # 0x4dbd10
callq 0xe2f0
jmp 0x3c3ea
movq %rax, %rbx
leaq 0x49f665(%rip), %rdi    # 0x4dbd10
callq 0xe2e0
movq %rbx, %rdi
callq 0xe810