// File: donfreiday[P]gb/./imgui/imgui.cpp
// Function: DataTypeApplyOpFromText(char const*, char const*, ImGuiDataType, void*, char const*)
static void DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* data_ptr, const char* scalar_format)
{
    while (ImCharIsSpace(*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 (ImCharIsSpace(*buf))
            buf++;
    }
    else
    {
        op = 0;
    }
    if (!buf[0])
        return;

    if (data_type == ImGuiDataType_Int)
    {
        if (!scalar_format)
            scalar_format = "%d";
        int* v = (int*)data_ptr;
        int ref_v = *v;
        if (op && sscanf(initial_value_buf, scalar_format, &ref_v) < 1)
            return;

        // 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
        float op_v = 0.0f;
        if (op == '+')      { if (sscanf(buf, "%f", &op_v) == 1) *v = (int)(ref_v + op_v); }                // Add (use "+-" to subtract)
        else if (op == '*') { if (sscanf(buf, "%f", &op_v) == 1) *v = (int)(ref_v * op_v); }                // Multiply
        else if (op == '/') { if (sscanf(buf, "%f", &op_v) == 1 && op_v != 0.0f) *v = (int)(ref_v / op_v); }// Divide
        else                { if (sscanf(buf, scalar_format, &ref_v) == 1) *v = ref_v; }                    // Assign constant
    }
    else if (data_type == ImGuiDataType_Float)
    {
        if (!scalar_format)
            scalar_format = "%f";
        float* v = (float*)data_ptr;
        float ref_v = *v;
        if (op && sscanf(initial_value_buf, scalar_format, &ref_v) < 1)
            return;
        float op_v = 0.0f;
        if (sscanf(buf, scalar_format, &op_v) < 1)
            return;

        if (op == '+')      { *v = ref_v + op_v; }                      // Add (use "+-" to subtract)
        else if (op == '*') { *v = ref_v * op_v; }                      // Multiply
        else if (op == '/') { if (op_v != 0.0f) *v = ref_v / op_v; }    // Divide
        else                { *v = op_v; }                              // Assign constant
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movsbl (%rax), %edi
callq 0x29b90
testb $0x1, %al
jne 0x1f93d
jmp 0x1f94b
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x1f92b
movq -0x8(%rbp), %rax
movb (%rax), %al
movb %al, -0x29(%rbp)
movsbl -0x29(%rbp), %eax
cmpl $0x2b, %eax
je 0x1f96f
movsbl -0x29(%rbp), %eax
cmpl $0x2a, %eax
je 0x1f96f
movsbl -0x29(%rbp), %eax
cmpl $0x2f, %eax
jne 0x1f99d
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movsbl (%rax), %edi
callq 0x29b90
testb $0x1, %al
jne 0x1f98d
jmp 0x1f99b
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x1f97b
jmp 0x1f9a1
movb $0x0, -0x29(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x1f9af
jmp 0x1fbe8
cmpl $0x0, -0x14(%rbp)
jne 0x1faf5
cmpq $0x0, -0x28(%rbp)
jne 0x1f9cb
leaq 0x3cb04(%rip), %rax     # 0x5c4cb
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
cmpb $0x0, -0x29(%rbp)
je 0x1f9ff
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
movb $0x0, %al
callq 0x70c0
cmpl $0x1, %eax
jge 0x1f9ff
jmp 0x1fbe8
xorps %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
movsbl -0x29(%rbp), %eax
cmpl $0x2b, %eax
jne 0x1fa44
movq -0x8(%rbp), %rdi
leaq 0x3e101(%rip), %rsi     # 0x5db1c
leaq -0x40(%rbp), %rdx
movb $0x0, %al
callq 0x70c0
cmpl $0x1, %eax
jne 0x1fa3f
cvtsi2ssl -0x3c(%rbp), %xmm0
addss -0x40(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1faf0
movsbl -0x29(%rbp), %eax
cmpl $0x2a, %eax
jne 0x1fa7e
movq -0x8(%rbp), %rdi
leaq 0x3e0c4(%rip), %rsi     # 0x5db1c
leaq -0x40(%rbp), %rdx
movb $0x0, %al
callq 0x70c0
cmpl $0x1, %eax
jne 0x1fa7c
cvtsi2ssl -0x3c(%rbp), %xmm0
mulss -0x40(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1faee
movsbl -0x29(%rbp), %eax
cmpl $0x2f, %eax
jne 0x1fac9
movq -0x8(%rbp), %rdi
leaq 0x3e08a(%rip), %rsi     # 0x5db1c
leaq -0x40(%rbp), %rdx
movb $0x0, %al
callq 0x70c0
cmpl $0x1, %eax
jne 0x1fac7
movss -0x40(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x1fab3
jp 0x1fab3
jmp 0x1fac7
cvtsi2ssl -0x3c(%rbp), %xmm0
divss -0x40(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1faec
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
movb $0x0, %al
callq 0x70c0
cmpl $0x1, %eax
jne 0x1faea
movl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1faec
jmp 0x1faee
jmp 0x1faf0
jmp 0x1fbe8
cmpl $0x1, -0x14(%rbp)
jne 0x1fbe6
cmpq $0x0, -0x28(%rbp)
jne 0x1fb11
leaq 0x3e00f(%rip), %rax     # 0x5db1c
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x4c(%rbp)
cmpb $0x0, -0x29(%rbp)
je 0x1fb49
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
movb $0x0, %al
callq 0x70c0
cmpl $0x1, %eax
jge 0x1fb49
jmp 0x1fbe8
xorps %xmm0, %xmm0
movss %xmm0, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movb $0x0, %al
callq 0x70c0
cmpl $0x1, %eax
jge 0x1fb6b
jmp 0x1fbe8
movsbl -0x29(%rbp), %eax
cmpl $0x2b, %eax
jne 0x1fb88
movss -0x4c(%rbp), %xmm0
addss -0x50(%rbp), %xmm0
movq -0x48(%rbp), %rax
movss %xmm0, (%rax)
jmp 0x1fbe4
movsbl -0x29(%rbp), %eax
cmpl $0x2a, %eax
jne 0x1fba5
movss -0x4c(%rbp), %xmm0
mulss -0x50(%rbp), %xmm0
movq -0x48(%rbp), %rax
movss %xmm0, (%rax)
jmp 0x1fbe2
movsbl -0x29(%rbp), %eax
cmpl $0x2f, %eax
jne 0x1fbd3
movss -0x50(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x1fbbf
jp 0x1fbbf
jmp 0x1fbd1
movss -0x4c(%rbp), %xmm0
divss -0x50(%rbp), %xmm0
movq -0x48(%rbp), %rax
movss %xmm0, (%rax)
jmp 0x1fbe0
movss -0x50(%rbp), %xmm0
movq -0x48(%rbp), %rax
movss %xmm0, (%rax)
jmp 0x1fbe2
jmp 0x1fbe4
jmp 0x1fbe6
jmp 0x1fbe8
addq $0x50, %rsp
popq %rbp
retq
nop