// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x38(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x6e00
movq %r12, %rdi
movq %r15, %rsi
callq 0x43b0
movq %r15, %rdi
callq 0x4170
cmpq $0x0, 0x8(%r12)
je 0x80ea
leaq 0x48(%rbx), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x9b84
cmpq $0x0, (%rax)
je 0x8116
movq 0x90(%rbx), %rdi
leaq 0x19297(%rip), %rsi     # 0x21365
callq 0x4300
movq %rax, %rdi
movq %r12, %rsi
callq 0x42e0
leaq 0x19084(%rip), %rsi     # 0x21169
movq %rax, %rdi
jmp 0x80f8
movq 0x90(%rbx), %rdi
leaq 0x19286(%rip), %rsi     # 0x2137e
callq 0x4300
movq %r14, %rdi
callq 0x45a0
movq %rbx, %rdi
movl %eax, %esi
callq 0x76b4
xorl %ebx, %ebx
jmp 0x8491
leaq 0x40(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x19267(%rip), %rsi     # 0x2139e
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x9c50
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
callq 0x9bea
andl $0x0, (%rax)
movq %rsp, %rdi
callq 0x4170
leaq 0x1923e(%rip), %rsi     # 0x213a1
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x9c50
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
callq 0x9bea
movl $0x1, (%rax)
movq %rsp, %rdi
callq 0x4170
leaq 0x19212(%rip), %rsi     # 0x213a4
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x9c50
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
callq 0x9bea
movl $0x2, (%rax)
movq %rsp, %rdi
callq 0x4170
leaq 0x191e6(%rip), %rsi     # 0x213a7
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x9c50
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
callq 0x9bea
movl $0x3, (%rax)
movq %rsp, %rdi
callq 0x4170
leaq 0x191bb(%rip), %rsi     # 0x213ab
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x9c50
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
callq 0x9bea
movl $0x4, (%rax)
movq %rsp, %rdi
callq 0x4170
leaq 0x19190(%rip), %rsi     # 0x213af
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x9c50
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
callq 0x9bea
movl $0x5, (%rax)
movq %rsp, %rdi
callq 0x4170
leaq 0x19164(%rip), %rsi     # 0x213b2
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x9c50
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
callq 0x9bea
movl $0x6, (%rax)
movq %rsp, %rdi
callq 0x4170
pushq $0x40
popq %rdi
callq 0x4320
movq %rax, %r15
movq %rax, %rdi
callq 0x9c8c
movq %r13, %rdi
movq %r12, %rsi
callq 0x9b84
movq %r15, (%rax)
movq %rsp, %r12
leaq 0x20(%rsp), %rbp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x71d2
testl %eax, %eax
jne 0x846c
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
andq $0x0, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x7050
testb %al, %al
je 0x8457
movq %r12, %rdi
leaq 0x18ff7(%rip), %rsi     # 0x212eb
callq 0x4d52
testb %al, %al
je 0x833e
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x7388
cmpl $0x2, %eax
jg 0x839c
movq 0x90(%rbx), %rdi
leaq 0x19094(%rip), %rsi     # 0x213b6
callq 0x4300
movq %r14, %rdi
callq 0x45a0
movq %rbx, %rdi
movl %eax, %esi
callq 0x76b4
jmp 0x844f
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
callq 0xb8d6
leaq 0x40(%rsp), %rcx
cmpq %rcx, %rax
je 0x83de
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x7388
testl %eax, %eax
jle 0x841f
movq %rbp, %rsi
pushq $0x1
popq %rdx
callq 0x76d4
movq 0x20(%rsp), %rax
movq (%rax), %r13
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
callq 0x9ca4
movslq (%rax), %rax
movq %r13, 0x8(%r15,%rax,8)
jmp 0x844f
movq %rbp, %rsi
pushq $0x3
popq %rdx
callq 0x76d4
pushq $0x18
popq %rdi
callq 0x4320
movq %rax, %r13
movq %rax, %rdi
callq 0x9b70
movq %r13, (%r15)
xorl %eax, %eax
cmpq $0x3, %rax
je 0x844f
movq 0x20(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq (%r15), %rdx
movq %rcx, (%rdx,%rax,8)
incq %rax
jmp 0x83bf
movq 0x90(%rbx), %rdi
leaq 0x18f46(%rip), %rsi     # 0x21332
callq 0x4300
movq %rax, %rdi
movq %r12, %rsi
callq 0x42e0
movq %rax, %rdi
leaq 0x18f3c(%rip), %rsi     # 0x21342
callq 0x4300
movq %r14, %rdi
callq 0x45a0
movq %rbx, %rdi
movl %eax, %esi
callq 0x76b4
jmp 0x844f
movq 0x90(%rbx), %rdi
movq %r12, %rsi
callq 0x42e0
movq %rax, %rdi
leaq 0x18ee2(%rip), %rsi     # 0x2131a
callq 0x4300
movq %r14, %rdi
callq 0x45a0
movq %rbx, %rdi
movl %eax, %esi
callq 0x76b4
movq %r14, %rsi
callq 0x72de
movq %rbp, %rdi
callq 0xa7f0
movq %r12, %rdi
callq 0x4170
jmp 0x829f
cmpl $0x1, %eax
jne 0x847d
movb $0x1, %bl
movq %r15, %rsi
callq 0x7fb8
jmp 0x8487
movq %r15, %rsi
callq 0x7fb8
xorl %ebx, %ebx
leaq 0x38(%rsp), %rdi
callq 0xa6f6
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x84cd
jmp 0x84bc
jmp 0x84cd
jmp 0x84bc
jmp 0x84cd
jmp 0x84bc
jmp 0x84cd
jmp 0x84bc
jmp 0x84cd
jmp 0x84bc
jmp 0x84cd
jmp 0x84bc
jmp 0x84cd
movq %rax, %rbx
jmp 0x84df
jmp 0x84cd
jmp 0x84d2
jmp 0x84cd
jmp 0x84d2
jmp 0x84d2
jmp 0x84d2
movq %rax, %rbx
jmp 0x84e7
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xa7f0
movq %rsp, %rdi
callq 0x4170
leaq 0x38(%rsp), %rdi
callq 0xa6f6
movq %rbx, %rdi
callq 0x45c0
nop