#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*/ EXIT_FAILURE;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char const *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char const *, char const *);
unsigned long strtoul(char const *, char **, int);
unsigned long strtoul_or_err(const char *str, const char *errmesg) {
  unsigned long num;
  char *end = NULL;
  if (str == NULL || *str == '\0')
    goto err;
  errno = 0;
  num = strtoul(str, &end, 10);
  if (errno || str == end || (end && *end))
    goto err;
  return num;
err:
  if (errno)
    err(EXIT_FAILURE, "%s: '%s'", errmesg, str);
  errx(EXIT_FAILURE, "%s: '%s'", errmesg, str);
}


x86 assembly (clang, -O0):
<strtoul_or_err>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1163 <strtoul_or_err+0x33>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1168 <strtoul_or_err+0x38>
jmp    11d8 <strtoul_or_err+0xa8>
mov    0x2e71(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e4d(%rip),%rax
cmpq   $0x0,(%rax)
jne    11c6 <strtoul_or_err+0x96>
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11c6 <strtoul_or_err+0x96>
cmpq   $0x0,-0x28(%rbp)
je     11cb <strtoul_or_err+0x9b>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cb <strtoul_or_err+0x9b>
jmp    11d8 <strtoul_or_err+0xa8>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1223 <strtoul_or_err+0xf3>
mov    0x2e01(%rip),%rax
cmpq   $0x0,(%rax)
je     1206 <strtoul_or_err+0xd6>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdff(%rip),%rsi
call   1040 <err@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xde2(%rip),%rsi
call   1030 <errx@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoul_or_err>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
test   %rdi,%rdi
je     118c <strtoul_or_err+0x5c>
cmpb   $0x0,(%rbx)
je     118c <strtoul_or_err+0x5c>
mov    0x2e87(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1050 <strtoul@plt>
cmpq   $0x0,(%r15)
jne    1199 <strtoul_or_err+0x69>
mov    0x8(%rsp),%rcx
cmp    %rbx,%rcx
je     11b4 <strtoul_or_err+0x84>
test   %rcx,%rcx
je     11cf <strtoul_or_err+0x9f>
cmpb   $0x0,(%rcx)
je     11cf <strtoul_or_err+0x9f>
mov    0x2e4d(%rip),%rax
cmpq   $0x0,(%rax)
je     11b4 <strtoul_or_err+0x84>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <err@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <errx@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@.str = [9 x i8] c"%s: '%s'\00"
define i64 @strtoul_or_err(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %7
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10, %2
br label %36
16: ; preds = %10
store i64 0, i64* @errno
%17 = load i8*, i8** %4
%18 = call i64 @strtoul(i8* %17, i8** %7, i32 10)
store i64 %18, i64* %6
%19 = load i64, i64* @errno
%20 = icmp ne i64 %19, 0
br i1 %20, label %33, label %21
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i8*, i8** %7
%24 = icmp eq i8* %22, %23
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = load i8*, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i8*, i8** %7
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28, %21, %16
br label %36
34: ; preds = %28, %25
%35 = load i64, i64* %6
store i64 %35, i64* %3
br label %49
36: ; preds = %33, %15
%37 = load i64, i64* @errno
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i32, i32* @EXIT_FAILURE
%41 = load i8*, i8** %5
%42 = load i8*, i8** %4
%43 = call i32 @err(i32 %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %41, i8* %42)
br label %44
44: ; preds = %39, %36
%45 = load i32, i32* @EXIT_FAILURE
%46 = load i8*, i8** %5
%47 = load i8*, i8** %4
%48 = call i32 @errx(i32 %45, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %46, i8* %47)
br label %49
49: ; preds = %44, %34
%50 = load i64, i64* %3
ret i64 %50
}

LLVM IR (-O2):
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@.str = [9 x i8] c"%s: '%s'\00"
define i64 @strtoul_or_err(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = icmp eq i8* %0, null
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %6
store i64 0, i64* @errno
%10 = call i64 @strtoul(i8* %0, i8** %3, i32 10)
%11 = load i64, i64* @errno
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, %0
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = icmp eq i8* %14, null
br i1 %17, label %30, label %18
18: ; preds = %16
%19 = load i8, i8* %14
%20 = icmp eq i8 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %18, %2, %6
%22 = load i64, i64* @errno
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %9, %21
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @err(i32 %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
br label %27
27: ; preds = %13, %24, %21
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @errx(i32 %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
br label %30
30: ; preds = %16, %18, %27
%31 = phi i64 [ undef, %27 ], [ %10, %18 ], [ %10, %16 ]
ret i64 %31
}