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

/* Variables and functions */
int /*<<< orphan*/ LogError(unsigned char *, ...);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
scalar_t__ time(int /*<<< orphan*/ *);
int sumFile(char *name, long sum[2]) {
  long buf[2];
  int fd;
  int ret_status = 0;
  if ((fd = open(name, 0)) < 0) {
    LogError((unsigned char *)"Cannot open randomFile \"%s\", errno = %d\n",
             name, errno);
    return 0;
  }
  sum[0] = 0;
  sum[1] = 0;
  if (read(fd, (char *)buf, (sizeof(long) * 2)) != (sizeof(long) * 2)) {
    LogError((unsigned char *)"Could not read %d bytes from '%s'\n",
             (sizeof(long) * 2), name);
    sum[0] = (long)time((time_t *)0);
    sum[1] = sum[0];
  } else {
    sum[0] = buf[0];
    sum[1] = buf[1];
    ret_status = 1;
  }
  close(fd);
  return ret_status;
}


x86 assembly (clang, -O0):
<sumFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11a5 <sumFile+0x55>
mov    -0x10(%rbp),%rsi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <LogError@plt>
movl   $0x0,-0x4(%rbp)
jmp    1243 <sumFile+0xf3>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1040 <read@plt>
cltq
cmp    $0x10,%rax
je     1217 <sumFile+0xc7>
mov    -0x10(%rbp),%rdx
lea    0xe45(%rip),%rdi
mov    $0x10,%esi
mov    $0x0,%al
call   1050 <LogError@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    1235 <sumFile+0xe5>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
movl   $0x1,-0x38(%rbp)
mov    -0x34(%rbp),%edi
call   1030 <close@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sumFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
js     119f <sumFile+0x4f>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
movups %xmm0,(%r15)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1040 <read@plt>
cmp    $0x10,%eax
jne    11bb <sumFile+0x6b>
mov    (%rsp),%rax
mov    %rax,(%r15)
mov    $0x1,%r14d
mov    0x8(%rsp),%rax
jmp    11de <sumFile+0x8e>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
lea    0xe51(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <LogError@plt>
jmp    11e9 <sumFile+0x99>
lea    0xe67(%rip),%rdi
xor    %r14d,%r14d
mov    $0x10,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <LogError@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,(%r15)
mov    %rax,0x8(%r15)
mov    %ebp,%edi
call   1030 <close@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Cannot open randomFile \22%s\22, errno = %d\0A\00"
@errno = global i32 0
@.str.1 = [35 x i8] c"Could not read %d bytes from '%s'\0A\00"
define i32 @sumFile(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca [2 x i64]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i64* %1, i64** %5
store i32 0, i32* %8
%9 = load i8*, i8** %4
%10 = call i32 @open(i8* %9, i32 0)
store i32 %10, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i32, i32* @errno
%15 = call i32 (i8*, ...) @LogError(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %14)
store i32 0, i32* %3
br label %51
16: ; preds = %2
%17 = load i64*, i64** %5
%18 = getelementptr inbounds i64, i64* %17, i64 0
store i64 0, i64* %18
%19 = load i64*, i64** %5
%20 = getelementptr inbounds i64, i64* %19, i64 1
store i64 0, i64* %20
%21 = load i32, i32* %7
%22 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
%23 = bitcast i64* %22 to i8*
%24 = call i32 @read(i32 %21, i8* %23, i32 16)
%25 = sext i32 %24 to i64
%26 = icmp ne i64 %25, 16
br i1 %26, label %27, label %38
27: ; preds = %16
%28 = load i8*, i8** %4
%29 = call i32 (i8*, ...) @LogError(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i64 16, i8* %28)
%30 = call i64 @time(i32* null)
%31 = load i64*, i64** %5
%32 = getelementptr inbounds i64, i64* %31, i64 0
store i64 %30, i64* %32
%33 = load i64*, i64** %5
%34 = getelementptr inbounds i64, i64* %33, i64 0
%35 = load i64, i64* %34
%36 = load i64*, i64** %5
%37 = getelementptr inbounds i64, i64* %36, i64 1
store i64 %35, i64* %37
br label %47
38: ; preds = %16
%39 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
%40 = load i64, i64* %39
%41 = load i64*, i64** %5
%42 = getelementptr inbounds i64, i64* %41, i64 0
store i64 %40, i64* %42
%43 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 1
%44 = load i64, i64* %43
%45 = load i64*, i64** %5
%46 = getelementptr inbounds i64, i64* %45, i64 1
store i64 %44, i64* %46
store i32 1, i32* %8
br label %47
47: ; preds = %38, %27
%48 = load i32, i32* %7
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* %8
store i32 %50, i32* %3
br label %51
51: ; preds = %47, %12
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [41 x i8] c"Cannot open randomFile \22%s\22, errno = %d\0A\00"
@errno = global i32 0
@.str.1 = [35 x i8] c"Could not read %d bytes from '%s'\0A\00"
define i32 @sumFile(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca [2 x i64]
%4 = bitcast [2 x i64]* %3 to i8*
%5 = tail call i32 @open(i8* %0, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = tail call i32 (i8*, ...) @LogError(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %8)
br label %27
10: ; preds = %2
%11 = getelementptr inbounds i64, i64* %1, i64 1
%12 = bitcast i64* %1 to i8*
%13 = call i32 @read(i32 %5, i8* %4, i32 16)
%14 = icmp eq i32 %13, 16
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = tail call i32 (i8*, ...) @LogError(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i64 16, i8* %0)
%17 = tail call i64 @time(i32* null)
store i64 %17, i64* %1
br label %23
18: ; preds = %10
%19 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
%20 = load i64, i64* %19
store i64 %20, i64* %1
%21 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 1
%22 = load i64, i64* %21
br label %23
23: ; preds = %18, %15
%24 = phi i64 [ %22, %18 ], [ %17, %15 ]
%25 = phi i32 [ 1, %18 ], [ 0, %15 ]
store i64 %24, i64* %11
%26 = tail call i32 @close(i32 %5)
br label %27
27: ; preds = %23, %7
%28 = phi i32 [ 0, %7 ], [ %25, %23 ]
ret i32 %28
}