#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 */
int /*<<< orphan*/ fatal(char *, ...);
long strtol(char const *, char **, int);
int strtoint(const char *s, int minVal, int maxVal) {
  char *ptr;
  if (!*s) {
    fatal("Missing numeric value.");
  }
  long l = strtol(s, &ptr, 10);
  if (*ptr || l < minVal || l > maxVal) {
    fatal("Range error on numeric value \"%s\".", s);
  }
  return l;
}


x86 assembly (clang, -O0):
<strtoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    114d <strtoint+0x2d>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <fatal@plt>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1195 <strtoint+0x75>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmp    %rcx,%rax
jl     1195 <strtoint+0x75>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmp    %rcx,%rax
jle    11a7 <strtoint+0x87>
mov    -0x8(%rbp),%rsi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <fatal@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoint>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
jne    1143 <strtoint+0x23>
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <fatal@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rbp
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    116f <strtoint+0x4f>
movslq %r15d,%rax
cmp    %rax,%rbp
jl     116f <strtoint+0x4f>
movslq %r14d,%rax
cmp    %rax,%rbp
jle    1180 <strtoint+0x60>
lea    0xea1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <fatal@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Missing numeric value.\00"
@.str.1 = [35 x i8] c"Range error on numeric value \22%s\22.\00"
define i32 @strtoint(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
%15 = load i8*, i8** %4
%16 = call i64 @strtol(i8* %15, i8** %7, i32 10)
store i64 %16, i64* %8
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %31, label %21
21: ; preds = %14
%22 = load i64, i64* %8
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = load i64, i64* %8
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = icmp sgt i64 %27, %29
br i1 %30, label %31, label %34
31: ; preds = %26, %21, %14
%32 = load i8*, i8** %4
%33 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %26
%35 = load i64, i64* %8
%36 = trunc i64 %35 to i32
ret i32 %36
}

LLVM IR (-O2):
@.str = [23 x i8] c"Missing numeric value.\00"
@.str.1 = [35 x i8] c"Range error on numeric value \22%s\22.\00"
define i32 @strtoint(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
%11 = call i64 @strtol(i8* %0, i8** %4, i32 10)
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
%15 = sext i32 %1 to i64
%16 = icmp slt i64 %11, %15
%17 = select i1 %14, i1 true, i1 %16
%18 = sext i32 %2 to i64
%19 = icmp sgt i64 %11, %18
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %21, label %23
21: ; preds = %10
%22 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %23
23: ; preds = %10, %21
%24 = trunc i64 %11 to i32
ret i32 %24
}