// File: Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::LoadIniSettingsFromMemory(char const*, unsigned long)
void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
{
    ImGuiContext& g = *GImGui;
    IM_ASSERT(g.Initialized);
    //IM_ASSERT(!g.WithinFrameScope && "Cannot be called between NewFrame() and EndFrame()");
    //IM_ASSERT(g.SettingsLoaded == false && g.FrameCount == 0);

    // For user convenience, we allow passing a non zero-terminated string (hence the ini_size parameter).
    // For our convenience and to make the code simpler, we'll also write zero-terminators within the buffer. So let's create a writable copy..
    if (ini_size == 0)
        ini_size = strlen(ini_data);
    g.SettingsIniData.Buf.resize((int)ini_size + 1);
    char* const buf = g.SettingsIniData.Buf.Data;
    char* const buf_end = buf + ini_size;
    memcpy(buf, ini_data, ini_size);
    buf_end[0] = 0;

    // Call pre-read handlers
    // Some types will clear their data (e.g. dock information) some types will allow merge/override (window)
    for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++)
        if (g.SettingsHandlers[handler_n].ReadInitFn)
            g.SettingsHandlers[handler_n].ReadInitFn(&g, &g.SettingsHandlers[handler_n]);

    void* entry_data = NULL;
    ImGuiSettingsHandler* entry_handler = NULL;

    char* line_end = NULL;
    for (char* line = buf; line < buf_end; line = line_end + 1)
    {
        // Skip new lines markers, then find end of the line
        while (*line == '\n' || *line == '\r')
            line++;
        line_end = line;
        while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
            line_end++;
        line_end[0] = 0;
        if (line[0] == ';')
            continue;
        if (line[0] == '[' && line_end > line && line_end[-1] == ']')
        {
            // Parse "[Type][Name]". Note that 'Name' can itself contains [] characters, which is acceptable with the current format and parsing code.
            line_end[-1] = 0;
            const char* name_end = line_end - 1;
            const char* type_start = line + 1;
            char* type_end = (char*)(void*)ImStrchrRange(type_start, name_end, ']');
            const char* name_start = type_end ? ImStrchrRange(type_end + 1, name_end, '[') : NULL;
            if (!type_end || !name_start)
                continue;
            *type_end = 0; // Overwrite first ']'
            name_start++;  // Skip second '['
            entry_handler = FindSettingsHandler(type_start);
            entry_data = entry_handler ? entry_handler->ReadOpenFn(&g, entry_handler, name_start) : NULL;
        }
        else if (entry_handler != NULL && entry_data != NULL)
        {
            // Let type handler parse the line
            entry_handler->ReadLineFn(&g, entry_handler, entry_data, line);
        }
    }
    g.SettingsLoaded = true;

    // [DEBUG] Restore untouched copy so it can be browsed in Metrics (not strictly necessary)
    memcpy(buf, ini_data, ini_size);

    // Call post-read handlers
    for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++)
        if (g.SettingsHandlers[handler_n].ApplyAllFn)
            g.SettingsHandlers[handler_n].ApplyAllFn(&g, &g.SettingsHandlers[handler_n]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x131bf6(%rip), %rax    # 0x212f40
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
testb $0x1, (%rax)
je 0xe1359
jmp 0xe1378
leaq 0x92628(%rip), %rdi     # 0x173988
leaq 0x91ba2(%rip), %rsi     # 0x172f09
movl $0x27a5, %edx           # imm = 0x27A5
leaq 0x94570(%rip), %rcx     # 0x1758e3
callq 0xd180
cmpq $0x0, -0x10(%rbp)
jne 0xe138c
movq -0x8(%rbp), %rdi
callq 0xd410
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rdi
addq $0x30e8, %rdi           # imm = 0x30E8
movq -0x10(%rbp), %rax
movl %eax, %esi
addl $0x1, %esi
callq 0xe84f0
movq -0x18(%rbp), %rax
movq 0x30f0(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0xd0a0
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x30f8(%rcx), %eax
jge 0xe145e
movq -0x18(%rbp), %rdi
addq $0x30f8, %rdi           # imm = 0x30F8
movl -0x2c(%rbp), %esi
callq 0xec5a0
cmpq $0x0, 0x18(%rax)
je 0xe1451
movq -0x18(%rbp), %rdi
addq $0x30f8, %rdi           # imm = 0x30F8
movl -0x2c(%rbp), %esi
callq 0xec5a0
movq 0x18(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rdi
addq $0x30f8, %rdi           # imm = 0x30F8
movl -0x2c(%rbp), %esi
callq 0xec5a0
movq -0x88(%rbp), %rdi
movq %rax, %rsi
movq -0x80(%rbp), %rax
callq *%rax
jmp 0xe1453
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xe13df
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0xe1691
jmp 0xe148e
movq -0x50(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0xa, %ecx
movb %al, -0x89(%rbp)
je 0xe14b5
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xd, %eax
sete %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0xe14c1
jmp 0xe14cf
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xe148e
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
xorl %eax, %eax
cmpq -0x28(%rbp), %rcx
movb %al, -0x8a(%rbp)
jae 0xe1510
movq -0x48(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, -0x8a(%rbp)
je 0xe1510
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xd, %eax
setne %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
testb $0x1, %al
jne 0xe151c
jmp 0xe152a
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xe14d7
movq -0x48(%rbp), %rax
movb $0x0, (%rax)
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3b, %eax
jne 0xe1542
jmp 0xe1680
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5b, %eax
jne 0xe1654
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0xe1654
movq -0x48(%rbp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x5d, %eax
jne 0xe1654
movq -0x48(%rbp), %rax
movb $0x0, -0x1(%rax)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl $0x5d, %edx
callq 0xc4980
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0xe15cd
movq -0x68(%rbp), %rdi
addq $0x1, %rdi
movq -0x58(%rbp), %rsi
movl $0x5b, %edx
callq 0xc4980
movq %rax, -0x98(%rbp)
jmp 0xe15d8
xorl %eax, %eax
movq %rax, -0x98(%rbp)
jmp 0xe15d8
movq -0x98(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0xe15f1
cmpq $0x0, -0x70(%rbp)
jne 0xe15f6
jmp 0xe1680
movq -0x68(%rbp), %rax
movb $0x0, (%rax)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdi
callq 0xe1180
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0xe163c
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq *%rax
movq %rax, -0xa0(%rbp)
jmp 0xe1647
xorl %eax, %eax
movq %rax, -0xa0(%rbp)
jmp 0xe1647
movq -0xa0(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xe167e
cmpq $0x0, -0x40(%rbp)
je 0xe167c
cmpq $0x0, -0x38(%rbp)
je 0xe167c
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq *%rax
jmp 0xe167e
jmp 0xe1680
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xe147e
movq -0x18(%rbp), %rax
movb $0x1, 0x30e1(%rax)
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0xd0a0
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x30f8(%rcx), %eax
jge 0xe173c
movq -0x18(%rbp), %rdi
addq $0x30f8, %rdi           # imm = 0x30F8
movl -0x74(%rbp), %esi
callq 0xec5a0
cmpq $0x0, 0x30(%rax)
je 0xe172c
movq -0x18(%rbp), %rdi
addq $0x30f8, %rdi           # imm = 0x30F8
movl -0x74(%rbp), %esi
callq 0xec5a0
movq 0x30(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rdi
addq $0x30f8, %rdi           # imm = 0x30F8
movl -0x74(%rbp), %esi
callq 0xec5a0
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
movq -0xa8(%rbp), %rax
callq *%rax
jmp 0xe172e
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xe16b4
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)