// File: /workspace/github_c_makefile_star2_O3/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 %r12
pushq %rbx
movq %rdx, %rbx
movzbl (%rdi), %eax
cmpl $0x2d, %eax
je 0x9392c
cmpl $0x2b, %eax
jne 0x93935
leaq 0x1(%rdi), %rax
xorl %ebp, %ebp
jmp 0x9393a
leaq 0x1(%rdi), %rax
movb $0x1, %bpl
jmp 0x9393a
xorl %ebp, %ebp
movq %rdi, %rax
cmpb $0x30, (%rax)
leaq 0x1(%rax), %rax
je 0x9393a
cmpl $0xa, %esi
jne 0x939b3
xorl %ecx, %ecx
leaq 0xc1d0f(%rip), %r15     # 0x155660
movq %rax, %r12
movzbl -0x1(%rax), %eax
movslq (%r15,%rax,4), %rdx
cmpq $0x9, %rdx
jg 0x93a5f
imulq $0xa, %rcx, %rcx
jo 0x93976
leaq 0x1(%r12), %rax
addq %rdx, %rcx
jno 0x93951
movabsq $-0x8000000000000000, %r14 # imm = 0x8000000000000000
leaq 0x82cf1(%rip), %rsi     # 0x116678
movl $0x14, %edx
callq 0x80b0
testl %eax, %eax
jne 0x939f6
movzbl (%r12), %eax
cmpl $0xa, (%r15,%rax,4)
jl 0x939f6
xorl %eax, %eax
cmpb $0x0, 0xb707e(%rip)     # 0x14aa28
cmoveq %rax, %r14
jmp 0x93a6c
movslq %esi, %rdi
xorl %ecx, %ecx
leaq 0xc1ca1(%rip), %rdx     # 0x155660
movzbl -0x1(%rax), %r8d
movslq (%rdx,%r8,4), %r8
cmpl %esi, %r8d
jge 0x93a5f
movq %rcx, %r14
imulq %rdi, %r14
jo 0x93a22
incq %rax
addq %r8, %r14
movq %r14, %rcx
jno 0x939bf
movl 0xb703d(%rip), %eax     # 0x14aa28
shlq $0x3f, %rax
cmpq %rax, %r14
jne 0x93a59
jmp 0x93a6c
movb $0x1, (%rbx)
xorl %eax, %eax
cmpb $0x0, 0xb7026(%rip)     # 0x14aa28
movl $0x0, %ecx
cmovneq %r14, %rcx
decq %r14
cmpb $0x0, 0xb71f3(%rip)     # 0x14ac08
cmoveq %rax, %r14
testb %bpl, %bpl
cmovneq %rcx, %r14
jmp 0x93a6c
cmpl $0x10, %esi
jne 0x93a41
movzbl (%rax), %esi
cmpl $0x10, (%rdx,%rsi,4)
jl 0x93a41
shlq $0x4, %rcx
addq %r8, %rcx
btsq $0x3f, %rcx
movq %rcx, %r14
jmp 0x93a6c
movl 0xb6fe1(%rip), %ecx     # 0x14aa28
shlq $0x3f, %rcx
cmpq %rcx, %r14
jne 0x93a59
movzbl (%rax), %eax
cmpl $0x9, (%rdx,%rax,4)
jg 0x93a6c
movb $0x1, (%rbx)
movq %r14, %rcx
movq %rcx, %r14
negq %r14
testb %bpl, %bpl
cmoveq %rcx, %r14
movq %r14, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq