#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*/ fprintf(int /*<<< orphan*/ *, char *, long);
long rand_range_long(int, int);
int create_file_of_weights(char filename[], long max_precincts,
                           int max_quality_layers) {
  FILE *f = fopen(filename, "w");
  if (!f)
    return -1;
  int i, j;
  for (i = 0; i < max_precincts; i++) {
    for (j = 0; j < max_quality_layers; j++) {
      long weight = rand_range_long(j * 100, (j + 1) * 100);
      fprintf(f, "%ld\n", weight);
    }
  }
  fclose(f);
  return 1;
}


x86 assembly (clang, -O0):
<create_file_of_weights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117e <create_file_of_weights+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <create_file_of_weights+0xc1>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11f1 <create_file_of_weights+0xb1>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11de <create_file_of_weights+0x9e>
imul   $0x64,-0x30(%rbp),%edi
mov    -0x30(%rbp),%eax
add    $0x1,%eax
imul   $0x64,%eax,%esi
call   1030 <rand_range_long@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xe37(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    119a <create_file_of_weights+0x5a>
jmp    11e3 <create_file_of_weights+0xa3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1185 <create_file_of_weights+0x45>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file_of_weights>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,0x4(%rsp)
mov    %rsi,%r14
lea    0xea7(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d2 <create_file_of_weights+0x92>
mov    %rax,%rbx
test   %r14,%r14
jle    11c3 <create_file_of_weights+0x83>
xor    %r13d,%r13d
lea    0xe8d(%rip),%r12
jmp    1189 <create_file_of_weights+0x49>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r14,%r13
je     11c3 <create_file_of_weights+0x83>
cmpl   $0x0,0x4(%rsp)
jle    1180 <create_file_of_weights+0x40>
mov    $0x64,%ebp
mov    0x4(%rsp),%r15d
nopw   0x0(%rax,%rax,1)
lea    -0x64(%rbp),%edi
mov    %ebp,%esi
call   1030 <rand_range_long@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1050 <fprintf@plt>
add    $0x64,%ebp
add    $0xffffffff,%r15d
jne    11a0 <create_file_of_weights+0x60>
jmp    1180 <create_file_of_weights+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
jmp    11d7 <create_file_of_weights+0x97>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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