// File: /workspace/github_cpp_makefile_star2_O1/donfreiday[P]gb/./imgui/imgui_impl_sdl.cpp
// Function: ImGui_ImplSdl_CreateDeviceObjects()
bool ImGui_ImplSdl_CreateDeviceObjects()
{
    // Backup GL state
    GLint last_texture, last_array_buffer;
    glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
    glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);

    const GLchar *vertex_shader =
        "uniform mat4 ProjMtx;\n"
        "attribute vec2 Position;\n"
        "attribute vec2 UV;\n"
        "attribute vec4 Color;\n"
        "varying vec2 Frag_UV;\n"
        "varying vec4 Frag_Color;\n"
        "void main()\n"
        "{\n"
        "	Frag_UV = UV;\n"
        "	Frag_Color = Color;\n"
        "	gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
        "}\n";

    const GLchar* fragment_shader =
#ifdef __EMSCRIPTEN__
        // WebGL requires precision specifiers but OpenGL 2.1 disallows
        // them, so I define the shader without it and then add it here.
        "precision mediump float;\n"
#endif
        "uniform sampler2D Texture;\n"
        "varying vec2 Frag_UV;\n"
        "varying vec4 Frag_Color;\n"
        "void main()\n"
        "{\n"
        "	gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV);\n"
        "}\n";

    g_ShaderHandle = glCreateProgram();
    g_VertHandle = glCreateShader(GL_VERTEX_SHADER);
    g_FragHandle = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(g_VertHandle, 1, &vertex_shader, 0);
    glShaderSource(g_FragHandle, 1, &fragment_shader, 0);
    glCompileShader(g_VertHandle);
    glCompileShader(g_FragHandle);
    glAttachShader(g_ShaderHandle, g_VertHandle);
    glAttachShader(g_ShaderHandle, g_FragHandle);
    glLinkProgram(g_ShaderHandle);
    
    g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture");
    g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx");
    g_AttribLocationPosition = glGetAttribLocation(g_ShaderHandle, "Position");
    g_AttribLocationUV = glGetAttribLocation(g_ShaderHandle, "UV");
    g_AttribLocationColor = glGetAttribLocation(g_ShaderHandle, "Color");

    glGenBuffers(1, &g_VboHandle);
    glGenBuffers(1, &g_ElementsHandle);

    ImGuiIO& io = ImGui::GetIO();

    // Build texture
    unsigned char* pixels;
    int width, height;
    io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);   // Load as RGBA 32-bits for OpenGL3 demo because it is more likely to be compatible with user's existing shader.

    // Create OpenGL texture
    glGenTextures(1, &g_FontTexture);
    glBindTexture(GL_TEXTURE_2D, g_FontTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

    // Store our identifier
    io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;

    // Cleanup (don't clear the input data if you want to append new fonts later)
    io.Fonts->ClearInputData();
    io.Fonts->ClearTexData();

    // Restore modified GL state
    glBindTexture(GL_TEXTURE_2D, last_texture);
    glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq -0x2c(%rbp), %rsi
movl $0x8069, %edi           # imm = 0x8069
callq 0x7660
leaq -0x38(%rbp), %r14
movl $0x8894, %edi           # imm = 0x8894
movq %r14, %rsi
callq 0x7660
leaq 0x10532(%rip), %rax     # 0x47fa0
leaq -0x50(%rbp), %r15
movq %rax, (%r15)
leaq 0x10610(%rip), %rax     # 0x4808c
leaq -0x48(%rbp), %rbx
movq %rax, (%rbx)
callq 0x77a0
movl %eax, 0x2832a(%rip)     # 0x5fdb8
movl $0x8b31, %edi           # imm = 0x8B31
callq 0x71c0
movl %eax, 0x28342(%rip)     # 0x5fde0
movl $0x8b30, %edi           # imm = 0x8B30
callq 0x71c0
movl %eax, 0x28336(%rip)     # 0x5fde4
movl 0x2832c(%rip), %edi     # 0x5fde0
movl $0x1, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x7690
movl 0x2831b(%rip), %edi     # 0x5fde4
movl $0x1, %esi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x7690
movl 0x28302(%rip), %edi     # 0x5fde0
callq 0x7090
movl 0x282fb(%rip), %edi     # 0x5fde4
callq 0x7090
movl 0x282c4(%rip), %edi     # 0x5fdb8
movl 0x282e6(%rip), %esi     # 0x5fde0
callq 0x7550
movl 0x282b3(%rip), %edi     # 0x5fdb8
movl 0x282d9(%rip), %esi     # 0x5fde4
callq 0x7550
movl 0x282a2(%rip), %edi     # 0x5fdb8
callq 0x7820
movl 0x28297(%rip), %edi     # 0x5fdb8
leaq 0x105f9(%rip), %rsi     # 0x48121
callq 0x7290
movl %eax, 0x28289(%rip)     # 0x5fdbc
movl 0x2827f(%rip), %edi     # 0x5fdb8
leaq 0x105e9(%rip), %rsi     # 0x48129
callq 0x7290
movl %eax, 0x28275(%rip)     # 0x5fdc0
movl 0x28267(%rip), %edi     # 0x5fdb8
leaq 0x105d9(%rip), %rsi     # 0x48131
callq 0x7710
movl %eax, 0x28265(%rip)     # 0x5fdc8
movl 0x2824f(%rip), %edi     # 0x5fdb8
leaq 0x105ca(%rip), %rsi     # 0x4813a
callq 0x7710
movl %eax, 0x28251(%rip)     # 0x5fdcc
movl 0x28237(%rip), %edi     # 0x5fdb8
leaq 0x105b5(%rip), %rsi     # 0x4813d
callq 0x7710
movl %eax, 0x2823d(%rip)     # 0x5fdd0
leaq 0x2822a(%rip), %rsi     # 0x5fdc4
movl $0x1, %edi
callq 0x7160
leaq 0x28229(%rip), %rsi     # 0x5fdd4
movl $0x1, %edi
callq 0x7160
callq 0xb1e1
movq %rax, %r15
movq 0x88(%rax), %rdi
leaq -0x40(%rbp), %r12
leaq -0x34(%rbp), %r13
leaq -0x30(%rbp), %rbx
movq %r12, %rsi
movq %r13, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x3449a
leaq 0x28200(%rip), %rsi     # 0x5fde8
movl $0x1, %edi
callq 0x72d0
movl 0x281f0(%rip), %esi     # 0x5fde8
movl $0xde1, %edi            # imm = 0xDE1
callq 0x78b0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2601, %edx           # imm = 0x2601
callq 0x7590
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2601, %edx           # imm = 0x2601
callq 0x7590
movl (%r13), %ecx
movl (%rbx), %r8d
subq $0x8, %rsp
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
movl $0x1908, %edx           # imm = 0x1908
xorl %r9d, %r9d
pushq (%r12)
pushq $0x1401                 # imm = 0x1401
pushq $0x1908                 # imm = 0x1908
callq 0x7810
addq $0x20, %rsp
movl 0x28187(%rip), %eax     # 0x5fde8
movq 0x88(%r15), %rdi
movq %rax, (%rdi)
callq 0x315f0
movq 0x88(%r15), %rdi
callq 0x316dc
leaq -0x2c(%rbp), %rax
movl (%rax), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x78b0
movl (%r14), %esi
movl $0x8892, %edi           # imm = 0x8892
callq 0x75b0
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq