#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 const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
long strtol(char *, char **, int /*<<< orphan*/);
int getintfile(const char *path, long *val) {
  char buffer[64];
  char *ep;
  FILE *f;
  f = fopen(path, "r");
  if (!f)
    return -1;
  ep = buffer + fread(buffer, 1, sizeof buffer - 1, f);
  fclose(f);
  *ep = '\0';
  *val = strtol(buffer, &ep, 0);
  if (*ep && *ep != '\n')
    return -1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<getintfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    117e <getintfile+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <getintfile+0xc9>
lea    -0x60(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x70(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3f,%edx
call   1030 <fread@plt>
mov    %eax,%ecx
mov    -0x78(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    -0x70(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x60(%rbp),%rdi
lea    -0x68(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1202 <getintfile+0xc2>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1202 <getintfile+0xc2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <getintfile+0xc9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getintfile>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c6 <getintfile+0x86>
mov    %rax,%rbx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x3f,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
movslq %eax,%r12
lea    (%rsp,%r12,1),%rax
add    $0x10,%rax
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
call   1040 <fclose@plt>
movb   $0x0,0x10(%rsp,%r12,1)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,(%r14)
mov    0x8(%rsp),%rax
mov    (%rax),%al
test   %al,%al
setne  %cl
cmp    $0xa,%al
setne  %al
and    %cl,%al
movzbl %al,%eax
neg    %eax
jmp    11cb <getintfile+0x8b>
mov    $0xffffffff,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @getintfile(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca [64 x i8]
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %4
store i64* %1, i64** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 -1, i32* %3
br label %38
14: ; preds = %2
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%17 = load i32*, i32** %8
%18 = call i32 @fread(i8* %16, i32 1, i32 63, i32* %17)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
store i8* %20, i8** %7
%21 = load i32*, i32** %8
%22 = call i32 @fclose(i32* %21)
%23 = load i8*, i8** %7
store i8 0, i8* %23
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%25 = call i64 @strtol(i8* %24, i8** %7, i32 0)
%26 = load i64*, i64** %5
store i64 %25, i64* %26
%27 = load i8*, i8** %7
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %14
%32 = load i8*, i8** %7
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 10
br i1 %35, label %36, label %37
36: ; preds = %31
store i32 -1, i32* %3
br label %38
37: ; preds = %31, %14
store i32 0, i32* %3
br label %38
38: ; preds = %37, %36, %13
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @getintfile(i8* nocapture %0, i64* nocapture writeonly %1) {
%3 = alloca [64 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = call i32 @fread(i8* %5, i32 1, i32 63, i32* %7)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %11
store i8* %12, i8** %4
%13 = call i32 @fclose(i32* %7)
store i8 0, i8* %12
%14 = call i64 @strtol(i8* %5, i8** %4, i32 0)
store i64 %14, i64* %1
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
%18 = icmp ne i8 %16, 10
%19 = and i1 %17, %18
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %9, %2
%22 = phi i32 [ -1, %2 ], [ %20, %9 ]
ret i32 %22
}