// File: night-shift[P]Srl/src/lib/ToolsStrConv.cpp
// Function: Srl::Tools::str_to_type(unsigned char const*, unsigned long, Srl::Type)
pair<bool, Value> Tools::str_to_type(const uint8_t* str, size_t str_len, Type hint)
{
    Tools::trim_space(str, str_len);

    if(str_len < 1) {
        return { false, Value(Type::Null) };
    }

    if(str_len >= 4 && str[0] >= 'f') {

        if((str[0] == 't' || str[0] == 'T') && cmp_str(str, str_len, str_true, 1)) {
            return { true, true };
        }

        if((str[0] == 'f' || str[0] == 'F') && cmp_str(str, str_len, str_false, 1)) {
            return { true, false };
        }

        if((str[0] == 'n' || str[0] == 'N') && cmp_str(str, str_len, str_null, 1)) {
            return { true, Value(Type::Null) };
        }
    }

    bool success = false;

    if(!TpTools::is_fp(hint)) {
        bool is_signed;
        uint64_t i;

        tie(i, is_signed, success) = str_to_int(str, str_len);

        if(success) {
            return is_signed ? make_pair(true, Value(-(int64_t)i)) : make_pair(true, Value(i));
        }
    }

    double fp;
    tie(fp, success) = str_to_double(str, str_len);

    return success ? make_pair(true, Value(fp)) : make_pair(false, Value(Type::Null));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x148(%rbp)
movb %cl, %al
movq %rdi, -0x140(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movb %al, -0x11(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x36140
cmpq $0x1, -0x10(%rbp)
jae 0x62ce5
movb $0x0, -0x12(%rbp)
leaq -0x30(%rbp), %rdi
movl $0xb, %esi
callq 0x33ff0
movq -0x148(%rbp), %rdi
leaq -0x12(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x38760
jmp 0x62f97
cmpq $0x4, -0x10(%rbp)
jb 0x62e14
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x66, %eax
jl 0x62e14
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x74, %eax
je 0x62d18
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x54, %eax
jne 0x62d58
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0x7519(%rip), %rdx      # 0x6a240
movl $0x1, %ecx
callq 0x62fb0
testb $0x1, %al
jne 0x62d37
jmp 0x62d58
movq -0x148(%rbp), %rdi
movb $0x1, -0x31(%rbp)
movb $0x1, -0x32(%rbp)
leaq -0x31(%rbp), %rsi
leaq -0x32(%rbp), %rdx
callq 0x38550
jmp 0x62f97
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x66, %eax
je 0x62d70
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x46, %eax
jne 0x62db0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0x74c6(%rip), %rdx      # 0x6a245
movl $0x1, %ecx
callq 0x63030
testb $0x1, %al
jne 0x62d8f
jmp 0x62db0
movq -0x148(%rbp), %rdi
movb $0x1, -0x33(%rbp)
movb $0x0, -0x34(%rbp)
leaq -0x33(%rbp), %rsi
leaq -0x34(%rbp), %rdx
callq 0x38550
jmp 0x62f97
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x6e, %eax
je 0x62dc8
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4e, %eax
jne 0x62e12
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0x7474(%rip), %rdx      # 0x6a24b
movl $0x1, %ecx
callq 0x62fb0
testb $0x1, %al
jne 0x62de7
jmp 0x62e12
movb $0x1, -0x35(%rbp)
leaq -0x50(%rbp), %rdi
movl $0xb, %esi
callq 0x33ff0
movq -0x148(%rbp), %rdi
leaq -0x35(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x38760
jmp 0x62f97
jmp 0x62e14
movb $0x0, -0x51(%rbp)
movzbl -0x11(%rbp), %edi
callq 0x35860
testb $0x1, %al
jne 0x62ee9
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x630b0
leaq -0x88(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x52(%rbp), %rdx
leaq -0x51(%rbp), %rcx
callq 0x383e0
leaq -0x88(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x38800
testb $0x1, -0x51(%rbp)
je 0x62ee7
testb $0x1, -0x52(%rbp)
je 0x62eb1
movb $0x1, -0x89(%rbp)
xorl %eax, %eax
subq -0x60(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x34be0
movq -0x148(%rbp), %rdi
leaq -0x89(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x36f00
jmp 0x62ee2
movb $0x1, -0xb1(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x33600
movq -0x148(%rbp), %rdi
leaq -0xb1(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x36f00
jmp 0x62f97
jmp 0x62ee9
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0x63200
leaq -0xf8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x51(%rbp), %rdx
callq 0x348e0
leaq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x37be0
testb $0x1, -0x51(%rbp)
je 0x62f63
movb $0x1, -0xf9(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x352c0
movq -0x148(%rbp), %rdi
leaq -0xf9(%rbp), %rsi
leaq -0x118(%rbp), %rdx
callq 0x36f00
jmp 0x62f95
movb $0x0, -0x119(%rbp)
leaq -0x138(%rbp), %rdi
movl $0xb, %esi
callq 0x33ff0
movq -0x148(%rbp), %rdi
leaq -0x119(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0x36f00
jmp 0x62f97
movq -0x140(%rbp), %rax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw (%rax,%rax)