// File: /workspace/github_cpp_makefile_star2_O1/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 0x7660
leaq -0x38(%rbp), %rsi
movl $0x8069, %edi           # imm = 0x8069
callq 0x7660
leaq -0x34(%rbp), %rsi
movl $0x8894, %edi           # imm = 0x8894
callq 0x7660
leaq -0x30(%rbp), %rsi
movl $0x8895, %edi           # imm = 0x8895
callq 0x7660
movl $0xbe2, %edi            # imm = 0xBE2
callq 0x7450
movl $0x8006, %edi           # imm = 0x8006
callq 0x7500
movl $0x302, %edi            # imm = 0x302
movl $0x303, %esi            # imm = 0x303
callq 0x7880
movl $0xb44, %edi            # imm = 0xB44
callq 0x76f0
movl $0xb71, %edi            # imm = 0xB71
callq 0x76f0
movl $0xc11, %edi            # imm = 0xC11
callq 0x7450
movl $0x84c0, %edi           # imm = 0x84C0
callq 0x7510
callq 0xb1e1
movq %rax, %r15
movss 0x4(%rax), %xmm0
leaq 0x98(%rax), %rsi
mulss 0x9c(%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x314a4
movss 0x5d68(%rip), %xmm0     # 0x3d3c4
divss (%r15), %xmm0
leaq -0x80(%rbp), %r14
movss %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%r14)
movss 0x5d92(%rip), %xmm1     # 0x3d40c
divss 0x4(%r15), %xmm1
movss %xmm1, 0x14(%r14)
movups %xmm0, 0x18(%r14)
movaps 0x108ae(%rip), %xmm0    # 0x47f40
movups %xmm0, 0x28(%r14)
movabsq $0x3f80000000000000, %rax # imm = 0x3F80000000000000
movq %rax, 0x38(%r14)
movl 0x2870d(%rip), %edi     # 0x5fdb8
callq 0x71d0
movl 0x28706(%rip), %edi     # 0x5fdbc
xorl %esi, %esi
callq 0x76a0
movl 0x286fd(%rip), %edi     # 0x5fdc0
movl $0x1, %esi
xorl %edx, %edx
movq %r14, %rcx
callq 0x7890
movl 0x286ec(%rip), %esi     # 0x5fdc4
movl $0x8892, %edi           # imm = 0x8892
callq 0x75b0
movl 0x286e0(%rip), %edi     # 0x5fdc8
callq 0x70f0
movl 0x286d9(%rip), %edi     # 0x5fdcc
callq 0x70f0
movl 0x286d2(%rip), %edi     # 0x5fdd0
callq 0x70f0
movl 0x286bf(%rip), %edi     # 0x5fdc8
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x14, %r8d
xorl %r9d, %r9d
callq 0x7750
movl 0x286a3(%rip), %edi     # 0x5fdcc
movl $0x8, %r9d
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x14, %r8d
callq 0x7750
movl 0x28684(%rip), %edi     # 0x5fdd0
movl $0x10, %r9d
movl $0x4, %esi
movl $0x1401, %edx           # imm = 0x1401
movl $0x1, %ecx
movl $0x14, %r8d
callq 0x7750
cmpl $0x0, 0x10(%rbx)
jle 0x3789f
xorl %r13d, %r13d
movq 0x8(%rbx), %rax
movq (%rax,%r13,8), %r14
movl 0x2863d(%rip), %esi     # 0x5fdc4
movl $0x8892, %edi           # imm = 0x8892
callq 0x75b0
movslq 0x20(%r14), %rax
testq %rax, %rax
jle 0x3791f
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 0x28615(%rip), %esi     # 0x5fdd4
movl $0x8893, %edi           # imm = 0x8893
callq 0x75b0
movl 0x10(%r14), %esi
testl %esi, %esi
jle 0x37908
addq %rsi, %rsi
movq 0x18(%r14), %rdx
movl $0x8893, %edi           # imm = 0x8893
movl $0x88e0, %ecx           # imm = 0x88E0
callq 0x7190
cmpl $0x0, (%r14)
je 0x3788f
movq 0x8(%r14), %r15
xorl %r12d, %r12d
movq 0x20(%r15), %rax
testq %rax, %rax
je 0x3780f
movq %r14, %rdi
movq %r15, %rsi
callq *%rax
jmp 0x3786c
movl 0x18(%r15), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x78b0
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 0x7480
movl (%r15), %esi
movl $0x4, %edi
movl $0x1403, %edx           # imm = 0x1403
movq %r12, %rcx
callq 0x71e0
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 0x377fc
incq %r13
movslq 0x10(%rbx), %rax
cmpq %rax, %r13
jl 0x37779
movl 0x28523(%rip), %edi     # 0x5fdc8
callq 0x75f0
movl 0x2851c(%rip), %edi     # 0x5fdcc
callq 0x75f0
movl 0x28515(%rip), %edi     # 0x5fdd0
callq 0x75f0
movl -0x3c(%rbp), %edi
callq 0x71d0
movl -0x38(%rbp), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x78b0
movl -0x34(%rbp), %esi
movl $0x8892, %edi           # imm = 0x8892
callq 0x75b0
movl -0x30(%rbp), %esi
movl $0x8893, %edi           # imm = 0x8893
callq 0x75b0
movl $0xc11, %edi            # imm = 0xC11
callq 0x76f0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf2a6(%rip), %rdi      # 0x46bb5
leaq 0x717d(%rip), %rsi      # 0x3ea93
leaq 0x1086d(%rip), %rcx     # 0x4818a
jmp 0x37934
leaq 0xf28f(%rip), %rdi      # 0x46bb5
leaq 0x7166(%rip), %rsi      # 0x3ea93
leaq 0x1080f(%rip), %rcx     # 0x48143
movl $0x325, %edx            # imm = 0x325
callq 0x7140