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


x86 assembly (clang, -O0):
<strtol_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 <strtol_or_err+0x33>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1168 <strtol_or_err+0x38>
jmp    11ca <strtol_or_err+0x9a>
mov    0x2e71(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e4d(%rip),%rax
cmpq   $0x0,(%rax)
jne    11b8 <strtol_or_err+0x88>
cmpq   $0x0,-0x28(%rbp)
je     11bd <strtol_or_err+0x8d>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11bd <strtol_or_err+0x8d>
jmp    11ca <strtol_or_err+0x9a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1222 <strtol_or_err+0xf2>
mov    0x2e0f(%rip),%rax
cmpq   $0x0,(%rax)
je     11fd <strtol_or_err+0xcd>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe0d(%rip),%rsi
call   1050 <err@plt>
jmp    121a <strtol_or_err+0xea>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdeb(%rip),%rsi
call   1030 <errx@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtol_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     1187 <strtol_or_err+0x57>
cmpb   $0x0,(%rbx)
je     1187 <strtol_or_err+0x57>
mov    0x2e87(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
cmpq   $0x0,(%r15)
jne    1194 <strtol_or_err+0x64>
mov    0x8(%rsp),%rcx
test   %rcx,%rcx
je     11ce <strtol_or_err+0x9e>
cmpb   $0x0,(%rcx)
je     11ce <strtol_or_err+0x9e>
mov    0x2e52(%rip),%rax
cmpq   $0x0,(%rax)
je     11b1 <strtol_or_err+0x81>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1050 <err@plt>
jmp    11cc <strtol_or_err+0x9c>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <errx@plt>
xor    %eax,%eax
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 @strtol_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 %32
16: ; preds = %10
store i64 0, i64* @errno
%17 = load i8*, i8** %4
%18 = call i64 @strtol(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 %29, label %21
21: ; preds = %16
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i8*, i8** %7
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24, %16
br label %32
30: ; preds = %24, %21
%31 = load i64, i64* %6
store i64 %31, i64* %3
br label %46
32: ; preds = %29, %15
%33 = load i64, i64* @errno
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i32, i32* @EXIT_FAILURE
%37 = load i8*, i8** %5
%38 = load i8*, i8** %4
%39 = call i32 @err(i32 %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %37, i8* %38)
br label %45
40: ; preds = %32
%41 = load i32, i32* @EXIT_FAILURE
%42 = load i8*, i8** %5
%43 = load i8*, i8** %4
%44 = call i32 @errx(i32 %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %42, i8* %43)
br label %45
45: ; preds = %40, %35
store i64 0, i64* %3
br label %46
46: ; preds = %45, %30
%47 = load i64, i64* %3
ret i64 %47
}

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