// File: /workspace/github_cpp_makefile_star2_O2/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 -0x30(%rbp), %rsi
movl $0x8069, %edi           # imm = 0x8069
callq 0x7630
leaq -0x2c(%rbp), %rsi
movl $0x8894, %edi           # imm = 0x8894
callq 0x7630
leaq 0x103ed(%rip), %rax     # 0x411d8
leaq -0x50(%rbp), %r14
movq %rax, (%r14)
leaq 0x104cb(%rip), %rax     # 0x412c4
leaq -0x48(%rbp), %rbx
movq %rax, (%rbx)
callq 0x7760
movl %eax, 0x29f9d(%rip)     # 0x5ada8
movl $0x8b31, %edi           # imm = 0x8B31
callq 0x71b0
movl %eax, 0x29fb5(%rip)     # 0x5add0
movl $0x8b30, %edi           # imm = 0x8B30
callq 0x71b0
movl %eax, 0x29fa9(%rip)     # 0x5add4
movl 0x29f9f(%rip), %edi     # 0x5add0
pushq $0x1
popq %r15
movl %r15d, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x7660
movl 0x29f8c(%rip), %edi     # 0x5add4
movl %r15d, %esi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x7660
movl 0x29f75(%rip), %edi     # 0x5add0
callq 0x7090
movl 0x29f6e(%rip), %edi     # 0x5add4
callq 0x7090
movl 0x29f37(%rip), %edi     # 0x5ada8
movl 0x29f59(%rip), %esi     # 0x5add0
callq 0x7530
movl 0x29f26(%rip), %edi     # 0x5ada8
movl 0x29f4c(%rip), %esi     # 0x5add4
callq 0x7530
movl 0x29f15(%rip), %edi     # 0x5ada8
callq 0x77e0
movl 0x29f0a(%rip), %edi     # 0x5ada8
leaq 0x104b4(%rip), %rsi     # 0x41359
callq 0x7290
movl %eax, 0x29efc(%rip)     # 0x5adac
movl 0x29ef2(%rip), %edi     # 0x5ada8
leaq 0x104a4(%rip), %rsi     # 0x41361
callq 0x7290
movl %eax, 0x29ee8(%rip)     # 0x5adb0
movl 0x29eda(%rip), %edi     # 0x5ada8
leaq 0x10494(%rip), %rsi     # 0x41369
callq 0x76e0
movl %eax, 0x29ed8(%rip)     # 0x5adb8
movl 0x29ec2(%rip), %edi     # 0x5ada8
leaq 0x10485(%rip), %rsi     # 0x41372
callq 0x76e0
movl %eax, 0x29ec4(%rip)     # 0x5adbc
movl 0x29eaa(%rip), %edi     # 0x5ada8
leaq 0x10470(%rip), %rsi     # 0x41375
callq 0x76e0
movl %eax, 0x29eb0(%rip)     # 0x5adc0
leaq 0x29e9d(%rip), %rsi     # 0x5adb4
movl %r15d, %edi
callq 0x7160
leaq 0x29e9e(%rip), %rsi     # 0x5adc4
movl %r15d, %edi
callq 0x7160
callq 0xa0f5
movq %rax, %r12
movq 0x88(%rax), %rdi
leaq -0x40(%rbp), %r13
leaq -0x38(%rbp), %rbx
leaq -0x34(%rbp), %r14
movq %r13, %rsi
movq %rbx, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x2d352
leaq 0x29e77(%rip), %rsi     # 0x5add8
movl %r15d, %edi
callq 0x72d0
movl 0x29e69(%rip), %esi     # 0x5add8
movl $0xde1, %edi            # imm = 0xDE1
callq 0x7870
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2601, %edx           # imm = 0x2601
callq 0x7570
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2601, %edx           # imm = 0x2601
callq 0x7570
movl (%rbx), %ecx
movl (%r14), %r8d
subq $0x8, %rsp
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
movl $0x1908, %edx           # imm = 0x1908
xorl %r9d, %r9d
pushq (%r13)
pushq $0x1401                 # imm = 0x1401
pushq $0x1908                 # imm = 0x1908
callq 0x77d0
addq $0x20, %rsp
movl 0x29e02(%rip), %eax     # 0x5add8
movq 0x88(%r12), %rdi
movq %rax, (%rdi)
callq 0x2a82a
movq 0x88(%r12), %rdi
callq 0x2a90c
leaq -0x30(%rbp), %rax
movl (%rax), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x7870
leaq -0x2c(%rbp), %rax
movl (%rax), %esi
movl $0x8892, %edi           # imm = 0x8892
callq 0x7580
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq