// File: /workspace/github_cpp_makefile_star2_O1/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 0x96dd8
btq %rbx, %rax
jae 0x96db5
incq %r15
jmp 0x96da0
movabsq $0x8c0000000000, %rax   # imm = 0x8C0000000000
btq %rbx, %rax
jae 0x96dd8
incq %r15
movzbl (%r15), %eax
cmpl $0x20, %eax
je 0x96dc5
cmpl $0x9, %eax
je 0x96dc5
jmp 0x96dda
xorl %ebx, %ebx
cmpb $0x0, (%r15)
je 0x96fdf
movq %rsi, -0x58(%rbp)
movq %r8, -0x68(%rbp)
cmpl $0xa, %r14d
jae 0x971eb
movl %r14d, %r13d
movq %r13, -0x60(%rbp)
shlq $0x5, %r13
leaq 0x61c08(%rip), %r12     # 0xf8a10
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 0x96e32
addq %r13, %r12
movq 0x18(%r12), %rsi
movl $0x0, -0x4c(%rbp)
cmpl $0x9, %r14d
je 0x96f5e
cmpl $0x8, %r14d
movq -0x38(%rbp), %rdx
je 0x96eda
cmpl $0x4, %r14d
jne 0x96fe6
movl (%rdx), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x40(%rbp)
testb %bl, %bl
je 0x97051
leaq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rdi
movq %rsi, %r14
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
jle 0x96fdf
cmpb $0x2a, %bl
je 0x9719d
movzbl %bl, %eax
cmpl $0x2f, %eax
je 0x9715b
cmpl $0x2b, %eax
movq %r14, %rsi
jne 0x97051
leaq 0x275d1(%rip), %rsi     # 0xbe482
leaq -0x4c(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
je 0x971ce
movl -0x4c(%rbp), %eax
addl -0x30(%rbp), %eax
jmp 0x971cc
movss (%rdx), %xmm0
movss %xmm0, -0x30(%rbp)
movl $0x0, -0x40(%rbp)
testb %bl, %bl
je 0x96f0c
leaq 0x2a624(%rip), %rsi     # 0xc1519
leaq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
jle 0x96fdf
leaq 0x2a606(%rip), %rsi     # 0xc1519
leaq -0x40(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
jle 0x96fdf
cmpb $0x2a, %bl
je 0x970f6
movzbl %bl, %eax
cmpl $0x2f, %eax
movq -0x48(%rbp), %rdx
je 0x970d4
cmpl $0x2b, %eax
movq -0x38(%rbp), %rsi
jne 0x9712e
movss -0x30(%rbp), %xmm0
addss -0x40(%rbp), %xmm0
jmp 0x97133
movq -0x38(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
testb %bl, %bl
je 0x96f91
leaq 0x3c7c1(%rip), %rsi     # 0xd373f
leaq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
jle 0x96fdf
leaq 0x3c7a7(%rip), %rsi     # 0xd373f
leaq -0x40(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
jle 0x96fdf
cmpb $0x2a, %bl
je 0x9713c
movzbl %bl, %eax
cmpl $0x2f, %eax
movq -0x48(%rbp), %rdx
je 0x9710a
cmpl $0x2b, %eax
movq -0x38(%rbp), %rsi
jne 0x97150
movsd -0x30(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
jmp 0x97155
xorl %eax, %eax
jmp 0x971dc
leal -0x5(%r14), %eax
cmpl $0x2, %eax
ja 0x97006
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
jmp 0x971ce
leaq -0x30(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
cmpl $0x3, %r14d
ja 0x9720a
leaq 0x3bf7b(%rip), %rax     # 0xd2fa0
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 0x970c9
leaq -0x4c(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
cmpl $0x1, %eax
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
jne 0x971ce
movl -0x4c(%rbp), %eax
jmp 0x971cc
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 0x970a9
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 0x971ce
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 0x971ce
movss -0x40(%rbp), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
movq -0x38(%rbp), %rsi
jne 0x970eb
jnp 0x971ce
movss -0x30(%rbp), %xmm0
divss %xmm1, %xmm0
jmp 0x97133
movss -0x30(%rbp), %xmm0
mulss -0x40(%rbp), %xmm0
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
jmp 0x97133
movsd -0x40(%rbp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movq -0x38(%rbp), %rsi
jne 0x97123
jnp 0x971ce
movsd -0x30(%rbp), %xmm0
divsd %xmm1, %xmm0
jmp 0x97155
movss -0x40(%rbp), %xmm0
movss %xmm0, (%rsi)
jmp 0x971ce
movsd -0x30(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
jmp 0x97155
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rsi)
jmp 0x971ce
leaq 0x2a3b7(%rip), %rsi     # 0xc1519
leaq -0x40(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
je 0x971ce
movss -0x40(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x9718b
jnp 0x971ce
xorps %xmm1, %xmm1
cvtsi2ssl -0x30(%rbp), %xmm1
divss %xmm0, %xmm1
cvttss2si %xmm1, %eax
jmp 0x971cc
leaq 0x2a375(%rip), %rsi     # 0xc1519
leaq -0x40(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0xc0c0
testl %eax, %eax
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
je 0x971ce
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 0x20202(%rip), %rdi     # 0xb73f4
leaq 0x3bf4f(%rip), %rsi     # 0xd3148
leaq 0x3c43d(%rip), %rcx     # 0xd363d
movl $0x70d, %edx            # imm = 0x70D
callq 0xc140
leaq 0x22edb(%rip), %rdi     # 0xba0ec
leaq 0x3bf30(%rip), %rsi     # 0xd3148
leaq 0x3c524(%rip), %rcx     # 0xd3743
movl $0x7b9, %edx            # imm = 0x7B9
callq 0xc140