#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 /*<<< orphan*/ die(char *, char *);
scalar_t__ errno;
char *strerror(scalar_t__);
unsigned long strtol(char const *, int /*<<< orphan*/ *, int);
unsigned long int estrtoul(const char *str, int base) {
  errno = 0;
  unsigned long int result = strtol(str, NULL, base);
  if (errno)
    die("estrtoul failed: %s", (errno == 0 ? "None" : strerror(errno)));
  return result;
}


x86 assembly (clang, -O0):
<estrtoul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e9a(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e78(%rip),%rax
cmpq   $0x0,(%rax)
je     11b6 <estrtoul+0x86>
mov    0x2e67(%rip),%rax
cmpq   $0x0,(%rax)
jne    1193 <estrtoul+0x63>
lea    0xe8a(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11a6 <estrtoul+0x76>
mov    0x2e46(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1040 <die@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<estrtoul>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%edx
mov    0x2ea3(%rip),%r14
movq   $0x0,(%r14)
xor    %esi,%esi
call   1030 <strtol@plt>
mov    %rax,%rbx
mov    (%r14),%rdi
test   %rdi,%rdi
je     116a <estrtoul+0x3a>
call   1050 <strerror@plt>
lea    0xe9e(%rip),%rdi
mov    %rax,%rsi
call   1040 <die@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [20 x i8] c"estrtoul failed: %s\00"
@.str.1 = [5 x i8] c"None\00"
define i64 @estrtoul(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
store i64 0, i64* @errno
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = call i64 @strtol(i8* %6, i32* null, i32 %7)
store i64 %8, i64* %5
%9 = load i64, i64* @errno
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
br label %18
15: ; preds = %11
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
br label %18
18: ; preds = %15, %14
%19 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %14 ], [ %17, %15 ]
%20 = call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %2
%22 = load i64, i64* %5
ret i64 %22
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [20 x i8] c"estrtoul failed: %s\00"
define i64 @estrtoul(i8* nocapture %0, i32 %1) {
store i64 0, i64* @errno
%3 = tail call i64 @strtol(i8* nocapture %0, i32* null, i32 %1)
%4 = load i64, i64* @errno
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i8* @strerror(i64 %4)
%8 = tail call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %9
9: ; preds = %6, %2
ret i64 %3
}