#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*/ eprintf(char *, char const *, ...);
scalar_t__ errno;
unsigned long strtoul(char const *, char **, int);
unsigned long estrtoul(const char *s, int base) {
  char *end;
  unsigned long n;
  errno = 0;
  n = strtoul(s, &end, base);
  if (*end != '\0') {
    if (base == 0)
      eprintf("%s: not an integer\n", s);
    else
      eprintf("%s: not a base %d integer\n", s, base);
  }
  if (errno != 0)
    eprintf("%s:", s);
  return n;
}


x86 assembly (clang, -O0):
<estrtoul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2eaa(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1040 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119c <estrtoul+0x7c>
cmpl   $0x0,-0xc(%rbp)
jne    1182 <estrtoul+0x62>
mov    -0x8(%rbp),%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <eprintf@plt>
jmp    1197 <estrtoul+0x77>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <eprintf@plt>
jmp    119c <estrtoul+0x7c>
mov    0x2e3d(%rip),%rax
cmpq   $0x0,(%rax)
je     11bf <estrtoul+0x9f>
mov    -0x8(%rbp),%rsi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <eprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<estrtoul>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2ead(%rip),%r15
movq   $0x0,(%r15)
mov    %rsp,%rsi
mov    %ebp,%edx
call   1040 <strtoul@plt>
mov    %rax,%r14
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     1167 <estrtoul+0x47>
test   %ebp,%ebp
je     118c <estrtoul+0x6c>
lea    0xeb9(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <eprintf@plt>
cmpq   $0x0,(%r15)
je     117e <estrtoul+0x5e>
lea    0xebb(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <eprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe6d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <eprintf@plt>
cmpq   $0x0,(%r15)
jne    116d <estrtoul+0x4d>
jmp    117e <estrtoul+0x5e>

LLVM IR (-O0):
@errno = global i64 0
@.str = [20 x i8] c"%s: not an integer\0A\00"
@.str.1 = [27 x i8] c"%s: not a base %d integer\0A\00"
@.str.2 = [4 x i8] c"%s:\00"
define i64 @estrtoul(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
store i64 0, i64* @errno
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = call i64 @strtoul(i8* %7, i8** %5, i32 %8)
store i64 %9, i64* %6
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = call i32 (i8*, i8*, ...) @eprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %24
20: ; preds = %14
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = call i32 (i8*, i8*, ...) @eprintf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %22)
br label %24
24: ; preds = %20, %17
br label %25
25: ; preds = %24, %2
%26 = load i64, i64* @errno
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %3
%30 = call i32 (i8*, i8*, ...) @eprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %25
%32 = load i64, i64* %6
ret i64 %32
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [20 x i8] c"%s: not an integer\0A\00"
@.str.1 = [27 x i8] c"%s: not a base %d integer\0A\00"
@.str.2 = [4 x i8] c"%s:\00"
define i64 @estrtoul(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call i64 @strtoul(i8* %0, i8** %3, i32 %1)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = icmp eq i32 %1, 0
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 (i8*, i8*, ...) @eprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %15
13: ; preds = %9
%14 = tail call i32 (i8*, i8*, ...) @eprintf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1)
br label %15
15: ; preds = %11, %13, %2
%16 = load i64, i64* @errno
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 (i8*, i8*, ...) @eprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %20
20: ; preds = %18, %15
ret i64 %5
}