#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;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
scalar_t__ strtol(char const *, char **, int /*<<< orphan*/);
int get_integer_opt(const char *str, int *ret_value) {
  char *endptr;
  int tmp;
  errno = 0;
  endptr = NULL;
  tmp = (int)strtol(str, &endptr, 0);
  if (errno != 0) {
    fprintf(stderr, "Unable to parse option as a number: \"%s\": %s\n", str,
            strerror(errno));
    exit(EXIT_FAILURE);
  } else if (endptr == str) {
    fprintf(stderr, "Unable to parse option as a number: \"%s\"\n", str);
    exit(EXIT_FAILURE);
  } else if (*endptr != 0) {
    fprintf(stderr, "Garbage after end of value: \"%s\"\n", str);
    exit(EXIT_FAILURE);
  }
  *ret_value = tmp;
  return (0);
}


x86 assembly (clang, -O0):
<get_integer_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e59(%rip),%rax
cmpq   $0x0,(%rax)
je     11d2 <get_integer_opt+0x92>
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1209 <get_integer_opt+0xc9>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1242 <get_integer_opt+0x102>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    1247 <get_integer_opt+0x107>
jmp    124c <get_integer_opt+0x10c>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_integer_opt>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e82(%rip),%rbx
movq   $0x0,(%rbx)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
jne    1198 <get_integer_opt+0x58>
mov    0x8(%rsp),%rcx
cmp    %r14,%rcx
je     11be <get_integer_opt+0x7e>
cmpb   $0x0,(%rcx)
jne    11d0 <get_integer_opt+0x90>
mov    %eax,(%r15)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e41(%rip),%rax
mov    (%rax),%ebx
call   1060 <strerror@plt>
lea    0xe53(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11ea <get_integer_opt+0xaa>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
jmp    11e0 <get_integer_opt+0xa0>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [46 x i8] c"Unable to parse option as a number: \22%s\22: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [42 x i8] c"Unable to parse option as a number: \22%s\22\0A\00"
@.str.2 = [34 x i8] c"Garbage after end of value: \22%s\22\0A\00"
define i32 @get_integer_opt(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i64 0, i64* @errno
store i8* null, i8** %5
%7 = load i8*, i8** %3
%8 = call i64 @strtol(i8* %7, i8** %5, i32 0)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %6
%10 = load i64, i64* @errno
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = load i64, i64* @errno
%16 = call i8* @strerror(i64 %15)
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %5
%22 = load i8*, i8** %3
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %3
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %20
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %3
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %30
br label %42
42: ; preds = %41
br label %43
43: ; preds = %42
%44 = load i32, i32* %6
%45 = load i32*, i32** %4
store i32 %44, i32* %45
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [46 x i8] c"Unable to parse option as a number: \22%s\22: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [42 x i8] c"Unable to parse option as a number: \22%s\22\0A\00"
@.str.2 = [34 x i8] c"Garbage after end of value: \22%s\22\0A\00"
define i32 @get_integer_opt(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
store i8* null, i8** %3
%5 = call i64 @strtol(i8* %0, i8** %3, i32 0)
%6 = load i64, i64* @errno
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i8* @strerror(i64 %6)
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = icmp eq i8* %15, %0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %14
%23 = load i8, i8* %15
%24 = icmp eq i8 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = trunc i64 %5 to i32
store i32 %31, i32* %1
ret i32 0
}