// File: srajangarg[P]raytracer/src/core/SceneLoader.cpp
// Function: SceneLoader::buildScene(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool SceneLoader::buildScene(string filename)
{
  buildEndlineTable(filename);
  ifstream file(filename.c_str());
  string line;

  while (findOpenParen(file))
  {
    file.tellg();

    if (readCommand(file, line))
    {
      if (line == "Include")
      {
        string instName;

        if (doInclude(file, instName))
        {
          cout << "included " << instName << endl;
        }
        else
        {
          cout << "mangled include at ";
          curPos(cout, file.tellg());
          cout << endl;
        }
      }
      else if (line == "Sphere")
      {
        string gname;

        if (doSphere(file, gname))
        {
          cout << "read sphere " << gname << endl;
        }
        else
        {
          *err << "mangled sphere command at ";
          errLine(file.tellg());
        }
      }
      else if (line == "Material")
      {
        string gname;

        if (doMaterial(file, gname))
        {
          cout << "read material " << gname << endl;
        }
        else
        {
          *err << "mangled material command at ";
          errLine(file.tellg());
        }
      }
      else if (line == "Light")
      {
        string gname;

        if (doLight(file, gname))
        {
          cout << "read light " << gname << endl;
        }
        else
        {
          *err << "mangled light command at ";
          errLine(file.tellg());
        }
      }
      else if (line == "Camera")
      {
        string gname;

        if (doCamera(file, gname))
        {
          cout << "read camera " << gname << endl;
        }
        else
        {
          *err << "mangled camera command at ";
          errLine(file.tellg());
        }
      }
      else if (line == "I")
      {
        *err << "Error: Instance commands must belong to a group, but I found in global scope at ";
        errLine(file.tellg());
        /*string iname; // code to handle I at global scope (doesn't make much sense now that instance names skip the names table)
        if (doI(file, iname))
        {
            cout << "got an instance named " << iname << endl;
        }*/
      }
      else if (line == "G")
      {
        string iname;

        if (doG(file, iname))
        {
          cout << "got a group named " << iname << endl;
        }
      }
      else if (line == "Render")
      {
        string iname;

        if (doRender(file, iname))
        {
          cout << "did render " << iname << endl;
        }
      }
      else
      {
        *err << "command not recognized: " << line << endl;
      }

      findCloseParen(file);
    }
    else
    {
    }
  }

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x570, %rsp            # imm = 0x570
movq %rsi, -0x3d0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x3c8(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x3c0(%rbp)
callq 0x51b0
movq -0x3c8(%rbp), %rdi
movq -0x3c0(%rbp), %rsi
callq 0xc790
jmp 0xba9a
leaq -0x30(%rbp), %rdi
callq 0x5290
movq -0x3d0(%rbp), %rdi
callq 0x51a0
movq %rax, %rsi
leaq -0x248(%rbp), %rdi
movl $0x8, %edx
callq 0x5760
leaq -0x268(%rbp), %rdi
callq 0x55a0
movq -0x3c8(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0xce90
movb %al, -0x3d1(%rbp)
jmp 0xbaea
movb -0x3d1(%rbp), %al
testb $0x1, %al
jne 0xbaf9
jmp 0xc5c4
leaq -0x248(%rbp), %rdi
callq 0x5700
movq %rdx, -0x3e8(%rbp)
movq %rax, -0x3e0(%rbp)
jmp 0xbb15
movq -0x3c8(%rbp), %rdi
movq -0x3e8(%rbp), %rax
movq -0x3e0(%rbp), %rcx
movq %rcx, -0x278(%rbp)
movq %rax, -0x270(%rbp)
leaq -0x248(%rbp), %rsi
leaq -0x268(%rbp), %rdx
callq 0xcdc0
movb %al, -0x3e9(%rbp)
jmp 0xbb53
movb -0x3e9(%rbp), %al
testb $0x1, %al
jne 0xbb62
jmp 0xc5bd
leaq 0x3bb6d(%rip), %rsi     # 0x476d6
leaq -0x268(%rbp), %rdi
callq 0x64f0
movb %al, -0x3ea(%rbp)
jmp 0xbb7d
movb -0x3ea(%rbp), %al
testb $0x1, %al
jne 0xbb8c
jmp 0xbd12
leaq -0x298(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x55a0
movq -0x3c8(%rbp), %rdi
movq -0x3f8(%rbp), %rdx
leaq -0x248(%rbp), %rsi
callq 0xfcc0
movb %al, -0x3eb(%rbp)
jmp 0xbbc1
movb -0x3eb(%rbp), %al
testb $0x1, %al
jne 0xbbd0
jmp 0xbc6a
movq 0x503f1(%rip), %rdi     # 0x5bfc8
leaq 0x3bb00(%rip), %rsi     # 0x476de
callq 0x53e0
movq %rax, -0x400(%rbp)
jmp 0xbbec
movq -0x400(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x53c0
movq %rax, -0x408(%rbp)
jmp 0xbc08
movq -0x408(%rbp), %rdi
movq 0x5039a(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0xbc1d
jmp 0xbd01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5290
jmp 0xc601
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xc5e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x5290
jmp 0xc5e9
movq 0x50357(%rip), %rdi     # 0x5bfc8
leaq 0x3ba70(%rip), %rsi     # 0x476e8
callq 0x53e0
jmp 0xbc7f
leaq -0x248(%rbp), %rdi
callq 0x5700
movq %rdx, -0x418(%rbp)
movq %rax, -0x410(%rbp)
jmp 0xbc9b
movq -0x418(%rbp), %rax
movq -0x410(%rbp), %rcx
movq %rcx, -0x2a8(%rbp)
movq %rax, -0x2a0(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x12bc0
movq %rax, -0x420(%rbp)
jmp 0xbccc
movq -0x3c8(%rbp), %rdi
movq -0x420(%rbp), %rax
movl %eax, %edx
movq 0x502e5(%rip), %rsi     # 0x5bfc8
callq 0xc990
jmp 0xbcea
movq 0x502d7(%rip), %rdi     # 0x5bfc8
movq 0x502b8(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0xbcff
jmp 0xbd01
leaq -0x298(%rbp), %rdi
callq 0x5290
jmp 0xc5a6
leaq 0x3b9e3(%rip), %rsi     # 0x476fc
leaq -0x268(%rbp), %rdi
callq 0x64f0
movb %al, -0x421(%rbp)
jmp 0xbd2d
movb -0x421(%rbp), %al
testb $0x1, %al
jne 0xbd3c
jmp 0xbe7f
leaq -0x2c8(%rbp), %rdi
movq %rdi, -0x430(%rbp)
callq 0x55a0
movq -0x3c8(%rbp), %rdi
movq -0x430(%rbp), %rdx
leaq -0x248(%rbp), %rsi
callq 0x103a0
movb %al, -0x422(%rbp)
jmp 0xbd71
movb -0x422(%rbp), %al
testb $0x1, %al
jne 0xbd7d
jmp 0xbdec
movq 0x50244(%rip), %rdi     # 0x5bfc8
leaq 0x3b978(%rip), %rsi     # 0x47703
callq 0x53e0
movq %rax, -0x438(%rbp)
jmp 0xbd99
movq -0x438(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x53c0
movq %rax, -0x440(%rbp)
jmp 0xbdb5
movq -0x440(%rbp), %rdi
movq 0x501ed(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0xbdca
jmp 0xbe6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x5290
jmp 0xc5e9
movq -0x3c8(%rbp), %rax
movq 0x90(%rax), %rdi
leaq 0x3b90f(%rip), %rsi     # 0x47710
callq 0x53e0
jmp 0xbe08
leaq -0x248(%rbp), %rdi
callq 0x5700
movq %rdx, -0x450(%rbp)
movq %rax, -0x448(%rbp)
jmp 0xbe24
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movq %rcx, -0x2d8(%rbp)
movq %rax, -0x2d0(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x12bc0
movq %rax, -0x458(%rbp)
jmp 0xbe55
movq -0x3c8(%rbp), %rdi
movq -0x458(%rbp), %rax
movl %eax, %esi
callq 0xd8e0
jmp 0xbe6c
jmp 0xbe6e
leaq -0x2c8(%rbp), %rdi
callq 0x5290
jmp 0xc5a4
leaq 0x3b8a5(%rip), %rsi     # 0x4772b
leaq -0x268(%rbp), %rdi
callq 0x64f0
movb %al, -0x459(%rbp)
jmp 0xbe9a
movb -0x459(%rbp), %al
testb $0x1, %al
jne 0xbea9
jmp 0xbfec
leaq -0x2f8(%rbp), %rdi
movq %rdi, -0x468(%rbp)
callq 0x55a0
movq -0x3c8(%rbp), %rdi
movq -0x468(%rbp), %rdx
leaq -0x248(%rbp), %rsi
callq 0xef70
movb %al, -0x45a(%rbp)
jmp 0xbede
movb -0x45a(%rbp), %al
testb $0x1, %al
jne 0xbeea
jmp 0xbf59
movq 0x500d7(%rip), %rdi     # 0x5bfc8
leaq 0x3b83c(%rip), %rsi     # 0x47734
callq 0x53e0
movq %rax, -0x470(%rbp)
jmp 0xbf06
movq -0x470(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
callq 0x53c0
movq %rax, -0x478(%rbp)
jmp 0xbf22
movq -0x478(%rbp), %rdi
movq 0x50080(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0xbf37
jmp 0xbfdb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x2f8(%rbp), %rdi
callq 0x5290
jmp 0xc5e9
movq -0x3c8(%rbp), %rax
movq 0x90(%rax), %rdi
leaq 0x3b7d5(%rip), %rsi     # 0x47743
callq 0x53e0
jmp 0xbf75
leaq -0x248(%rbp), %rdi
callq 0x5700
movq %rdx, -0x488(%rbp)
movq %rax, -0x480(%rbp)
jmp 0xbf91
movq -0x488(%rbp), %rax
movq -0x480(%rbp), %rcx
movq %rcx, -0x308(%rbp)
movq %rax, -0x300(%rbp)
leaq -0x308(%rbp), %rdi
callq 0x12bc0
movq %rax, -0x490(%rbp)
jmp 0xbfc2
movq -0x3c8(%rbp), %rdi
movq -0x490(%rbp), %rax
movl %eax, %esi
callq 0xd8e0
jmp 0xbfd9
jmp 0xbfdb
leaq -0x2f8(%rbp), %rdi
callq 0x5290
jmp 0xc5a2
leaq 0x3b76d(%rip), %rsi     # 0x47760
leaq -0x268(%rbp), %rdi
callq 0x64f0
movb %al, -0x491(%rbp)
jmp 0xc007
movb -0x491(%rbp), %al
testb $0x1, %al
jne 0xc016
jmp 0xc159
leaq -0x328(%rbp), %rdi
movq %rdi, -0x4a0(%rbp)
callq 0x55a0
movq -0x3c8(%rbp), %rdi
movq -0x4a0(%rbp), %rdx
leaq -0x248(%rbp), %rsi
callq 0x10dd0
movb %al, -0x492(%rbp)
jmp 0xc04b
movb -0x492(%rbp), %al
testb $0x1, %al
jne 0xc057
jmp 0xc0c6
movq 0x4ff6a(%rip), %rdi     # 0x5bfc8
leaq 0x3b701(%rip), %rsi     # 0x47766
callq 0x53e0
movq %rax, -0x4a8(%rbp)
jmp 0xc073
movq -0x4a8(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x53c0
movq %rax, -0x4b0(%rbp)
jmp 0xc08f
movq -0x4b0(%rbp), %rdi
movq 0x4ff13(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0xc0a4
jmp 0xc148
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x328(%rbp), %rdi
callq 0x5290
jmp 0xc5e9
movq -0x3c8(%rbp), %rax
movq 0x90(%rax), %rdi
leaq 0x3b697(%rip), %rsi     # 0x47772
callq 0x53e0
jmp 0xc0e2
leaq -0x248(%rbp), %rdi
callq 0x5700
movq %rdx, -0x4c0(%rbp)
movq %rax, -0x4b8(%rbp)
jmp 0xc0fe
movq -0x4c0(%rbp), %rax
movq -0x4b8(%rbp), %rcx
movq %rcx, -0x338(%rbp)
movq %rax, -0x330(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x12bc0
movq %rax, -0x4c8(%rbp)
jmp 0xc12f
movq -0x3c8(%rbp), %rdi
movq -0x4c8(%rbp), %rax
movl %eax, %esi
callq 0xd8e0
jmp 0xc146
jmp 0xc148
leaq -0x328(%rbp), %rdi
callq 0x5290
jmp 0xc5a0
leaq 0x3b62c(%rip), %rsi     # 0x4778c
leaq -0x268(%rbp), %rdi
callq 0x64f0
movb %al, -0x4c9(%rbp)
jmp 0xc174
movb -0x4c9(%rbp), %al
testb $0x1, %al
jne 0xc183
jmp 0xc2c6
leaq -0x358(%rbp), %rdi
movq %rdi, -0x4d8(%rbp)
callq 0x55a0
movq -0x3c8(%rbp), %rdi
movq -0x4d8(%rbp), %rdx
leaq -0x248(%rbp), %rsi
callq 0x11b50
movb %al, -0x4ca(%rbp)
jmp 0xc1b8
movb -0x4ca(%rbp), %al
testb $0x1, %al
jne 0xc1c4
jmp 0xc233
movq 0x4fdfd(%rip), %rdi     # 0x5bfc8
leaq 0x3b5c1(%rip), %rsi     # 0x47793
callq 0x53e0
movq %rax, -0x4e0(%rbp)
jmp 0xc1e0
movq -0x4e0(%rbp), %rdi
leaq -0x358(%rbp), %rsi
callq 0x53c0
movq %rax, -0x4e8(%rbp)
jmp 0xc1fc
movq -0x4e8(%rbp), %rdi
movq 0x4fda6(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0xc211
jmp 0xc2b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x358(%rbp), %rdi
callq 0x5290
jmp 0xc5e9
movq -0x3c8(%rbp), %rax
movq 0x90(%rax), %rdi
leaq 0x3b558(%rip), %rsi     # 0x477a0
callq 0x53e0
jmp 0xc24f
leaq -0x248(%rbp), %rdi
callq 0x5700
movq %rdx, -0x4f8(%rbp)
movq %rax, -0x4f0(%rbp)
jmp 0xc26b
movq -0x4f8(%rbp), %rax
movq -0x4f0(%rbp), %rcx
movq %rcx, -0x368(%rbp)
movq %rax, -0x360(%rbp)
leaq -0x368(%rbp), %rdi
callq 0x12bc0
movq %rax, -0x500(%rbp)
jmp 0xc29c
movq -0x3c8(%rbp), %rdi
movq -0x500(%rbp), %rax
movl %eax, %esi
callq 0xd8e0
jmp 0xc2b3
jmp 0xc2b5
leaq -0x358(%rbp), %rdi
callq 0x5290
jmp 0xc59e
leaq 0x3bc46(%rip), %rsi     # 0x47f13
leaq -0x268(%rbp), %rdi
callq 0x64f0
movb %al, -0x501(%rbp)
jmp 0xc2e1
movb -0x501(%rbp), %al
testb $0x1, %al
jne 0xc2f0
jmp 0xc375
movq -0x3c8(%rbp), %rax
movq 0x90(%rax), %rdi
leaq 0x3b4b6(%rip), %rsi     # 0x477bb
callq 0x53e0
jmp 0xc30c
leaq -0x248(%rbp), %rdi
callq 0x5700
movq %rdx, -0x518(%rbp)
movq %rax, -0x510(%rbp)
jmp 0xc328
movq -0x518(%rbp), %rax
movq -0x510(%rbp), %rcx
movq %rcx, -0x378(%rbp)
movq %rax, -0x370(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x12bc0
movq %rax, -0x520(%rbp)
jmp 0xc359
movq -0x3c8(%rbp), %rdi
movq -0x520(%rbp), %rax
movl %eax, %esi
callq 0xd8e0
jmp 0xc370
jmp 0xc59c
leaq 0x3b801(%rip), %rsi     # 0x47b7d
leaq -0x268(%rbp), %rdi
callq 0x64f0
movb %al, -0x521(%rbp)
jmp 0xc390
movb -0x521(%rbp), %al
testb $0x1, %al
jne 0xc39f
jmp 0xc45d
leaq -0x398(%rbp), %rdi
movq %rdi, -0x530(%rbp)
callq 0x55a0
movq -0x3c8(%rbp), %rdi
movq -0x530(%rbp), %rdx
leaq -0x248(%rbp), %rsi
callq 0x121a0
movb %al, -0x522(%rbp)
jmp 0xc3d4
movb -0x522(%rbp), %al
testb $0x1, %al
jne 0xc3e0
jmp 0xc44c
movq 0x4fbe1(%rip), %rdi     # 0x5bfc8
leaq 0x3b41e(%rip), %rsi     # 0x4780c
callq 0x53e0
movq %rax, -0x538(%rbp)
jmp 0xc3fc
movq -0x538(%rbp), %rdi
leaq -0x398(%rbp), %rsi
callq 0x53c0
movq %rax, -0x540(%rbp)
jmp 0xc418
movq -0x540(%rbp), %rdi
movq 0x4fb8a(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0xc42d
jmp 0xc44c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x398(%rbp), %rdi
callq 0x5290
jmp 0xc5e9
leaq -0x398(%rbp), %rdi
callq 0x5290
jmp 0xc59a
leaq 0x3b3bb(%rip), %rsi     # 0x4781f
leaq -0x268(%rbp), %rdi
callq 0x64f0
movb %al, -0x541(%rbp)
jmp 0xc478
movb -0x541(%rbp), %al
testb $0x1, %al
jne 0xc487
jmp 0xc542
leaq -0x3b8(%rbp), %rdi
movq %rdi, -0x550(%rbp)
callq 0x55a0
movq -0x3c8(%rbp), %rdi
movq -0x550(%rbp), %rdx
leaq -0x248(%rbp), %rsi
callq 0x125d0
movb %al, -0x542(%rbp)
jmp 0xc4bc
movb -0x542(%rbp), %al
testb $0x1, %al
jne 0xc4c8
jmp 0xc534
movq 0x4faf9(%rip), %rdi     # 0x5bfc8
leaq 0x3b350(%rip), %rsi     # 0x47826
callq 0x53e0
movq %rax, -0x558(%rbp)
jmp 0xc4e4
movq -0x558(%rbp), %rdi
leaq -0x3b8(%rbp), %rsi
callq 0x53c0
movq %rax, -0x560(%rbp)
jmp 0xc500
movq -0x560(%rbp), %rdi
movq 0x4faa2(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0xc515
jmp 0xc534
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x3b8(%rbp), %rdi
callq 0x5290
jmp 0xc5e9
leaq -0x3b8(%rbp), %rdi
callq 0x5290
jmp 0xc598
movq -0x3c8(%rbp), %rax
movq 0x90(%rax), %rdi
leaq 0x3b2db(%rip), %rsi     # 0x47832
callq 0x53e0
movq %rax, -0x568(%rbp)
jmp 0xc565
movq -0x568(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x53c0
movq %rax, -0x570(%rbp)
jmp 0xc581
movq -0x570(%rbp), %rdi
movq 0x4fa21(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0xc596
jmp 0xc598
jmp 0xc59a
jmp 0xc59c
jmp 0xc59e
jmp 0xc5a0
jmp 0xc5a2
jmp 0xc5a4
jmp 0xc5a6
movq -0x3c8(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0xd240
jmp 0xc5bb
jmp 0xc5bf
jmp 0xc5bf
jmp 0xbacf
leaq -0x268(%rbp), %rdi
callq 0x5290
leaq -0x248(%rbp), %rdi
callq 0x5120
movb $0x1, %al
andb $0x1, %al
addq $0x570, %rsp            # imm = 0x570
popq %rbp
retq
leaq -0x268(%rbp), %rdi
callq 0x5290
leaq -0x248(%rbp), %rdi
callq 0x5120
movq -0x38(%rbp), %rdi
callq 0x5720
nopw (%rax,%rax)