// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGui::DataTypeApplyOpFromText(char const*, char const*, int, void*, char const*)
bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* p_data, const char* format)
{
    while (ImCharIsBlankA(*buf))
        buf++;

    // We don't support '-' op because it would conflict with inputing negative value.
    // Instead you can use +-100 to subtract from an existing value
    char op = buf[0];
    if (op == '+' || op == '*' || op == '/')
    {
        buf++;
        while (ImCharIsBlankA(*buf))
            buf++;
    }
    else
    {
        op = 0;
    }
    if (!buf[0])
        return false;

    // Copy the value in an opaque buffer so we can compare at the end of the function if it changed at all.
    const ImGuiDataTypeInfo* type_info = DataTypeGetInfo(data_type);
    ImGuiDataTypeTempStorage data_backup;
    memcpy(&data_backup, p_data, type_info->Size);

    if (format == NULL)
        format = type_info->ScanFmt;

    // FIXME-LEGACY: The aim is to remove those operators and write a proper expression evaluator at some point..
    int arg1i = 0;
    if (data_type == ImGuiDataType_S32)
    {
        int* v = (int*)p_data;
        int arg0i = *v;
        float arg1f = 0.0f;
        if (op && sscanf(initial_value_buf, format, &arg0i) < 1)
            return false;
        // Store operand in a float so we can use fractional value for multipliers (*1.1), but constant always parsed as integer so we can fit big integers (e.g. 2000000003) past float precision
        if (op == '+')      { if (sscanf(buf, "%d", &arg1i)) *v = (int)(arg0i + arg1i); }                   // Add (use "+-" to subtract)
        else if (op == '*') { if (sscanf(buf, "%f", &arg1f)) *v = (int)(arg0i * arg1f); }                   // Multiply
        else if (op == '/') { if (sscanf(buf, "%f", &arg1f) && arg1f != 0.0f) *v = (int)(arg0i / arg1f); }  // Divide
        else                { if (sscanf(buf, format, &arg1i) == 1) *v = arg1i; }                           // Assign constant
    }
    else if (data_type == ImGuiDataType_Float)
    {
        // For floats we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in
        format = "%f";
        float* v = (float*)p_data;
        float arg0f = *v, arg1f = 0.0f;
        if (op && sscanf(initial_value_buf, format, &arg0f) < 1)
            return false;
        if (sscanf(buf, format, &arg1f) < 1)
            return false;
        if (op == '+')      { *v = arg0f + arg1f; }                    // Add (use "+-" to subtract)
        else if (op == '*') { *v = arg0f * arg1f; }                    // Multiply
        else if (op == '/') { if (arg1f != 0.0f) *v = arg0f / arg1f; } // Divide
        else                { *v = arg1f; }                            // Assign constant
    }
    else if (data_type == ImGuiDataType_Double)
    {
        format = "%lf"; // scanf differentiate float/double unlike printf which forces everything to double because of ellipsis
        double* v = (double*)p_data;
        double arg0f = *v, arg1f = 0.0;
        if (op && sscanf(initial_value_buf, format, &arg0f) < 1)
            return false;
        if (sscanf(buf, format, &arg1f) < 1)
            return false;
        if (op == '+')      { *v = arg0f + arg1f; }                    // Add (use "+-" to subtract)
        else if (op == '*') { *v = arg0f * arg1f; }                    // Multiply
        else if (op == '/') { if (arg1f != 0.0f) *v = arg0f / arg1f; } // Divide
        else                { *v = arg1f; }                            // Assign constant
    }
    else if (data_type == ImGuiDataType_U32 || data_type == ImGuiDataType_S64 || data_type == ImGuiDataType_U64)
    {
        // All other types assign constant
        // We don't bother handling support for legacy operators since they are a little too crappy. Instead we will later implement a proper expression evaluator in the future.
        sscanf(buf, format, p_data);
    }
    else
    {
        // Small types need a 32-bit buffer to receive the result from scanf()
        int v32;
        sscanf(buf, format, &v32);
        if (data_type == ImGuiDataType_S8)
            *(ImS8*)p_data = (ImS8)ImClamp(v32, (int)IM_S8_MIN, (int)IM_S8_MAX);
        else if (data_type == ImGuiDataType_U8)
            *(ImU8*)p_data = (ImU8)ImClamp(v32, (int)IM_U8_MIN, (int)IM_U8_MAX);
        else if (data_type == ImGuiDataType_S16)
            *(ImS16*)p_data = (ImS16)ImClamp(v32, (int)IM_S16_MIN, (int)IM_S16_MAX);
        else if (data_type == ImGuiDataType_U16)
            *(ImU16*)p_data = (ImU16)ImClamp(v32, (int)IM_U16_MIN, (int)IM_U16_MAX);
        else
            IM_ASSERT(0);
    }

    return memcmp(&data_backup, p_data, type_info->Size) != 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r14d
movq %rdi, %r15
movabsq $0x100000200, %rax      # imm = 0x100000200
movzbl (%r15), %ebx
cmpq $0x2f, %rbx
ja 0x9519b
btq %rbx, %rax
jae 0x95178
incq %r15
jmp 0x95163
movabsq $0x8c0000000000, %rax   # imm = 0x8C0000000000
btq %rbx, %rax
jae 0x9519b
incq %r15
movzbl (%r15), %eax
cmpl $0x20, %eax
je 0x95188
cmpl $0x9, %eax
je 0x95188
jmp 0x9519f
movl %ebx, %eax
xorl %ebx, %ebx
testb %al, %al
je 0x953a2
movq %rsi, -0x58(%rbp)
movq %r8, -0x68(%rbp)
cmpl $0xa, %r14d
jae 0x955ae
movl %r14d, %r13d
movq %r13, -0x60(%rbp)
shlq $0x5, %r13
leaq 0x61845(%rip), %r12     # 0xf6a10
movq (%r13,%r12), %rdx
leaq -0x70(%rbp), %rdi
movq %rcx, -0x38(%rbp)
movq %rcx, %rsi
movq %rdx, -0x48(%rbp)
callq 0xc080
movq -0x68(%rbp), %rsi
testq %rsi, %rsi
jne 0x951f5
addq %r13, %r12
movq 0x18(%r12), %rsi
movl $0x0, -0x4c(%rbp)
cmpl $0x9, %r14d
je 0x95321
cmpl $0x8, %r14d
movq -0x38(%rbp), %rdx
je 0x9529d
cmpl $0x4, %r14d
jne 0x953a9
movl (%rdx), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x40(%rbp)
testb %bl, %bl
je 0x95414
leaq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rdi
movq %rsi, %r14
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
jle 0x953a2
cmpb $0x2a, %bl
je 0x95560
movzbl %bl, %eax
cmpl $0x2f, %eax
je 0x9551e
cmpl $0x2b, %eax
movq %r14, %rsi
jne 0x95414
leaq 0x271de(%rip), %rsi     # 0xbc452
leaq -0x4c(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
je 0x95591
movl -0x4c(%rbp), %eax
addl -0x30(%rbp), %eax
jmp 0x9558f
movss (%rdx), %xmm0
movss %xmm0, -0x30(%rbp)
movl $0x0, -0x40(%rbp)
testb %bl, %bl
je 0x952cf
leaq 0x2a231(%rip), %rsi     # 0xbf4e9
leaq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
jle 0x953a2
leaq 0x2a213(%rip), %rsi     # 0xbf4e9
leaq -0x40(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
jle 0x953a2
cmpb $0x2a, %bl
je 0x954b9
movzbl %bl, %eax
cmpl $0x2f, %eax
movq -0x48(%rbp), %rdx
je 0x95497
cmpl $0x2b, %eax
movq -0x38(%rbp), %rsi
jne 0x954f1
movss -0x30(%rbp), %xmm0
addss -0x40(%rbp), %xmm0
jmp 0x954f6
movq -0x38(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
testb %bl, %bl
je 0x95354
leaq 0x3c2ce(%rip), %rsi     # 0xd160f
leaq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
jle 0x953a2
leaq 0x3c2b4(%rip), %rsi     # 0xd160f
leaq -0x40(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
jle 0x953a2
cmpb $0x2a, %bl
je 0x954ff
movzbl %bl, %eax
cmpl $0x2f, %eax
movq -0x48(%rbp), %rdx
je 0x954cd
cmpl $0x2b, %eax
movq -0x38(%rbp), %rsi
jne 0x95513
movsd -0x30(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
jmp 0x95518
xorl %eax, %eax
jmp 0x9559f
leal -0x5(%r14), %eax
cmpl $0x2, %eax
ja 0x953c9
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
jmp 0x95591
leaq -0x30(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
cmpl $0x3, %r14d
ja 0x955cd
leaq 0x3ba88(%rip), %rax     # 0xd0e70
movq -0x60(%rbp), %rcx
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
movq -0x48(%rbp), %rdx
jmpq *%rcx
movl -0x30(%rbp), %eax
cmpl $0x7f, %eax
movl $0x7f, %ecx
cmovll %eax, %ecx
cmpl $-0x7f, %ecx
movl $0xffffff80, %eax       # imm = 0xFFFFFF80
cmovgel %ecx, %eax
jmp 0x9548c
leaq -0x4c(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
cmpl $0x1, %eax
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
jne 0x95591
movl -0x4c(%rbp), %eax
jmp 0x9558f
movl -0x30(%rbp), %eax
movl $0x7fff, %ecx           # imm = 0x7FFF
cmpl %ecx, %eax
cmovll %eax, %ecx
cmpl $0xffff8001, %ecx       # imm = 0xFFFF8001
movl $0xffff8000, %eax       # imm = 0xFFFF8000
cmovgel %ecx, %eax
jmp 0x9546c
movl -0x30(%rbp), %eax
movl $0xffff, %ecx           # imm = 0xFFFF
cmpl %ecx, %eax
cmovll %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovgl %ecx, %eax
movq -0x38(%rbp), %rsi
movw %ax, (%rsi)
jmp 0x95591
movl -0x30(%rbp), %eax
movl $0xff, %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovgl %ecx, %eax
movq -0x38(%rbp), %rsi
movb %al, (%rsi)
jmp 0x95591
movss -0x40(%rbp), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
movq -0x38(%rbp), %rsi
jne 0x954ae
jnp 0x95591
movss -0x30(%rbp), %xmm0
divss %xmm1, %xmm0
jmp 0x954f6
movss -0x30(%rbp), %xmm0
mulss -0x40(%rbp), %xmm0
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
jmp 0x954f6
movsd -0x40(%rbp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movq -0x38(%rbp), %rsi
jne 0x954e6
jnp 0x95591
movsd -0x30(%rbp), %xmm0
divsd %xmm1, %xmm0
jmp 0x95518
movss -0x40(%rbp), %xmm0
movss %xmm0, (%rsi)
jmp 0x95591
movsd -0x30(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
jmp 0x95518
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rsi)
jmp 0x95591
leaq 0x29fc4(%rip), %rsi     # 0xbf4e9
leaq -0x40(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
je 0x95591
movss -0x40(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x9554e
jnp 0x95591
xorps %xmm1, %xmm1
cvtsi2ssl -0x30(%rbp), %xmm1
divss %xmm0, %xmm1
cvttss2si %xmm1, %eax
jmp 0x9558f
leaq 0x29f82(%rip), %rsi     # 0xbf4e9
leaq -0x40(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
je 0x95591
cvtsi2ssl -0x30(%rbp), %xmm0
mulss -0x40(%rbp), %xmm0
cvttss2si %xmm0, %eax
movl %eax, (%rsi)
leaq -0x70(%rbp), %rdi
callq 0xc5b0
testl %eax, %eax
setne %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1fe3f(%rip), %rdi     # 0xb53f4
leaq 0x3ba5c(%rip), %rsi     # 0xd1018
leaq 0x3bf4a(%rip), %rcx     # 0xd150d
movl $0x70d, %edx            # imm = 0x70D
callq 0xc140
leaq 0x22b18(%rip), %rdi     # 0xb80ec
leaq 0x3ba3d(%rip), %rsi     # 0xd1018
leaq 0x3c031(%rip), %rcx     # 0xd1613
movl $0x7b9, %edx            # imm = 0x7B9
callq 0xc140