// File: /workspace/github_c_makefile_star2_O3/vlenhart[P]q3bsp/q3shader.cpp
// Function: QuakeShaderFactory::AddShader(StringRef const&)
bool  QuakeShaderFactory::AddShader(const StringRef &sname)
{

  mBraceCount = 0;
  mCurrent    = 0;

  mCurrentStage = 0;

  char filename[1024];
  sprintf(filename, "scripts/%s", sname.Get());
  Fload shader(filename);

  if (!shader.GetData()) {
    printf("***********SHADER FILE NOT FOUND in scripts/ : %s \n",sname.c_str());
    return false;
  }

  // TODO (vlaube): should we use the full filename here?
  mShaderFiles[sname] = true; 

  printf("***********SHADER FILE PROCESS : %s \n",sname.c_str());

  while ( 1 )
  {

    char *str = shader.GetString();

    if ( !str ) break;

    ShaderString(str); // process one string.
  }

  delete mCurrent;
  mCurrent = 0;
  delete mCurrentStage;
  mCurrentStage = 0;
  return true;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x450, %rsp            # imm = 0x450
movq %rsi, %r14
movq %rdi, %rbx
movl $0x0, 0x18(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movq (%rsi), %rdx
leaq 0x6f4d(%rip), %rsi      # 0x13595
leaq -0x470(%rbp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x2080
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
movq %r15, %rdi
callq 0x2120
leaq (%rax,%rbp), %rdx
addq $-0x470, %rdx           # imm = 0xFB90
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x6d58
leaq -0x68(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x7b2c
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0xc6a3
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x2230
movq -0x60(%rbp), %r15
testq %r15, %r15
je 0xc7c9
leaq 0x60(%rbx), %rdi
movq %r14, %rsi
callq 0xd978
leaq 0x20(%rbx), %r12
movb $0x1, (%rax)
movq (%r14), %rsi
leaq 0x6f07(%rip), %rdi      # 0x135d4
xorl %eax, %eax
callq 0x2050
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x7c32
testq %rax, %rax
je 0xc6f2
movq %rbx, %rdi
movq %rax, %rsi
callq 0xc9b8
jmp 0xc6d8
movq (%r12), %r14
testq %r14, %r14
je 0xc731
leaq 0x50(%r14), %rdi
callq 0xdcac
movq 0x38(%r14), %rdi
testq %rdi, %rdi
je 0xc719
movq 0x48(%r14), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x10(%r14), %rdi
leaq 0x20(%r14), %rax
cmpq %rax, %rdi
je 0xc731
movq (%rax), %rsi
incq %rsi
callq 0x2230
movl $0x68, %esi
movq %r14, %rdi
callq 0x2230
movq $0x0, 0x20(%rbx)
movq 0x28(%rbx), %r14
testq %r14, %r14
je 0xc7b2
movq 0x88(%r14), %rdi
leaq 0x98(%r14), %rax
cmpq %rax, %rdi
je 0xc76d
movq (%rax), %rsi
incq %rsi
callq 0x2230
movq 0x68(%r14), %rdi
leaq 0x78(%r14), %rax
cmpq %rax, %rdi
je 0xc785
movq (%rax), %rsi
incq %rsi
callq 0x2230
movq 0x48(%r14), %rdi
leaq 0x58(%r14), %rax
cmpq %rax, %rdi
je 0xc79d
movq (%rax), %rsi
incq %rsi
callq 0x2230
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0xc7b2
movq 0x18(%r14), %rsi
subq %rdi, %rsi
callq 0x2230
movl $0xb8, %esi
movq %r14, %rdi
callq 0x2230
movq $0x0, 0x28(%rbx)
jmp 0xc7da
movq (%r14), %rsi
leaq 0x6dcd(%rip), %rdi      # 0x135a0
xorl %eax, %eax
callq 0x2050
testq %r15, %r15
setne %bl
leaq -0x68(%rbp), %rdi
callq 0x7c1e
movl %ebx, %eax
addq $0x450, %rsp            # imm = 0x450
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc81c
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0xc828
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x2230
jmp 0xc828
movq %rax, %rbx
jmp 0xc828
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x7c1e
movq %rbx, %rdi
callq 0x23c0