// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Graphics/R3Scene.cpp
// Function: gaps::R3Scene::ReadRectangleFile(char const*, gaps::R3SceneNode*)
int R3Scene::
ReadRectangleFile(const char *filename, R3SceneNode *parent_node)
{
  // Get/check parent node
  if (!parent_node) parent_node = root;

  // Open file
  FILE *fp;
  if (!(fp = fopen(filename, "r"))) {
    RNFail("Unable to open file %s", filename);
    return 0;
  }

  // Read file
  char buffer[4096];
  int line_number = 0;
  int assignment_index = 0;
  while (fgets(buffer, 4096, fp)) {
    // Check line
    line_number++;
    char *bufferp = buffer;
    while (*bufferp && isspace(*bufferp)) bufferp++;
    if (!bufferp) continue;
    if (*bufferp == '#') continue;

    // Parse line
    char name[4096];
    double x1, y1, x2, y2, x3, y3, x4, y4, zmin, zmax, score;
    if (sscanf(bufferp, "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%s", 
       &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4, &zmin, &zmax, &score, name) != (unsigned int) 12) {
      RNFail("Error parsing line %d of %s\n", line_number, filename);
      return 0;
    }

    // Create node
    R3SceneNode *node = new R3SceneNode(this);
    parent_node->InsertChild(node);

    // Create shape element
    RNArray<R3Triangle *> triangles;
    RNArray<R3TriangleVertex *> vertices;
    R3TriangleVertex *v1 = new R3TriangleVertex(R3Point(x1, y1, zmin)); vertices.Insert(v1);
    R3TriangleVertex *v2 = new R3TriangleVertex(R3Point(x2, y2, zmin)); vertices.Insert(v2);
    R3TriangleVertex *v3 = new R3TriangleVertex(R3Point(x3, y3, zmin)); vertices.Insert(v3);
    R3TriangleVertex *v4 = new R3TriangleVertex(R3Point(x4, y4, zmin)); vertices.Insert(v4);
    R3Triangle *t1 = new R3Triangle(v1, v2, v3); triangles.Insert(t1);
    R3Triangle *t2 = new R3Triangle(v1, v3, v4); triangles.Insert(t2);
    R3TriangleArray *base = new R3TriangleArray(vertices, triangles);
    R3Point base_centroid = base->BBox().Centroid();
    R3Point top_centroid = base_centroid + (zmax - zmin) * R3posz_vector;
    R3Cylinder *marker = new R3Cylinder(base_centroid, top_centroid, 0.01 * base->BBox().DiagonalRadius());
    R3Brdf *brdf = new R3Brdf(RNRgb(0, 0.25 + score, 0));
    InsertBrdf(brdf);
    R3Material *material = new R3Material(brdf);
    InsertMaterial(material);
    R3SceneElement *element = new R3SceneElement();
    element->SetMaterial(material);
    element->InsertShape(base);
    element->InsertShape(marker);
    node->InsertElement(element);
    
    // Set node name
    char node_name[1024];
    sprintf(node_name, "A%d_S%03d", assignment_index++, (int) (1000*score));
    node->SetName(node_name);
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x24f8, %rsp           # imm = 0x24F8
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
movq %rdx, 0x40(%rsp)
testq %rdx, %rdx
jne 0x2d296
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
leaq 0xb5da6(%rip), %rsi     # 0xe3043
movq %r14, %rdi
callq 0x21ac0
testq %rax, %rax
je 0x2d7ec
movq %r14, 0x70(%rsp)
leaq 0x4f0(%rsp), %rbx
movq %rbx, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %rax, 0x48(%rsp)
movq %rax, %rdx
callq 0x21f40
testq %rax, %rax
je 0x2d7db
movq 0x8(%rsp), %rax
leaq 0x38(%rax), %rcx
movq %rcx, 0x68(%rsp)
addq $0x28, %rax
movq %rax, 0x60(%rsp)
leaq 0xf0(%rsp), %r14
movl $0x0, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
incl 0x2c(%rsp)
movb 0x4f0(%rsp), %bpl
testb %bpl, %bpl
je 0x2d34b
leaq 0x4f0(%rsp), %rbx
movsbl %bpl, %edi
callq 0x210b0
testl %eax, %eax
je 0x2d33c
movb 0x1(%rbx), %bpl
incq %rbx
testb %bpl, %bpl
jne 0x2d321
jmp 0x2d34b
movl $0x2, %eax
cmpb $0x23, %bpl
je 0x2d7b4
movq %rbx, %rdi
leaq 0xaf7c7(%rip), %rsi     # 0xdcb1c
leaq 0xb8(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
leaq 0xa8(%rsp), %r8
leaq 0xa0(%rsp), %r9
xorl %eax, %eax
leaq 0x14f0(%rsp), %r10
pushq %r10
leaq 0x60(%rsp), %r10
pushq %r10
leaq 0x88(%rsp), %r10
pushq %r10
leaq 0x38(%rsp), %r10
pushq %r10
leaq 0xa0(%rsp), %r10
pushq %r10
leaq 0xb0(%rsp), %r10
pushq %r10
leaq 0xc0(%rsp), %r10
pushq %r10
leaq 0xd0(%rsp), %r10
pushq %r10
callq 0x21890
addq $0x40, %rsp
cmpl $0xc, %eax
jne 0x2d798
movl $0x1b0, %edi            # imm = 0x1B0
callq 0x218c0
movq %rax, %rbx
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x3bab8
movq 0x40(%rsp), %rdi
movq %rbx, 0x50(%rsp)
movq %rbx, %rsi
callq 0x3ce8e
leaq 0x30(%rsp), %rdi
callq 0x886bc
leaq 0x10(%rsp), %rdi
callq 0x886bc
movl $0x68, %edi
callq 0x218c0
movq %rax, %r12
movsd 0xb8(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movq %r14, %rdi
callq 0x762ba
movq %r12, %rdi
movq %r14, %rsi
callq 0x6a2e8
movl 0x1c(%rsp), %edx
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x88752
movl $0x68, %edi
callq 0x218c0
movq %rax, %rbx
movsd 0xa8(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movq %r14, %rdi
callq 0x762ba
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6a2e8
movl 0x1c(%rsp), %edx
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x88752
movl $0x68, %edi
callq 0x218c0
movq %rax, %r15
movsd 0x98(%rsp), %xmm0
movsd 0x90(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movq %r14, %rdi
callq 0x762ba
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a2e8
movl 0x1c(%rsp), %edx
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x88752
movl $0x68, %edi
callq 0x218c0
movq %rax, %rbp
movsd 0x88(%rsp), %xmm0
movsd 0x80(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movq %r14, %rdi
callq 0x762ba
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6a2e8
movl 0x1c(%rsp), %edx
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x88752
movl $0x88, %edi
callq 0x218c0
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x6a800
movl 0x3c(%rsp), %edx
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x88752
movl $0x88, %edi
callq 0x218c0
movq %rax, %rbx
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x6a800
movl 0x3c(%rsp), %edx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x88752
movl $0x70, %edi
callq 0x218c0
movq %rax, %r12
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x68918
movq (%r12), %rax
movq %r14, %rdi
movq %r12, %rsi
callq *0x88(%rax)
leaq 0xc0(%rsp), %rdi
movq %r14, %rsi
callq 0x6e32e
movq %r14, %rdi
callq 0x6e944
movsd 0x78(%rsp), %xmm0
subsd 0x20(%rsp), %xmm0
movq %r14, %rdi
leaq 0xb17de(%rip), %rsi     # 0xdedd0
callq 0x77722
leaq 0xd8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
movq %r14, %rdx
callq 0x76605
movl $0xe8, %edi
callq 0x218c0
movq %rax, %rbx
movq (%r12), %rax
movq %r14, %rdi
movq %r12, %rsi
callq *0x88(%rax)
movq %r14, %rdi
callq 0x6e16c
mulsd 0xae9e4(%rip), %xmm0    # 0xdc020
mulsd 0xae9e4(%rip), %xmm0    # 0xdc028
movq %rbx, %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x6c044
movq %r14, %rdi
callq 0x6e944
movl $0xb8, %edi
callq 0x218c0
movq %rax, %r15
movsd 0x58(%rsp), %xmm1
addsd 0xaee59(%rip), %xmm1    # 0xdc4d8
xorpd %xmm0, %xmm0
xorpd %xmm2, %xmm2
movq %r14, %rdi
callq 0x88530
xorpd %xmm0, %xmm0
movq %r15, %rdi
movq %r14, %rsi
movsd 0xae977(%rip), %xmm1    # 0xdc018
movapd %xmm1, %xmm2
xorl %edx, %edx
callq 0x44488
movq 0x8(%rsp), %rax
movq %rax, 0x8(%r15)
movl 0x44(%rax), %edx
movl %edx, 0x10(%r15)
movq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x88752
movl $0x30, %edi
callq 0x218c0
movq %rax, %rbp
movq %rax, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x440f8
movq 0x8(%rsp), %rax
movq %rax, (%rbp)
movl 0x34(%rax), %edx
movl %edx, 0x8(%rbp)
movq 0x60(%rsp), %rdi
movq %rbp, %rsi
callq 0x88752
movl $0x60, %edi
callq 0x218c0
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
callq 0x3d9c4
movq %r15, %rdi
movq %rbp, %rsi
callq 0x3dc66
movq %r15, %rdi
movq %r12, %rsi
callq 0x3dc6c
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3dc6c
movq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x3ceca
movsd 0x58(%rsp), %xmm0
mulsd 0xaed8e(%rip), %xmm0    # 0xdc4e0
cvttsd2si %xmm0, %ecx
movq %r14, %rdi
leaq 0xaf94d(%rip), %rsi     # 0xdd0ad
movl 0x28(%rsp), %ebx
movl %ebx, %edx
xorl %eax, %eax
callq 0x21140
movq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x3d0ca
incl %ebx
movl %ebx, 0x28(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x88726
leaq 0x30(%rsp), %rdi
callq 0x88726
xorl %eax, %eax
jmp 0x2d7b4
leaq 0xaf8f1(%rip), %rdi     # 0xdd090
movl 0x2c(%rsp), %esi
movq 0x70(%rsp), %rdx
xorl %eax, %eax
callq 0x8b53a
movl $0x1, %eax
leaq 0x4f0(%rsp), %rbx
testb $0x1, %al
jne 0x2d801
movq %rbx, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq 0x48(%rsp), %rdx
callq 0x21f40
testq %rax, %rax
jne 0x2d308
movq 0x48(%rsp), %rdi
callq 0x218b0
movl $0x1, %ebx
jmp 0x2d803
leaq 0xaee53(%rip), %rdi     # 0xdc646
xorl %ebx, %ebx
movq %r14, %rsi
xorl %eax, %eax
callq 0x8b53a
jmp 0x2d803
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x24f8, %rsp           # imm = 0x24F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movl $0x60, %esi
jmp 0x2d8bc
jmp 0x2d903
movq %rax, %r14
movl $0x88, %esi
jmp 0x2d8ea
movq %rax, %r14
leaq 0xf0(%rsp), %rdi
callq 0x6e944
jmp 0x2d906
movq %rax, %r14
jmp 0x2d910
jmp 0x2d903
movq %rax, %r14
movl $0x30, %esi
jmp 0x2d8ab
movq %rax, %r14
movl $0x1b0, %esi            # imm = 0x1B0
movq %rbx, %rdi
callq 0x218e0
jmp 0x2d91a
movq %rax, %r14
movl $0x70, %esi
jmp 0x2d8f7
movq %rax, %r14
jmp 0x2d8d1
movq %rax, %r14
movl $0x88, %esi
movq %r13, %rdi
jmp 0x2d8fa
jmp 0x2d903
jmp 0x2d903
jmp 0x2d903
movq %rax, %r14
movl $0xb8, %esi
jmp 0x2d8bc
movq %rax, %r14
movl $0x68, %esi
movq %rbp, %rdi
jmp 0x2d8fa
jmp 0x2d903
jmp 0x2d903
movq %rax, %r14
movl $0x68, %esi
movq %r15, %rdi
jmp 0x2d8fa
movq %rax, %r14
leaq 0xf0(%rsp), %rdi
callq 0x6e944
movl $0xe8, %esi
jmp 0x2d8ea
jmp 0x2d903
jmp 0x2d903
jmp 0x2d903
jmp 0x2d903
jmp 0x2d903
movq %rax, %r14
movl $0x68, %esi
movq %rbx, %rdi
jmp 0x2d8fa
movq %rax, %r14
movl $0x68, %esi
movq %r12, %rdi
callq 0x218e0
jmp 0x2d906
jmp 0x2d903
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x88726
leaq 0x30(%rsp), %rdi
callq 0x88726
movq %r14, %rdi
callq 0x220d0