// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Draw.cpp
// Function: gaps::R3Box::Draw(gaps::RNFlags) const
void R3Box::
Draw(const R3DrawFlags draw_flags) const
{
    static R3Vector normals[6] = {
	R3Vector(-1.0, 0.0, 0.0),
	R3Vector(1.0, 0.0, 0.0),
	R3Vector(0.0, -1.0, 0.0),
	R3Vector(0.0, 1.0, 0.0),
	R3Vector(0.0, 0.0, -1.0),
	R3Vector(0.0, 0.0, 1.0)
    };
    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]) 
		R3LoadNormal(normals[i]);
	    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:
subq $0x208, %rsp            # imm = 0x208
movq %rsi, 0x200(%rsp)
movq %rdi, 0x1f8(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpb $0x0, 0x502285(%rip)    # 0x579770
jne 0x775ba
leaq 0x502278(%rip), %rdi    # 0x579770
callq 0xf8e0
cmpl $0x0, %eax
je 0x775ba
leaq 0x5021d3(%rip), %rdi    # 0x5796e0
movsd 0xbbb03(%rip), %xmm0    # 0x133018
xorps %xmm2, %xmm2
movaps %xmm2, %xmm1
callq 0x6fcb0
jmp 0x77522
leaq 0x5021cf(%rip), %rdi    # 0x5796f8
movsd 0xbbad7(%rip), %xmm0    # 0x133008
xorps %xmm2, %xmm2
movaps %xmm2, %xmm1
callq 0x6fcb0
jmp 0x7753e
leaq 0x5021cb(%rip), %rdi    # 0x579710
movsd 0xbbacb(%rip), %xmm1    # 0x133018
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
callq 0x6fcb0
jmp 0x7755a
leaq 0x5021c7(%rip), %rdi    # 0x579728
movsd 0xbba9f(%rip), %xmm1    # 0x133008
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
callq 0x6fcb0
jmp 0x77576
leaq 0x5021c3(%rip), %rdi    # 0x579740
xorps %xmm1, %xmm1
movsd 0xbba90(%rip), %xmm2    # 0x133018
movaps %xmm1, %xmm0
callq 0x6fcb0
jmp 0x77592
leaq 0x5021bf(%rip), %rdi    # 0x579758
xorps %xmm1, %xmm1
movsd 0xbba64(%rip), %xmm2    # 0x133008
movaps %xmm1, %xmm0
callq 0x6fcb0
jmp 0x775ae
leaq 0x5021bb(%rip), %rdi    # 0x579770
callq 0xf310
cmpb $0x0, 0x5021ff(%rip)    # 0x5797c0
jne 0x7763f
leaq 0x5021f6(%rip), %rdi    # 0x5797c0
callq 0xf8e0
cmpl $0x0, %eax
je 0x7763f
leaq 0x5021a5(%rip), %rdi    # 0x579780
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xc3140
jmp 0x775e8
leaq 0x5021a1(%rip), %rdi    # 0x579790
movsd 0xbba11(%rip), %xmm0    # 0x133008
xorps %xmm1, %xmm1
callq 0xc3140
jmp 0x77601
leaq 0x502198(%rip), %rdi    # 0x5797a0
movsd 0xbb9f8(%rip), %xmm1    # 0x133008
movaps %xmm1, %xmm0
callq 0xc3140
jmp 0x7761a
leaq 0x50218f(%rip), %rdi    # 0x5797b0
xorps %xmm0, %xmm0
movsd 0xbb9dc(%rip), %xmm1    # 0x133008
callq 0xc3140
jmp 0x77633
leaq 0x502186(%rip), %rdi    # 0x5797c0
callq 0xf310
leaq 0x120(%rsp), %rax
movq %rax, %rcx
addq $0xc0, %rcx
movq %rcx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x6eb40
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, 0x18(%rsp)
jne 0x7765b
movq 0x20(%rsp), %rsi
leaq 0x108(%rsp), %rdi
xorl %edx, %edx
callq 0x42e40
leaq 0x120(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x6f1e0
movq 0x20(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
movl $0x1, %edx
callq 0x42e40
leaq 0x120(%rsp), %rdi
addq $0x18, %rdi
leaq 0xf0(%rsp), %rsi
callq 0x6f1e0
movq 0x20(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
movl $0x3, %edx
callq 0x42e40
leaq 0x120(%rsp), %rdi
addq $0x30, %rdi
leaq 0xd8(%rsp), %rsi
callq 0x6f1e0
movq 0x20(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
movl $0x2, %edx
callq 0x42e40
leaq 0x120(%rsp), %rdi
addq $0x48, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x6f1e0
movq 0x20(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
movl $0x4, %edx
callq 0x42e40
leaq 0x120(%rsp), %rdi
addq $0x60, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x6f1e0
movq 0x20(%rsp), %rsi
leaq 0x90(%rsp), %rdi
movl $0x5, %edx
callq 0x42e40
leaq 0x120(%rsp), %rdi
addq $0x78, %rdi
leaq 0x90(%rsp), %rsi
callq 0x6f1e0
movq 0x20(%rsp), %rsi
leaq 0x78(%rsp), %rdi
movl $0x7, %edx
callq 0x42e40
leaq 0x120(%rsp), %rdi
addq $0x90, %rdi
leaq 0x78(%rsp), %rsi
callq 0x6f1e0
movq 0x20(%rsp), %rsi
leaq 0x60(%rsp), %rdi
movl $0x6, %edx
callq 0x42e40
leaq 0x120(%rsp), %rdi
addq $0xa8, %rdi
leaq 0x60(%rsp), %rsi
callq 0x6f1e0
leaq 0x58(%rsp), %rdi
movl $0x2, %esi
callq 0x13d80
movq 0x58(%rsp), %rsi
leaq 0x200(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x77965
movl $0x0, 0x54(%rsp)
cmpl $0x6, 0x54(%rsp)
jge 0x77963
callq 0x38e90
leaq 0x48(%rsp), %rdi
movl $0x20, %esi
callq 0x13d80
movq 0x48(%rsp), %rsi
leaq 0x200(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x778c1
movslq 0x54(%rsp), %rax
leaq 0x501e77(%rip), %rdi    # 0x5796e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x38ea0
jmp 0x778c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
leaq 0x501ede(%rip), %rdi    # 0x579770
callq 0xf300
jmp 0x779dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
leaq 0x501f09(%rip), %rdi    # 0x5797c0
callq 0xf300
jmp 0x779dd
movl $0x0, 0x44(%rsp)
cmpl $0x4, 0x44(%rsp)
jge 0x7794e
leaq 0x38(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x13d80
movq 0x38(%rsp), %rsi
leaq 0x200(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x7790e
movslq 0x44(%rsp), %rax
leaq 0x501e7e(%rip), %rdi    # 0x579780
shlq $0x4, %rax
addq %rax, %rdi
callq 0x789f0
movslq 0x54(%rsp), %rcx
leaq 0x100a46(%rip), %rax    # 0x178360
shlq $0x4, %rcx
addq %rcx, %rax
movslq 0x44(%rsp), %rcx
movslq (%rax,%rcx,4), %rax
leaq 0x120(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x38e40
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x778c9
callq 0x38ec0
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x77827
jmp 0x77965
leaq 0x30(%rsp), %rdi
movl $0x1, %esi
callq 0x13d80
movq 0x30(%rsp), %rsi
leaq 0x200(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x779d5
callq 0x38e70
movl $0x0, 0x2c(%rsp)
cmpl $0x10, 0x2c(%rsp)
jge 0x779d0
movslq 0x2c(%rsp), %rcx
leaq 0x100a15(%rip), %rax    # 0x1783c0
movslq (%rax,%rcx,4), %rax
leaq 0x120(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x38e40
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x77998
callq 0x38e80
addq $0x208, %rsp            # imm = 0x208
retq
movq 0x1f0(%rsp), %rdi
callq 0xf890
nopw (%rax,%rax)