#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*/ line;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int filename__read_int(const char *filename, int *value) {
  char line[64];
  int fd = open(filename, O_RDONLY), err = -1;
  if (fd < 0)
    return -1;
  if (read(fd, line, sizeof(line)) > 0) {
    *value = atoi(line);
    err = 0;
  }
  close(fd);
  return err;
}


x86 assembly (clang, -O0):
<filename__read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x64(%rbp)
movl   $0xffffffff,-0x68(%rbp)
cmpl   $0x0,-0x64(%rbp)
jge    1182 <filename__read_int+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <filename__read_int+0x83>
mov    -0x64(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jle    11b5 <filename__read_int+0x75>
lea    -0x60(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x68(%rbp)
mov    -0x64(%rbp),%edi
call   1030 <close@plt>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename__read_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r14
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     1182 <filename__read_int+0x42>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x40,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    1189 <filename__read_int+0x49>
mov    %rsp,%rdi
call   1060 <atoi@plt>
mov    %eax,(%r14)
xor    %ebp,%ebp
jmp    118e <filename__read_int+0x4e>
mov    $0xffffffff,%ebp
jmp    1195 <filename__read_int+0x55>
mov    $0xffffffff,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @filename__read_int(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [64 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %7
store i32 -1, i32* %8
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %28
15: ; preds = %2
%16 = load i32, i32* %7
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%18 = call i64 @read(i32 %16, i8* %17, i32 64)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
%23 = load i32*, i32** %5
store i32 %22, i32* %23
store i32 0, i32* %8
br label %24
24: ; preds = %20, %15
%25 = load i32, i32* %7
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %8
store i32 %27, i32* %3
br label %28
28: ; preds = %24, %14
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @filename__read_int(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %2
%9 = call i64 @read(i32 %6, i8* %4, i32 64)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @atoi(i8* %4)
store i32 %12, i32* %1
br label %13
13: ; preds = %11, %8
%14 = phi i32 [ 0, %11 ], [ -1, %8 ]
%15 = tail call i32 @close(i32 %6)
br label %16
16: ; preds = %2, %13
%17 = phi i32 [ %14, %13 ], [ -1, %2 ]
ret i32 %17
}