#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__ EINVAL;
scalar_t__ ERANGE;
long INT_MAX;
long INT_MIN;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
long strtol(char *, char **, int);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("USAGE\n\tint_arg number\n");
    exit(1);
  }
  char *endptr = NULL;
  errno = 0;
  long x = strtol(argv[1], &endptr, 10);
  if (*endptr != 0 || errno) {
    if (errno == EINVAL) {
      printf("No conversion could be performed!\n");
      exit(1);
    } else if (errno == ERANGE) {
      printf("Conversion out of range!\n");
      exit(1);
    }
    printf("Error occured at: %s\n", endptr);
    exit(1);
  }
  if (x > INT_MAX) {
    printf("INT_MAX: %d\n", INT_MAX);
    printf("Passed value %ld is too big for an int!\n", x);
    exit(1);
  }
  if (x < INT_MIN) {
    printf("INT_MIN: %d\n", INT_MIN);
    printf("Passed value %ld is too small for an int!\n", x);
    exit(1);
  }
  printf("Successful, x is: %d\n", (int)x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1168 <main+0x38>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movq   $0x0,-0x18(%rbp)
mov    0x2e51(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b9 <main+0x89>
mov    0x2e19(%rip),%rax
cmpq   $0x0,(%rax)
je     123e <main+0x10e>
mov    0x2e08(%rip),%rax
mov    (%rax),%rax
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%rax
jne    11eb <main+0xbb>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%rax
jne    121d <main+0xed>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1222 <main+0xf2>
mov    -0x18(%rbp),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%rax
jle    1286 <main+0x156>
mov    0x2d8f(%rip),%rax
mov    (%rax),%rsi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
mov    0x2d4f(%rip),%rcx
cmp    (%rcx),%rax
jge    12ce <main+0x19e>
mov    0x2d3f(%rip),%rax
mov    (%rax),%rsi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11bc <main+0x7c>
movq   $0x0,(%rsp)
mov    0x2e70(%rip),%r14
movq   $0x0,(%r14)
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rbx
mov    (%rsp),%rsi
cmpb   $0x0,(%rsi)
mov    (%r14),%rax
jne    11c5 <main+0x85>
test   %rax,%rax
jne    11c5 <main+0x85>
mov    0x2e5d(%rip),%rax
mov    (%rax),%rsi
cmp    %rsi,%rbx
jg     11da <main+0x9a>
mov    0x2e46(%rip),%rax
mov    (%rax),%rsi
cmp    %rsi,%rbx
jl     11f4 <main+0xb4>
lea    0xedb(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xf12(%rip),%rdi
jmp    1221 <main+0xe1>
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%rax
jne    120e <main+0xce>
lea    0xedb(%rip),%rdi
jmp    1221 <main+0xe1>
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe34(%rip),%rdi
mov    %rbx,%rsi
jmp    1237 <main+0xf7>
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe50(%rip),%rdi
mov    %rbx,%rsi
jmp    1237 <main+0xf7>
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%rax
jne    1230 <main+0xf0>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xdc9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"USAGE\0A\09int_arg number\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [35 x i8] c"No conversion could be performed!\0A\00"
@ERANGE = global i64 0
@.str.2 = [26 x i8] c"Conversion out of range!\0A\00"
@.str.3 = [22 x i8] c"Error occured at: %s\0A\00"
@INT_MAX = global i64 0
@.str.4 = [13 x i8] c"INT_MAX: %d\0A\00"
@.str.5 = [41 x i8] c"Passed value %ld is too big for an int!\0A\00"
@INT_MIN = global i64 0
@.str.6 = [13 x i8] c"INT_MIN: %d\0A\00"
@.str.7 = [43 x i8] c"Passed value %ld is too small for an int!\0A\00"
@.str.8 = [22 x i8] c"Successful, x is: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
store i8* null, i8** %6
store i64 0, i64* @errno
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strtol(i8* %16, i8** %6, i32 10)
store i64 %17, i64* %7
%18 = load i8*, i8** %6
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %13
%23 = load i64, i64* @errno
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %44
25: ; preds = %22, %13
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINVAL
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %25
%33 = load i64, i64* @errno
%34 = load i64, i64* @ERANGE
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %32
br label %40
40: ; preds = %39
%41 = load i8*, i8** %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %22
%45 = load i64, i64* %7
%46 = load i64, i64* @INT_MAX
%47 = icmp sgt i64 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %44
%49 = load i64, i64* @INT_MAX
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 %49)
%51 = load i64, i64* %7
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i64 %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %44
%55 = load i64, i64* %7
%56 = load i64, i64* @INT_MIN
%57 = icmp slt i64 %55, %56
br i1 %57, label %58, label %64
58: ; preds = %54
%59 = load i64, i64* @INT_MIN
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 %59)
%61 = load i64, i64* %7
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i64 %61)
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %54
%65 = load i64, i64* %7
%66 = trunc i64 %65 to i32
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i32 %66)
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@.str.3 = [22 x i8] c"Error occured at: %s\0A\00"
@INT_MAX = global i64 0
@.str.4 = [13 x i8] c"INT_MAX: %d\0A\00"
@.str.5 = [41 x i8] c"Passed value %ld is too big for an int!\0A\00"
@INT_MIN = global i64 0
@.str.6 = [13 x i8] c"INT_MIN: %d\0A\00"
@.str.7 = [43 x i8] c"Passed value %ld is too small for an int!\0A\00"
@.str.8 = [22 x i8] c"Successful, x is: %d\0A\00"
@str = [25 x i8] c"Conversion out of range!\00"
@str.9 = [34 x i8] c"No conversion could be performed!\00"
@str.10 = [22 x i8] c"USAGE\0A\09int_arg number\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = bitcast i8** %3 to i8*
store i8* null, i8** %3
store i64 0, i64* @errno
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @strtol(i8* %11, i8** %3, i32 10)
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
%16 = load i64, i64* @errno
%17 = icmp ne i64 %16, 0
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %34
19: ; preds = %8
%20 = load i64, i64* @EINVAL
%21 = icmp eq i64 %16, %20
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.9, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %19
%26 = load i64, i64* @ERANGE
%27 = icmp eq i64 %16, %26
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %25
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %8
%35 = load i64, i64* @INT_MAX
%36 = icmp sgt i64 %12, %35
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 %35)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i64 %12)
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %34
%42 = load i64, i64* @INT_MIN
%43 = icmp slt i64 %12, %42
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 %42)
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i64 %12)
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %41
%49 = trunc i64 %12 to i32
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i32 %49)
ret i32 0
}