#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;
unsigned long long ULLONG_MAX;
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
unsigned long long strtoull(char *, int /*<<< orphan*/ *, int);
int filename__read_ull(const char *filename, unsigned long long *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 = strtoull(line, NULL, 10);
    if (*value != ULLONG_MAX)
      err = 0;
  }
  close(fd);
  return err;
}


x86 assembly (clang, -O0):
<filename__read_ull>:
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   1060 <open@plt>
mov    %eax,-0x64(%rbp)
movl   $0xffffffff,-0x68(%rbp)
cmpl   $0x0,-0x64(%rbp)
jge    1182 <filename__read_ull+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ea <filename__read_ull+0xaa>
mov    -0x64(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jle    11dc <filename__read_ull+0x9c>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
je     11d7 <filename__read_ull+0x97>
movl   $0x0,-0x68(%rbp)
jmp    11dc <filename__read_ull+0x9c>
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_ull>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r14
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     1199 <filename__read_ull+0x59>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x40,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    11a0 <filename__read_ull+0x60>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoull@plt>
mov    %rax,(%r14)
mov    0x2e54(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
sete   %bpl
neg    %ebp
jmp    11a5 <filename__read_ull+0x65>
mov    $0xffffffff,%ebp
jmp    11ac <filename__read_ull+0x6c>
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
@ULLONG_MAX = global i64 0
define i32 @filename__read_ull(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca [64 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i64* %1, i64** %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 %34
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 %30
20: ; preds = %15
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%22 = call i64 @strtoull(i8* %21, i32* null, i32 10)
%23 = load i64*, i64** %5
store i64 %22, i64* %23
%24 = load i64*, i64** %5
%25 = load i64, i64* %24
%26 = load i64, i64* @ULLONG_MAX
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 0, i32* %8
br label %29
29: ; preds = %28, %20
br label %30
30: ; preds = %29, %15
%31 = load i32, i32* %7
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %8
store i32 %33, i32* %3
br label %34
34: ; preds = %30, %14
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@ULLONG_MAX = global i64 0
define i32 @filename__read_ull(i8* nocapture %0, i64* 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 %19, 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 %16
11: ; preds = %8
%12 = call i64 @strtoull(i8* nocapture %4, i32* null, i32 10)
store i64 %12, i64* %1
%13 = load i64, i64* @ULLONG_MAX
%14 = icmp eq i64 %12, %13
%15 = sext i1 %14 to i32
br label %16
16: ; preds = %11, %8
%17 = phi i32 [ -1, %8 ], [ %15, %11 ]
%18 = tail call i32 @close(i32 %6)
br label %19
19: ; preds = %2, %16
%20 = phi i32 [ %17, %16 ], [ -1, %2 ]
ret i32 %20
}