#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__ ERANGE;
int /*<<< orphan*/ EXIT_FAILURE;
int LONG_MAX;
int LONG_MIN;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int strtol(char *, char **, int);
int dioctrl_get_int(char *str) {
  char *endptr;
  errno = 0;
  int val = strtol(str, &endptr, 16);
  if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) ||
      (errno != 0 && val == 0)) {
    perror("strtol");
    exit(EXIT_FAILURE);
  }
  if (*endptr != '\0') {
    fprintf(stderr, "Error! Bad parameter %s\n", str);
    exit(EXIT_FAILURE);
  }
  return val;
}


x86 assembly (clang, -O0):
<dioctrl_get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%rax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%rax
jne    11ad <dioctrl_get_int+0x6d>
mov    -0x14(%rbp),%eax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%eax
je     11c8 <dioctrl_get_int+0x88>
mov    -0x14(%rbp),%eax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
je     11c8 <dioctrl_get_int+0x88>
mov    0x2e0c(%rip),%rax
cmpq   $0x0,(%rax)
je     11e2 <dioctrl_get_int+0xa2>
cmpl   $0x0,-0x14(%rbp)
jne    11e2 <dioctrl_get_int+0xa2>
lea    0xe31(%rip),%rdi
call   1050 <perror@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1219 <dioctrl_get_int+0xd9>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe01(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dioctrl_get_int>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e72(%rip),%rbx
movq   $0x0,(%rbx)
mov    %rsp,%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    (%rbx),%rcx
mov    0x2e74(%rip),%rdx
cmp    (%rdx),%rcx
jne    1187 <dioctrl_get_int+0x47>
mov    0x2e50(%rip),%rdx
cmp    (%rdx),%eax
je     11a1 <dioctrl_get_int+0x61>
mov    0x2e65(%rip),%rdx
cmp    (%rdx),%eax
je     11a1 <dioctrl_get_int+0x61>
test   %rcx,%rcx
je     1190 <dioctrl_get_int+0x50>
test   %eax,%eax
je     11a1 <dioctrl_get_int+0x61>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    11af <dioctrl_get_int+0x6f>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe58(%rip),%rdi
call   1050 <perror@plt>
jmp    11c7 <dioctrl_get_int+0x87>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i32 0
@LONG_MIN = global i32 0
@.str = [7 x i8] c"strtol\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"Error! Bad parameter %s\0A\00"
define i32 @dioctrl_get_int(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i32 @strtol(i8* %5, i8** %3, i32 16)
store i32 %6, i32* %4
%7 = load i64, i64* @errno
%8 = load i64, i64* @ERANGE
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = load i32, i32* %4
%12 = load i32, i32* @LONG_MAX
%13 = icmp eq i32 %11, %12
br i1 %13, label %24, label %14
14: ; preds = %10
%15 = load i32, i32* %4
%16 = load i32, i32* @LONG_MIN
%17 = icmp eq i32 %15, %16
br i1 %17, label %24, label %18
18: ; preds = %14, %1
%19 = load i64, i64* @errno
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21, %14, %10
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %21, %18
%29 = load i8*, i8** %3
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %2
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %28
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i32 0
@LONG_MIN = global i32 0
@.str = [7 x i8] c"strtol\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"Error! Bad parameter %s\0A\00"
define i32 @dioctrl_get_int(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call i32 @strtol(i8* %0, i8** %2, i32 16)
%5 = load i64, i64* @errno
%6 = load i64, i64* @ERANGE
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* @LONG_MAX
%10 = icmp eq i32 %4, %9
%11 = load i32, i32* @LONG_MIN
%12 = icmp eq i32 %4, %11
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %18, label %14
14: ; preds = %8, %1
%15 = icmp ne i64 %5, 0
%16 = icmp eq i32 %4, 0
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %22
18: ; preds = %14, %8
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %14
%23 = load i8*, i8** %2
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %22
ret i32 %4
}