#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 errno;
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
scalar_t__ strlen(char *);
unsigned long strtoul(char *, char **, int);
int main(int argc, char **argv) {
  char *endptr;
  char *dec;
  int i, base, save_errno;
  unsigned long result;
  base = 0;
  for (i = 1; ((i == 1) || (i < argc)); ++i) {
    dec = (argc > i) ? argv[i] : "508882404962533554393";
    printf("input: '%s'\n", dec);
    errno = 0;
    result = strtoul(dec, &endptr, base);
    save_errno = errno;
    if (endptr && strlen(endptr) > 0) {
      printf("endptr '%s'\n", endptr);
    }
    if (save_errno) {
      printf("errno %d: '%s'\n", save_errno, strerror(save_errno));
    }
    printf("result: %lu\n", result);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x24(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x24(%rbp)
mov    %al,-0x39(%rbp)
je     117f <main+0x3f>
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    118f <main+0x4f>
jmp    1283 <main+0x143>
mov    -0x8(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    11b0 <main+0x70>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
jmp    11c0 <main+0x80>
lea    0xe49(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    11c0 <main+0x80>
mov    -0x48(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dff(%rip),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1050 <strtoul@plt>
mov    %rax,-0x38(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1237 <main+0xf7>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jle    1237 <main+0xf7>
mov    -0x18(%rbp),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1263 <main+0x123>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x2c(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x4c(%rbp),%esi
mov    %rax,%rdx
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1164 <main+0x24>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,(%rsp)
cmp    $0x2,%edi
setge  %al
movslq %edi,%rdx
cmp    $0x3,%edx
mov    $0x2,%ecx
mov    %rdx,0x8(%rsp)
cmovge %edx,%ecx
mov    $0x1,%r12d
sub    %rcx,%r12
mov    $0x2,%ebx
mov    0x2e60(%rip),%r15
jmp    11bf <main+0x7f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xea9(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0x8(%rsp),%rbx
setl   %al
lea    (%r12,%rbx,1),%rcx
add    $0x1,%rcx
add    $0x1,%rbx
cmp    $0x2,%rcx
je     1252 <main+0x112>
lea    0xe3a(%rip),%rbp
test   $0x1,%al
je     11d3 <main+0x93>
mov    (%rsp),%rax
mov    -0x8(%rax,%rbx,8),%rbp
lea    0xe3c(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%r15)
mov    %rbp,%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,%rbp
mov    (%r15),%r13d
mov    0x10(%rsp),%r14
test   %r14,%r14
je     1228 <main+0xe8>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
jle    1228 <main+0xe8>
lea    0xe05(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r13d,%r13d
je     1190 <main+0x50>
mov    %r13d,%edi
call   1060 <strerror@plt>
lea    0xdf0(%rip),%rdi
mov    %r13d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1190 <main+0x50>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"508882404962533554393\00"
@.str.1 = [13 x i8] c"input: '%s'\0A\00"
@errno = global i32 0
@.str.2 = [13 x i8] c"endptr '%s'\0A\00"
@.str.3 = [16 x i8] c"errno %d: '%s'\0A\00"
@.str.4 = [13 x i8] c"result: %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 1, i32* %8
br label %12
12: ; preds = %60, %2
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, 1
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = load i32, i32* %8
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ true, %12 ], [ %18, %15 ]
br i1 %20, label %21, label %63
21: ; preds = %19
%22 = load i32, i32* %4
%23 = load i32, i32* %8
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
br label %32
31: ; preds = %21
br label %32
32: ; preds = %31, %25
%33 = phi i8* [ %30, %25 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %31 ]
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %34)
store i32 0, i32* @errno
%36 = load i8*, i8** %7
%37 = load i32, i32* %9
%38 = call i64 @strtoul(i8* %36, i8** %6, i32 %37)
store i64 %38, i64* %11
%39 = load i32, i32* @errno
store i32 %39, i32* %10
%40 = load i8*, i8** %6
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %49
42: ; preds = %32
%43 = load i8*, i8** %6
%44 = call i64 @strlen(i8* %43)
%45 = icmp sgt i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i8*, i8** %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %42, %32
%50 = load i32, i32* %10
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = load i32, i32* %10
%54 = load i32, i32* %10
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %53, i8* %55)
br label %57
57: ; preds = %52, %49
%58 = load i64, i64* %11
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 %58)
br label %60
60: ; preds = %57
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %12
63: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"508882404962533554393\00"
@.str.1 = [13 x i8] c"input: '%s'\0A\00"
@errno = global i32 0
@.str.2 = [13 x i8] c"endptr '%s'\0A\00"
@.str.3 = [16 x i8] c"errno %d: '%s'\0A\00"
@.str.4 = [13 x i8] c"result: %lu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp sgt i32 %0, 1
%6 = sext i32 %0 to i64
%7 = call i32 @llvm.smax.i32(i32 %0, i32 2)
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %2, %32
%10 = phi i64 [ 1, %2 ], [ %34, %32 ]
%11 = phi i1 [ %5, %2 ], [ %35, %32 ]
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = getelementptr inbounds i8*, i8** %1, i64 %10
%14 = load i8*, i8** %13
br label %15
15: ; preds = %9, %12
%16 = phi i8* [ %14, %12 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %9 ]
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 0, i32* @errno
%18 = call i64 @strtoul(i8* %16, i8** %3, i32 0)
%19 = load i32, i32* @errno
%20 = load i8*, i8** %3
%21 = icmp eq i8* %20, null
br i1 %21, label %27, label %22
22: ; preds = %15
%23 = tail call i64 @strlen(i8* %20)
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %27
27: ; preds = %25, %22, %15
%28 = icmp eq i32 %19, 0
br i1 %28, label %32, label %29
29: ; preds = %27
%30 = tail call i8* @strerror(i32 %19)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %19, i8* %30)
br label %32
32: ; preds = %29, %27
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 %18)
%34 = add nuw nsw i64 %10, 1
%35 = icmp slt i64 %34, %6
%36 = icmp eq i64 %34, %8
br i1 %36, label %37, label %9
37: ; preds = %32
ret i32 0
}