// File: /workspace/github_cpp_makefile_star2_O3/donfreiday[P]gb/./imgui/imgui_impl_sdl.cpp
// Function: ImGui_ImplSdl_RenderDrawLists(ImDrawData*)
void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data)
{
    // Backup GL state
    GLint last_program, last_texture, last_array_buffer, last_element_array_buffer;
    glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
    glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
    glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
    glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer);

    // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
    glEnable(GL_BLEND);
    glBlendEquation(GL_FUNC_ADD);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_SCISSOR_TEST);
    glActiveTexture(GL_TEXTURE0);

    // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
    ImGuiIO& io = ImGui::GetIO();
    float fb_height = io.DisplaySize.y * io.DisplayFramebufferScale.y;
    draw_data->ScaleClipRects(io.DisplayFramebufferScale);

    // Setup orthographic projection matrix
    const float ortho_projection[4][4] =
    {
        { 2.0f/io.DisplaySize.x, 0.0f,                   0.0f, 0.0f },
        { 0.0f,                  2.0f/-io.DisplaySize.y, 0.0f, 0.0f },
        { 0.0f,                  0.0f,                  -1.0f, 0.0f },
        {-1.0f,                  1.0f,                   0.0f, 1.0f },
    };
    glUseProgram(g_ShaderHandle);
    glUniform1i(g_AttribLocationTex, 0);
    glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);

    // Render command lists
    glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
    glEnableVertexAttribArray(g_AttribLocationPosition);
    glEnableVertexAttribArray(g_AttribLocationUV);
    glEnableVertexAttribArray(g_AttribLocationColor);

#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
    glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos));
    glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv));
    glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col));
#undef OFFSETOF
    
    for (int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList* cmd_list = draw_data->CmdLists[n];
        const ImDrawIdx* idx_buffer_offset = 0;

        glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
        glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.size() * sizeof(ImDrawVert), (GLvoid*)&cmd_list->VtxBuffer.front(), GL_STREAM_DRAW);

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx), (GLvoid*)&cmd_list->IdxBuffer.front(), GL_STREAM_DRAW);
        
        for (const ImDrawCmd* pcmd = cmd_list->CmdBuffer.begin(); pcmd != cmd_list->CmdBuffer.end(); pcmd++)
        {
            if (pcmd->UserCallback)
            {
                pcmd->UserCallback(cmd_list, pcmd);
            }
            else
            {
                glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
                glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
                glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer_offset);
            }
            idx_buffer_offset += pcmd->ElemCount;
        }
    }

    // Restore modified state
    glDisableVertexAttribArray(g_AttribLocationPosition);
    glDisableVertexAttribArray(g_AttribLocationUV);
    glDisableVertexAttribArray(g_AttribLocationColor);
    glUseProgram(last_program);
    glBindTexture(GL_TEXTURE_2D, last_texture);
    glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer);
    glDisable(GL_SCISSOR_TEST);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq -0x3c(%rbp), %rsi
movl $0x8b8d, %edi           # imm = 0x8B8D
callq 0x7650
leaq -0x38(%rbp), %rsi
movl $0x8069, %edi           # imm = 0x8069
callq 0x7650
leaq -0x34(%rbp), %rsi
movl $0x8894, %edi           # imm = 0x8894
callq 0x7650
leaq -0x30(%rbp), %rsi
movl $0x8895, %edi           # imm = 0x8895
callq 0x7650
movl $0xbe2, %edi            # imm = 0xBE2
callq 0x7440
movl $0x8006, %edi           # imm = 0x8006
callq 0x74f0
movl $0x302, %edi            # imm = 0x302
movl $0x303, %esi            # imm = 0x303
callq 0x7860
movl $0xb44, %edi            # imm = 0xB44
callq 0x76e0
movl $0xb71, %edi            # imm = 0xB71
callq 0x76e0
movl $0xc11, %edi            # imm = 0xC11
callq 0x7440
movl $0x84c0, %edi           # imm = 0x84C0
callq 0x7500
callq 0xb0ca
movq %rax, %r15
movss 0x4(%rax), %xmm0
leaq 0x98(%rax), %rsi
mulss 0x9c(%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x30be8
movss 0x66e0(%rip), %xmm0     # 0x3d3d4
divss (%r15), %xmm0
leaq -0x80(%rbp), %r14
movss %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%r14)
movss 0x670a(%rip), %xmm1     # 0x3d41c
divss 0x4(%r15), %xmm1
movss %xmm1, 0x14(%r14)
movups %xmm0, 0x18(%r14)
movaps 0x111c6(%rip), %xmm0    # 0x47ef0
movups %xmm0, 0x28(%r14)
movabsq $0x3f80000000000000, %rax # imm = 0x3F80000000000000
movq %rax, 0x38(%r14)
movl 0x29065(%rip), %edi     # 0x5fda8
callq 0x71c0
movl 0x2905e(%rip), %edi     # 0x5fdac
xorl %esi, %esi
callq 0x7690
movl 0x29055(%rip), %edi     # 0x5fdb0
movl $0x1, %esi
xorl %edx, %edx
movq %r14, %rcx
callq 0x7870
movl 0x29044(%rip), %esi     # 0x5fdb4
movl $0x8892, %edi           # imm = 0x8892
callq 0x75a0
movl 0x29038(%rip), %edi     # 0x5fdb8
callq 0x70f0
movl 0x29031(%rip), %edi     # 0x5fdbc
callq 0x70f0
movl 0x2902a(%rip), %edi     # 0x5fdc0
callq 0x70f0
movl 0x29017(%rip), %edi     # 0x5fdb8
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x14, %r8d
xorl %r9d, %r9d
callq 0x7730
movl 0x28ffb(%rip), %edi     # 0x5fdbc
movl $0x8, %r9d
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x14, %r8d
callq 0x7730
movl 0x28fdc(%rip), %edi     # 0x5fdc0
movl $0x10, %r9d
movl $0x4, %esi
movl $0x1401, %edx           # imm = 0x1401
movl $0x1, %ecx
movl $0x14, %r8d
callq 0x7730
cmpl $0x0, 0x10(%rbx)
jle 0x36f37
xorl %r13d, %r13d
movq 0x8(%rbx), %rax
movq (%rax,%r13,8), %r14
movl 0x28f95(%rip), %esi     # 0x5fdb4
movl $0x8892, %edi           # imm = 0x8892
callq 0x75a0
movslq 0x20(%r14), %rax
testq %rax, %rax
jle 0x36fb7
shlq $0x2, %rax
leaq (%rax,%rax,4), %rsi
movq 0x28(%r14), %rdx
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e0, %ecx           # imm = 0x88E0
callq 0x7190
movl 0x28f6d(%rip), %esi     # 0x5fdc4
movl $0x8893, %edi           # imm = 0x8893
callq 0x75a0
movl 0x10(%r14), %esi
testl %esi, %esi
jle 0x36fa0
addq %rsi, %rsi
movq 0x18(%r14), %rdx
movl $0x8893, %edi           # imm = 0x8893
movl $0x88e0, %ecx           # imm = 0x88E0
callq 0x7190
cmpl $0x0, (%r14)
je 0x36f27
movq 0x8(%r14), %r15
xorl %r12d, %r12d
movq 0x20(%r15), %rax
testq %rax, %rax
je 0x36ea7
movq %r14, %rdi
movq %r15, %rsi
callq *%rax
jmp 0x36f04
movl 0x18(%r15), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x7890
movss 0x4(%r15), %xmm0
cvttss2si %xmm0, %edi
movss 0x10(%r15), %xmm1
movss -0x2c(%rbp), %xmm2
subss %xmm1, %xmm2
cvttss2si %xmm2, %esi
movss 0xc(%r15), %xmm2
subss %xmm0, %xmm2
cvttss2si %xmm2, %edx
subss 0x8(%r15), %xmm1
cvttss2si %xmm1, %ecx
callq 0x7470
movl (%r15), %esi
movl $0x4, %edi
movl $0x1403, %edx           # imm = 0x1403
movq %r12, %rcx
callq 0x71d0
movl (%r15), %eax
leaq (%r12,%rax,2), %r12
addq $0x30, %r15
movslq (%r14), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
addq 0x8(%r14), %rax
cmpq %rax, %r15
jne 0x36e94
incq %r13
movslq 0x10(%rbx), %rax
cmpq %rax, %r13
jl 0x36e11
movl 0x28e7b(%rip), %edi     # 0x5fdb8
callq 0x75e0
movl 0x28e74(%rip), %edi     # 0x5fdbc
callq 0x75e0
movl 0x28e6d(%rip), %edi     # 0x5fdc0
callq 0x75e0
movl -0x3c(%rbp), %edi
callq 0x71c0
movl -0x38(%rbp), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x7890
movl -0x34(%rbp), %esi
movl $0x8892, %edi           # imm = 0x8892
callq 0x75a0
movl -0x30(%rbp), %esi
movl $0x8893, %edi           # imm = 0x8893
callq 0x75a0
movl $0xc11, %edi            # imm = 0xC11
callq 0x76e0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xfb8e(%rip), %rdi      # 0x46b35
leaq 0x7b15(%rip), %rsi      # 0x3eac3
leaq 0x1117d(%rip), %rcx     # 0x48132
jmp 0x36fcc
leaq 0xfb77(%rip), %rdi      # 0x46b35
leaq 0x7afe(%rip), %rsi      # 0x3eac3
leaq 0x1111f(%rip), %rcx     # 0x480eb
movl $0x325, %edx            # imm = 0x325
callq 0x7140