#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 */
long LONG_MAX;
long LONG_MIN;
int /*<<< orphan*/ progerr(char *, ...);
int /*<<< orphan*/ progerrno(char *, char *, char *);
long strtol(char *, char **, int);
int read_integer(char *string, char *message, int low, int high) {
  char *badchar;
  long num;
  int result;
  if (!string)
    progerr("'%s' requires an integer between %d and %d.", message, low, high);
  num = strtol(string, &badchar, 10);
  if (num == LONG_MAX || num == LONG_MIN)
    progerrno("'%s': Failed to convert '%s' to a number: ", message, string);
  if (*badchar)
    progerr("Invalid char '%c' found in argument to '%s %s'", badchar[0],
            message, string);
  result = (int)num;
  if (result < low || result > high)
    progerr("'%s' value of '%d' is not an integer between %d and %d.", message,
            result, low, high);
  return result;
}


x86 assembly (clang, -O0):
<read_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1169 <read_integer+0x39>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <progerr@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
je     11a7 <read_integer+0x77>
mov    -0x28(%rbp),%rax
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%rax
jne    11bb <read_integer+0x8b>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe76(%rip),%rdi
call   1050 <progerrno@plt>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e5 <read_integer+0xb5>
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <progerr@plt>
mov    -0x28(%rbp),%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1204 <read_integer+0xd4>
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1220 <read_integer+0xf0>
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <progerr@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_integer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1164 <read_integer+0x34>
lea    0xeac(%rip),%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1030 <progerr@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rbp
mov    0x2e58(%rip),%rax
cmp    (%rax),%rbp
je     1191 <read_integer+0x61>
mov    0x2e5c(%rip),%rax
cmp    (%rax),%rbp
jne    11a3 <read_integer+0x73>
lea    0xe94(%rip),%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <progerrno@plt>
mov    0x8(%rsp),%rax
movsbl (%rax),%esi
test   %esi,%esi
je     11c3 <read_integer+0x93>
lea    0xea1(%rip),%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <progerr@plt>
cmp    %r15d,%ebp
jl     11cd <read_integer+0x9d>
cmp    %r14d,%ebp
jle    11e6 <read_integer+0xb6>
lea    0xeb2(%rip),%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1030 <progerr@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"'%s' requires an integer between %d and %d.\00"
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str.1 = [43 x i8] c"'%s': Failed to convert '%s' to a number: \00"
@.str.2 = [47 x i8] c"Invalid char '%c' found in argument to '%s %s'\00"
@.str.3 = [56 x i8] c"'%s' value of '%d' is not an integer between %d and %d.\00"
define i32 @read_integer(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %19, label %14
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = call i32 (i8*, ...) @progerr(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16, i32 %17)
br label %19
19: ; preds = %14, %4
%20 = load i8*, i8** %5
%21 = call i64 @strtol(i8* %20, i8** %9, i32 10)
store i64 %21, i64* %10
%22 = load i64, i64* %10
%23 = load i64, i64* @LONG_MAX
%24 = icmp eq i64 %22, %23
br i1 %24, label %29, label %25
25: ; preds = %19
%26 = load i64, i64* %10
%27 = load i64, i64* @LONG_MIN
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25, %19
%30 = load i8*, i8** %6
%31 = load i8*, i8** %5
%32 = call i32 @progerrno(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
br label %33
33: ; preds = %29, %25
%34 = load i8*, i8** %9
%35 = load i8, i8* %34
%36 = icmp ne i8 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %33
%38 = load i8*, i8** %9
%39 = getelementptr inbounds i8, i8* %38, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = load i8*, i8** %6
%43 = load i8*, i8** %5
%44 = call i32 (i8*, ...) @progerr(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %41, i8* %42, i8* %43)
br label %45
45: ; preds = %37, %33
%46 = load i64, i64* %10
%47 = trunc i64 %46 to i32
store i32 %47, i32* %11
%48 = load i32, i32* %11
%49 = load i32, i32* %7
%50 = icmp slt i32 %48, %49
br i1 %50, label %55, label %51
51: ; preds = %45
%52 = load i32, i32* %11
%53 = load i32, i32* %8
%54 = icmp sgt i32 %52, %53
br i1 %54, label %55, label %61
55: ; preds = %51, %45
%56 = load i8*, i8** %6
%57 = load i32, i32* %11
%58 = load i32, i32* %7
%59 = load i32, i32* %8
%60 = call i32 (i8*, ...) @progerr(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i8* %56, i32 %57, i32 %58, i32 %59)
br label %61
61: ; preds = %55, %51
%62 = load i32, i32* %11
ret i32 %62
}

LLVM IR (-O2):
@.str = [44 x i8] c"'%s' requires an integer between %d and %d.\00"
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str.1 = [43 x i8] c"'%s': Failed to convert '%s' to a number: \00"
@.str.2 = [47 x i8] c"Invalid char '%c' found in argument to '%s %s'\00"
@.str.3 = [56 x i8] c"'%s' value of '%d' is not an integer between %d and %d.\00"
define i32 @read_integer(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = icmp eq i8* %0, null
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 (i8*, ...) @progerr(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2, i32 %3)
br label %10
10: ; preds = %8, %4
%11 = call i64 @strtol(i8* %0, i8** %5, i32 10)
%12 = load i64, i64* @LONG_MAX
%13 = icmp eq i64 %11, %12
%14 = load i64, i64* @LONG_MIN
%15 = icmp eq i64 %11, %14
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = tail call i32 @progerrno(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %0)
br label %19
19: ; preds = %10, %17
%20 = load i8*, i8** %5
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = sext i8 %21 to i32
%25 = tail call i32 (i8*, ...) @progerr(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %24, i8* %1, i8* %0)
br label %26
26: ; preds = %23, %19
%27 = trunc i64 %11 to i32
%28 = icmp slt i32 %27, %2
%29 = icmp sgt i32 %27, %3
%30 = or i1 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = tail call i32 (i8*, ...) @progerr(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %27, i32 %2, i32 %3)
br label %33
33: ; preds = %26, %31
ret i32 %27
}