#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;
int /*<<< orphan*/ close(int);
int open_file(char *, char *, int /*<<< orphan*/);
int read_unsigned_int_from_fd(int);
int read_unsigned_int_from_file(char *prefix, char *path) {
  int fd;
  int rv;
  fd = open_file(prefix, path, O_RDONLY);
  if (fd < 0)
    return fd;
  rv = read_unsigned_int_from_fd(fd);
  close(fd);
  return rv;
}


x86 assembly (clang, -O0):
<read_unsigned_int_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
call   1040 <open_file@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    116e <read_unsigned_int_from_file+0x3e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <read_unsigned_int_from_file+0x57>
mov    -0x1c(%rbp),%edi
call   1030 <read_unsigned_int_from_fd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_unsigned_int_from_file>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    (%rax),%edx
call   1040 <open_file@plt>
mov    %eax,%ebx
test   %eax,%eax
js     115b <read_unsigned_int_from_file+0x2b>
mov    %ebx,%edi
call   1030 <read_unsigned_int_from_fd@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%eax
jmp    115d <read_unsigned_int_from_file+0x2d>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @read_unsigned_int_from_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open_file(i8* %8, i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %6
store i32 %15, i32* %3
br label %22
16: ; preds = %2
%17 = load i32, i32* %6
%18 = call i32 @read_unsigned_int_from_fd(i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %6
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %7
store i32 %21, i32* %3
br label %22
22: ; preds = %16, %14
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @read_unsigned_int_from_file(i8* %0, i8* %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open_file(i8* %0, i8* %1, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @read_unsigned_int_from_fd(i32 %4)
%8 = tail call i32 @close(i32 %4)
br label %9
9: ; preds = %2, %6
%10 = phi i32 [ %7, %6 ], [ %4, %2 ]
ret i32 %10
}