#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
scalar_t__ ntohl(scalar_t__);
int read_saved_posns(const char *path, uint32_t *saved_posns, size_t size) {
  FILE *f = NULL;
  int ii = 0;
  size_t nread = 0;
  f = fopen(path, "r");
  if (NULL == f) {
    if (ENOENT == errno) {
      for (ii = 0; ii < size; ++ii) {
        saved_posns[ii] = 0;
      }
      return 0;
    } else {
      return 1;
    }
  }
  for (ii = 0; ii < size; ++ii) {
    nread = fread(saved_posns + ii, sizeof(uint32_t), 1, f);
    if (nread < 1) {
      fclose(f);
      return 1;
    }
    saved_posns[ii] = ntohl(saved_posns[ii]);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<read_saved_posns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11f0 <read_saved_posns+0xb0>
mov    0x2e3e(%rip),%rax
mov    (%rax),%rax
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%rax
jne    11e4 <read_saved_posns+0xa4>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11d8 <read_saved_posns+0x98>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ac <read_saved_posns+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    1289 <read_saved_posns+0x149>
movl   $0x1,-0x4(%rbp)
jmp    1289 <read_saved_posns+0x149>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1279 <read_saved_posns+0x139>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rcx
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x1,-0x38(%rbp)
jae    124b <read_saved_posns+0x10b>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1289 <read_saved_posns+0x149>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <ntohl@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f7 <read_saved_posns+0xb7>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_saved_posns>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bb <read_saved_posns+0x6b>
mov    %rax,%r15
test   %r14,%r14
je     11af <read_saved_posns+0x5f>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11f0 <read_saved_posns+0xa0>
mov    (%rbx),%rdi
call   1070 <ntohl@plt>
mov    %rax,(%rbx)
add    $0x8,%rbx
add    $0xffffffffffffffff,%r14
jne    1180 <read_saved_posns+0x30>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
jmp    11fd <read_saved_posns+0xad>
mov    0x2e0e(%rip),%rax
mov    (%rax),%rax
mov    0x2e14(%rip),%rcx
mov    $0x1,%ebp
cmp    (%rcx),%rax
jne    11fd <read_saved_posns+0xad>
test   %r14,%r14
je     11b7 <read_saved_posns+0x67>
shl    $0x3,%r14
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
jmp    11fd <read_saved_posns+0xad>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@ENOENT = global i64 0
@errno = global i64 0
define i32 @read_saved_posns(i8* %0, i64* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i64
store i8* %0, i8** %5
store i64* %1, i64** %6
store i64 %2, i64* %7
store i32* null, i32** %8
store i32 0, i32* %9
store i64 0, i64* %10
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* null, %13
br i1 %14, label %15, label %35
15: ; preds = %3
%16 = load i64, i64* @ENOENT
%17 = load i64, i64* @errno
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %34
19: ; preds = %15
store i32 0, i32* %9
br label %20
20: ; preds = %30, %19
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = load i64, i64* %7
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load i64*, i64** %6
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i64, i64* %26, i64 %28
store i64 0, i64* %29
br label %30
30: ; preds = %25
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %20
33: ; preds = %20
store i32 0, i32* %4
br label %70
34: ; preds = %15
store i32 1, i32* %4
br label %70
35: ; preds = %3
store i32 0, i32* %9
br label %36
36: ; preds = %64, %35
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = load i64, i64* %7
%40 = icmp ult i64 %38, %39
br i1 %40, label %41, label %67
41: ; preds = %36
%42 = load i64*, i64** %6
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i64, i64* %42, i64 %44
%46 = load i32*, i32** %8
%47 = call i64 @fread(i64* %45, i32 8, i32 1, i32* %46)
store i64 %47, i64* %10
%48 = load i64, i64* %10
%49 = icmp ult i64 %48, 1
br i1 %49, label %50, label %53
50: ; preds = %41
%51 = load i32*, i32** %8
%52 = call i32 @fclose(i32* %51)
store i32 1, i32* %4
br label %70
53: ; preds = %41
%54 = load i64*, i64** %6
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i64, i64* %54, i64 %56
%58 = load i64, i64* %57
%59 = call i64 @ntohl(i64 %58)
%60 = load i64*, i64** %6
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i64, i64* %60, i64 %62
store i64 %59, i64* %63
br label %64
64: ; preds = %53
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %36
67: ; preds = %36
%68 = load i32*, i32** %8
%69 = call i32 @fclose(i32* %68)
store i32 0, i32* %4
br label %70
70: ; preds = %67, %50, %34, %33
%71 = load i32, i32* %4
ret i32 %71
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@ENOENT = global i64 0
@errno = global i64 0
define i32 @read_saved_posns(i8* nocapture %0, i64* nocapture %1, i64 %2) {
%4 = bitcast i64* %1 to i8*
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = icmp eq i64 %2, 0
br i1 %8, label %29, label %17
9: ; preds = %3
%10 = load i64, i64* @ENOENT
%11 = load i64, i64* @errno
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = icmp eq i64 %2, 0
br i1 %14, label %31, label %15
15: ; preds = %13
%16 = shl nuw i64 %2, 3
br label %31
17: ; preds = %7, %24
%18 = phi i64 [ %27, %24 ], [ 0, %7 ]
%19 = getelementptr inbounds i64, i64* %1, i64 %18
%20 = tail call i64 @fread(i64* %19, i32 8, i32 1, i32* %5)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 @fclose(i32* %5)
br label %31
24: ; preds = %17
%25 = load i64, i64* %19
%26 = tail call i64 @ntohl(i64 %25)
store i64 %26, i64* %19
%27 = add nuw i64 %18, 1
%28 = icmp eq i64 %27, %2
br i1 %28, label %29, label %17
29: ; preds = %24, %7
%30 = tail call i32 @fclose(i32* %5)
br label %31
31: ; preds = %15, %13, %9, %29, %22
%32 = phi i32 [ 1, %22 ], [ 0, %29 ], [ 1, %9 ], [ 0, %13 ], [ 0, %15 ]
ret i32 %32
}