// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/apps/scn2img/scn2img.cpp
// Function: DrawSceneWithOpenGL(gaps::R3Camera const&, gaps::R3Scene*, int, int)
static int
DrawSceneWithOpenGL(const R3Camera& camera, R3Scene *scene, int color_scheme, RNBoolean omit_objects = FALSE)
{
  // Clear window
  glClearColor(background.R(), background.G(), background.B(), 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Check color scheme
  if (color_scheme == RGB_COLOR_SCHEME) {
    // Draw scene
    glEnable(GL_LIGHTING);
    scene->LoadLights(headlight);
    DrawRootWithOpenGL(camera, scene, color_scheme, omit_objects);
  }
  else if (color_scheme == ALBEDO_COLOR_SCHEME) {
    // Load ambient light
    static GLfloat ambient[4];
    ambient[0] = 1;
    ambient[1] = 1;
    ambient[2] = 1;
    ambient[3] = 1;
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);

    // Copy diffuse reflections into ambient reflections
    RNRgb *saved_ambients = NULL;
    if (scene->NBrdfs() > 0) {
      saved_ambients = new RNRgb [ scene->NBrdfs() ];
      for (int i = 0; i < scene->NBrdfs(); i++) {
        R3Brdf *brdf = scene->Brdf(i);
        saved_ambients[i] = brdf->Ambient();
        brdf->SetAmbient(brdf->Diffuse());
      }
    }

    // Disable lights
    for (int i = 0; i < 8; i++) {
      glDisable(GL_LIGHT0 + i);
    }

    // Draw scene with only ambient light
    RNLoadRgb(1.0, 1.0, 1.0);
    glEnable(GL_LIGHTING);
    DrawRootWithOpenGL(camera, scene, color_scheme, omit_objects);

    // Restore lights
    if (headlight) {
      glEnable(GL_LIGHT0);
    }

    // Restore ambient reflections
    if (saved_ambients) {
      for (int i = 0; i < scene->NBrdfs(); i++) {
        R3Brdf *brdf = scene->Brdf(i);
        brdf->SetAmbient(saved_ambients[i]);
      }
      delete [] saved_ambients;
    }
  }
  else {
    // Draw scene
    glDisable(GL_LIGHTING);
    RNLoadRgb(1.0, 1.0, 1.0);
    DrawRootWithOpenGL(camera, scene, color_scheme, omit_objects);
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movl %edx, %r15d
cvtsd2ss 0x131bae(%rip), %xmm0   # 0x159840
movq %rsi, %rbx
cvtsd2ss 0x131bab(%rip), %xmm1   # 0x159848
movq %rdi, %r14
cvtsd2ss 0x131ba8(%rip), %xmm2   # 0x159850
movss 0xc4410(%rip), %xmm3    # 0xec0c0
callq 0x22e00
movl $0x4100, %edi           # imm = 0x4100
callq 0x221d0
cmpl $0x9, %r15d
je 0x27cfd
movl $0xb50, %edi            # imm = 0xB50
cmpl $0x1, %r15d
jne 0x27d96
callq 0x227e0
movzbl 0x131bb0(%rip), %esi    # 0x159890
movq %rbx, %rdi
movl $0x7, %edx
callq 0x2bede
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
jmp 0x27db7
movaps 0xc43cc(%rip), %xmm0    # 0xec0d0
movaps %xmm0, 0x131c05(%rip)   # 0x159910
leaq 0x131bfe(%rip), %rsi    # 0x159910
movl $0xb53, %edi            # imm = 0xB53
callq 0x231d0
movslq 0x44(%rbx), %rax
testq %rax, %rax
jle 0x27dcc
shlq $0x3, %rax
leaq (%rax,%rax,2), %r12
movq %r12, %rdi
callq 0x22040
movq %rax, %r15
xorl %r13d, %r13d
leaq (%r15,%r13), %rdi
callq 0x98c5c
addq $0x18, %r13
cmpq %r13, %r12
jne 0x27d3f
cmpl $0x0, 0x44(%rbx)
jle 0x27dcf
movl %ebp, 0x4(%rsp)
xorl %ebp, %ebp
movq %r15, %r12
movq 0x38(%rbx), %rax
movq (%rax,%rbp,8), %r13
leaq 0x20(%r13), %rsi
movq %r12, %rdi
callq 0x98d0e
leaq 0x38(%r13), %rsi
movq %r13, %rdi
callq 0x46d00
incq %rbp
movslq 0x44(%rbx), %rax
addq $0x18, %r12
cmpq %rax, %rbp
jl 0x27d60
movl 0x4(%rsp), %ebp
jmp 0x27dcf
callq 0x221e0
movsd 0xc42cd(%rip), %xmm0    # 0xec070
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x22e50
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %edx
movl %ebp, %ecx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2a1f9
xorl %r15d, %r15d
movl $0x4000, %r12d          # imm = 0x4000
movl %r12d, %edi
callq 0x221e0
incl %r12d
cmpl $0x4008, %r12d          # imm = 0x4008
jne 0x27dd5
movsd 0xc427f(%rip), %xmm0    # 0xec070
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x22e50
movl $0xb50, %edi            # imm = 0xB50
callq 0x227e0
movq %r14, %rdi
movq %rbx, %rsi
movl $0x9, %edx
movl %ebp, %ecx
callq 0x2a1f9
cmpb $0x0, 0x131a71(%rip)    # 0x159890
je 0x27e2b
movl $0x4000, %edi           # imm = 0x4000
callq 0x227e0
testq %r15, %r15
je 0x27e72
cmpl $0x0, 0x44(%rbx)
jle 0x27e5c
xorl %r12d, %r12d
movq %r15, %r14
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rdi
movq %r14, %rsi
callq 0x46d00
incq %r12
movslq 0x44(%rbx), %rax
addq $0x18, %r14
cmpq %rax, %r12
jl 0x27e3c
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22c00
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r15, %rdi
movq %r12, %rsi
callq 0x23270
movq %rbx, %rdi
callq 0x230a0