#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int read_int_file(char *name, int *out) {
  int rv = 0;
  FILE *f;
  f = fopen(name, "rb");
  if (f == NULL) {
    return -1;
  }
  if (fscanf(f, "%d", out) != 1) {
    rv = -1;
  }
  fclose(f);
  return rv;
}


x86 assembly (clang, -O0):
<read_int_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1172 <read_int_file+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <read_int_file+0x75>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     1196 <read_int_file+0x66>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1172 <read_int_file+0x42>
mov    %rax,%rbx
lea    0xeb1(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1040 <fscanf@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
setne  %bpl
neg    %ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1177 <read_int_file+0x47>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @read_int_file(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
store i32 0, i32* %6
%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** %7
%10 = load i32*, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %23
13: ; preds = %2
%14 = load i32*, i32** %7
%15 = load i32*, i32** %5
%16 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -1, i32* %6
br label %19
19: ; preds = %18, %13
%20 = load i32*, i32** %7
%21 = call i32 @fclose(i32* %20)
%22 = load i32, i32* %6
store i32 %22, i32* %3
br label %23
23: ; preds = %19, %12
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @read_int_file(i8* nocapture %0, i32* %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 %10, label %5
5: ; preds = %2
%6 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = icmp ne i32 %6, 1
%8 = sext i1 %7 to i32
%9 = tail call i32 @fclose(i32* %3)
br label %10
10: ; preds = %2, %5
%11 = phi i32 [ %8, %5 ], [ -1, %2 ]
ret i32 %11
}