#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_SUCCESS;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char const *);
long strtol(char const *, char **, int);
long getnum(const char *str) {
  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_SUCCESS, ("cannot parse number '%s'"), str);
  else
    errx(EXIT_SUCCESS, ("cannot parse number '%s'"), str);
  return 0;
}


x86 assembly (clang, -O0):
<getnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115f <getnum+0x2f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1164 <getnum+0x34>
jmp    11c6 <getnum+0x96>
mov    0x2e75(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e51(%rip),%rax
cmpq   $0x0,(%rax)
jne    11b4 <getnum+0x84>
cmpq   $0x0,-0x20(%rbp)
je     11b9 <getnum+0x89>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b9 <getnum+0x89>
jmp    11c6 <getnum+0x96>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1216 <getnum+0xe6>
mov    0x2e13(%rip),%rax
cmpq   $0x0,(%rax)
je     11f5 <getnum+0xc5>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe15(%rip),%rsi
call   1050 <err@plt>
jmp    120e <getnum+0xde>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf7(%rip),%rsi
call   1030 <errx@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnum>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movq   $0x0,(%rsp)
test   %rdi,%rdi
je     117b <getnum+0x4b>
cmpb   $0x0,(%rbx)
je     117b <getnum+0x4b>
mov    0x2e90(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
cmpq   $0x0,(%r14)
jne    1188 <getnum+0x58>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     11bc <getnum+0x8c>
cmpb   $0x0,(%rcx)
je     11bc <getnum+0x8c>
mov    0x2e5e(%rip),%rax
cmpq   $0x0,(%rax)
je     11a2 <getnum+0x72>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
mov    %rbx,%rdx
call   1050 <err@plt>
jmp    11ba <getnum+0x8a>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdx
call   1030 <errx@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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