#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 */
scalar_t__ errno;
int /*<<< orphan*/ gnFail(char const *, char *, char const *, char const *);
long strtol(char const *, char **, int);
long getNum(const char *fname, const char *arg, int flags, const char *name) {
  long res;
  char *endptr;
  int base;
  if (arg == NULL || *arg == '\0')
    gnFail(fname, "null or empty string", arg, name);
  base = (flags & 0100) ? 0 : (flags & 0200) ? 8 : (flags & 0400) ? 16 : 10;
  errno = 0;
  res = strtol(arg, &endptr, base);
  if (errno != 0)
    gnFail(fname, "strtol() failed", arg, name);
  if (*endptr != '\0')
    gnFail(fname, "nonnumeric characters", arg, name);
  if ((flags & 01) && res < 0)
    gnFail(fname, "negative value not allowed", arg, name);
  if ((flags & 02) && res <= 0)
    gnFail(fname, "value must be > 0", arg, name);
  return res;
}


x86 assembly (clang, -O0):
<getNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1152 <getNum+0x32>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116a <getNum+0x4a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe9b(%rip),%rsi
call   1040 <gnFail@plt>
mov    -0x14(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     1183 <getNum+0x63>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    11c3 <getNum+0xa3>
mov    -0x14(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     11a1 <getNum+0x81>
mov    $0x8,%eax
mov    %eax,-0x3c(%rbp)
jmp    11bd <getNum+0x9d>
mov    -0x14(%rbp),%edx
and    $0x100,%edx
mov    $0xa,%eax
mov    $0x10,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e10(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    -0x30(%rbp),%rsi
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    0x2dee(%rip),%rax
cmpq   $0x0,(%rax)
je     1214 <getNum+0xf4>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe06(%rip),%rsi
call   1040 <gnFail@plt>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     123c <getNum+0x11c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdee(%rip),%rsi
call   1040 <gnFail@plt>
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     126e <getNum+0x14e>
cmpq   $0x0,-0x28(%rbp)
jge    126e <getNum+0x14e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdd2(%rip),%rsi
call   1040 <gnFail@plt>
mov    -0x14(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     12a0 <getNum+0x180>
cmpq   $0x0,-0x28(%rbp)
jg     12a0 <getNum+0x180>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdbb(%rip),%rsi
call   1040 <gnFail@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r15
test   %rsi,%rsi
je     1141 <getNum+0x21>
cmpb   $0x0,(%rbx)
jne    1156 <getNum+0x36>
lea    0xeb8(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <gnFail@plt>
xor    %edx,%edx
test   $0x40,%r12b
jne    117d <getNum+0x5d>
mov    $0x8,%edx
test   $0x80,%r12b
jne    117d <getNum+0x5d>
test   $0x100,%r12d
mov    $0xa,%eax
mov    $0x10,%edx
cmove  %eax,%edx
mov    0x2e5c(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strtol@plt>
mov    %rax,%r13
cmpq   $0x0,0x0(%rbp)
je     11b6 <getNum+0x96>
lea    0xe6d(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <gnFail@plt>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     11d4 <getNum+0xb4>
lea    0xe5f(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <gnFail@plt>
test   $0x1,%r12b
je     11f4 <getNum+0xd4>
test   %r13,%r13
jns    11f4 <getNum+0xd4>
lea    0xe55(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <gnFail@plt>
test   $0x2,%r12b
je     1214 <getNum+0xf4>
test   %r13,%r13
jg     1214 <getNum+0xf4>
lea    0xe50(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <gnFail@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"null or empty string\00"
@errno = global i64 0
@.str.1 = [16 x i8] c"strtol() failed\00"
@.str.2 = [22 x i8] c"nonnumeric characters\00"
@.str.3 = [27 x i8] c"negative value not allowed\00"
@.str.4 = [18 x i8] c"value must be > 0\00"
define i64 @getNum(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %19, label %14
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14, %4
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = load i8*, i8** %8
%23 = call i32 @gnFail(i8* %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
br label %24
24: ; preds = %19, %14
%25 = load i32, i32* %7
%26 = and i32 %25, 64
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
br label %42
29: ; preds = %24
%30 = load i32, i32* %7
%31 = and i32 %30, 128
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
br label %40
34: ; preds = %29
%35 = load i32, i32* %7
%36 = and i32 %35, 256
%37 = icmp ne i32 %36, 0
%38 = zext i1 %37 to i64
%39 = select i1 %37, i32 16, i32 10
br label %40
40: ; preds = %34, %33
%41 = phi i32 [ 8, %33 ], [ %39, %34 ]
br label %42
42: ; preds = %40, %28
%43 = phi i32 [ 0, %28 ], [ %41, %40 ]
store i32 %43, i32* %11
store i64 0, i64* @errno
%44 = load i8*, i8** %6
%45 = load i32, i32* %11
%46 = call i64 @strtol(i8* %44, i8** %10, i32 %45)
store i64 %46, i64* %9
%47 = load i64, i64* @errno
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %42
%50 = load i8*, i8** %5
%51 = load i8*, i8** %6
%52 = load i8*, i8** %8
%53 = call i32 @gnFail(i8* %50, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %51, i8* %52)
br label %54
54: ; preds = %49, %42
%55 = load i8*, i8** %10
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %54
%60 = load i8*, i8** %5
%61 = load i8*, i8** %6
%62 = load i8*, i8** %8
%63 = call i32 @gnFail(i8* %60, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %61, i8* %62)
br label %64
64: ; preds = %59, %54
%65 = load i32, i32* %7
%66 = and i32 %65, 1
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %76
68: ; preds = %64
%69 = load i64, i64* %9
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %68
%72 = load i8*, i8** %5
%73 = load i8*, i8** %6
%74 = load i8*, i8** %8
%75 = call i32 @gnFail(i8* %72, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %73, i8* %74)
br label %76
76: ; preds = %71, %68, %64
%77 = load i32, i32* %7
%78 = and i32 %77, 2
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %88
80: ; preds = %76
%81 = load i64, i64* %9
%82 = icmp sle i64 %81, 0
br i1 %82, label %83, label %88
83: ; preds = %80
%84 = load i8*, i8** %5
%85 = load i8*, i8** %6
%86 = load i8*, i8** %8
%87 = call i32 @gnFail(i8* %84, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %85, i8* %86)
br label %88
88: ; preds = %83, %80, %76
%89 = load i64, i64* %9
ret i64 %89
}

LLVM IR (-O2):
@.str = [21 x i8] c"null or empty string\00"
@errno = global i64 0
@.str.1 = [16 x i8] c"strtol() failed\00"
@.str.2 = [22 x i8] c"nonnumeric characters\00"
@.str.3 = [27 x i8] c"negative value not allowed\00"
@.str.4 = [18 x i8] c"value must be > 0\00"
define i64 @getNum(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = icmp eq i8* %1, null
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8, %4
%12 = tail call i32 @gnFail(i8* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %3)
br label %13
13: ; preds = %11, %8
%14 = and i32 %2, 64
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = and i32 %2, 128
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = and i32 %2, 256
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i32 10, i32 16
br label %23
23: ; preds = %19, %16, %13
%24 = phi i32 [ 0, %13 ], [ %22, %19 ], [ 8, %16 ]
store i64 0, i64* @errno
%25 = call i64 @strtol(i8* %1, i8** %5, i32 %24)
%26 = load i64, i64* @errno
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = tail call i32 @gnFail(i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %3)
br label %30
30: ; preds = %28, %23
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = tail call i32 @gnFail(i8* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %3)
br label %36
36: ; preds = %34, %30
%37 = and i32 %2, 1
%38 = icmp ne i32 %37, 0
%39 = icmp slt i64 %25, 0
%40 = select i1 %38, i1 %39, i1 false
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = tail call i32 @gnFail(i8* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %3)
br label %43
43: ; preds = %41, %36
%44 = and i32 %2, 2
%45 = icmp ne i32 %44, 0
%46 = icmp slt i64 %25, 1
%47 = select i1 %45, i1 %46, i1 false
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = tail call i32 @gnFail(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %3)
br label %50
50: ; preds = %48, %43
ret i64 %25
}