// File: /workspace/github_c_makefile_star2_O2/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 0x7668e
cmpl $0x2b, %eax
jne 0x76697
leaq 0x1(%rdi), %rax
xorl %ebp, %ebp
jmp 0x7669c
leaq 0x1(%rdi), %rax
movb $0x1, %bpl
jmp 0x7669c
xorl %ebp, %ebp
movq %rdi, %rax
cmpb $0x30, (%rax)
leaq 0x1(%rax), %rax
je 0x7669c
cmpl $0xa, %esi
jne 0x76713
xorl %ecx, %ecx
leaq 0xadfad(%rip), %r15     # 0x124660
movq %rax, %r12
movzbl -0x1(%rax), %eax
movslq (%r15,%rax,4), %rdx
cmpq $0x9, %rdx
jg 0x767bf
imulq $0xa, %rcx, %rcx
jo 0x766d8
leaq 0x1(%r12), %rax
addq %rdx, %rcx
jno 0x766b3
movabsq $-0x8000000000000000, %r14 # imm = 0x8000000000000000
leaq 0x6bf2f(%rip), %rsi     # 0xe2618
pushq $0x14
popq %rdx
callq 0x80b0
testl %eax, %eax
jne 0x76756
movzbl (%r12), %eax
cmpl $0xa, (%r15,%rax,4)
jl 0x76756
xorl %eax, %eax
cmpb $0x0, 0xa331e(%rip)     # 0x119a28
cmoveq %rax, %r14
jmp 0x767cc
movslq %esi, %rdi
xorl %ecx, %ecx
leaq 0xadf41(%rip), %rdx     # 0x124660
movzbl -0x1(%rax), %r8d
movslq (%rdx,%r8,4), %r8
cmpl %esi, %r8d
jge 0x767bf
movq %rcx, %r14
imulq %rdi, %r14
jo 0x76782
incq %rax
addq %r8, %r14
movq %r14, %rcx
jno 0x7671f
movl 0xa32dd(%rip), %eax     # 0x119a28
shlq $0x3f, %rax
cmpq %rax, %r14
jne 0x767b9
jmp 0x767cc
movb $0x1, (%rbx)
xorl %eax, %eax
cmpb $0x0, 0xa32c6(%rip)     # 0x119a28
movl $0x0, %ecx
cmovneq %r14, %rcx
decq %r14
cmpb $0x0, 0xa3493(%rip)     # 0x119c08
cmoveq %rax, %r14
testb %bpl, %bpl
cmovneq %rcx, %r14
jmp 0x767cc
cmpl $0x10, %esi
jne 0x767a1
movzbl (%rax), %esi
cmpl $0x10, (%rdx,%rsi,4)
jl 0x767a1
shlq $0x4, %rcx
addq %r8, %rcx
btsq $0x3f, %rcx
movq %rcx, %r14
jmp 0x767cc
movl 0xa3281(%rip), %ecx     # 0x119a28
shlq $0x3f, %rcx
cmpq %rcx, %r14
jne 0x767b9
movzbl (%rax), %eax
cmpl $0x9, (%rdx,%rax,4)
jg 0x767cc
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