#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*/ O_RDONLY;
char *__bufFromFd(int);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
int strtoul(char *, int /*<<< orphan*/ *, int);
int __readHex(char *name) {
  int fd, ret;
  char *buf;
  fd = open(name, O_RDONLY);
  if (fd == -1)
    return 0;
  buf = __bufFromFd(fd);
  if (!buf)
    return 0;
  ret = strtoul(buf, NULL, 16);
  free(buf);
  return ret;
}


x86 assembly (clang, -O0):
<__readHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1177 <__readHex+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11be <__readHex+0x7e>
mov    -0x14(%rbp),%edi
call   1040 <__bufFromFd@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119a <__readHex+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    11be <__readHex+0x7e>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__readHex>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1182 <__readHex+0x42>
mov    %eax,%edi
call   1040 <__bufFromFd@plt>
test   %rax,%rax
je     1182 <__readHex+0x42>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    1184 <__readHex+0x44>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @__readHex(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = tail call i8* @__bufFromFd(i32 %3)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @strtoul(i8* nocapture %6, i32* null, i32 16)
%10 = tail call i32 @free(i8* %6)
br label %11
11: ; preds = %5, %1, %8
%12 = phi i32 [ %9, %8 ], [ 0, %1 ], [ 0, %5 ]
ret i32 %12
}