#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ ERANGE;
scalar_t__ errno;
unsigned long long strtoull(char const *, char **, int /*<<< orphan*/);
int string_to_number_ll(const char *s, unsigned long long min,
                        unsigned long long max, unsigned long long *ret) {
  unsigned long long number;
  char *end;
  errno = 0;
  number = strtoull(s, &end, 0);
  if (*end == '\0' && end != s) {
    if (errno != ERANGE && min <= number && (!max || number <= max)) {
      *ret = number;
      return 0;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<string_to_number_ll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2ea9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c4 <string_to_number_ll+0xb4>
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11c4 <string_to_number_ll+0xb4>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
je     11bf <string_to_number_ll+0xaf>
mov    -0x18(%rbp),%rax
cmp    -0x30(%rbp),%rax
ja     11bf <string_to_number_ll+0xaf>
cmpq   $0x0,-0x20(%rbp)
je     11a8 <string_to_number_ll+0x98>
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     11bf <string_to_number_ll+0xaf>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11cb <string_to_number_ll+0xbb>
jmp    11c4 <string_to_number_ll+0xb4>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_number_ll>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2ea8(%rip),%r13
movq   $0x0,0x0(%r13)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    %rax,%rcx
mov    0x8(%rsp),%rdx
mov    $0xffffffff,%eax
cmp    %rbx,%rdx
je     117f <string_to_number_ll+0x6f>
cmpb   $0x0,(%rdx)
jne    117f <string_to_number_ll+0x6f>
mov    0x0(%r13),%rdx
mov    0x2e82(%rip),%rsi
cmp    (%rsi),%rdx
je     117f <string_to_number_ll+0x6f>
cmp    %r12,%rcx
jb     117f <string_to_number_ll+0x6f>
test   %r15,%r15
je     117a <string_to_number_ll+0x6a>
cmp    %r15,%rcx
ja     117f <string_to_number_ll+0x6f>
mov    %rcx,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @string_to_number_ll(i8* %0, i64 %1, i64 %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i64* %3, i64** %9
store i64 0, i64* @errno
%12 = load i8*, i8** %6
%13 = call i64 @strtoull(i8* %12, i8** %11, i32 0)
store i64 %13, i64* %10
%14 = load i8*, i8** %11
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %41
18: ; preds = %4
%19 = load i8*, i8** %11
%20 = load i8*, i8** %6
%21 = icmp ne i8* %19, %20
br i1 %21, label %22, label %41
22: ; preds = %18
%23 = load i64, i64* @errno
%24 = load i64, i64* @ERANGE
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %40
26: ; preds = %22
%27 = load i64, i64* %7
%28 = load i64, i64* %10
%29 = icmp ule i64 %27, %28
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = load i64, i64* %8
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i64, i64* %10
%35 = load i64, i64* %8
%36 = icmp ule i64 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %33, %30
%38 = load i64, i64* %10
%39 = load i64*, i64** %9
store i64 %38, i64* %39
store i32 0, i32* %5
br label %42
40: ; preds = %33, %26, %22
br label %41
41: ; preds = %40, %18, %4
store i32 -1, i32* %5
br label %42
42: ; preds = %41, %37
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @string_to_number_ll(i8* %0, i64 %1, i64 %2, i64* nocapture writeonly %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
store i64 0, i64* @errno
%7 = call i64 @strtoull(i8* %0, i8** %5, i32 0)
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
%11 = icmp eq i8* %8, %0
%12 = or i1 %11, %10
br i1 %12, label %24, label %13
13: ; preds = %4
%14 = load i64, i64* @errno
%15 = load i64, i64* @ERANGE
%16 = icmp eq i64 %14, %15
%17 = icmp ult i64 %7, %1
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %24, label %19
19: ; preds = %13
%20 = icmp ne i64 %2, 0
%21 = icmp ugt i64 %7, %2
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %24, label %23
23: ; preds = %19
store i64 %7, i64* %3
br label %24
24: ; preds = %4, %13, %19, %23
%25 = phi i32 [ 0, %23 ], [ -1, %19 ], [ -1, %13 ], [ -1, %4 ]
ret i32 %25
}