// File: /workspace/github_c_makefile_star2_O1/FredTheDino[P]Fog/src/engine/renderer/opengl_renderer.cpp
// Function: Renderer::Impl::compile_shader_program_from_source(char const*)
static Program compile_shader_program_from_source(const char *source) {
#define SHADER_ERROR_CHECK(SHDR)                             \
    do {                                                     \
        GLint success = 0;                                   \
        glGetShaderiv(SHDR, GL_COMPILE_STATUS, &success);    \
        if (success == GL_FALSE) {                           \
            char buffer[512];                                \
            glGetShaderInfoLog(SHDR, 500, NULL, &buffer[0]); \
            ERR("%s: %s\n", "\"" #SHDR "\"", buffer);        \
            glDeleteShader(frag);                            \
            glDeleteShader(vert);                            \
            return Program::invalid_prog();                         \
        }                                                    \
    } while (false);

    u32 frag = glCreateShader(GL_FRAGMENT_SHADER);
    u32 vert = glCreateShader(GL_VERTEX_SHADER);

    const char *complete_source[] = {
        "#version 330\n",
        "#define VERT\n",
        "struct Camera\n"
        "{\n"
        "    vec2  pos;\n"
        "    vec2  offset;\n"
        "    float zoom;\n"
        "    float aspect_ratio;\n"
        "};"
        "struct Window\n"
        "{\n"
        "    float width;\n"
        "    float height;\n"
        "    float aspect_ratio;\n"
        "};"
        "layout (std140) uniform Global\n"
        "{\n"
        "   Camera cam[" STR(OPENGL_NUM_CAMERAS) "];\n"
        "   Window win;\n"
        "};\n"
        "uniform uint current_cam;\n"
        ,
        source};
    glShaderSource(vert, LEN(complete_source), complete_source, NULL);
    glCompileShader(vert);
    SHADER_ERROR_CHECK(vert);

    complete_source[1] = "#define FRAG\n";
    glShaderSource(frag, LEN(complete_source), complete_source, NULL);
    glCompileShader(frag);
    SHADER_ERROR_CHECK(frag);

    Program shader = {(s32) glCreateProgram()};
    glAttachShader(shader.id, vert);
    glAttachShader(shader.id, frag);
    glLinkProgram(shader.id);

    glDeleteShader(frag);
    glDeleteShader(vert);

    GLint success = 0;
    glGetProgramiv(shader.id, GL_LINK_STATUS, &success);
    if (success == GL_FALSE) {
        char buffer[512];
        glGetProgramInfoLog(shader.id, 500, NULL, &buffer[0]);
        ERR("Program: %s\n", buffer);
        return Program::invalid_prog();
    }

    unsigned int block = glGetUniformBlockIndex(shader, "Camera");
    glUniformBlockBinding(shader, block, GLSL_GLOBAL_BLOCK);

    return shader;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdi, %r15
leaq 0x43b29(%rip), %rbx     # 0x64d28
movl $0x8b30, %edi           # imm = 0x8B30
callq *(%rbx)
movl %eax, %r14d
movl $0x8b31, %edi           # imm = 0x8B31
callq *(%rbx)
movl %eax, %ebx
leaq 0x243ef(%rip), %rax     # 0x45608
leaq -0x50(%rbp), %rdx
movq %rax, (%rdx)
leaq 0x243ef(%rip), %rax     # 0x45616
movq %rax, 0x8(%rdx)
leaq 0x243f2(%rip), %rax     # 0x45624
movq %rax, 0x10(%rdx)
movq %r15, 0x18(%rdx)
leaq 0x44647(%rip), %rax     # 0x65888
movl %ebx, %edi
movl $0x4, %esi
xorl %ecx, %ecx
callq *(%rax)
leaq 0x43a5d(%rip), %r12     # 0x64cb0
movl %ebx, %edi
callq *(%r12)
leaq -0x2c(%rbp), %r15
movl $0x0, (%r15)
leaq 0x43ed5(%rip), %r13     # 0x65140
movl %ebx, %edi
movl $0x8b81, %esi           # imm = 0x8B81
movq %r15, %rdx
callq *(%r13)
cmpl $0x0, (%r15)
je 0x21367
leaq 0x244d4(%rip), %rax     # 0x4575e
leaq -0x50(%rbp), %rdx
movq %rax, 0x8(%rdx)
movl %r14d, %edi
movl $0x4, %esi
xorl %ecx, %ecx
leaq 0x445e5(%rip), %rax     # 0x65888
callq *(%rax)
movl %r14d, %edi
callq *(%r12)
movl $0x0, (%r15)
movl %r14d, %edi
movl $0x8b81, %esi           # imm = 0x8B81
movq %r15, %rdx
callq *(%r13)
cmpl $0x0, (%r15)
je 0x213b7
leaq 0x43a4d(%rip), %rax     # 0x64d20
callq *(%rax)
movl %eax, %r15d
leaq 0x43771(%rip), %r12     # 0x64a50
movl %eax, %edi
movl %ebx, %esi
callq *(%r12)
movl %r15d, %edi
movl %r14d, %esi
callq *(%r12)
leaq 0x44058(%rip), %rax     # 0x65350
movl %r15d, %edi
callq *(%rax)
leaq 0x43a64(%rip), %r12     # 0x64d68
movl %r14d, %edi
callq *(%r12)
movl %ebx, %edi
callq *(%r12)
leaq -0x2c(%rbp), %rbx
movl $0x0, (%rbx)
leaq 0x43de6(%rip), %rax     # 0x65108
movl %r15d, %edi
movl $0x8b82, %esi           # imm = 0x8B82
movq %rbx, %rdx
callq *(%rax)
cmpl $0x0, (%rbx)
je 0x21442
leaq 0x43e89(%rip), %rax     # 0x651c8
xorl %ebx, %ebx
cmpl $-0x1, %r15d
setne %bl
leaq 0x24431(%rip), %rsi     # 0x45780
movl %ebx, %edi
callq *(%rax)
leaq 0x4480e(%rip), %rcx     # 0x65b68
movl %ebx, %edi
movl %eax, %esi
xorl %edx, %edx
callq *(%rcx)
jmp 0x2142d
leaq 0x43dc2(%rip), %rax     # 0x65130
leaq -0x250(%rbp), %r15
movl %ebx, %edi
movl $0x1f4, %esi            # imm = 0x1F4
xorl %edx, %edx
movq %r15, %rcx
callq *(%rax)
movq 0x2dc46(%rip), %rax     # 0x4efd0
movq (%rax), %rsi
leaq 0x243c3(%rip), %r10     # 0x45757
leaq 0xf914(%rip), %rdi      # 0x30caf
leaq 0xfce3(%rip), %rdx      # 0x31085
leaq 0x24383(%rip), %r8      # 0x4572c
leaq 0x2439f(%rip), %r9      # 0x4574f
movl $0x34, %ecx
jmp 0x21406
leaq 0x43d72(%rip), %rax     # 0x65130
leaq -0x250(%rbp), %r15
movl %r14d, %edi
movl $0x1f4, %esi            # imm = 0x1F4
xorl %edx, %edx
movq %r15, %rcx
callq *(%rax)
movq 0x2dbf5(%rip), %rax     # 0x4efd0
movq (%rax), %rsi
leaq 0x24387(%rip), %r10     # 0x4576c
leaq 0xf8c3(%rip), %rdi      # 0x30caf
leaq 0xfc92(%rip), %rdx      # 0x31085
leaq 0x24332(%rip), %r8      # 0x4572c
leaq 0x2434e(%rip), %r9      # 0x4574f
movl $0x39, %ecx
xorl %eax, %eax
pushq %r15
pushq %r10
callq 0x711f
addq $0x10, %rsp
leaq 0x4394c(%rip), %r15     # 0x64d68
movl %r14d, %edi
callq *(%r15)
movl %ebx, %edi
callq *(%r15)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x43cb7(%rip), %rax     # 0x65100
leaq -0x250(%rbp), %rbx
movl %r15d, %edi
movl $0x1f4, %esi            # imm = 0x1F4
xorl %edx, %edx
movq %rbx, %rcx
callq *(%rax)
movq 0x2db6a(%rip), %rax     # 0x4efd0
movq (%rax), %rsi
subq $0x8, %rsp
leaq 0xf83b(%rip), %rdi      # 0x30caf
leaq 0xfc0a(%rip), %rdx      # 0x31085
leaq 0x242aa(%rip), %r8      # 0x4572c
leaq 0x242ea(%rip), %r9      # 0x45773
movl $0x48, %ecx
xorl %eax, %eax
pushq %rbx
callq 0x711f
addq $0x10, %rsp
jmp 0x21427