#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int O_RDONLY;
int O_SYNC;
scalar_t__ file_close(int);
int file_open(char *, int);
int file_read_int_fd(int, int *);
int file_read_int_path(char *path, int *tmp) {
  int fd, ret;
  fd = file_open(path, O_SYNC | O_RDONLY);
  if (fd < 0) {
    return EXIT_FAILURE;
  }
  ret = file_read_int_fd(fd, tmp);
  if (file_close(fd) < 0 || ret == EXIT_FAILURE) {
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<file_read_int_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    0x2e8c(%rip),%rax
or     (%rax),%esi
call   1040 <file_open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1179 <file_read_int_path+0x49>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c9 <file_read_int_path+0x99>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <file_read_int_fd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <file_close@plt>
cmp    $0x0,%rax
jl     11ac <file_read_int_path+0x7c>
mov    -0x20(%rbp),%eax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%eax
jne    11bd <file_read_int_path+0x8d>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c9 <file_read_int_path+0x99>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read_int_path>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2eab(%rip),%rax
mov    0x2e9c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1040 <file_open@plt>
test   %eax,%eax
js     1184 <file_read_int_path+0x54>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1030 <file_read_int_fd@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <file_close@plt>
mov    0x2e63(%rip),%rdx
mov    %rdx,%rcx
cmp    (%rdx),%ebx
je     117b <file_read_int_path+0x4b>
mov    0x2e4d(%rip),%rcx
test   %rax,%rax
cmovs  %rdx,%rcx
jmp    118b <file_read_int_path+0x5b>
mov    0x2e45(%rip),%rcx
mov    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_SYNC = global i32 0
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @file_read_int_path(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_SYNC
%10 = load i32, i32* @O_RDONLY
%11 = or i32 %9, %10
%12 = call i32 @file_open(i8* %8, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %32
17: ; preds = %2
%18 = load i32, i32* %6
%19 = load i32*, i32** %5
%20 = call i32 @file_read_int_fd(i32 %18, i32* %19)
store i32 %20, i32* %7
%21 = load i32, i32* %6
%22 = call i64 @file_close(i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %17
%25 = load i32, i32* %7
%26 = load i32, i32* @EXIT_FAILURE
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24, %17
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %32
30: ; preds = %24
%31 = load i32, i32* @EXIT_SUCCESS
store i32 %31, i32* %3
br label %32
32: ; preds = %30, %28, %15
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@O_SYNC = global i32 0
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @file_read_int_path(i8* %0, i32* %1) {
%3 = load i32, i32* @O_SYNC
%4 = load i32, i32* @O_RDONLY
%5 = or i32 %4, %3
%6 = tail call i32 @file_open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %2
%9 = tail call i32 @file_read_int_fd(i32 %6, i32* %1)
%10 = tail call i64 @file_close(i32 %6)
%11 = icmp slt i64 %10, 0
%12 = load i32, i32* @EXIT_FAILURE
%13 = icmp eq i32 %9, %12
%14 = select i1 %11, i1 true, i1 %13
%15 = select i1 %14, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %16
16: ; preds = %8, %2
%17 = phi i32* [ @EXIT_FAILURE, %2 ], [ %15, %8 ]
%18 = load i32, i32* %17
ret i32 %18
}