// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]plasma/src/cube_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;
    }
    gUniformModelLocation = glGetUniformLocation(gProgramId, "uModel");
    if (gUniformModelLocation == -1) {
        LogError("could not get uniform location for uModel");
        return -1;
    }
    gUniformViewLocation = glGetUniformLocation(gProgramId, "uView");
    if (gUniformViewLocation == -1) {
        LogError("could not get uniform location for uView");
        return -1;
    }
    gUniformProjectionLocation =
        glGetUniformLocation(gProgramId, "uProjection");
    if (gUniformProjectionLocation == -1) {
        LogError("could not get uniform location for uProjection");
        return -1;
    }
    gUniformViewPositionLocation =
        glGetUniformLocation(gProgramId, "uViewPosition");
    if (gUniformViewPositionLocation == -1) {
        LogError("could not get uniform location for uViewPosition");
        return -1;
    }

    glViewport(0, 0, gWidth, gHeight);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_MULTISAMPLE);

    GLfloat vertexData[] = {
        -0.5f, -0.5f, -0.5f, 0.0f,  0.0f,  -1.0f, 0.5f,  -0.5f, -0.5f,
        0.0f,  0.0f,  -1.0f, 0.5f,  0.5f,  -0.5f, 0.0f,  0.0f,  -1.0f,
        0.5f,  0.5f,  -0.5f, 0.0f,  0.0f,  -1.0f, -0.5f, 0.5f,  -0.5f,
        0.0f,  0.0f,  -1.0f, -0.5f, -0.5f, -0.5f, 0.0f,  0.0f,  -1.0f,

        -0.5f, -0.5f, 0.5f,  0.0f,  0.0f,  1.0f,  0.5f,  -0.5f, 0.5f,
        0.0f,  0.0f,  1.0f,  0.5f,  0.5f,  0.5f,  0.0f,  0.0f,  1.0f,
        0.5f,  0.5f,  0.5f,  0.0f,  0.0f,  1.0f,  -0.5f, 0.5f,  0.5f,
        0.0f,  0.0f,  1.0f,  -0.5f, -0.5f, 0.5f,  0.0f,  0.0f,  1.0f,

        -0.5f, 0.5f,  0.5f,  -1.0f, 0.0f,  0.0f,  -0.5f, 0.5f,  -0.5f,
        -1.0f, 0.0f,  0.0f,  -0.5f, -0.5f, -0.5f, -1.0f, 0.0f,  0.0f,
        -0.5f, -0.5f, -0.5f, -1.0f, 0.0f,  0.0f,  -0.5f, -0.5f, 0.5f,
        -1.0f, 0.0f,  0.0f,  -0.5f, 0.5f,  0.5f,  -1.0f, 0.0f,  0.0f,

        0.5f,  0.5f,  0.5f,  1.0f,  0.0f,  0.0f,  0.5f,  0.5f,  -0.5f,
        1.0f,  0.0f,  0.0f,  0.5f,  -0.5f, -0.5f, 1.0f,  0.0f,  0.0f,
        0.5f,  -0.5f, -0.5f, 1.0f,  0.0f,  0.0f,  0.5f,  -0.5f, 0.5f,
        1.0f,  0.0f,  0.0f,  0.5f,  0.5f,  0.5f,  1.0f,  0.0f,  0.0f,

        -0.5f, -0.5f, -0.5f, 0.0f,  -1.0f, 0.0f,  0.5f,  -0.5f, -0.5f,
        0.0f,  -1.0f, 0.0f,  0.5f,  -0.5f, 0.5f,  0.0f,  -1.0f, 0.0f,
        0.5f,  -0.5f, 0.5f,  0.0f,  -1.0f, 0.0f,  -0.5f, -0.5f, 0.5f,
        0.0f,  -1.0f, 0.0f,  -0.5f, -0.5f, -0.5f, 0.0f,  -1.0f, 0.0f,

        -0.5f, 0.5f,  -0.5f, 0.0f,  1.0f,  0.0f,  0.5f,  0.5f,  -0.5f,
        0.0f,  1.0f,  0.0f,  0.5f,  0.5f,  0.5f,  0.0f,  1.0f,  0.0f,
        0.5f,  0.5f,  0.5f,  0.0f,  1.0f,  0.0f,  -0.5f, 0.5f,  0.5f,
        0.0f,  1.0f,  0.0f,  -0.5f, 0.5f,  -0.5f, 0.0f,  1.0f,  0.0f};

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

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

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

    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float),
                          (void *)(3 * sizeof(float)));
    glEnableVertexAttribArray(1);

    Mat4Perspective(0.785398, (float)gWidth / (float)gHeight, 1.0f, 10.0f,
                    gProj);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x390, %rsp            # imm = 0x390
movq 0x4506(%rip), %rax      # 0x6f38
callq *(%rax)
movl %eax, 0x47e6(%rip)      # 0x7220
leaq 0x27ab(%rip), %rdi      # 0x51ec
callq 0x28b0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x2a68
xorl %edi, %edi
leaq 0x27af(%rip), %rsi      # 0x5209
leaq 0x278b(%rip), %rdx      # 0x51ec
movb $0x0, %al
callq 0x22c0
movl $0x8b31, %edi           # imm = 0x8B31
leaq -0x10(%rbp), %rsi
leaq -0x8(%rbp), %rdx
callq 0x2990
movzbl %al, %eax
cmpl $0x1, %eax
je 0x2a96
movl -0x8(%rbp), %edi
callq 0x2710
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2e8b
leaq 0x2783(%rip), %rdi      # 0x5220
callq 0x28b0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x2ac4
xorl %edi, %edi
leaq 0x2753(%rip), %rsi      # 0x5209
leaq 0x2763(%rip), %rdx      # 0x5220
movb $0x0, %al
callq 0x22c0
movl $0x8b30, %edi           # imm = 0x8B30
leaq -0x20(%rbp), %rsi
leaq -0x14(%rbp), %rdx
callq 0x2990
movzbl %al, %eax
cmpl $0x1, %eax
je 0x2af2
movl -0x14(%rbp), %edi
callq 0x2710
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2e8b
movq -0x20(%rbp), %rdi
callq 0x2090
movq -0x10(%rbp), %rdi
callq 0x2090
movq 0x448d(%rip), %rax      # 0x6f98
movq (%rax), %rax
movl 0x470c(%rip), %edi      # 0x7220
movl -0x8(%rbp), %esi
callq *%rax
movq 0x4478(%rip), %rax      # 0x6f98
movq (%rax), %rax
movl 0x46f7(%rip), %edi      # 0x7220
movl -0x14(%rbp), %esi
callq *%rax
movq 0x4473(%rip), %rax      # 0x6fa8
movq (%rax), %rax
movl 0x46e2(%rip), %edi      # 0x7220
callq *%rax
movl $0x1, -0x24(%rbp)
movq 0x43ba(%rip), %rax      # 0x6f08
movq (%rax), %rax
movl 0x46c9(%rip), %edi      # 0x7220
movl $0x8b82, %esi           # imm = 0x8B82
leaq -0x24(%rbp), %rdx
callq *%rax
cmpl $0x1, -0x24(%rbp)
je 0x2b7f
movl 0x46b2(%rip), %edi      # 0x7220
callq 0x27e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2e8b
movq 0x443a(%rip), %rax      # 0x6fc0
movq (%rax), %rax
movl -0x14(%rbp), %edi
callq *%rax
movq 0x442b(%rip), %rax      # 0x6fc0
movq (%rax), %rax
movl -0x8(%rbp), %edi
callq *%rax
movq 0x4344(%rip), %rax      # 0x6ee8
movq (%rax), %rax
movl 0x4673(%rip), %edi      # 0x7220
leaq 0x26ac(%rip), %rsi      # 0x5260
callq *%rax
movl %eax, 0x45d4(%rip)      # 0x7190
cmpl $-0x1, 0x45cd(%rip)     # 0x7190
jne 0x2be1
xorl %edi, %edi
leaq 0x266f(%rip), %rsi      # 0x523d
movb $0x0, %al
callq 0x22c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2e8b
movq 0x4300(%rip), %rax      # 0x6ee8
movq (%rax), %rax
movl 0x462f(%rip), %edi      # 0x7220
leaq 0x2691(%rip), %rsi      # 0x5289
callq *%rax
movl %eax, 0x4594(%rip)      # 0x7194
cmpl $-0x1, 0x458d(%rip)     # 0x7194
jne 0x2c25
xorl %edi, %edi
leaq 0x2654(%rip), %rsi      # 0x5266
movb $0x0, %al
callq 0x22c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2e8b
movq 0x42bc(%rip), %rax      # 0x6ee8
movq (%rax), %rax
movl 0x45eb(%rip), %edi      # 0x7220
leaq 0x2677(%rip), %rsi      # 0x52b3
callq *%rax
movl %eax, 0x4554(%rip)      # 0x7198
cmpl $-0x1, 0x454d(%rip)     # 0x7198
jne 0x2c69
xorl %edi, %edi
leaq 0x263a(%rip), %rsi      # 0x5290
movb $0x0, %al
callq 0x22c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2e8b
movq 0x4278(%rip), %rax      # 0x6ee8
movq (%rax), %rax
movl 0x45a7(%rip), %edi      # 0x7220
leaq 0x265d(%rip), %rsi      # 0x52dd
callq *%rax
movl %eax, 0x4514(%rip)      # 0x719c
cmpl $-0x1, 0x450d(%rip)     # 0x719c
jne 0x2cad
xorl %edi, %edi
leaq 0x2620(%rip), %rsi      # 0x52ba
movb $0x0, %al
callq 0x22c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2e8b
movq 0x4234(%rip), %rax      # 0x6ee8
movq (%rax), %rax
movl 0x4563(%rip), %edi      # 0x7220
leaq 0x2642(%rip), %rsi      # 0x5306
callq *%rax
movl %eax, 0x44d4(%rip)      # 0x71a0
cmpl $-0x1, 0x44cd(%rip)     # 0x71a0
jne 0x2cf1
xorl %edi, %edi
leaq 0x2605(%rip), %rsi      # 0x52e3
movb $0x0, %al
callq 0x22c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2e8b
movq 0x41f0(%rip), %rax      # 0x6ee8
movq (%rax), %rax
movl 0x451f(%rip), %edi      # 0x7220
leaq 0x262d(%rip), %rsi      # 0x5335
callq *%rax
movl %eax, 0x4494(%rip)      # 0x71a4
cmpl $-0x1, 0x448d(%rip)     # 0x71a4
jne 0x2d35
xorl %edi, %edi
leaq 0x25f0(%rip), %rsi      # 0x5312
movb $0x0, %al
callq 0x22c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2e8b
movl 0x44b5(%rip), %edx      # 0x71f0
movl 0x44b3(%rip), %ecx      # 0x71f4
xorl %esi, %esi
movl %esi, %edi
callq 0x2110
movl $0xb71, %edi            # imm = 0xB71
callq 0x2180
movl $0x809d, %edi           # imm = 0x809D
callq 0x2180
leaq -0x390(%rbp), %rdi
leaq 0x2704(%rip), %rsi      # 0x5470
movl $0x360, %edx            # imm = 0x360
callq 0x2050
movl $0x1, %edi
leaq 0x44a2(%rip), %rsi      # 0x7224
movq 0x4217(%rip), %rax      # 0x6fa0
callq *(%rax)
movq 0x4256(%rip), %rax      # 0x6fe8
movq (%rax), %rax
movl 0x4489(%rip), %edi      # 0x7224
callq *%rax
movl $0x1, %edi
leaq 0x447f(%rip), %rsi      # 0x7228
movq 0x4168(%rip), %rax      # 0x6f18
callq *(%rax)
movq 0x4127(%rip), %rax      # 0x6ee0
movq (%rax), %rax
movl 0x4466(%rip), %esi      # 0x7228
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movq 0x4140(%rip), %rax      # 0x6f10
movq (%rax), %rax
leaq -0x390(%rbp), %rdx
movl $0x8892, %edi           # imm = 0x8892
movl $0x360, %esi            # imm = 0x360
movl $0x88e4, %ecx           # imm = 0x88E4
callq *%rax
xorl %ecx, %ecx
movl $0x3, %esi
movl $0x1406, %edx           # imm = 0x1406
movl $0x18, %r8d
xorl %eax, %eax
movl %eax, %r9d
movq 0x41d7(%rip), %rax      # 0x6fe0
movl %ecx, %edi
callq *(%rax)
xorl %edi, %edi
movq 0x41ba(%rip), %rax      # 0x6fd0
callq *(%rax)
movl $0x1, %edi
movl $0x3, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x18, %r8d
movl $0xc, %r9d
movq 0x41a4(%rip), %rax      # 0x6fe0
callq *(%rax)
movl $0x1, %edi
movq 0x4186(%rip), %rax      # 0x6fd0
callq *(%rax)
cvtsi2ssl 0x439c(%rip), %xmm1 # 0x71f0
cvtsi2ssl 0x4398(%rip), %xmm0 # 0x71f4
divss %xmm0, %xmm1
movss 0x2210(%rip), %xmm0     # 0x5078
movss 0x220c(%rip), %xmm2     # 0x507c
movss 0x2208(%rip), %xmm3     # 0x5080
leaq 0x43b1(%rip), %rdi      # 0x7230
callq 0x2ea0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x390, %rsp            # imm = 0x390
popq %rbp
retq
nopw (%rax,%rax)