// File: tomfunkhouser[P]gaps/pkgs/R3Graphics/R3Scene.cpp
// Function: gaps::WritePrincetonLight(gaps::R3Scene const*, gaps::R3Light const*, _IO_FILE*)
static int
WritePrincetonLight(const R3Scene *scene, const R3Light *light, FILE *fp)
{
  // Get light color
  RNRgb color = light->Color();
  
  // Write light in format appropriate for type
  if (light->ClassID() == R3DirectionalLight::CLASS_ID()) {
    R3DirectionalLight *directional_light = (R3DirectionalLight *) light;
    const R3Vector& direction = directional_light->Direction();
    fprintf(fp, "dir_light  %g %g %g  %g %g %g\n",
            color.R(), color.G(), color.B(),
            direction.X(), direction.Y(), direction.Z());
  }
  else if (light->ClassID() == R3PointLight::CLASS_ID()) {
    R3PointLight *point_light = (R3PointLight *) light;
    const R3Point& position = point_light->Position();
    RNScalar ca = point_light->ConstantAttenuation();
    RNScalar la = point_light->LinearAttenuation();
    RNScalar qa = point_light->QuadraticAttenuation();
    fprintf(fp, "point_light  %g %g %g  %g %g %g  %g %g %g\n",
            color.R(), color.G(), color.B(),
            position.X(), position.Y(), position.Z(),
            ca, la, qa);
  }
  else if (light->ClassID() == R3SpotLight::CLASS_ID()) {
    R3SpotLight *spot_light = (R3SpotLight *) light;
    const R3Point& position = spot_light->Position();
    const R3Vector& direction = spot_light->Direction();
    RNScalar ca = spot_light->ConstantAttenuation();
    RNScalar la = spot_light->LinearAttenuation();
    RNScalar qa = spot_light->QuadraticAttenuation();
    RNScalar sc = spot_light->CutOffAngle();
    RNScalar sd = spot_light->DropOffRate();
    fprintf(fp, "spot_light  %g %g %g  %g %g %g  %g %g %g  %g %g %g  %g %g\n",
            color.R(), color.G(), color.B(),
            position.X(), position.Y(), position.Z(),
            direction.X(), direction.Y(), direction.Z(),
            ca, la, qa, sc, sd);
  }
  else if (light->ClassID() == R3AreaLight::CLASS_ID()) {
    R3AreaLight *area_light = (R3AreaLight *) light;
    const R3Point& position = area_light->Position();
    const R3Vector& direction = area_light->Direction();
    RNScalar radius = area_light->Radius();
    RNScalar ca = area_light->ConstantAttenuation();
    RNScalar la = area_light->LinearAttenuation();
    RNScalar qa = area_light->QuadraticAttenuation();
    fprintf(fp, "area_light  %g %g %g  %g %g %g  %g %g %g  %g  %g %g %g\n",
            color.R(), color.G(), color.B(),
            position.X(), position.Y(), position.Z(),
            direction.X(), direction.Y(), direction.Z(),
            radius, ca, la, qa);
  }
  else {
    // fprintf("Unrecognized light type\n");
    // return 0;
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x228, %rsp            # imm = 0x228
movq %rdi, 0x220(%rsp)
movq %rsi, 0x218(%rsp)
movq %rdx, 0x210(%rsp)
movq 0x218(%rsp), %rdi
callq 0x2ba40
movq %rax, %rsi
leaq 0x1f8(%rsp), %rdi
callq 0xef300
movq 0x218(%rsp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movl %eax, 0x144(%rsp)
callq 0x62130
movl %eax, %ecx
movl 0x144(%rsp), %eax
cmpl %ecx, %eax
jne 0x3d2c2
movq 0x218(%rsp), %rax
movq %rax, 0x1f0(%rsp)
movq 0x1f0(%rsp), %rdi
callq 0x2ba50
movq %rax, 0x1e8(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x110(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4a0
movsd %xmm0, 0x138(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4b0
movsd %xmm0, 0x118(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4c0
movsd %xmm0, 0x120(%rsp)
movq 0x1e8(%rsp), %rdi
callq 0x2b910
movsd %xmm0, 0x128(%rsp)
movq 0x1e8(%rsp), %rdi
callq 0x2b920
movsd %xmm0, 0x130(%rsp)
movq 0x1e8(%rsp), %rdi
callq 0x2b930
movq 0x110(%rsp), %rdi
movsd 0x118(%rsp), %xmm1
movsd 0x120(%rsp), %xmm2
movsd 0x128(%rsp), %xmm3
movsd 0x130(%rsp), %xmm4
movaps %xmm0, %xmm5
movsd 0x138(%rsp), %xmm0
leaq 0x1524a0(%rip), %rsi    # 0x18f756
movb $0x6, %al
callq 0x22f30
jmp 0x3d8b8
movq 0x218(%rsp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movl %eax, 0x10c(%rsp)
callq 0x61290
movl %eax, %ecx
movl 0x10c(%rsp), %eax
cmpl %ecx, %eax
jne 0x3d44c
movq 0x218(%rsp), %rax
movq %rax, 0x1e0(%rsp)
movq 0x1e0(%rsp), %rdi
callq 0x2ba60
movq %rax, 0x1d8(%rsp)
movq 0x1e0(%rsp), %rdi
callq 0x4e670
movsd %xmm0, 0x1d0(%rsp)
movq 0x1e0(%rsp), %rdi
callq 0x4e680
movsd %xmm0, 0x1c8(%rsp)
movq 0x1e0(%rsp), %rdi
callq 0x4e690
movsd %xmm0, 0x1c0(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4a0
movsd %xmm0, 0x100(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4b0
movsd %xmm0, 0xe0(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4c0
movsd %xmm0, 0xe8(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x2b820
movsd %xmm0, 0xf0(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x2b830
movsd %xmm0, 0xf8(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x2b840
movq 0xd8(%rsp), %rdi
movsd 0xe0(%rsp), %xmm1
movsd 0xe8(%rsp), %xmm2
movsd 0xf0(%rsp), %xmm3
movsd 0xf8(%rsp), %xmm4
movaps %xmm0, %xmm5
movsd 0x100(%rsp), %xmm0
movsd 0x1d0(%rsp), %xmm6
movsd 0x1c8(%rsp), %xmm7
movsd 0x1c0(%rsp), %xmm8
leaq 0x15233b(%rip), %rsi    # 0x18f775
movsd %xmm8, (%rsp)
movb $0x8, %al
callq 0x22f30
jmp 0x3d8b6
movq 0x218(%rsp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movl %eax, 0xd4(%rsp)
callq 0x60b60
movl %eax, %ecx
movl 0xd4(%rsp), %eax
cmpl %ecx, %eax
jne 0x3d6ae
movq 0x218(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x2ba60
movq %rax, 0x1b0(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x2ba80
movq %rax, 0x1a8(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x4e670
movsd %xmm0, 0x1a0(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x4e680
movsd %xmm0, 0x198(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x4e690
movsd %xmm0, 0x190(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x4e6a0
movsd %xmm0, 0x188(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x4e6c0
movsd %xmm0, 0x180(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4a0
movsd %xmm0, 0xc8(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4b0
movsd %xmm0, 0x90(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4c0
movsd %xmm0, 0x98(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0x2b820
movsd %xmm0, 0xa0(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0x2b830
movsd %xmm0, 0xa8(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0x2b840
movsd %xmm0, 0xb0(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x2b910
movsd %xmm0, 0xb8(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x2b920
movsd %xmm0, 0xc0(%rsp)
movq 0x1a8(%rsp), %rdi
callq 0x2b930
movq 0x88(%rsp), %rdi
movsd 0x90(%rsp), %xmm1
movsd 0x98(%rsp), %xmm2
movsd 0xa0(%rsp), %xmm3
movsd 0xa8(%rsp), %xmm4
movsd 0xb0(%rsp), %xmm5
movsd 0xb8(%rsp), %xmm6
movsd 0xc0(%rsp), %xmm7
movaps %xmm0, %xmm13
movsd 0xc8(%rsp), %xmm0
movsd 0x1a0(%rsp), %xmm12
movsd 0x198(%rsp), %xmm11
movsd 0x190(%rsp), %xmm10
movsd 0x188(%rsp), %xmm9
movsd 0x180(%rsp), %xmm8
leaq 0x152127(%rip), %rsi    # 0x18f7a0
movsd %xmm13, (%rsp)
movsd %xmm12, 0x8(%rsp)
movsd %xmm11, 0x10(%rsp)
movsd %xmm10, 0x18(%rsp)
movsd %xmm9, 0x20(%rsp)
movsd %xmm8, 0x28(%rsp)
movb $0x8, %al
callq 0x22f30
jmp 0x3d8b4
movq 0x218(%rsp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movl %eax, 0x84(%rsp)
callq 0x5f070
movl %eax, %ecx
movl 0x84(%rsp), %eax
cmpl %ecx, %eax
jne 0x3d8b0
movq 0x218(%rsp), %rax
movq %rax, 0x178(%rsp)
movq 0x178(%rsp), %rdi
callq 0x4e6e0
movq %rax, 0x170(%rsp)
movq 0x178(%rsp), %rdi
callq 0x4e700
movq %rax, 0x168(%rsp)
movq 0x178(%rsp), %rdi
callq 0x4e720
movsd %xmm0, 0x160(%rsp)
movq 0x178(%rsp), %rdi
callq 0x4e740
movsd %xmm0, 0x158(%rsp)
movq 0x178(%rsp), %rdi
callq 0x4e760
movsd %xmm0, 0x150(%rsp)
movq 0x178(%rsp), %rdi
callq 0x4e780
movsd %xmm0, 0x148(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4a0
movsd %xmm0, 0x78(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4b0
movsd %xmm0, 0x40(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x2b4c0
movsd %xmm0, 0x48(%rsp)
movq 0x170(%rsp), %rdi
callq 0x2b820
movsd %xmm0, 0x50(%rsp)
movq 0x170(%rsp), %rdi
callq 0x2b830
movsd %xmm0, 0x58(%rsp)
movq 0x170(%rsp), %rdi
callq 0x2b840
movsd %xmm0, 0x60(%rsp)
movq 0x168(%rsp), %rdi
callq 0x2b910
movsd %xmm0, 0x68(%rsp)
movq 0x168(%rsp), %rdi
callq 0x2b920
movsd %xmm0, 0x70(%rsp)
movq 0x168(%rsp), %rdi
callq 0x2b930
movq 0x38(%rsp), %rdi
movsd 0x40(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
movsd 0x50(%rsp), %xmm3
movsd 0x58(%rsp), %xmm4
movsd 0x60(%rsp), %xmm5
movsd 0x68(%rsp), %xmm6
movsd 0x70(%rsp), %xmm7
movaps %xmm0, %xmm12
movsd 0x78(%rsp), %xmm0
movsd 0x160(%rsp), %xmm11
movsd 0x158(%rsp), %xmm10
movsd 0x150(%rsp), %xmm9
movsd 0x148(%rsp), %xmm8
leaq 0x151f56(%rip), %rsi    # 0x18f7db
movsd %xmm12, (%rsp)
movsd %xmm11, 0x8(%rsp)
movsd %xmm10, 0x10(%rsp)
movsd %xmm9, 0x18(%rsp)
movsd %xmm8, 0x20(%rsp)
movb $0x8, %al
callq 0x22f30
jmp 0x3d8b2
jmp 0x3d8b2
jmp 0x3d8b4
jmp 0x3d8b6
jmp 0x3d8b8
movl $0x1, %eax
addq $0x228, %rsp            # imm = 0x228
retq
nopw %cs:(%rax,%rax)