#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 *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, long *);
int read_file_ordered_list(char filename[], long max_precincts,
                           long *ordered_list) {
  FILE *f = fopen(filename, "r");
  if (!f)
    return -1;
  int i;
  for (i = 0; i < max_precincts; i++) {
    fscanf(f, "%ld\n", &ordered_list[i]);
  }
  fclose(f);
  return 1;
}


x86 assembly (clang, -O0):
<read_file_ordered_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116f <read_file_ordered_list+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <read_file_ordered_list+0x91>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11b1 <read_file_ordered_list+0x81>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe64(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1176 <read_file_ordered_list+0x46>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file_ordered_list>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0xebb(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1187 <read_file_ordered_list+0x57>
mov    %rax,%r15
test   %r14,%r14
jle    1178 <read_file_ordered_list+0x48>
lea    0xea4(%rip),%r12
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
add    $0x8,%rbx
add    $0xffffffffffffffff,%r14
jne    1160 <read_file_ordered_list+0x30>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    118c <read_file_ordered_list+0x5c>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @read_file_ordered_list(i8* nocapture %0, i64 %1, i64* %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = icmp sgt i64 %1, 0
br i1 %7, label %8, label %14
8: ; preds = %6, %8
%9 = phi i64 [ %12, %8 ], [ 0, %6 ]
%10 = getelementptr inbounds i64, i64* %2, i64 %9
%11 = tail call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %10)
%12 = add nuw nsw i64 %9, 1
%13 = icmp eq i64 %12, %1
br i1 %13, label %14, label %8
14: ; preds = %8, %6
%15 = tail call i32 @fclose(i32* %4)
br label %16
16: ; preds = %3, %14
%17 = phi i32 [ 1, %14 ], [ -1, %3 ]
ret i32 %17
}