// File: /workspace/github_c_makefile_star2_O3/adelciotto[P]plasma/src/gl_rgb_plasma.c
// Function: InitGL
int InitGL(void) {
    gProgramId = glCreateProgram();

    GLuint vertexShader;
    char *vertexShaderSource = ReadFile(VERTEX_SHADER_PATH);
    if (vertexShaderSource == NULL) {
        LogError("could not read file %s", VERTEX_SHADER_PATH);
    }
    if (compileShader(GL_VERTEX_SHADER, (const char **)&vertexShaderSource,
                      &vertexShader) != GL_TRUE) {
        LogShaderError(vertexShader);
        return -1;
    }

    GLuint fragmentShader;
    char *fragmentShaderSource = ReadFile(FRAGMENT_SHADER_PATH);
    if (fragmentShaderSource == NULL) {
        LogError("could not read file %s", FRAGMENT_SHADER_PATH);
    }
    if (compileShader(GL_FRAGMENT_SHADER, (const char **)&fragmentShaderSource,
                      &fragmentShader) != GL_TRUE) {
        LogShaderError(fragmentShader);
        return -1;
    }

    free(fragmentShaderSource);
    free(vertexShaderSource);

    glAttachShader(gProgramId, vertexShader);
    glAttachShader(gProgramId, fragmentShader);

    glLinkProgram(gProgramId);
    GLint programSuccess = GL_TRUE;
    glGetProgramiv(gProgramId, GL_LINK_STATUS, &programSuccess);
    if (programSuccess != GL_TRUE) {
        LogProgramError(gProgramId);
        return -1;
    }

    glDeleteShader(fragmentShader);
    glDeleteShader(vertexShader);

    gUniformTimeLocation = glGetUniformLocation(gProgramId, "uTime");
    if (gUniformTimeLocation == -1) {
        LogError("could not get uniform location for uTime");
        return -1;
    }
    gUniformScaleLocation = glGetUniformLocation(gProgramId, "uScale");
    if (gUniformScaleLocation == -1) {
        LogError("could not get uniform location for uScale");
        return -1;
    }
    gUniformResolutionLocation =
        glGetUniformLocation(gProgramId, "uResolution");
    if (gUniformResolutionLocation == -1) {
        LogError("could not get uniform location for uResolution");
        return -1;
    }

    glViewport(0, 0, gWidth, gHeight);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    GLfloat vertexData[] = {-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f};
    GLuint elements[] = {0, 1, 2, 2, 3, 0};

    glGenVertexArrays(1, &gVAO);
    glBindVertexArray(gVAO);

    glGenBuffers(1, &gVBO);
    glBindBuffer(GL_ARRAY_BUFFER, gVBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData,
                 GL_STATIC_DRAW);

    glGenBuffers(1, &gEBO);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gEBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements,
                 GL_STATIC_DRAW);

    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),
                          (void *)0);
    glEnableVertexAttribArray(0);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq 0x36b9(%rip), %rax      # 0x5f40
callq *(%rax)
movl %eax, 0x38f1(%rip)      # 0x6180
leaq 0x190c(%rip), %rdi      # 0x41a2
callq 0x277c
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x28bc
leaq 0x1915(%rip), %rsi      # 0x41c1
leaq 0x18ef(%rip), %rdx      # 0x41a2
xorl %edi, %edi
xorl %eax, %eax
callq 0x2250
movq 0x3715(%rip), %r12      # 0x5fd8
movl $0x8b31, %edi           # imm = 0x8B31
callq *(%r12)
movl %eax, %ebx
movq 0x36e3(%rip), %rbp      # 0x5fb8
leaq 0x10(%rsp), %rdx
movl %eax, %edi
movl $0x1, %esi
xorl %ecx, %ecx
callq *(%rbp)
movq 0x368b(%rip), %r15      # 0x5f78
movl %ebx, %edi
callq *(%r15)
leaq 0x20(%rsp), %r14
movl $0x0, (%r14)
movq 0x3643(%rip), %r13      # 0x5f48
movl %ebx, %edi
movl $0x8b81, %esi           # imm = 0x8B81
movq %r14, %rdx
callq *(%r13)
cmpl $0x1, (%r14)
jne 0x2ba0
movq %rbp, %r14
leaq 0x18b1(%rip), %rdi      # 0x41d8
callq 0x277c
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x294d
leaq 0x1884(%rip), %rsi      # 0x41c1
leaq 0x1894(%rip), %rdx      # 0x41d8
xorl %edi, %edi
xorl %eax, %eax
callq 0x2250
movl $0x8b30, %edi           # imm = 0x8B30
callq *(%r12)
movl %eax, %ebp
leaq 0x8(%rsp), %rdx
movl %eax, %edi
movl $0x1, %esi
xorl %ecx, %ecx
callq *(%r14)
movl %ebp, %edi
callq *(%r15)
leaq 0x20(%rsp), %r14
movl $0x0, (%r14)
movl %ebp, %edi
movl $0x8b81, %esi           # imm = 0x8B81
movq %r14, %rdx
callq *(%r13)
cmpl $0x1, (%r14)
jne 0x2ba4
movq 0x8(%rsp), %rdi
callq 0x2070
movq 0x10(%rsp), %rdi
callq 0x2070
movq 0x35eb(%rip), %r14      # 0x5f98
movl 0x37cd(%rip), %edi      # 0x6180
movl %ebx, %esi
callq *(%r14)
movl 0x37c2(%rip), %edi      # 0x6180
movl %ebp, %esi
callq *(%r14)
movq 0x35de(%rip), %rax      # 0x5fa8
movl 0x37b0(%rip), %edi      # 0x6180
callq *(%rax)
leaq 0x1c(%rsp), %r14
movl $0x1, (%r14)
movq 0x3533(%rip), %rax      # 0x5f18
movl 0x3795(%rip), %edi      # 0x6180
movl $0x8b82, %esi           # imm = 0x8B82
movq %r14, %rdx
callq *(%rax)
cmpl $0x1, (%r14)
jne 0x2bc1
movq 0x35ba(%rip), %r14      # 0x5fc0
movl %ebp, %edi
callq *(%r14)
movl %ebx, %edi
callq *(%r14)
movq 0x34d9(%rip), %rbx      # 0x5ef0
movl 0x3763(%rip), %edi      # 0x6180
leaq 0x17f6(%rip), %rsi      # 0x421a
callq *(%rbx)
movl %eax, 0x3724(%rip)      # 0x6150
cmpl $-0x1, %eax
je 0x2bce
movl 0x3745(%rip), %edi      # 0x6180
leaq 0x1801(%rip), %rsi      # 0x4243
callq *(%rbx)
movl %eax, 0x370e(%rip)      # 0x6158
cmpl $-0x1, %eax
je 0x2bd7
movl 0x3727(%rip), %edi      # 0x6180
leaq 0x180d(%rip), %rsi      # 0x426d
callq *(%rbx)
movl %eax, 0x36ec(%rip)      # 0x6154
cmpl $-0x1, %eax
je 0x2be0
movl 0x36e5(%rip), %edx      # 0x615c
movl 0x36e3(%rip), %ecx      # 0x6160
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
callq 0x20f0
movss 0x15b0(%rip), %xmm3     # 0x4040
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
callq 0x2050
movaps 0x190b(%rip), %xmm0     # 0x43b0
leaq 0x20(%rsp), %r15
movaps %xmm0, 0x10(%r15)
movaps 0x18ea(%rip), %xmm0     # 0x43a0
movaps %xmm0, (%r15)
movaps 0x18ff(%rip), %xmm0     # 0x43c0
leaq 0x40(%rsp), %r14
movaps %xmm0, (%r14)
movq $0x3, 0x10(%r14)
movq 0x34c7(%rip), %rax      # 0x5fa0
leaq 0x36a4(%rip), %rsi      # 0x6184
movl $0x1, %edi
callq *(%rax)
movq 0x34fa(%rip), %rax      # 0x5fe8
movl 0x3690(%rip), %edi      # 0x6184
callq *(%rax)
movq 0x342b(%rip), %r12      # 0x5f28
leaq 0x3684(%rip), %rsi      # 0x6188
movl $0x1, %edi
callq *(%r12)
movq 0x33d4(%rip), %r13      # 0x5ee8
movl 0x366e(%rip), %esi      # 0x6188
movl $0x8892, %edi           # imm = 0x8892
callq *(%r13)
movq 0x33f6(%rip), %rbp      # 0x5f20
movl $0x20, %esi
movl $0x8892, %edi           # imm = 0x8892
movq %r15, %rdx
movl $0x88e4, %ecx           # imm = 0x88E4
callq *(%rbp)
leaq 0x3646(%rip), %rsi      # 0x618c
movl $0x1, %edi
callq *(%r12)
movl 0x3637(%rip), %esi      # 0x618c
movl $0x8893, %edi           # imm = 0x8893
callq *(%r13)
movl $0x18, %esi
movl $0x8893, %edi           # imm = 0x8893
movq %r14, %rdx
movl $0x88e4, %ecx           # imm = 0x88E4
callq *(%rbp)
movq 0x3466(%rip), %rax      # 0x5fe0
xorl %edi, %edi
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x8, %r8d
xorl %r9d, %r9d
callq *(%rax)
movq 0x3436(%rip), %rax      # 0x5fd0
xorl %edi, %edi
callq *(%rax)
jmp 0x2bb0
movl %ebx, %edi
jmp 0x2ba6
movl %ebp, %edi
callq 0x25f2
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x35b9(%rip), %edi      # 0x6180
callq 0x26b7
jmp 0x2bab
leaq 0x1622(%rip), %rsi      # 0x41f7
jmp 0x2be7
leaq 0x1642(%rip), %rsi      # 0x4220
jmp 0x2be7
leaq 0x1663(%rip), %rsi      # 0x424a
xorl %edi, %edi
xorl %eax, %eax
callq 0x2250
jmp 0x2bab