#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__ errno;
int /*<<< orphan*/ fatal(char *, ...);
int /*<<< orphan*/ strerror(scalar_t__);
long long strtoll(char const *, char **, int);
long long cli_strtonum(const char *str, long long min, long long max) {
  long long l;
  char *ep;
  if (min > max)
    fatal("cli_strtonum: min > max");
  errno = 0;
  l = strtoll(str, &ep, 10);
  if (errno != 0 || str == ep || *ep != '\0')
    fatal("strtoll(): %s", strerror(errno));
  if (l < min)
    fatal("cli_strtonum: value < min");
  if (l > max)
    fatal("cli_strtonum: value > max");
  return (l);
}


x86 assembly (clang, -O0):
<cli_strtonum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jle    1160 <cli_strtonum+0x30>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1050 <fatal@plt>
mov    0x2e79(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e55(%rip),%rax
cmpq   $0x0,(%rax)
jne    11b3 <cli_strtonum+0x83>
mov    -0x8(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11b3 <cli_strtonum+0x83>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d2 <cli_strtonum+0xa2>
mov    0x2e26(%rip),%rax
mov    (%rax),%rdi
call   1040 <strerror@plt>
mov    %eax,%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <fatal@plt>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11ee <cli_strtonum+0xbe>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <fatal@plt>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jle    120a <cli_strtonum+0xda>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <fatal@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cli_strtonum>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
cmp    %rdx,%rsi
jle    1159 <cli_strtonum+0x29>
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1050 <fatal@plt>
mov    0x2e80(%rip),%r13
movq   $0x0,0x0(%r13)
lea    0x8(%rsp),%rsi
mov    %r12,%rdi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    %rax,%rbx
mov    0x0(%r13),%rdi
test   %rdi,%rdi
je     11d2 <cli_strtonum+0xa2>
call   1040 <strerror@plt>
lea    0xe86(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <fatal@plt>
cmp    %r15,%rbx
jge    11ae <cli_strtonum+0x7e>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <fatal@plt>
cmp    %r14,%rbx
jle    11c1 <cli_strtonum+0x91>
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <fatal@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x8(%rsp),%rax
cmp    %r12,%rax
je     1186 <cli_strtonum+0x56>
cmpb   $0x0,(%rax)
jne    1186 <cli_strtonum+0x56>
jmp    119b <cli_strtonum+0x6b>

LLVM IR (-O0):
@.str = [24 x i8] c"cli_strtonum: min > max\00"
@errno = global i64 0
@.str.1 = [14 x i8] c"strtoll(): %s\00"
@.str.2 = [26 x i8] c"cli_strtonum: value < min\00"
@.str.3 = [26 x i8] c"cli_strtonum: value > max\00"
define i64 @cli_strtonum(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i64, i64* %5
%10 = load i64, i64* %6
%11 = icmp sgt i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
store i64 0, i64* @errno
%15 = load i8*, i8** %4
%16 = call i64 @strtoll(i8* %15, i8** %8, i32 10)
store i64 %16, i64* %7
%17 = load i64, i64* @errno
%18 = icmp ne i64 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = load i8*, i8** %8
%22 = icmp eq i8* %20, %21
br i1 %22, label %28, label %23
23: ; preds = %19
%24 = load i8*, i8** %8
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23, %19, %14
%29 = load i64, i64* @errno
%30 = call i32 @strerror(i64 %29)
%31 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %28, %23
%33 = load i64, i64* %7
%34 = load i64, i64* %5
%35 = icmp slt i64 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
%39 = load i64, i64* %7
%40 = load i64, i64* %6
%41 = icmp sgt i64 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = load i64, i64* %7
ret i64 %45
}

LLVM IR (-O2):
@.str = [24 x i8] c"cli_strtonum: min > max\00"
@errno = global i64 0
@.str.1 = [14 x i8] c"strtoll(): %s\00"
@.str.2 = [26 x i8] c"cli_strtonum: value < min\00"
@.str.3 = [26 x i8] c"cli_strtonum: value > max\00"
define i64 @cli_strtonum(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp sgt i64 %1, %2
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
store i64 0, i64* @errno
%10 = call i64 @strtoll(i8* %0, i8** %4, i32 10)
%11 = load i64, i64* @errno
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, %0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i8, i8* %14
%18 = icmp eq i8 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16, %13, %9
%20 = tail call i32 @strerror(i64 %11)
%21 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %16
%23 = icmp slt i64 %10, %1
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %22
%27 = icmp sgt i64 %10, %2
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %26
ret i64 %10
}