// File: /workspace/github_c_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %rsi, %r14
movq %rdi, %rbx
movl $0x0, 0x18(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movq (%rsi), %rdx
leaq 0x6eaf(%rip), %rsi      # 0x135b9
leaq -0x470(%rbp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x2080
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
movq %r15, %rdi
callq 0x2120
leaq (%rax,%rbp), %rdx
addq $-0x470, %rdx           # imm = 0xFB90
leaq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x6d42
leaq -0x70(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x7b70
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0xc765
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
movq -0x68(%rbp), %r12
testq %r12, %r12
je 0xc891
leaq 0x60(%rbx), %rdi
movq %r14, %rsi
callq 0xda5e
leaq 0x20(%rbx), %r13
movb $0x1, (%rax)
movq (%r14), %rsi
leaq 0x6e69(%rip), %rdi      # 0x135f8
xorl %eax, %eax
callq 0x2050
leaq -0x70(%rbp), %r14
movq %r14, %rdi
callq 0x7c7c
movq %rax, %r15
testq %rax, %rax
je 0xc7ba
movq %rbx, %rdi
movq %r15, %rsi
callq 0xca80
testq %r15, %r15
jne 0xc79a
movq (%r13), %r14
testq %r14, %r14
je 0xc806
leaq 0x50(%r14), %rdi
callq 0xdd96
movq 0x38(%r14), %rdi
testq %rdi, %rdi
je 0xc7e1
movq 0x48(%r14), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x10(%r14), %rdi
leaq 0x20(%r14), %rax
cmpq %rax, %rdi
je 0xc7f9
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 0xc887
movq 0x88(%r14), %rdi
leaq 0x98(%r14), %rax
cmpq %rax, %rdi
je 0xc835
movq (%rax), %rsi
incq %rsi
callq 0x2230
movq 0x68(%r14), %rdi
leaq 0x78(%r14), %rax
cmpq %rax, %rdi
je 0xc84d
movq (%rax), %rsi
incq %rsi
callq 0x2230
movq 0x48(%r14), %rdi
leaq 0x58(%r14), %rax
cmpq %rax, %rdi
je 0xc865
movq (%rax), %rsi
incq %rsi
callq 0x2230
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0xc87a
movq 0x18(%r14), %rsi
subq %rdi, %rsi
callq 0x2230
movl $0xb8, %esi
movq %r14, %rdi
callq 0x2230
movq $0x0, 0x28(%rbx)
jmp 0xc8a2
movq (%r14), %rsi
leaq 0x6d29(%rip), %rdi      # 0x135c4
xorl %eax, %eax
callq 0x2050
testq %r12, %r12
setne %bl
leaq -0x70(%rbp), %rdi
callq 0x7c62
movl %ebx, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc8e6
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0xc8f2
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
jmp 0xc8f2
movq %rax, %rbx
jmp 0xc8f2
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x7c62
movq %rbx, %rdi
callq 0x23c0