// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/hlrad/qrad.cpp
// Function: ReadLightFile(char const*)
static void     ReadLightFile(const char* const filename)
{
    FILE*           f;
    char            scan[MAXTOKEN];
    short           argCnt;
    unsigned int    file_texlights = 0;

    f = fopen(filename, "r");
    if (!f)
    {
        Warning("Could not open texlight file %s", filename);
        return;
    }
    else
    {
#ifdef HLRAD_CUSTOMTEXLIGHT
		Log("Reading texlights from '%s'\n", filename);
#else
        Log("[Reading texlights from '%s']\n", filename);
#endif
    }

    while (fgets(scan, sizeof(scan), f))
    {
        char*           comment;
        char            szTexlight[_MAX_PATH];
        vec_t           r, g, b, i = 1;

        comment = strstr(scan, "//");
        if (comment)
        {
            // Newline and Null terminate the string early if there is a c++ style single line comment
            comment[0] = '\n';
            comment[1] = 0;
        }

        argCnt = sscanf(scan, "%s %f %f %f %f", szTexlight, &r, &g, &b, &i);

        if (argCnt == 2)
        {
            // With 1+1 args, the R,G,B values are all equal to the first value
            g = b = r;
        }
        else if (argCnt == 5)
        {
            // With 1+4 args, the R,G,B values are "scaled" by the fourth numeric value i;
            r *= i / 255.0;
            g *= i / 255.0;
            b *= i / 255.0;
        }
        else if (argCnt != 4)
        {
            if (strlen(scan) > 4)
            {
                Warning("ignoring bad texlight '%s' in %s", scan, filename);
            }
            continue;
        }

        texlight_i it;
        for (it = s_texlights.begin(); it != s_texlights.end(); it++)
        {
            if (strcmp(it->name.c_str(), szTexlight) == 0)
            {
                if (strcmp(it->filename, filename) == 0)
                {
                    Warning("Duplication of texlight '%s' in file '%s'!", it->name.c_str(), it->filename);
                }
                else if (it->value[0] != r || it->value[1] != g || it->value[2] != b)
                {
                    Warning("Overriding '%s' from '%s' with '%s'!", it->name.c_str(), it->filename, filename);
                }
                else
                {
                    Warning("Redundant '%s' def in '%s' AND '%s'!", it->name.c_str(), it->filename, filename);
                }
                s_texlights.erase(it);
                break;
            }
        }

        texlight_t      texlight;
        texlight.name = szTexlight;
        texlight.value[0] = r;
        texlight.value[1] = g;
        texlight.value[2] = b;
        texlight.filename = filename;
        file_texlights++;
        s_texlights.push_back(texlight);
    }
	fclose (f); //--vluzacn
#ifndef HLRAD_CUSTOMTEXLIGHT
    Log("[%u texlights parsed from '%s']\n\n", file_texlights, filename);
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2068, %rsp           # imm = 0x2068
movq %rdi, %rbx
leaq 0x10760(%rip), %rsi     # 0x35038
callq 0x4370
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x24b62
leaq 0x13135(%rip), %rdi     # 0x37a27
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8790
leaq 0x60(%rsp), %r15
leaq 0x1060(%rsp), %rbp
leaq 0x28(%rsp), %r14
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq 0x20(%rsp), %rdx
callq 0x4540
testq %rax, %rax
je 0x24b46
movl $0x3f800000, 0x1c(%rsp) # imm = 0x3F800000
movq %r15, %rdi
leaq 0x13109(%rip), %rsi     # 0x37a44
callq 0x40c0
testq %rax, %rax
je 0x2494a
movw $0xa, (%rax)
leaq 0x1c(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
leaq 0x130ea(%rip), %rsi     # 0x37a47
movq %rbp, %rdx
leaq 0x18(%rsp), %rcx
leaq 0x14(%rsp), %r8
leaq 0x10(%rsp), %r9
xorl %eax, %eax
callq 0x42c0
cmpw $0x5, %ax
je 0x249a1
movzwl %ax, %eax
cmpl $0x4, %eax
je 0x249eb
cmpl $0x2, %eax
jne 0x24a7f
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x10(%rsp)
movss %xmm0, 0x14(%rsp)
jmp 0x249eb
cvtss2sd 0x1c(%rsp), %xmm0
divsd 0x121f9(%rip), %xmm0    # 0x36ba8
cvtss2sd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd 0x14(%rsp), %xmm2
mulsd %xmm0, %xmm2
cvtsd2ss %xmm2, %xmm2
movss %xmm1, 0x18(%rsp)
movss %xmm2, 0x14(%rsp)
cvtss2sd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x10(%rsp)
movq %r14, %r15
movq 0x551217b(%rip), %r12   # 0x5536b70
movq 0x551217c(%rip), %r13   # 0x5536b78
cmpq %r13, %r12
je 0x24acd
movq (%r12), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4460
testl %eax, %eax
je 0x24a1e
addq $0x38, %r12
jmp 0x249fc
movq 0x30(%r12), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4460
testl %eax, %eax
je 0x24aaa
movss 0x20(%r12), %xmm0
ucomiss 0x18(%rsp), %xmm0
jne 0x24a66
jp 0x24a66
movss 0x24(%r12), %xmm0
ucomiss 0x14(%rsp), %xmm0
jne 0x24a66
jp 0x24a66
movss 0x28(%r12), %xmm0
ucomiss 0x10(%rsp), %xmm0
jne 0x24a66
jnp 0x24b3a
leaq 0x13035(%rip), %rdi     # 0x37aa2
movq %r14, %rsi
movq %r13, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x8ea5
jmp 0x24abe
movq %r15, %rdi
callq 0x4150
cmpq $0x5, %rax
jb 0x2490e
leaq 0x12fbe(%rip), %rdi     # 0x37a56
movq %r15, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x8ea5
jmp 0x2490e
leaq 0x12fc6(%rip), %rdi     # 0x37a77
movq %r14, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x8ea5
leaq 0x55120ab(%rip), %rdi   # 0x5536b70
movq %r12, %rsi
callq 0x2b02a
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
movq %r15, %r14
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4620
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x48(%rsp)
movss 0x14(%rsp), %xmm0
movss %xmm0, 0x4c(%rsp)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x50(%rsp)
movq %rbx, 0x58(%rsp)
leaq 0x5512050(%rip), %rdi   # 0x5536b70
movq %r14, %rsi
callq 0x2affe
movq %r14, %rdi
callq 0x4160
leaq 0x60(%rsp), %r15
jmp 0x2490e
leaq 0x12f86(%rip), %rdi     # 0x37ac7
jmp 0x24a6d
movq 0x20(%rsp), %rdi
callq 0x42d0
addq $0x2068, %rsp           # imm = 0x2068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12e9e(%rip), %rdi     # 0x37a07
movq %rbx, %rsi
xorl %eax, %eax
addq $0x2068, %rsp           # imm = 0x2068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ea5
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4160
movq %rbx, %rdi
callq 0x45a0