// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x35e1(%rip), %rax      # 0x5f40
callq *(%rax)
movl %eax, 0x3819(%rip)      # 0x6180
leaq 0x1834(%rip), %rdi      # 0x41a2
callq 0x27e0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x2995
xorl %edi, %edi
leaq 0x183a(%rip), %rsi      # 0x41c1
leaq 0x1814(%rip), %rdx      # 0x41a2
movb $0x0, %al
callq 0x2250
movl $0x8b31, %edi           # imm = 0x8B31
leaq -0x10(%rbp), %rsi
leaq -0x8(%rbp), %rdx
callq 0x28c0
movzbl %al, %eax
cmpl $0x1, %eax
je 0x29c3
movl -0x8(%rbp), %edi
callq 0x2640
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2cff
leaq 0x180e(%rip), %rdi      # 0x41d8
callq 0x27e0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x29f1
xorl %edi, %edi
leaq 0x17de(%rip), %rsi      # 0x41c1
leaq 0x17ee(%rip), %rdx      # 0x41d8
movb $0x0, %al
callq 0x2250
movl $0x8b30, %edi           # imm = 0x8B30
leaq -0x20(%rbp), %rsi
leaq -0x14(%rbp), %rdx
callq 0x28c0
movzbl %al, %eax
cmpl $0x1, %eax
je 0x2a1f
movl -0x14(%rbp), %edi
callq 0x2640
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2cff
movq -0x20(%rbp), %rdi
callq 0x2070
movq -0x10(%rbp), %rdi
callq 0x2070
movq 0x3560(%rip), %rax      # 0x5f98
movq (%rax), %rax
movl 0x373f(%rip), %edi      # 0x6180
movl -0x8(%rbp), %esi
callq *%rax
movq 0x354b(%rip), %rax      # 0x5f98
movq (%rax), %rax
movl 0x372a(%rip), %edi      # 0x6180
movl -0x14(%rbp), %esi
callq *%rax
movq 0x3546(%rip), %rax      # 0x5fa8
movq (%rax), %rax
movl 0x3715(%rip), %edi      # 0x6180
callq *%rax
movl $0x1, -0x24(%rbp)
movq 0x349d(%rip), %rax      # 0x5f18
movq (%rax), %rax
movl 0x36fc(%rip), %edi      # 0x6180
movl $0x8b82, %esi           # imm = 0x8B82
leaq -0x24(%rbp), %rdx
callq *%rax
cmpl $0x1, -0x24(%rbp)
je 0x2aac
movl 0x36e5(%rip), %edi      # 0x6180
callq 0x2710
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2cff
movq 0x350d(%rip), %rax      # 0x5fc0
movq (%rax), %rax
movl -0x14(%rbp), %edi
callq *%rax
movq 0x34fe(%rip), %rax      # 0x5fc0
movq (%rax), %rax
movl -0x8(%rbp), %edi
callq *%rax
movq 0x341f(%rip), %rax      # 0x5ef0
movq (%rax), %rax
movl 0x36a6(%rip), %edi      # 0x6180
leaq 0x1739(%rip), %rsi      # 0x421a
callq *%rax
movl %eax, 0x3667(%rip)      # 0x6150
cmpl $-0x1, 0x3660(%rip)     # 0x6150
jne 0x2b0e
xorl %edi, %edi
leaq 0x16fc(%rip), %rsi      # 0x41f7
movb $0x0, %al
callq 0x2250
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2cff
movq 0x33db(%rip), %rax      # 0x5ef0
movq (%rax), %rax
movl 0x3662(%rip), %edi      # 0x6180
leaq 0x171e(%rip), %rsi      # 0x4243
callq *%rax
movl %eax, 0x362b(%rip)      # 0x6158
cmpl $-0x1, 0x3624(%rip)     # 0x6158
jne 0x2b52
xorl %edi, %edi
leaq 0x16e1(%rip), %rsi      # 0x4220
movb $0x0, %al
callq 0x2250
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2cff
movq 0x3397(%rip), %rax      # 0x5ef0
movq (%rax), %rax
movl 0x361e(%rip), %edi      # 0x6180
leaq 0x1704(%rip), %rsi      # 0x426d
callq *%rax
movl %eax, 0x35e3(%rip)      # 0x6154
cmpl $-0x1, 0x35dc(%rip)     # 0x6154
jne 0x2b96
xorl %edi, %edi
leaq 0x16c7(%rip), %rsi      # 0x424a
movb $0x0, %al
callq 0x2250
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2cff
movl 0x35c0(%rip), %edx      # 0x615c
movl 0x35be(%rip), %ecx      # 0x6160
xorl %esi, %esi
movl %esi, %edi
callq 0x20f0
xorps %xmm2, %xmm2
movss 0x148a(%rip), %xmm3     # 0x4040
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x2050
movq 0x17d8(%rip), %rax      # 0x43a0
movq %rax, -0x50(%rbp)
movq 0x17d5(%rip), %rax      # 0x43a8
movq %rax, -0x48(%rbp)
movq 0x17d2(%rip), %rax      # 0x43b0
movq %rax, -0x40(%rbp)
movq 0x17cf(%rip), %rax      # 0x43b8
movq %rax, -0x38(%rbp)
movq 0x17cc(%rip), %rax      # 0x43c0
movq %rax, -0x70(%rbp)
movq 0x17c9(%rip), %rax      # 0x43c8
movq %rax, -0x68(%rbp)
movq 0x17c6(%rip), %rax      # 0x43d0
movq %rax, -0x60(%rbp)
movl $0x1, %edi
leaq 0x356a(%rip), %rsi      # 0x6184
movq 0x337f(%rip), %rax      # 0x5fa0
callq *(%rax)
movq 0x33be(%rip), %rax      # 0x5fe8
movq (%rax), %rax
movl 0x3551(%rip), %edi      # 0x6184
callq *%rax
movl $0x1, %edi
leaq 0x3547(%rip), %rsi      # 0x6188
movq 0x32e0(%rip), %rax      # 0x5f28
callq *(%rax)
movq 0x3297(%rip), %rax      # 0x5ee8
movq (%rax), %rax
movl 0x352e(%rip), %esi      # 0x6188
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movq 0x32b8(%rip), %rax      # 0x5f20
movq (%rax), %rax
leaq -0x50(%rbp), %rdx
movl $0x8892, %edi           # imm = 0x8892
movl $0x20, %esi
movl $0x88e4, %ecx           # imm = 0x88E4
callq *%rax
movl $0x1, %edi
leaq 0x3500(%rip), %rsi      # 0x618c
movq 0x3295(%rip), %rax      # 0x5f28
callq *(%rax)
movq 0x324c(%rip), %rax      # 0x5ee8
movq (%rax), %rax
movl 0x34e7(%rip), %esi      # 0x618c
movl $0x8893, %edi           # imm = 0x8893
callq *%rax
movq 0x326d(%rip), %rax      # 0x5f20
movq (%rax), %rax
leaq -0x70(%rbp), %rdx
movl $0x8893, %edi           # imm = 0x8893
movl $0x18, %esi
movl $0x88e4, %ecx           # imm = 0x88E4
callq *%rax
xorl %ecx, %ecx
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
movl $0x8, %r8d
xorl %eax, %eax
movl %eax, %r9d
movq 0x32f7(%rip), %rax      # 0x5fe0
movl %ecx, %edi
callq *(%rax)
xorl %edi, %edi
movq 0x32da(%rip), %rax      # 0x5fd0
callq *(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)