// File: 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
subq $0x50, %rsp
movl $0x8069, %edi           # imm = 0x8069
leaq -0x4(%rbp), %rsi
callq 0x7690
movl $0x8894, %edi           # imm = 0x8894
leaq -0x8(%rbp), %rsi
callq 0x7690
leaq 0x1811d(%rip), %rax     # 0x65d68
movq %rax, -0x10(%rbp)
leaq 0x181fe(%rip), %rax     # 0x65e54
movq %rax, -0x18(%rbp)
callq 0x77c0
movl %eax, 0x36183(%rip)     # 0x83de8
movl $0x8b31, %edi           # imm = 0x8B31
callq 0x71e0
movl %eax, 0x3619b(%rip)     # 0x83e10
movl $0x8b30, %edi           # imm = 0x8B30
callq 0x71e0
movl %eax, 0x3618f(%rip)     # 0x83e14
movl 0x36185(%rip), %edi     # 0x83e10
movl $0x1, %esi
leaq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x76c0
movl 0x36171(%rip), %edi     # 0x83e14
movl $0x1, %esi
leaq -0x18(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x76c0
movl 0x36155(%rip), %edi     # 0x83e10
callq 0x7090
movl 0x3614e(%rip), %edi     # 0x83e14
callq 0x7090
movl 0x36117(%rip), %edi     # 0x83de8
movl 0x36139(%rip), %esi     # 0x83e10
callq 0x7570
movl 0x36106(%rip), %edi     # 0x83de8
movl 0x3612c(%rip), %esi     # 0x83e14
callq 0x7570
movl 0x360f5(%rip), %edi     # 0x83de8
callq 0x7850
movl 0x360ea(%rip), %edi     # 0x83de8
leaq 0x181e4(%rip), %rsi     # 0x65ee9
callq 0x72c0
movl %eax, 0x360dc(%rip)     # 0x83dec
movl 0x360d2(%rip), %edi     # 0x83de8
leaq 0x181d4(%rip), %rsi     # 0x65ef1
callq 0x72c0
movl %eax, 0x360c8(%rip)     # 0x83df0
movl 0x360ba(%rip), %edi     # 0x83de8
leaq 0x181c4(%rip), %rsi     # 0x65ef9
callq 0x7750
movl %eax, 0x360b8(%rip)     # 0x83df8
movl 0x360a2(%rip), %edi     # 0x83de8
leaq 0x181b5(%rip), %rsi     # 0x65f02
callq 0x7750
movl %eax, 0x360a4(%rip)     # 0x83dfc
movl 0x3608a(%rip), %edi     # 0x83de8
leaq 0x181a0(%rip), %rsi     # 0x65f05
callq 0x7750
movl %eax, 0x36090(%rip)     # 0x83e00
movl $0x1, %edi
leaq 0x36078(%rip), %rsi     # 0x83df4
callq 0x7180
movl $0x1, %edi
leaq 0x36077(%rip), %rsi     # 0x83e04
callq 0x7180
callq 0xca90
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
leaq -0x30(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x43150
movl $0x1, %edi
leaq 0x36050(%rip), %rsi     # 0x83e18
callq 0x7310
movl 0x36045(%rip), %esi     # 0x83e18
movl $0xde1, %edi            # imm = 0xDE1
callq 0x78f0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2601, %edx           # imm = 0x2601
callq 0x75c0
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2601, %edx           # imm = 0x2601
callq 0x75c0
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %r8d
movq -0x28(%rbp), %rax
movl $0xde1, %edi            # imm = 0xDE1
xorl %r9d, %r9d
movl $0x1908, %edx           # imm = 0x1908
movl %r9d, %esi
movl $0x1908, (%rsp)         # imm = 0x1908
movl $0x1401, 0x8(%rsp)      # imm = 0x1401
movq %rax, 0x10(%rsp)
callq 0x7840
movl 0x35fd9(%rip), %eax     # 0x83e18
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rdi
callq 0x41c80
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rdi
callq 0x41dd0
movl -0x4(%rbp), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x78f0
movl -0x8(%rbp), %esi
movl $0x8892, %edi           # imm = 0x8892
callq 0x75d0
movb $0x1, %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)