// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/include/imgui/imgui_draw.cpp
// Function: ImDrawListSplitter::Merge(ImDrawList*)
void ImDrawListSplitter::Merge(ImDrawList* draw_list)
{
    // Note that we never use or rely on _Channels.Size because it is merely a buffer that we never shrink back to 0 to keep all sub-buffers ready for use.
    if (_Count <= 1)
        return;

    SetCurrentChannel(draw_list, 0);
    draw_list->_PopUnusedDrawCmd();

    // Calculate our final buffer sizes. Also fix the incorrect IdxOffset values in each command.
    int new_cmd_buffer_count = 0;
    int new_idx_buffer_count = 0;
    ImDrawCmd* last_cmd = (_Count > 0 && draw_list->CmdBuffer.Size > 0) ? &draw_list->CmdBuffer.back() : NULL;
    int idx_offset = last_cmd ? last_cmd->IdxOffset + last_cmd->ElemCount : 0;
    for (int i = 1; i < _Count; i++)
    {
        ImDrawChannel& ch = _Channels[i];

        // Equivalent of PopUnusedDrawCmd() for this channel's cmdbuffer and except we don't need to test for UserCallback.
        if (ch._CmdBuffer.Size > 0 && ch._CmdBuffer.back().ElemCount == 0)
            ch._CmdBuffer.pop_back();

        if (ch._CmdBuffer.Size > 0 && last_cmd != NULL)
        {
            ImDrawCmd* next_cmd = &ch._CmdBuffer[0];
            if (ImDrawCmd_HeaderCompare(last_cmd, next_cmd) == 0 && last_cmd->UserCallback == NULL && next_cmd->UserCallback == NULL)
            {
                // Merge previous channel last draw command with current channel first draw command if matching.
                last_cmd->ElemCount += next_cmd->ElemCount;
                idx_offset += next_cmd->ElemCount;
                ch._CmdBuffer.erase(ch._CmdBuffer.Data); // FIXME-OPT: Improve for multiple merges.
            }
        }
        if (ch._CmdBuffer.Size > 0)
            last_cmd = &ch._CmdBuffer.back();
        new_cmd_buffer_count += ch._CmdBuffer.Size;
        new_idx_buffer_count += ch._IdxBuffer.Size;
        for (int cmd_n = 0; cmd_n < ch._CmdBuffer.Size; cmd_n++)
        {
            ch._CmdBuffer.Data[cmd_n].IdxOffset = idx_offset;
            idx_offset += ch._CmdBuffer.Data[cmd_n].ElemCount;
        }
    }
    draw_list->CmdBuffer.resize(draw_list->CmdBuffer.Size + new_cmd_buffer_count);
    draw_list->IdxBuffer.resize(draw_list->IdxBuffer.Size + new_idx_buffer_count);

    // Write commands and indices in order (they are fairly small structures, we don't copy vertices only indices)
    ImDrawCmd* cmd_write = draw_list->CmdBuffer.Data + draw_list->CmdBuffer.Size - new_cmd_buffer_count;
    ImDrawIdx* idx_write = draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size - new_idx_buffer_count;
    for (int i = 1; i < _Count; i++)
    {
        ImDrawChannel& ch = _Channels[i];
        if (int sz = ch._CmdBuffer.Size) { memcpy(cmd_write, ch._CmdBuffer.Data, sz * sizeof(ImDrawCmd)); cmd_write += sz; }
        if (int sz = ch._IdxBuffer.Size) { memcpy(idx_write, ch._IdxBuffer.Data, sz * sizeof(ImDrawIdx)); idx_write += sz; }
    }
    draw_list->_IdxWritePtr = idx_write;

    // Ensure there's always a non-callback draw command trailing the command-buffer
    if (draw_list->CmdBuffer.Size == 0 || draw_list->CmdBuffer.back().UserCallback != NULL)
        draw_list->AddDrawCmd();

    // If current command is used with different settings we need to add a new command
    ImDrawCmd* curr_cmd = &draw_list->CmdBuffer.Data[draw_list->CmdBuffer.Size - 1];
    if (curr_cmd->ElemCount == 0)
        ImDrawCmd_HeaderCopy(curr_cmd, &draw_list->_CmdHeader); // Copy ClipRect, TextureId, VtxOffset
    else if (ImDrawCmd_HeaderCompare(curr_cmd, &draw_list->_CmdHeader) != 0)
        draw_list->AddDrawCmd();

    _Count = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpl $0x2, 0x4(%rdi)
jl 0x7a94b
xorl %r13d, %r13d
xorl %edx, %edx
movq %rdi, -0x38(%rbp)
movq %rsi, %rbx
callq 0x7a998
movq %rbx, -0x30(%rbp)
movq %rbx, %rdi
callq 0x7590a
movq -0x38(%rbp), %r8
movl 0x4(%r8), %eax
movl $0x0, %r12d
testl %eax, %eax
jle 0x7a6e4
movq -0x30(%rbp), %rdx
movslq (%rdx), %rcx
xorl %r13d, %r13d
testq %rcx, %rcx
jle 0x7a5d2
imulq $0x38, %rcx, %rcx
addq 0x8(%rdx), %rcx
movq %rcx, %r9
addq $-0x38, %r9
je 0x7a5d2
movl -0x18(%rcx), %r15d
addl -0x1c(%rcx), %r15d
jmp 0x7a5d8
xorl %r9d, %r9d
xorl %r15d, %r15d
cmpl $0x1, %eax
je 0x7a6e4
xorl %r12d, %r12d
movl $0x1, %r14d
xorl %r13d, %r13d
movslq 0x8(%r8), %rax
cmpq %rax, %r14
jge 0x7a95a
movq 0x10(%r8), %rax
movq %r14, %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rbx
movslq (%rax,%rcx), %rax
testq %rax, %rax
jle 0x7a6cb
movq 0x8(%rbx), %rcx
imulq $0x38, %rax, %rdx
cmpl $0x0, -0x18(%rcx,%rdx)
jne 0x7a629
decl %eax
movl %eax, (%rbx)
testl %eax, %eax
je 0x7a69c
testq %r9, %r9
je 0x7a69c
movq 0x8(%rbx), %rdi
movdqu (%r9), %xmm0
movdqu 0xc(%r9), %xmm1
movdqu (%rdi), %xmm2
pcmpeqb %xmm0, %xmm2
movdqu 0xc(%rdi), %xmm0
pcmpeqb %xmm1, %xmm0
pand %xmm2, %xmm0
pmovmskb %xmm0, %ecx
cmpl $0xffff, %ecx           # imm = 0xFFFF
jne 0x7a6a0
movq 0x28(%rdi), %rcx
orq 0x28(%r9), %rcx
jne 0x7a6a0
movl 0x20(%rdi), %ecx
addl %ecx, 0x20(%r9)
addl 0x20(%rdi), %r15d
movl %eax, %eax
leaq 0x38(%rdi), %rsi
imulq $0x38, %rax, %rdx
addq $-0x38, %rdx
movq %r9, -0x40(%rbp)
callq 0xc130
movq -0x40(%rbp), %r9
movq -0x38(%rbp), %r8
movl (%rbx), %eax
decl %eax
movl %eax, (%rbx)
testl %eax, %eax
jle 0x7a6cb
movq 0x8(%rbx), %rdx
movl %eax, %esi
imulq $0x38, %rsi, %rcx
leaq (%rdx,%rcx), %r9
addq $-0x38, %r9
movl 0x10(%rbx), %ecx
addq $0x20, %rdx
movl %r15d, -0x4(%rdx)
addl (%rdx), %r15d
addq $0x38, %rdx
decq %rsi
jne 0x7a6b9
jmp 0x7a6ce
movl 0x10(%rbx), %ecx
addl %ecx, %r13d
addl %eax, %r12d
incq %r14
movslq 0x4(%r8), %rax
cmpq %rax, %r14
jl 0x7a5ed
movq -0x30(%rbp), %rdi
movl (%rdi), %r14d
addl %r12d, %r14d
movl 0x4(%rdi), %eax
cmpl %r14d, %eax
jge 0x7a75a
testl %eax, %eax
je 0x7a707
movl %eax, %ebx
shrl $0x1f, %ebx
addl %eax, %ebx
sarl %ebx
addl %eax, %ebx
jmp 0x7a70c
movl $0x8, %ebx
cmpl %r14d, %ebx
cmovlel %r14d, %ebx
movslq %ebx, %rax
imulq $0x38, %rax, %rdi
callq 0x41c63
movq %rax, %r15
movq -0x30(%rbp), %rdi
movq 0x8(%rdi), %rsi
testq %rsi, %rsi
je 0x7a74f
movslq (%rdi), %rax
imulq $0x38, %rax, %rdx
movq %r15, %rdi
callq 0xc080
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x41d3c
movq -0x30(%rbp), %rdi
movq %r15, 0x8(%rdi)
movl %ebx, 0x4(%rdi)
movq -0x38(%rbp), %r8
movl %r14d, (%rdi)
movslq 0x10(%rdi), %r15
movslq %r13d, %rbx
addq %rbx, %r15
movl 0x14(%rdi), %eax
cmpl %r15d, %eax
jge 0x7a785
testl %eax, %eax
je 0x7a78b
movl %eax, %r14d
shrl $0x1f, %r14d
addl %eax, %r14d
sarl %r14d
addl %eax, %r14d
jmp 0x7a791
movq 0x18(%rdi), %r13
jmp 0x7a7e2
movl $0x8, %r14d
cmpl %r15d, %r14d
cmovlel %r15d, %r14d
movslq %r14d, %rdi
addq %rdi, %rdi
callq 0x41c63
movq %rax, %r13
movq -0x30(%rbp), %rdi
movq 0x18(%rdi), %rsi
testq %rsi, %rsi
je 0x7a7d3
movslq 0x10(%rdi), %rdx
addq %rdx, %rdx
movq %r13, %rdi
callq 0xc080
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x41d3c
movq -0x30(%rbp), %rdi
movq %r13, 0x18(%rdi)
movl %r14d, 0x14(%rdi)
movl (%rdi), %r14d
movq -0x38(%rbp), %r8
movl %r15d, 0x10(%rdi)
leaq (,%r15,2), %rax
addq %r13, %rax
addq %rbx, %rbx
subq %rbx, %rax
cmpl $0x2, 0x4(%r8)
jl 0x7a8a4
movq %rax, -0x40(%rbp)
movslq %r14d, %rax
imulq $0x38, %rax, %rax
addq 0x8(%rdi), %rax
movslq %r12d, %rcx
negq %rcx
imulq $0x38, %rcx, %r12
addq %rax, %r12
movl $0x1, %ebx
movl $0x38, %r14d
movslq 0x8(%r8), %rax
cmpq %rax, %rbx
jge 0x7a95a
movq 0x10(%r8), %r15
movslq -0x18(%r15,%r14), %rax
testq %rax, %rax
je 0x7a85b
movq -0x10(%r15,%r14), %rsi
imulq $0x38, %rax, %r13
movq %r12, %rdi
movq %r13, %rdx
callq 0xc080
addq %r13, %r12
movslq -0x8(%r15,%r14), %r13
testq %r13, %r13
je 0x7a885
movq (%r15,%r14), %rsi
leaq (,%r13,2), %rdx
movq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0xc080
leaq (%r15,%r13,2), %r15
movq %r15, -0x40(%rbp)
incq %rbx
movq -0x38(%rbp), %r8
movslq 0x4(%r8), %rax
addq $0x20, %r14
cmpq %rax, %rbx
jl 0x7a829
movq -0x30(%rbp), %rdi
movl (%rdi), %r14d
movq -0x40(%rbp), %rax
movq %rax, 0x50(%rdi)
testl %r14d, %r14d
je 0x7a8ca
jle 0x7a979
movq 0x8(%rdi), %rax
movl %r14d, %ecx
imulq $0x38, %rcx, %rcx
cmpq $0x0, -0x10(%rax,%rcx)
movq -0x30(%rbp), %rdi
je 0x7a8de
callq 0x757a8
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %r8
movq 0x8(%rdi), %rax
movl (%rdi), %r14d
movslq %r14d, %rcx
imulq $0x38, %rcx, %rcx
addq %rax, %rcx
addq $-0x38, %rcx
leaq 0x88(%rdi), %rax
cmpl $0x0, 0x20(%rcx)
je 0x7a931
movdqu (%rcx), %xmm0
movdqu 0xc(%rcx), %xmm1
movdqu (%rax), %xmm2
pcmpeqb %xmm0, %xmm2
movdqu 0xc(%rax), %xmm0
pcmpeqb %xmm1, %xmm0
pand %xmm2, %xmm0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x7a943
movq -0x30(%rbp), %rdi
callq 0x757a8
movq -0x38(%rbp), %r8
jmp 0x7a943
movdqu (%rax), %xmm0
movdqu 0xc(%rax), %xmm1
movdqu %xmm1, 0xc(%rcx)
movdqu %xmm0, (%rcx)
movl $0x1, 0x4(%r8)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3ed17(%rip), %rdi     # 0xb9678
leaq 0x3ed23(%rip), %rsi     # 0xb968b
leaq 0x541ac(%rip), %rcx     # 0xceb1b
movl $0x65c, %edx            # imm = 0x65C
callq 0xc140
leaq 0x5302a(%rip), %rdi     # 0xcd9aa
leaq 0x3ed04(%rip), %rsi     # 0xb968b
leaq 0x4026e(%rip), %rcx     # 0xbabfc
movl $0x666, %edx            # imm = 0x666
callq 0xc140