// File: /workspace/github_c_makefile_star2_O1/BernardTatin[P]s7sh/s7.c
// Function: string_to_integer
static s7_int string_to_integer(const char *str, int32_t radix, bool *overflow)
    {
        bool negative = false;
        s7_int lval = 0;
        int32_t dig;
        char *tmp = (char *)str;
#if WITH_GMP
        char *tmp1;
#endif

        if (str[0] == '+')
            tmp++;
        else
        {
            if (str[0] == '-')
            {
                negative = true;
                tmp++;
            }
        }
        while (*tmp == '0') {tmp++;};
#if WITH_GMP
        tmp1 = tmp;
#endif

        if (radix == 10)
        {
            while (true)
            {
                dig = digits[(uint8_t)(*tmp++)];
                if (dig > 9) break;
#if HAVE_OVERFLOW_CHECKS
                if ((multiply_overflow(lval, (s7_int)10, &lval)) ||
                        (add_overflow(lval, (s7_int)dig, &lval)))
                {
                    if ((radix == 10) &&
                            (strncmp(str, "-9223372036854775808", 20) == 0) &&
                            (digits[(uint8_t)(*tmp++)] > 9)) /* i.e. next thing is not a digit -- "/" for example */
                        return(s7_int_min);
                    *overflow = true;
                    return((negative) ? s7_int_min : s7_int_max);
                    break;
                }
#else
                lval = dig + (lval * 10);
                dig = digits[(uint8_t)(*tmp++)];
                if (dig > 9) break;
                lval = dig + (lval * 10);
#endif
            }
        }
        else
        {
            while (true)
            {
                dig = digits[(uint8_t)(*tmp++)];
                if (dig >= radix) break;
#if HAVE_OVERFLOW_CHECKS && (!WITH_GMP)
                {
                    s7_int oval = 0;
                    if (multiply_overflow(lval, (s7_int)radix, &oval))
                    {
                        /* maybe a bad idea!  #xffffffffffffffff -> -1??? this is needed for 64-bit number hacks (see s7test.scm bit-reverse) */
                        if ((radix == 16) &&
                                (digits[(uint8_t)(*tmp)] >= radix))
                        {
                            lval -= 576460752303423488LL; /* turn off sign bit */
                            lval *= radix;
                            lval += dig;
                            lval -= 9223372036854775807LL;
                            return(lval - 1);
                        }
                        lval = oval; /* old case */
                        if ((lval == s7_int_min)  && (digits[(uint8_t)(*tmp++)] > 9))
                            return(lval);
                        *overflow = true;
                        break;
                    }
                    else lval = oval;
                    if (add_overflow(lval, (s7_int)dig, &lval))
                    {
                        if (lval == s7_int_min) return(lval);
                        *overflow = true;
                        break;
                    }
                }
#else
                lval = dig + (lval * radix);
                dig = digits[(uint8_t)(*tmp++)];
                if (dig >= radix) break;
                lval = dig + (lval * radix);
#endif
            }
        }

#if WITH_GMP
        if (!(*overflow))
            (*overflow) = ((lval > s7_int32_max) ||
                    ((tmp - tmp1) > s7_int_digits_by_radix[radix]));
        /* this tells the string->number readers to create a bignum.  We need to be very
         *    conservative here to catch contexts such as (/ 1/524288 19073486328125)
         */
#endif

        if (negative) return(-lval);
        return(lval);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movzbl (%rdi), %eax
cmpl $0x2d, %eax
je 0x99fb4
cmpl $0x2b, %eax
jne 0x99fbd
leaq 0x1(%rdi), %r10
xorl %ebp, %ebp
jmp 0x99fc2
leaq 0x1(%rdi), %r10
movb $0x1, %bpl
jmp 0x99fc2
xorl %ebp, %ebp
movq %rdi, %r10
cmpb $0x30, (%r10)
leaq 0x1(%r10), %r10
je 0x99fc2
cmpl $0xa, %esi
jne 0x9a04f
xorl %r8d, %r8d
leaq 0xc3685(%rip), %r15     # 0x15d660
movzbl -0x1(%r10), %eax
movslq (%r15,%rax,4), %rax
cmpq $0x9, %rax
jg 0x9a12c
movq %r10, %r12
imulq $0xa, %r8, %r8
jo 0x9a001
leaq 0x1(%r12), %r10
addq %rax, %r8
jno 0x99fdb
movabsq $-0x8000000000000000, %r14 # imm = 0x8000000000000000
cmpl $0xa, %esi
jne 0x9a13b
leaq 0x8554d(%rip), %rsi     # 0x11f568
movl $0x14, %edx
callq 0x90b0
testl %eax, %eax
jne 0x9a13b
movzbl (%r12), %eax
cmpl $0xa, (%r15,%rax,4)
jl 0x9a13b
xorl %eax, %eax
cmpb $0x0, 0xb89e2(%rip)     # 0x152a28
cmoveq %rax, %r14
jmp 0x9a165
decq %r10
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
movslq %esi, %rcx
movl 0xb89c3(%rip), %edx     # 0x152a28
shlq $0x3f, %rdx
xorl %r8d, %r8d
leaq 0xc35ed(%rip), %rdi     # 0x15d660
movabsq $-0x800000000000000, %r9 # imm = 0xF800000000000000
movzbl (%r10), %r11d
movslq (%rdi,%r11,4), %r13
cmpl %esi, %r13d
jge 0x9a12c
leaq 0x1(%r10), %r11
movq %r8, %r12
imulq %rcx, %r12
jno 0x9a0cd
cmpl $0x10, %esi
jne 0x9a0e5
movzbl (%r11), %r15d
cmpl $0x10, (%rdi,%r15,4)
jl 0x9a0e5
addq %r9, %r8
imulq %rcx, %r8
addq %r13, %r8
leaq (%rax,%r8), %r10
incq %r10
orq %rax, %r8
movl $0x1, %r15d
movq %r8, %r14
movq %r10, %r8
jmp 0x9a11a
xorl %r15d, %r15d
addq %r13, %r12
jno 0x9a117
movl $0x1, %r15d
cmpq %rdx, %r12
jne 0x9a10e
movq %r12, %r14
jmp 0x9a117
cmpq %rdx, %r12
jne 0x9a10e
movzbl 0x1(%r10), %r8d
addq $0x2, %r10
movl $0x1, %r15d
cmpl $0x9, (%rdi,%r8,4)
movq %r10, %r11
jle 0x9a10e
movq %r12, %r14
movq %r12, %r8
movq %r10, %r11
jmp 0x9a11a
movb $0x1, (%rbx)
movl $0x7, %r15d
movq %r12, %r8
movq %r11, %r10
testl %r15d, %r15d
je 0x9a07d
cmpl $0x7, %r15d
jne 0x9a165
movq %r8, %r14
negq %r14
testb %bpl, %bpl
cmoveq %r8, %r14
jmp 0x9a165
movb $0x1, (%rbx)
xorl %eax, %eax
cmpb $0x0, 0xb88e1(%rip)     # 0x152a28
movl $0x0, %ecx
cmovneq %r14, %rcx
decq %r14
cmpb $0x0, 0xb8aae(%rip)     # 0x152c08
cmoveq %rax, %r14
testb %bpl, %bpl
cmovneq %rcx, %r14
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq