// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %rdi, %r13
leaq -0x3c(%rbp), %rsi
movl $0x8b8d, %edi           # imm = 0x8B8D
callq 0x7630
leaq -0x38(%rbp), %rsi
movl $0x8069, %edi           # imm = 0x8069
callq 0x7630
leaq -0x34(%rbp), %rsi
movl $0x8894, %edi           # imm = 0x8894
callq 0x7630
leaq -0x30(%rbp), %rsi
movl $0x8895, %edi           # imm = 0x8895
callq 0x7630
movl $0xbe2, %edi            # imm = 0xBE2
callq 0x7430
movl $0x8006, %edi           # imm = 0x8006
callq 0x74f0
movl $0x302, %edi            # imm = 0x302
movl $0x303, %esi            # imm = 0x303
callq 0x7840
movl $0xb44, %edi            # imm = 0xB44
callq 0x76c0
movl $0xb71, %edi            # imm = 0xB71
callq 0x76c0
movl $0xc11, %edi            # imm = 0xC11
callq 0x7430
movl $0x84c0, %edi           # imm = 0x84C0
callq 0x7500
callq 0xa0f5
movq %rax, %r15
movss 0x4(%rax), %xmm0
leaq 0x98(%rax), %rsi
mulss 0x9c(%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
movq %r13, %rdi
callq 0x2a6f0
movss 0x59c4(%rip), %xmm0     # 0x363d8
divss (%r15), %xmm0
leaq -0x90(%rbp), %r14
movss %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%r14)
movss 0x59e7(%rip), %xmm1     # 0x3641c
divss 0x4(%r15), %xmm1
movss %xmm1, 0x14(%r14)
movups %xmm0, 0x18(%r14)
movaps 0x10733(%rip), %xmm0    # 0x41180
movups %xmm0, 0x28(%r14)
movabsq $0x3f80000000000000, %rax # imm = 0x3F80000000000000
movq %rax, 0x38(%r14)
movl 0x2a342(%rip), %edi     # 0x5ada8
callq 0x71c0
movl 0x2a33b(%rip), %edi     # 0x5adac
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x7670
movl 0x2a330(%rip), %edi     # 0x5adb0
pushq $0x1
popq %r15
movl %r15d, %esi
xorl %edx, %edx
movq %r14, %rcx
callq 0x7850
movl 0x2a31d(%rip), %esi     # 0x5adb4
movl $0x8892, %edi           # imm = 0x8892
callq 0x7580
movl 0x2a311(%rip), %edi     # 0x5adb8
callq 0x70f0
movl 0x2a30a(%rip), %edi     # 0x5adbc
callq 0x70f0
movl 0x2a303(%rip), %edi     # 0x5adc0
callq 0x70f0
movl 0x2a2f0(%rip), %edi     # 0x5adb8
pushq $0x2
popq %r14
pushq $0x14
popq %r12
movl %r14d, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl %r12d, %r8d
xorl %r9d, %r9d
callq 0x7700
movl 0x2a2d1(%rip), %edi     # 0x5adbc
pushq $0x8
popq %r9
movl %r14d, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl %r12d, %r8d
callq 0x7700
movl 0x2a2b9(%rip), %edi     # 0x5adc0
pushq $0x4
popq %r14
pushq $0x10
popq %r9
movl %r14d, %esi
movl $0x1401, %edx           # imm = 0x1401
movl %r15d, %ecx
movl %r12d, %r8d
callq 0x7700
movq %r13, -0x48(%rbp)
movslq 0x10(%r13), %rax
cmpq %rax, %rbx
jge 0x30c53
movq 0x8(%r13), %rax
movq (%rax,%rbx,8), %r15
movl 0x2a273(%rip), %esi     # 0x5adb4
movl $0x8892, %edi           # imm = 0x8892
callq 0x7580
leaq 0x20(%r15), %rdi
movslq 0x20(%r15), %rax
imulq $0x14, %rax, %r12
callq 0x312e4
movl $0x8892, %edi           # imm = 0x8892
movq %r12, %rsi
movq %rax, %rdx
movl $0x88e0, %ecx           # imm = 0x88E0
callq 0x7190
movl 0x2a24d(%rip), %esi     # 0x5adc4
movl $0x8893, %edi           # imm = 0x8893
callq 0x7580
leaq 0x10(%r15), %rdi
movslq 0x10(%r15), %r12
addq %r12, %r12
callq 0x31312
movl $0x8893, %edi           # imm = 0x8893
movq %r12, %rsi
movq %rax, %rdx
movl $0x88e0, %ecx           # imm = 0x88E0
callq 0x7190
movq 0x8(%r15), %rax
xorl %r12d, %r12d
movq %rax, %r13
movslq (%r15), %rcx
imulq $0x30, %rcx, %rcx
addq %rax, %rcx
cmpq %rcx, %r13
je 0x30c47
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x30bd6
movq %r15, %rdi
movq %r13, %rsi
callq *%rax
jmp 0x30c32
movl 0x18(%r13), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x7870
movss 0x4(%r13), %xmm0
cvttss2si %xmm0, %edi
movss 0x10(%r13), %xmm1
movss -0x2c(%rbp), %xmm2
subss %xmm1, %xmm2
cvttss2si %xmm2, %esi
movss 0xc(%r13), %xmm2
subss %xmm0, %xmm2
cvttss2si %xmm2, %edx
subss 0x8(%r13), %xmm1
cvttss2si %xmm1, %ecx
callq 0x7470
movl (%r13), %esi
movl %r14d, %edi
movl $0x1403, %edx           # imm = 0x1403
movq %r12, %rcx
callq 0x71d0
movl (%r13), %eax
leaq (%r12,%rax,2), %r12
addq $0x30, %r13
movq 0x8(%r15), %rax
jmp 0x30bb0
incq %rbx
movq -0x48(%rbp), %r13
jmp 0x30b26
movl 0x2a15f(%rip), %edi     # 0x5adb8
callq 0x75c0
movl 0x2a158(%rip), %edi     # 0x5adbc
callq 0x75c0
movl 0x2a151(%rip), %edi     # 0x5adc0
callq 0x75c0
movl -0x3c(%rbp), %edi
callq 0x71c0
movl -0x38(%rbp), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x7870
movl -0x34(%rbp), %esi
movl $0x8892, %edi           # imm = 0x8892
callq 0x7580
movl -0x30(%rbp), %esi
movl $0x8893, %edi           # imm = 0x8893
callq 0x7580
movl $0xc11, %edi            # imm = 0xC11
callq 0x76c0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq