#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, long long *);
int parse_int_file(const char *path, long long *lret) {
  FILE *file;
  int ret;
  file = fopen(path, "rb");
  if (!file)
    return -1;
  ret = fscanf(file, "%lld", lret);
  if (ret != 1) {
    fclose(file);
    errno = EINVAL;
    return -1;
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<parse_int_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116b <parse_int_file+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <parse_int_file+0x93>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     11b3 <parse_int_file+0x83>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3b(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <parse_int_file+0x93>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    $0xffffffff,%eax
test   %rbx,%rbx
je     118a <parse_int_file+0x5a>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
cmp    $0x1,%ebp
je     118a <parse_int_file+0x5a>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    0x2e5d(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [5 x i8] c"%lld\00"
@EINVAL = global i32 0
@errno = global i32 0
define i32 @parse_int_file(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %4
store i64* %1, i64** %5
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 -1, i32* %3
br label %26
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = load i64*, i64** %5
%16 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32*, i32** %6
%21 = call i32 @fclose(i32* %20)
%22 = load i32, i32* @EINVAL
store i32 %22, i32* @errno
store i32 -1, i32* %3
br label %26
23: ; preds = %13
%24 = load i32*, i32** %6
%25 = call i32 @fclose(i32* %24)
store i32 0, i32* %3
br label %26
26: ; preds = %23, %19, %12
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [5 x i8] c"%lld\00"
@EINVAL = global i32 0
@errno = global i32 0
define i32 @parse_int_file(i8* nocapture %0, i64* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%7 = icmp eq i32 %6, 1
%8 = tail call i32 @fclose(i32* %3)
br i1 %7, label %11, label %9
9: ; preds = %5
%10 = load i32, i32* @EINVAL
store i32 %10, i32* @errno
br label %11
11: ; preds = %5, %2, %9
%12 = phi i32 [ -1, %9 ], [ -1, %2 ], [ 0, %5 ]
ret i32 %12
}