#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 ERANGE;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
long strtol(char *, int /*<<< orphan*/ *, int);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  long n;
  unsigned long u;
  if (argc < 2) {
    puts("no argument");
    exit(1);
  }
  errno = 0;
  n = strtol(argv[1], NULL, 10);
  printf("strtol(%s) = %ld\n", argv[1], n);
  if (errno == 0) {
    printf("errno == 0\n");
  } else if (errno == ERANGE) {
    printf("errno == ERANGE\n");
  } else {
    printf("errno == %d\n", errno);
  }
  errno = 0;
  u = strtoul("-1", NULL, 10);
  printf("strtoul(\"-1\") = %lu\n", u);
  printf("errno == %d\n", errno);
  u = strtoul("-3", NULL, 10);
  printf("strtoul(\"-3\") = %lu\n", u);
  u = (unsigned long)(-1L);
  printf("(unsigned long)(-1L) = %lu\n", u);
  exit(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)
jge    1186 <main+0x36>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e4b(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e0a(%rip),%rax
cmpl   $0x0,(%rax)
jne    11ea <main+0x9a>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1231 <main+0xe1>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    0x2dee(%rip),%rcx
cmp    (%rcx),%eax
jne    1215 <main+0xc5>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122c <main+0xdc>
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1231 <main+0xe1>
mov    0x2da0(%rip),%rax
movl   $0x0,(%rax)
lea    0xe03(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdd9(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0xffffffffffffffff,-0x20(%rbp)
ff
mov    -0x20(%rbp),%rsi
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     116f <main+0x1f>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %rsi,%rbx
mov    0x2e5f(%rip),%r14
movl   $0x0,(%r14)
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    0x8(%rbx),%rsi
lea    0xe71(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%esi
test   %esi,%esi
jne    11ba <main+0x6a>
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
jmp    11e1 <main+0x91>
mov    0x2e27(%rip),%rax
cmp    (%rax),%esi
jne    11d3 <main+0x83>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
jmp    11e1 <main+0x91>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%r14)
lea    0xe3c(%rip),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
lea    0xe2c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%esi
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe1f(%rip),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
lea    0xe0f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe13(%rip),%rdi
mov    $0xffffffffffffffff,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"no argument\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"strtol(%s) = %ld\0A\00"
@.str.2 = [12 x i8] c"errno == 0\0A\00"
@ERANGE = global i32 0
@.str.3 = [17 x i8] c"errno == ERANGE\0A\00"
@.str.4 = [13 x i8] c"errno == %d\0A\00"
@.str.5 = [3 x i8] c"-1\00"
@.str.6 = [21 x i8] c"strtoul(\22-1\22) = %lu\0A\00"
@.str.7 = [3 x i8] c"-3\00"
@.str.8 = [21 x i8] c"strtoul(\22-3\22) = %lu\0A\00"
@.str.9 = [28 x i8] c"(unsigned long)(-1L) = %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%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 slt i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
store i32 0, i32* @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, i32* null, i32 10)
store i64 %17, i64* %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i64, i64* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %20, i64 %21)
%23 = load i32, i32* @errno
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %13
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %37
27: ; preds = %13
%28 = load i32, i32* @errno
%29 = load i32, i32* @ERANGE
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %36
33: ; preds = %27
%34 = load i32, i32* @errno
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %31
br label %37
37: ; preds = %36, %25
store i32 0, i32* @errno
%38 = call i64 @strtoul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* null, i32 10)
store i64 %38, i64* %7
%39 = load i64, i64* %7
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i64 %39)
%41 = load i32, i32* @errno
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = call i64 @strtoul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* null, i32 10)
store i64 %43, i64* %7
%44 = load i64, i64* %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i64 %44)
store i64 -1, i64* %7
%46 = load i64, i64* %7
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i64 %46)
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"no argument\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"strtol(%s) = %ld\0A\00"
@ERANGE = global i32 0
@.str.4 = [13 x i8] c"errno == %d\0A\00"
@.str.5 = [3 x i8] c"-1\00"
@.str.6 = [21 x i8] c"strtoul(\22-1\22) = %lu\0A\00"
@.str.7 = [3 x i8] c"-3\00"
@.str.8 = [21 x i8] c"strtoul(\22-3\22) = %lu\0A\00"
@.str.9 = [28 x i8] c"(unsigned long)(-1L) = %lu\0A\00"
@str = [16 x i8] c"errno == ERANGE\00"
@str.10 = [11 x i8] c"errno == 0\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
store i32 0, i32* @errno
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strtol(i8* nocapture %9, i32* null, i32 10)
%11 = load i8*, i8** %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %11, i64 %10)
%13 = load i32, i32* @errno
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.10, i64 0, i64 0))
br label %24
17: ; preds = %7
%18 = load i32, i32* @ERANGE
%19 = icmp eq i32 %13, %18
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %24
22: ; preds = %17
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %13)
br label %24
24: ; preds = %20, %22, %15
store i32 0, i32* @errno
%25 = tail call i64 @strtoul(i8* nocapture getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* null, i32 10)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i64 %25)
%27 = load i32, i32* @errno
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = tail call i64 @strtoul(i8* nocapture getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* null, i32 10)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i64 %29)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i64 -1)
%32 = tail call i32 @exit(i32 0)
unreachable
}