// File: /workspace/github_c_makefile_star2_O1/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 0x36bd(%rip), %rax      # 0x5f40
callq *(%rax)
movl %eax, 0x38f5(%rip)      # 0x6180
leaq 0x1910(%rip), %rdi      # 0x41a2
callq 0x2778
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x28b8
leaq 0x1919(%rip), %rsi      # 0x41c1
leaq 0x18f3(%rip), %rdx      # 0x41a2
xorl %edi, %edi
xorl %eax, %eax
callq 0x2250
movq 0x3719(%rip), %r12      # 0x5fd8
movl $0x8b31, %edi           # imm = 0x8B31
callq *(%r12)
movl %eax, %ebx
movq 0x36e7(%rip), %rbp      # 0x5fb8
leaq 0x10(%rsp), %rdx
movl %eax, %edi
movl $0x1, %esi
xorl %ecx, %ecx
callq *(%rbp)
movq 0x368f(%rip), %r15      # 0x5f78
movl %ebx, %edi
callq *(%r15)
leaq 0x20(%rsp), %r14
movl $0x0, (%r14)
movq 0x3647(%rip), %r13      # 0x5f48
movl %ebx, %edi
movl $0x8b81, %esi           # imm = 0x8B81
movq %r14, %rdx
callq *(%r13)
cmpl $0x1, (%r14)
jne 0x2b9c
movq %rbp, %r14
leaq 0x18b5(%rip), %rdi      # 0x41d8
callq 0x2778
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x2949
leaq 0x1888(%rip), %rsi      # 0x41c1
leaq 0x1898(%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 0x2ba0
movq 0x8(%rsp), %rdi
callq 0x2070
movq 0x10(%rsp), %rdi
callq 0x2070
movq 0x35ef(%rip), %r14      # 0x5f98
movl 0x37d1(%rip), %edi      # 0x6180
movl %ebx, %esi
callq *(%r14)
movl 0x37c6(%rip), %edi      # 0x6180
movl %ebp, %esi
callq *(%r14)
movq 0x35e2(%rip), %rax      # 0x5fa8
movl 0x37b4(%rip), %edi      # 0x6180
callq *(%rax)
leaq 0x1c(%rsp), %r14
movl $0x1, (%r14)
movq 0x3537(%rip), %rax      # 0x5f18
movl 0x3799(%rip), %edi      # 0x6180
movl $0x8b82, %esi           # imm = 0x8B82
movq %r14, %rdx
callq *(%rax)
cmpl $0x1, (%r14)
jne 0x2bbd
movq 0x35be(%rip), %r14      # 0x5fc0
movl %ebp, %edi
callq *(%r14)
movl %ebx, %edi
callq *(%r14)
movq 0x34dd(%rip), %rbx      # 0x5ef0
movl 0x3767(%rip), %edi      # 0x6180
leaq 0x17fa(%rip), %rsi      # 0x421a
callq *(%rbx)
movl %eax, 0x3728(%rip)      # 0x6150
cmpl $-0x1, %eax
je 0x2bca
movl 0x3749(%rip), %edi      # 0x6180
leaq 0x1805(%rip), %rsi      # 0x4243
callq *(%rbx)
movl %eax, 0x3712(%rip)      # 0x6158
cmpl $-0x1, %eax
je 0x2bd3
movl 0x372b(%rip), %edi      # 0x6180
leaq 0x1811(%rip), %rsi      # 0x426d
callq *(%rbx)
movl %eax, 0x36f0(%rip)      # 0x6154
cmpl $-0x1, %eax
je 0x2bdc
movl 0x36e9(%rip), %edx      # 0x615c
movl 0x36e7(%rip), %ecx      # 0x6160
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
callq 0x20f0
movss 0x15b4(%rip), %xmm3     # 0x4040
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
callq 0x2050
movaps 0x190f(%rip), %xmm0     # 0x43b0
leaq 0x20(%rsp), %r15
movaps %xmm0, 0x10(%r15)
movaps 0x18ee(%rip), %xmm0     # 0x43a0
movaps %xmm0, (%r15)
movaps 0x1903(%rip), %xmm0     # 0x43c0
leaq 0x40(%rsp), %r14
movaps %xmm0, (%r14)
movq $0x3, 0x10(%r14)
movq 0x34cb(%rip), %rax      # 0x5fa0
leaq 0x36a8(%rip), %rsi      # 0x6184
movl $0x1, %edi
callq *(%rax)
movq 0x34fe(%rip), %rax      # 0x5fe8
movl 0x3694(%rip), %edi      # 0x6184
callq *(%rax)
movq 0x342f(%rip), %r12      # 0x5f28
leaq 0x3688(%rip), %rsi      # 0x6188
movl $0x1, %edi
callq *(%r12)
movq 0x33d8(%rip), %r13      # 0x5ee8
movl 0x3672(%rip), %esi      # 0x6188
movl $0x8892, %edi           # imm = 0x8892
callq *(%r13)
movq 0x33fa(%rip), %rbp      # 0x5f20
movl $0x20, %esi
movl $0x8892, %edi           # imm = 0x8892
movq %r15, %rdx
movl $0x88e4, %ecx           # imm = 0x88E4
callq *(%rbp)
leaq 0x364a(%rip), %rsi      # 0x618c
movl $0x1, %edi
callq *(%r12)
movl 0x363b(%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 0x346a(%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 0x343a(%rip), %rax      # 0x5fd0
xorl %edi, %edi
callq *(%rax)
jmp 0x2bac
movl %ebx, %edi
jmp 0x2ba2
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 0x35bd(%rip), %edi      # 0x6180
callq 0x26b5
jmp 0x2ba7
leaq 0x1626(%rip), %rsi      # 0x41f7
jmp 0x2be3
leaq 0x1646(%rip), %rsi      # 0x4220
jmp 0x2be3
leaq 0x1667(%rip), %rsi      # 0x424a
xorl %edi, %edi
xorl %eax, %eax
callq 0x2250
jmp 0x2ba7