// File: srajangarg[P]raytracer/src/core/SceneLoader.cpp
// Function: SceneLoader::doMaterial(std::istream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool SceneLoader::doMaterial(istream & str, string & name)
{
  name = getString(str);

  if (name.empty())
  {
    *err << "Couldn't read material name at ";
    errLine(str.tellg());
    return false;
  }

  if (materials[name] != NULL)
  {
    *err << "Illegal re-use of name \"" << name << "\" at ";
    errLine(str.tellg());
    return false;
  }

  map<string, int> indices;
  indices["ma"] = MAT_MA;
  indices["ml"] = MAT_MD;
  indices["ms"] = MAT_MS;
  indices["msp"] = MAT_MSP;
  indices["msm"] = MAT_MSM;
  indices["mt"] = MAT_MT;
  indices["mtn"] = MAT_MTN;
  ParametricMaterial * n = new ParametricMaterial();
  materials[name] = n;

  do
  {
    int state = findOpenOrClosedParen(str);

    if (state == ERROR)
    {
      setMaterialDefaults(n);
      return false;
    }
    else if (state == CLOSED)
    {
      setMaterialDefaults(n);
      return true;
    }
    else if (state == OPEN)
    {
      string cmd;
      vector<ParametricValue *> values;

      if (readCommand(str, cmd))
      {
        if (cmd == "color")
        {
          if (getValues(str, values) < 3)
          {
            *err << "Color with insufficent parameters at ";
            errLine(str.tellg());
          }
          else
          {
            cleanAfter(values, 3);
            n->RGB_ = new ParametricColor();

            for (int ci = 0; ci < 3; ci++)
              n->RGB_->color_[ci] = values[ci];
          }
        }
        else if (indices.find(cmd) != indices.end())
        {
          if (getValues(str, values) < 1)
          {
            *err << cmd << " with no parameters at ";
            errLine(str.tellg());
          }
          else
          {
            cleanAfter(values, 1);
            n->coefficients_[indices[cmd]] = values[0];
          }
        }
        else
        {
          *err << "Error: command " << cmd << " not recognized at ";
          errLine(str.tellg());
        }

        findCloseParen(str);
      }
    }
  }
  while (true);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x390, %rsp            # imm = 0x390
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rsi
movq %rsi, -0x250(%rbp)
movq -0x18(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0xcaa0
movq -0x20(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x54d0
leaq -0x40(%rbp), %rdi
callq 0x5290
movq -0x20(%rbp), %rdi
callq 0x5690
testb $0x1, %al
jne 0xefc4
jmp 0xf00f
movq -0x250(%rbp), %rax
movq 0x90(%rax), %rdi
leaq 0x38435(%rip), %rsi     # 0x4740e
callq 0x53e0
movq -0x18(%rbp), %rdi
callq 0x5700
movq %rax, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x12bc0
movq -0x250(%rbp), %rdi
movl %eax, %esi
callq 0xd8e0
movb $0x0, -0x1(%rbp)
jmp 0xfba5
movq -0x250(%rbp), %rdi
addq $0x48, %rdi
movq -0x20(%rbp), %rsi
callq 0x133b0
cmpq $0x0, (%rax)
je 0xf08f
movq -0x250(%rbp), %rax
movq 0x90(%rax), %rdi
leaq 0x383b7(%rip), %rsi     # 0x473f5
callq 0x53e0
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x53c0
movq %rax, %rdi
leaq 0x381a0(%rip), %rsi     # 0x471f9
callq 0x53e0
movq -0x18(%rbp), %rdi
callq 0x5700
movq %rax, -0x60(%rbp)
movq %rdx, -0x58(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x12bc0
movq -0x250(%rbp), %rdi
movl %eax, %esi
callq 0xd8e0
movb $0x0, -0x1(%rbp)
jmp 0xfba5
leaq -0x90(%rbp), %rdi
callq 0x13490
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x5730
movq -0x258(%rbp), %rdx
leaq 0x38372(%rip), %rsi     # 0x4742e
leaq -0xb0(%rbp), %rdi
callq 0x13590
jmp 0xf0ca
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x134b0
movq %rax, -0x260(%rbp)
jmp 0xf0e6
movq -0x260(%rbp), %rax
movl $0x0, (%rax)
leaq -0xb0(%rbp), %rdi
callq 0x5290
leaq -0xb1(%rbp), %rdi
callq 0x5460
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x5730
movq -0x268(%rbp), %rdx
leaq 0x38305(%rip), %rsi     # 0x47431
leaq -0xe8(%rbp), %rdi
callq 0x13590
jmp 0xf13a
leaq -0x90(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x134b0
movq %rax, -0x270(%rbp)
jmp 0xf156
movq -0x270(%rbp), %rax
movl $0x1, (%rax)
leaq -0xe8(%rbp), %rdi
callq 0x5290
leaq -0xe9(%rbp), %rdi
callq 0x5460
leaq -0x111(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x5730
movq -0x278(%rbp), %rdx
leaq 0x38298(%rip), %rsi     # 0x47434
leaq -0x110(%rbp), %rdi
callq 0x13590
jmp 0xf1aa
leaq -0x90(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x134b0
movq %rax, -0x280(%rbp)
jmp 0xf1c6
movq -0x280(%rbp), %rax
movl $0x2, (%rax)
leaq -0x110(%rbp), %rdi
callq 0x5290
leaq -0x111(%rbp), %rdi
callq 0x5460
leaq -0x139(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x5730
movq -0x288(%rbp), %rdx
leaq 0x3822b(%rip), %rsi     # 0x47437
leaq -0x138(%rbp), %rdi
callq 0x13590
jmp 0xf21a
leaq -0x90(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x134b0
movq %rax, -0x290(%rbp)
jmp 0xf236
movq -0x290(%rbp), %rax
movl $0x3, (%rax)
leaq -0x138(%rbp), %rdi
callq 0x5290
leaq -0x139(%rbp), %rdi
callq 0x5460
leaq -0x161(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x5730
movq -0x298(%rbp), %rdx
leaq 0x381bf(%rip), %rsi     # 0x4743b
leaq -0x160(%rbp), %rdi
callq 0x13590
jmp 0xf28a
leaq -0x90(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x134b0
movq %rax, -0x2a0(%rbp)
jmp 0xf2a6
movq -0x2a0(%rbp), %rax
movl $0x4, (%rax)
leaq -0x160(%rbp), %rdi
callq 0x5290
leaq -0x161(%rbp), %rdi
callq 0x5460
leaq -0x189(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x5730
movq -0x2a8(%rbp), %rdx
leaq 0x38153(%rip), %rsi     # 0x4743f
leaq -0x188(%rbp), %rdi
callq 0x13590
jmp 0xf2fa
leaq -0x90(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x134b0
movq %rax, -0x2b0(%rbp)
jmp 0xf316
movq -0x2b0(%rbp), %rax
movl $0x5, (%rax)
leaq -0x188(%rbp), %rdi
callq 0x5290
leaq -0x189(%rbp), %rdi
callq 0x5460
leaq -0x1b1(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x5730
movq -0x2b8(%rbp), %rdx
leaq 0x380e6(%rip), %rsi     # 0x47442
leaq -0x1b0(%rbp), %rdi
callq 0x13590
jmp 0xf36a
leaq -0x90(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x134b0
movq %rax, -0x2c0(%rbp)
jmp 0xf386
movq -0x2c0(%rbp), %rax
movl $0x6, (%rax)
leaq -0x1b0(%rbp), %rdi
callq 0x5290
leaq -0x1b1(%rbp), %rdi
callq 0x5460
movl $0x40, %edi
callq 0x5400
movq %rax, -0x2c8(%rbp)
jmp 0xf3be
movq -0x2c8(%rbp), %rdi
callq 0x13640
jmp 0xf3cc
movq -0x250(%rbp), %rdi
movq -0x2c8(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x1c0(%rbp), %rax
movq %rax, -0x2d8(%rbp)
addq $0x48, %rdi
movq -0x20(%rbp), %rsi
callq 0x133b0
movq %rax, -0x2d0(%rbp)
jmp 0xf405
movq -0x2d0(%rbp), %rax
movq -0x2d8(%rbp), %rcx
movq %rcx, (%rax)
movq -0x250(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xd050
movl %eax, -0x2dc(%rbp)
jmp 0xf42e
movl -0x2dc(%rbp), %eax
movl %eax, -0x1c4(%rbp)
cmpl $0x2, -0x1c4(%rbp)
jne 0xf683
movq -0x250(%rbp), %rdi
movq -0x1c0(%rbp), %rsi
callq 0xeda0
jmp 0xf45c
movb $0x0, -0x1(%rbp)
movl $0x1, -0x1c8(%rbp)
jmp 0xfb89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xf4a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x5290
leaq -0xb1(%rbp), %rdi
callq 0x5460
jmp 0xfb97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xf4e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x5290
leaq -0xe9(%rbp), %rdi
callq 0x5460
jmp 0xfb97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xf527
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x5290
leaq -0x111(%rbp), %rdi
callq 0x5460
jmp 0xfb97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xf56a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x5290
leaq -0x139(%rbp), %rdi
callq 0x5460
jmp 0xfb97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xf5ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x5290
leaq -0x161(%rbp), %rdi
callq 0x5460
jmp 0xfb97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xf5f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x5290
leaq -0x189(%rbp), %rdi
callq 0x5460
jmp 0xfb97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xf633
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x5290
leaq -0x1b1(%rbp), %rdi
callq 0x5460
jmp 0xfb97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xfb97
movq -0x2c8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
movl $0x40, %esi
callq 0x5410
jmp 0xfb97
cmpl $0x1, -0x1c4(%rbp)
jne 0xf6b4
movq -0x250(%rbp), %rdi
movq -0x1c0(%rbp), %rsi
callq 0xeda0
jmp 0xf6a1
movb $0x1, -0x1(%rbp)
movl $0x1, -0x1c8(%rbp)
jmp 0xfb89
cmpl $0x0, -0x1c4(%rbp)
jne 0xfb75
leaq -0x1e8(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x55a0
leaq -0x200(%rbp), %rdi
callq 0x13130
movq -0x250(%rbp), %rdi
movq -0x2e8(%rbp), %rdx
movq -0x18(%rbp), %rsi
callq 0xcdc0
movb %al, -0x2dd(%rbp)
jmp 0xf6ff
movb -0x2dd(%rbp), %al
testb $0x1, %al
jne 0xf70e
jmp 0xfb41
leaq 0x37c66(%rip), %rsi     # 0x4737b
leaq -0x1e8(%rbp), %rdi
callq 0x64f0
movb %al, -0x2e9(%rbp)
jmp 0xf729
movb -0x2e9(%rbp), %al
testb $0x1, %al
jne 0xf738
jmp 0xf8c7
movq -0x250(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x200(%rbp), %rdx
callq 0xd330
movl %eax, -0x2f0(%rbp)
jmp 0xf757
movl -0x2f0(%rbp), %eax
cmpl $0x3, %eax
jge 0xf7ff
movq -0x250(%rbp), %rax
movq 0x90(%rax), %rdi
leaq 0x37ccb(%rip), %rsi     # 0x47446
callq 0x53e0
jmp 0xf782
movq -0x18(%rbp), %rdi
callq 0x5700
movq %rdx, -0x300(%rbp)
movq %rax, -0x2f8(%rbp)
jmp 0xf79b
movq -0x300(%rbp), %rax
movq -0x2f8(%rbp), %rcx
movq %rcx, -0x210(%rbp)
movq %rax, -0x208(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x12bc0
movq %rax, -0x308(%rbp)
jmp 0xf7cc
movq -0x250(%rbp), %rdi
movq -0x308(%rbp), %rax
movl %eax, %esi
callq 0xd8e0
jmp 0xf7e3
jmp 0xf8c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0xfb5b
movq -0x250(%rbp), %rdi
leaq -0x200(%rbp), %rsi
movl $0x3, %edx
callq 0xd930
movl $0x18, %edi
callq 0x5400
movq %rax, -0x310(%rbp)
jmp 0xf82a
movq -0x310(%rbp), %rdi
callq 0x132f0
jmp 0xf838
movq -0x310(%rbp), %rcx
movq -0x1c0(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x214(%rbp)
cmpl $0x3, -0x214(%rbp)
jge 0xf8c0
movslq -0x214(%rbp), %rsi
leaq -0x200(%rbp), %rdi
callq 0x12fc0
movq (%rax), %rdx
movq -0x1c0(%rbp), %rax
movq (%rax), %rax
movslq -0x214(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x214(%rbp)
jmp 0xf853
movq -0x310(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
movl $0x18, %esi
callq 0x5410
jmp 0xfb5b
jmp 0xf8c2
jmp 0xfb2d
leaq -0x90(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x136c0
movq %rax, -0x318(%rbp)
jmp 0xf8e3
movq -0x318(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x136f0
movq %rax, -0x228(%rbp)
leaq -0x220(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x13690
testb $0x1, %al
jne 0xf920
jmp 0xfa74
movq -0x250(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x200(%rbp), %rdx
callq 0xd330
movl %eax, -0x31c(%rbp)
jmp 0xf93f
movl -0x31c(%rbp), %eax
cmpl $0x1, %eax
jge 0xf9ec
movq -0x250(%rbp), %rax
movq 0x90(%rax), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x53c0
movq %rax, -0x328(%rbp)
jmp 0xf971
movq -0x328(%rbp), %rdi
leaq 0x37a2b(%rip), %rsi     # 0x473aa
callq 0x53e0
jmp 0xf986
movq -0x18(%rbp), %rdi
callq 0x5700
movq %rdx, -0x338(%rbp)
movq %rax, -0x330(%rbp)
jmp 0xf99f
movq -0x338(%rbp), %rax
movq -0x330(%rbp), %rcx
movq %rcx, -0x238(%rbp)
movq %rax, -0x230(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x12bc0
movq %rax, -0x340(%rbp)
jmp 0xf9d0
movq -0x250(%rbp), %rdi
movq -0x340(%rbp), %rax
movl %eax, %esi
callq 0xd8e0
jmp 0xf9e7
jmp 0xfa6f
movq -0x250(%rbp), %rdi
leaq -0x200(%rbp), %rsi
movq %rsi, -0x360(%rbp)
movl $0x1, %edx
callq 0xd930
movq -0x360(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12fc0
movq (%rax), %rax
movq %rax, -0x358(%rbp)
movq -0x1c0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x350(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x13720
movq %rax, -0x348(%rbp)
jmp 0xfa53
movq -0x350(%rbp), %rax
movq -0x358(%rbp), %rdx
movq -0x348(%rbp), %rcx
movslq (%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0xfb2b
movq -0x250(%rbp), %rax
movq 0x90(%rax), %rdi
leaq 0x37939(%rip), %rsi     # 0x473c2
callq 0x53e0
movq %rax, -0x368(%rbp)
jmp 0xfa97
movq -0x368(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x53c0
movq %rax, -0x370(%rbp)
jmp 0xfab3
movq -0x370(%rbp), %rdi
leaq 0x37911(%rip), %rsi     # 0x473d2
callq 0x53e0
jmp 0xfac8
movq -0x18(%rbp), %rdi
callq 0x5700
movq %rdx, -0x380(%rbp)
movq %rax, -0x378(%rbp)
jmp 0xfae1
movq -0x380(%rbp), %rax
movq -0x378(%rbp), %rcx
movq %rcx, -0x248(%rbp)
movq %rax, -0x240(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x12bc0
movq %rax, -0x388(%rbp)
jmp 0xfb12
movq -0x250(%rbp), %rdi
movq -0x388(%rbp), %rax
movl %eax, %esi
callq 0xd8e0
jmp 0xfb29
jmp 0xfb2b
jmp 0xfb2d
movq -0x250(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xd240
jmp 0xfb3f
jmp 0xfb41
leaq -0x200(%rbp), %rdi
callq 0x13350
leaq -0x1e8(%rbp), %rdi
callq 0x5290
jmp 0xfb75
leaq -0x200(%rbp), %rdi
callq 0x13350
leaq -0x1e8(%rbp), %rdi
callq 0x5290
jmp 0xfb97
jmp 0xfb77
jmp 0xfb79
jmp 0xfb7b
movb $0x1, %al
testb $0x1, %al
jne 0xf416
jmp 0xfb87
ud2
leaq -0x90(%rbp), %rdi
callq 0x13800
jmp 0xfba5
leaq -0x90(%rbp), %rdi
callq 0x13800
jmp 0xfbb3
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x390, %rsp            # imm = 0x390
popq %rbp
retq
movq -0xc0(%rbp), %rdi
callq 0x5720
nop