#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 LONG_MAX;
int LONG_MIN;
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int strtol(char *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  int error;
  char *end_ptr;
  if (argc < 2) {
    usage(argv[0]);
    return -1;
  }
  error = strtol(argv[1], &end_ptr, 0);
  if (end_ptr == argv[1]) {
    printf("Invalid input string - %s\n", argv[1]);
  } else if (error == LONG_MIN) {
    printf("Underflow on - %s\n", argv[1]);
  } else if (error == LONG_MAX) {
    printf("Overflow on - %s\n", argv[1]);
  } else {
    printf("errno: %d - %s\n", error, strerror(error));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1178 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1248 <main+0x108>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
jne    11bb <main+0x7b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <main+0x101>
mov    -0x14(%rbp),%eax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%eax
jne    11e8 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123c <main+0xfc>
mov    -0x14(%rbp),%eax
mov    0x2de6(%rip),%rcx
cmp    (%rcx),%eax
jne    1215 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1237 <main+0xf7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%esi
mov    %rax,%rdx
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123c <main+0xfc>
jmp    1241 <main+0x101>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
jg     1160 <main+0x20>
mov    0x0(%rbp),%rdi
call   1050 <usage@plt>
mov    $0xffffffff,%ebx
jmp    11c0 <main+0x80>
mov    0x8(%rbp),%rdi
lea    0x8(%rsp),%rsi
xor    %ebx,%ebx
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%r14d
mov    0x8(%rsp),%rax
mov    0x8(%rbp),%rsi
cmp    %rsi,%rax
je     1198 <main+0x58>
mov    0x2e5e(%rip),%rax
cmp    (%rax),%r14d
jne    11a4 <main+0x64>
lea    0xe85(%rip),%rdi
jmp    11b7 <main+0x77>
lea    0xe61(%rip),%rdi
mov    %rax,%rsi
jmp    11b9 <main+0x79>
mov    0x2e2d(%rip),%rax
cmp    (%rax),%r14d
jne    11cb <main+0x8b>
lea    0xe77(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14d,%edi
call   1060 <strerror@plt>
lea    0xe66(%rip),%rdi
xor    %ebx,%ebx
mov    %r14d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c0 <main+0x80>

LLVM IR (-O0):
@.str = [27 x i8] c"Invalid input string - %s\0A\00"
@LONG_MIN = global i32 0
@.str.1 = [19 x i8] c"Underflow on - %s\0A\00"
@LONG_MAX = global i32 0
@.str.2 = [18 x i8] c"Overflow on - %s\0A\00"
@.str.3 = [16 x i8] c"errno: %d - %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @usage(i8* %13)
store i32 -1, i32* %3
br label %56
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strtol(i8* %18, i8** %7, i32 0)
store i32 %19, i32* %6
%20 = load i8*, i8** %7
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = icmp eq i8* %20, %23
br i1 %24, label %25, label %30
25: ; preds = %15
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %55
30: ; preds = %15
%31 = load i32, i32* %6
%32 = load i32, i32* @LONG_MIN
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %54
39: ; preds = %30
%40 = load i32, i32* %6
%41 = load i32, i32* @LONG_MAX
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %53
48: ; preds = %39
%49 = load i32, i32* %6
%50 = load i32, i32* %6
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %49, i8* %51)
br label %53
53: ; preds = %48, %43
br label %54
54: ; preds = %53, %34
br label %55
55: ; preds = %54, %25
store i32 0, i32* %3
br label %56
56: ; preds = %55, %10
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [27 x i8] c"Invalid input string - %s\0A\00"
@LONG_MIN = global i32 0
@.str.1 = [19 x i8] c"Underflow on - %s\0A\00"
@LONG_MAX = global i32 0
@.str.2 = [18 x i8] c"Overflow on - %s\0A\00"
@.str.3 = [16 x i8] c"errno: %d - %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %31
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @strtol(i8* %11, i8** %3, i32 0)
%13 = load i8*, i8** %3
%14 = load i8*, i8** %10
%15 = icmp eq i8* %13, %14
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %31
18: ; preds = %9
%19 = load i32, i32* @LONG_MIN
%20 = icmp eq i32 %12, %19
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %31
23: ; preds = %18
%24 = load i32, i32* @LONG_MAX
%25 = icmp eq i32 %12, %24
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %31
28: ; preds = %23
%29 = tail call i8* @strerror(i32 %12)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %12, i8* %29)
br label %31
31: ; preds = %16, %26, %28, %21, %6
%32 = phi i32 [ -1, %6 ], [ 0, %21 ], [ 0, %28 ], [ 0, %26 ], [ 0, %16 ]
ret i32 %32
}