// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movl %esi, 0x44(%rsp)
movq %rdx, 0x38(%rsp)
movb $0x0, 0x37(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0xcdbd7
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
jmp 0xcdbf9
movq 0x48(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0xcdbf7
movb $0x1, 0x37(%rsp)
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
jmp 0xcdbf9
jmp 0xcdbfb
movq 0x18(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0xcdc18
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
jmp 0xcdbfb
cmpl $0xa, 0x44(%rsp)
jne 0xcdd1e
jmp 0xcdc25
movq 0x14fd6c(%rip), %rax    # 0x21d998
movq 0x18(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rsp)
movzbl (%rcx), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, 0x24(%rsp)
cmpl $0x9, 0x24(%rsp)
jle 0xcdc53
jmp 0xcdd19
movl $0xa, %ecx
imulq 0x28(%rsp), %rcx
seto %al
movq %rcx, 0x28(%rsp)
testb $0x1, %al
jne 0xcdc88
movq 0x28(%rsp), %rcx
movslq 0x24(%rsp), %rax
addq %rax, %rcx
seto %al
movq %rcx, 0x28(%rsp)
testb $0x1, %al
jne 0xcdc88
jmp 0xcdd14
cmpl $0xa, 0x44(%rsp)
jne 0xcdcdc
movq 0x48(%rsp), %rdi
leaq 0x1204b2(%rip), %rsi    # 0x1ee14d
movl $0x14, %edx
callq 0x90b0
cmpl $0x0, %eax
jne 0xcdcdc
movq 0x14fce7(%rip), %rax    # 0x21d998
movq 0x18(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rsp)
movzbl (%rcx), %ecx
cmpl $0x9, (%rax,%rcx,4)
jle 0xcdcdc
movq 0x14c886(%rip), %rax    # 0x21a558
movq %rax, 0x50(%rsp)
jmp 0xcdeb6
movq 0x38(%rsp), %rax
movb $0x1, (%rax)
testb $0x1, 0x37(%rsp)
je 0xcdcf9
movq 0x14c866(%rip), %rax    # 0x21a558
movq %rax, 0x8(%rsp)
jmp 0xcdd05
movq 0x14ca38(%rip), %rax    # 0x21a738
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0xcdeb6
jmp 0xcdc25
jmp 0xcde97
jmp 0xcdd20
movq 0x14fc71(%rip), %rax    # 0x21d998
movq 0x18(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rsp)
movzbl (%rcx), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x44(%rsp), %eax
jl 0xcdd51
jmp 0xcde95
movq $0x0, 0x10(%rsp)
movq 0x28(%rsp), %rcx
movslq 0x44(%rsp), %rax
imulq %rax, %rcx
seto %al
movq %rcx, 0x10(%rsp)
testb $0x1, %al
jne 0xcdd79
jmp 0xcde47
cmpl $0x10, 0x44(%rsp)
jne 0xcddf8
movq 0x14fc11(%rip), %rax    # 0x21d998
movq 0x18(%rsp), %rcx
movzbl (%rcx), %ecx
movl (%rax,%rcx,4), %eax
cmpl 0x44(%rsp), %eax
jl 0xcddf8
movq 0x28(%rsp), %rax
movabsq $0x800000000000000, %rcx # imm = 0x800000000000000
subq %rcx, %rax
movq %rax, 0x28(%rsp)
movslq 0x44(%rsp), %rax
imulq 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
movslq 0x24(%rsp), %rax
addq 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
subq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0xcdeb6
movq 0x10(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x14c74a(%rip), %rax    # 0x21a558
jne 0xcde3d
movq 0x14fb81(%rip), %rax    # 0x21d998
movq 0x18(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rsp)
movzbl (%rcx), %ecx
cmpl $0x9, (%rax,%rcx,4)
jle 0xcde3d
movq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0xcdeb6
movq 0x38(%rsp), %rax
movb $0x1, (%rax)
jmp 0xcde95
movq 0x10(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rcx
movslq 0x24(%rsp), %rax
addq %rax, %rcx
seto %al
movq %rcx, 0x28(%rsp)
testb $0x1, %al
jne 0xcde6c
jmp 0xcde90
movq 0x28(%rsp), %rax
cmpq 0x14c6e0(%rip), %rax    # 0x21a558
jne 0xcde86
movq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0xcdeb6
movq 0x38(%rsp), %rax
movb $0x1, (%rax)
jmp 0xcde95
jmp 0xcdd20
jmp 0xcde97
testb $0x1, 0x37(%rsp)
je 0xcdeac
xorl %eax, %eax
subq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0xcdeb6
movq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq