#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*/ free(char *);
char *load_string(char *, char *);
long strtol(char *, char **, int);
int load_hex(char *dir, char *file) {
  char *line;
  char *end;
  long i;
  line = load_string(dir, file);
  if (!line)
    return -1;
  i = strtol(line, &end, 16);
  free(line);
  if (end == line)
    return -1;
  return i;
}


x86 assembly (clang, -O0):
<load_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <load_string@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1168 <load_hex+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <load_hex+0x78>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    11a1 <load_hex+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <load_hex+0x78>
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_hex>:
push   %r14
push   %rbx
push   %rax
call   1050 <load_string@plt>
test   %rax,%rax
je     116b <load_hex+0x3b>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
cmp    %rbx,(%rsp)
mov    $0xffffffff,%eax
cmovne %r14d,%eax
jmp    1170 <load_hex+0x40>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @load_hex(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @load_string(i8* %9, i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 -1, i32* %3
br label %27
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i64 @strtol(i8* %16, i8** %7, i32 16)
store i64 %17, i64* %8
%18 = load i8*, i8** %6
%19 = call i32 @free(i8* %18)
%20 = load i8*, i8** %7
%21 = load i8*, i8** %6
%22 = icmp eq i8* %20, %21
br i1 %22, label %23, label %24
23: ; preds = %15
store i32 -1, i32* %3
br label %27
24: ; preds = %15
%25 = load i64, i64* %8
%26 = trunc i64 %25 to i32
store i32 %26, i32* %3
br label %27
27: ; preds = %24, %23, %14
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @load_hex(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8* @load_string(i8* %0, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = call i64 @strtol(i8* %5, i8** %3, i32 16)
%9 = tail call i32 @free(i8* %5)
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, %5
%12 = trunc i64 %8 to i32
%13 = select i1 %11, i32 -1, i32 %12
br label %14
14: ; preds = %7, %2
%15 = phi i32 [ -1, %2 ], [ %13, %7 ]
ret i32 %15
}