#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 INT_MAX;
int /*<<< orphan*/ err_exit(char *, char const *);
scalar_t__ errno;
long strtol(char const *, char **, int /*<<< orphan*/);
int get_int_arg(const char *arg) {
  long res;
  char *tail;
  errno = 0;
  res = strtol(arg, &tail, 0);
  if (errno)
    err_exit("number overflow (%s)", arg);
  if (*tail)
    err_exit("invalid number (%s)\n", arg);
  if (res > INT_MAX)
    err_exit("integer out of range (%s)\n", arg);
  if (res < 1)
    err_exit("not a positive integer (%s)\n", arg);
  return (int)res;
}


x86 assembly (clang, -O0):
<get_int_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e84(%rip),%rax
cmpq   $0x0,(%rax)
je     116e <get_int_arg+0x4e>
mov    -0x8(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1040 <err_exit@plt>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     118b <get_int_arg+0x6b>
mov    -0x8(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1040 <err_exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%rax
jle    11af <get_int_arg+0x8f>
mov    -0x8(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1040 <err_exit@plt>
cmpq   $0x1,-0x10(%rbp)
jge    11ca <get_int_arg+0xaa>
mov    -0x8(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1040 <err_exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_int_arg>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2ea5(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,%rbx
cmpq   $0x0,(%r15)
je     115e <get_int_arg+0x3e>
lea    0xeaa(%rip),%rdi
mov    %r14,%rsi
call   1040 <err_exit@plt>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1177 <get_int_arg+0x57>
lea    0xea6(%rip),%rdi
mov    %r14,%rsi
call   1040 <err_exit@plt>
mov    0x2e6a(%rip),%rax
cmp    (%rax),%rbx
jle    1192 <get_int_arg+0x72>
lea    0xea0(%rip),%rdi
mov    %r14,%rsi
call   1040 <err_exit@plt>
test   %rbx,%rbx
jg     11a6 <get_int_arg+0x86>
lea    0xea7(%rip),%rdi
mov    %r14,%rsi
call   1040 <err_exit@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [21 x i8] c"number overflow (%s)\00"
@.str.1 = [21 x i8] c"invalid number (%s)\0A\00"
@INT_MAX = global i64 0
@.str.2 = [27 x i8] c"integer out of range (%s)\0A\00"
@.str.3 = [29 x i8] c"not a positive integer (%s)\0A\00"
define i32 @get_int_arg(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i64 @strtol(i8* %5, i8** %4, i32 0)
store i64 %6, i64* %3
%7 = load i64, i64* @errno
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @err_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %9, %1
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = call i32 @err_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %12
%20 = load i64, i64* %3
%21 = load i64, i64* @INT_MAX
%22 = icmp sgt i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** %2
%25 = call i32 @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %19
%27 = load i64, i64* %3
%28 = icmp slt i64 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8*, i8** %2
%31 = call i32 @err_exit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %26
%33 = load i64, i64* %3
%34 = trunc i64 %33 to i32
ret i32 %34
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [21 x i8] c"number overflow (%s)\00"
@.str.1 = [21 x i8] c"invalid number (%s)\0A\00"
@INT_MAX = global i64 0
@.str.2 = [27 x i8] c"integer out of range (%s)\0A\00"
@.str.3 = [29 x i8] c"not a positive integer (%s)\0A\00"
define i32 @get_int_arg(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 @err_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %1
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @err_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %13, %9
%16 = load i64, i64* @INT_MAX
%17 = icmp sgt i64 %4, %16
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %20
20: ; preds = %18, %15
%21 = icmp slt i64 %4, 1
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 @err_exit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %24
24: ; preds = %22, %20
%25 = trunc i64 %4 to i32
ret i32 %25
}