// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movq 0x2747(%rip), %rax      # 0x4f40
callq *(%rax)
movl %eax, 0x297f(%rip)      # 0x5180
leaq 0x99a(%rip), %rdi       # 0x31a2
callq 0x26f7
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x282e
leaq 0x9a3(%rip), %rsi       # 0x31c1
leaq 0x97d(%rip), %rdx       # 0x31a2
xorl %edi, %edi
xorl %eax, %eax
callq 0x2250
leaq 0x10(%rsp), %rsi
leaq 0x4(%rsp), %rdx
movl $0x8b31, %edi           # imm = 0x8B31
callq 0x2781
testb %al, %al
je 0x2a99
leaq 0x987(%rip), %rdi       # 0x31d8
callq 0x26f7
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x2877
leaq 0x95a(%rip), %rsi       # 0x31c1
leaq 0x96a(%rip), %rdx       # 0x31d8
xorl %edi, %edi
xorl %eax, %eax
callq 0x2250
leaq 0x8(%rsp), %rsi
movq %rsp, %rdx
movl $0x8b30, %edi           # imm = 0x8B30
callq 0x2781
testb %al, %al
je 0x2a9f
movq 0x8(%rsp), %rdi
callq 0x2070
movq 0x10(%rsp), %rdi
callq 0x2070
movq 0x26ec(%rip), %r14      # 0x4f98
movl 0x28ce(%rip), %edi      # 0x5180
movl 0x4(%rsp), %ebx
movl %ebx, %esi
callq *(%r14)
movl 0x28bf(%rip), %edi      # 0x5180
movl (%rsp), %ebp
movl %ebp, %esi
callq *(%r14)
movq 0x26d8(%rip), %rax      # 0x4fa8
movl 0x28aa(%rip), %edi      # 0x5180
callq *(%rax)
leaq 0x1c(%rsp), %r14
movl $0x1, (%r14)
movq 0x262d(%rip), %rax      # 0x4f18
movl 0x288f(%rip), %edi      # 0x5180
movl $0x8b82, %esi           # imm = 0x8B82
movq %r14, %rdx
callq *(%rax)
cmpl $0x1, (%r14)
jne 0x2aa9
movq 0x26b4(%rip), %r14      # 0x4fc0
movl %ebp, %edi
callq *(%r14)
movl %ebx, %edi
callq *(%r14)
movq 0x25d3(%rip), %rbx      # 0x4ef0
movl 0x285d(%rip), %edi      # 0x5180
leaq 0x8f0(%rip), %rsi       # 0x321a
callq *(%rbx)
movl %eax, 0x281e(%rip)      # 0x5150
cmpl $-0x1, %eax
je 0x2ab6
movl 0x283f(%rip), %edi      # 0x5180
leaq 0x8fb(%rip), %rsi       # 0x3243
callq *(%rbx)
movl %eax, 0x2808(%rip)      # 0x5158
cmpl $-0x1, %eax
je 0x2abf
movl 0x2821(%rip), %edi      # 0x5180
leaq 0x907(%rip), %rsi       # 0x326d
callq *(%rbx)
movl %eax, 0x27e6(%rip)      # 0x5154
cmpl $-0x1, %eax
je 0x2ac8
movl 0x27df(%rip), %edx      # 0x515c
movl 0x27dd(%rip), %ecx      # 0x5160
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
callq 0x20f0
movss 0x6aa(%rip), %xmm3      # 0x3040
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
callq 0x2050
movaps 0xa05(%rip), %xmm0      # 0x33b0
leaq 0x40(%rsp), %r15
movaps %xmm0, 0x10(%r15)
movaps 0x9e4(%rip), %xmm0      # 0x33a0
movaps %xmm0, (%r15)
movaps 0x9f9(%rip), %xmm0      # 0x33c0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
movq $0x3, 0x10(%rax)
movq 0x25c2(%rip), %rax      # 0x4fa0
leaq 0x279f(%rip), %rsi      # 0x5184
pushq $0x1
popq %rbp
movl %ebp, %edi
callq *(%rax)
movq 0x25f5(%rip), %rax      # 0x4fe8
movl 0x278b(%rip), %edi      # 0x5184
callq *(%rax)
movq 0x2526(%rip), %r12      # 0x4f28
leaq 0x277f(%rip), %rsi      # 0x5188
movl %ebp, %edi
callq *(%r12)
movq 0x24d2(%rip), %r13      # 0x4ee8
movl 0x276c(%rip), %esi      # 0x5188
movl $0x8892, %edi           # imm = 0x8892
callq *(%r13)
movq 0x24f4(%rip), %r14      # 0x4f20
pushq $0x20
popq %rsi
movl $0x8892, %edi           # imm = 0x8892
movq %r15, %rdx
movl $0x88e4, %ecx           # imm = 0x88E4
callq *(%r14)
leaq 0x2746(%rip), %rsi      # 0x518c
movl %ebp, %edi
callq *(%r12)
movl 0x273a(%rip), %esi      # 0x518c
movl $0x8893, %edi           # imm = 0x8893
callq *(%r13)
pushq $0x18
popq %rsi
movl $0x8893, %edi           # imm = 0x8893
leaq 0x20(%rsp), %rdx
movl $0x88e4, %ecx           # imm = 0x88E4
callq *(%r14)
movq 0x2569(%rip), %rax      # 0x4fe0
pushq $0x2
popq %rsi
pushq $0x8
popq %r8
xorl %edi, %edi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
xorl %r9d, %r9d
callq *(%rax)
movq 0x253d(%rip), %rax      # 0x4fd0
xorl %edi, %edi
callq *(%rax)
jmp 0x2adb
movl 0x4(%rsp), %edi
jmp 0x2aa2
movl (%rsp), %edi
callq 0x256d
jmp 0x2ad8
movl 0x26d1(%rip), %edi      # 0x5180
callq 0x2632
jmp 0x2ad8
leaq 0x73a(%rip), %rsi       # 0x31f7
jmp 0x2acf
leaq 0x75a(%rip), %rsi       # 0x3220
jmp 0x2acf
leaq 0x77b(%rip), %rsi       # 0x324a
xorl %edi, %edi
xorl %eax, %eax
callq 0x2250
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq