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

    /* Get texture coordinates */
    static R2Point texcoords[4] = {
	R2Point(0.0, 0.0),
	R2Point(1.0, 0.0),
	R2Point(1.0, 1.0),
	R2Point(0.0, 1.0)
    };

    /* Get box corner points */
    R3Point corners[4];
    corners[0] = Corner(RN_NN_QUADRANT);
    corners[1] = Corner(RN_PN_QUADRANT);
    corners[2] = Corner(RN_PP_QUADRANT);
    corners[3] = Corner(RN_NP_QUADRANT);

    // Draw surface
    if (draw_flags[R3_SURFACES_DRAW_FLAG]) {
        if (draw_flags[R3_SURFACE_NORMALS_DRAW_FLAG]) 
            R3LoadNormal(Normal());

        R3BeginPolygon();
        for (int j = 0; j < 4; j++) {
            if (draw_flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG])
                R3LoadTextureCoords(texcoords[j]);
	    R3LoadPoint(corners[j]);
        }
        R3EndPolygon();
    }

    // Draw edges
    if (draw_flags[R3_EDGES_DRAW_FLAG]) {
	R3BeginLoop();
	for (int i = 0; i < 4; i++)
	    R3LoadPoint(corners[i]);
	R3EndLoop();
    }    
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rsi, 0x130(%rsp)
movq %rdi, 0x128(%rsp)
movq 0x128(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x78ac0
cmpl $0x0, %eax
je 0x77073
jmp 0x7734e
cmpb $0x0, 0x502656(%rip)    # 0x5796d0
jne 0x770f8
leaq 0x50264d(%rip), %rdi    # 0x5796d0
callq 0xf8e0
cmpl $0x0, %eax
je 0x770f8
leaq 0x5025fc(%rip), %rdi    # 0x579690
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xc3140
jmp 0x770a1
leaq 0x5025f8(%rip), %rdi    # 0x5796a0
movsd 0xbbf58(%rip), %xmm0    # 0x133008
xorps %xmm1, %xmm1
callq 0xc3140
jmp 0x770ba
leaq 0x5025ef(%rip), %rdi    # 0x5796b0
movsd 0xbbf3f(%rip), %xmm1    # 0x133008
movaps %xmm1, %xmm0
callq 0xc3140
jmp 0x770d3
leaq 0x5025e6(%rip), %rdi    # 0x5796c0
xorps %xmm0, %xmm0
movsd 0xbbf23(%rip), %xmm1    # 0x133008
callq 0xc3140
jmp 0x770ec
leaq 0x5025dd(%rip), %rdi    # 0x5796d0
callq 0xf310
leaq 0xb0(%rsp), %rax
movq %rax, %rcx
addq $0x60, %rcx
movq %rcx, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x6eb40
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, 0x10(%rsp)
jne 0x77111
movq 0x18(%rsp), %rsi
leaq 0x98(%rsp), %rdi
xorl %edx, %edx
callq 0x78af0
leaq 0xb0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x6f1e0
movq 0x18(%rsp), %rsi
leaq 0x80(%rsp), %rdi
movl $0x2, %edx
callq 0x78af0
leaq 0xb0(%rsp), %rdi
addq $0x18, %rdi
leaq 0x80(%rsp), %rsi
callq 0x6f1e0
movq 0x18(%rsp), %rsi
leaq 0x68(%rsp), %rdi
movl $0x3, %edx
callq 0x78af0
leaq 0xb0(%rsp), %rdi
addq $0x30, %rdi
leaq 0x68(%rsp), %rsi
callq 0x6f1e0
movq 0x18(%rsp), %rsi
leaq 0x50(%rsp), %rdi
movl $0x1, %edx
callq 0x78af0
leaq 0xb0(%rsp), %rdi
addq $0x48, %rdi
leaq 0x50(%rsp), %rsi
callq 0x6f1e0
leaq 0x48(%rsp), %rdi
movl $0x2, %esi
callq 0x13d80
movq 0x48(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x772e9
leaq 0x40(%rsp), %rdi
movl $0x20, %esi
callq 0x13d80
movq 0x40(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x7726c
movq 0x18(%rsp), %rdi
callq 0x78ca0
movq %rax, %rdi
callq 0x38ea0
jmp 0x7726c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0x50246e(%rip), %rdi    # 0x5796d0
callq 0xf300
jmp 0x77356
callq 0x38e90
movl $0x0, 0x3c(%rsp)
cmpl $0x4, 0x3c(%rsp)
jge 0x772e4
leaq 0x30(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x13d80
movq 0x30(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x772be
movslq 0x3c(%rsp), %rax
leaq 0x5023de(%rip), %rdi    # 0x579690
shlq $0x4, %rax
addq %rax, %rdi
callq 0x789f0
movslq 0x3c(%rsp), %rax
leaq 0xb0(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x38e40
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x77279
callq 0x38ec0
leaq 0x28(%rsp), %rdi
movl $0x1, %esi
callq 0x13d80
movq 0x28(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x7734e
callq 0x78a60
movl $0x0, 0x24(%rsp)
cmpl $0x4, 0x24(%rsp)
jge 0x77349
movslq 0x24(%rsp), %rax
leaq 0xb0(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x38e40
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x7731c
callq 0x78a70
addq $0x138, %rsp            # imm = 0x138
retq
movq 0x120(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)