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


x86 assembly (clang, -O0):
<read_file_of_weights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1172 <read_file_of_weights+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <read_file_of_weights+0xc2>
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11e2 <read_file_of_weights+0xb2>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11cf <read_file_of_weights+0x9f>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x38(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe46(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    118e <read_file_of_weights+0x5e>
jmp    11d4 <read_file_of_weights+0xa4>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1179 <read_file_of_weights+0x49>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file_of_weights>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r13
mov    %edx,0xc(%rsp)
mov    %rsi,%r15
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11cd <read_file_of_weights+0x9d>
mov    %rax,%rbp
test   %r15,%r15
jle    11be <read_file_of_weights+0x8e>
mov    0xc(%rsp),%ebx
shl    $0x3,%rbx
xor    %r14d,%r14d
lea    0xe8f(%rip),%r12
mov    %r15,0x10(%rsp)
jmp    118e <read_file_of_weights+0x5e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
mov    0x10(%rsp),%r15
cmp    %r15,%r14
je     11be <read_file_of_weights+0x8e>
cmpl   $0x0,0xc(%rsp)
jle    1180 <read_file_of_weights+0x50>
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%r14,8),%rdx
add    %r15,%rdx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <fscanf@plt>
add    $0x8,%r15
cmp    %r15,%rbx
jne    11a0 <read_file_of_weights+0x70>
jmp    1180 <read_file_of_weights+0x50>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    11d2 <read_file_of_weights+0xa2>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @read_file_of_weights(i8* nocapture %0, i64 %1, i32 %2, i64** nocapture %3) {
%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 %28, label %7
7: ; preds = %4
%8 = icmp sgt i64 %1, 0
br i1 %8, label %9, label %26
9: ; preds = %7
%10 = icmp sgt i32 %2, 0
%11 = zext i32 %2 to i64
br label %12
12: ; preds = %9, %23
%13 = phi i64 [ 0, %9 ], [ %24, %23 ]
br i1 %10, label %14, label %23
14: ; preds = %12
%15 = getelementptr inbounds i64*, i64** %3, i64 %13
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %21, %16 ]
%18 = load i64*, i64** %15
%19 = getelementptr inbounds i64, i64* %18, i64 %17
%20 = tail call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %19)
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %16
23: ; preds = %16, %12
%24 = add nuw nsw i64 %13, 1
%25 = icmp eq i64 %24, %1
br i1 %25, label %26, label %12
26: ; preds = %23, %7
%27 = tail call i32 @fclose(i32* %5)
br label %28
28: ; preds = %4, %26
%29 = phi i32 [ 1, %26 ], [ -1, %4 ]
ret i32 %29
}