#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 */
double atof(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
double *malloc(int);
int /*<<< orphan*/ printf(char *);
double *realloc(double *, int);
void load_ranking(char *fname, int *N, double **R) {
  char buff[256];
  int size = 10;
  FILE *f;
  if (*R == NULL) {
    *R = malloc(size * sizeof(double));
  }
  f = fopen(fname, "r");
  if (!f) {
    printf("Unable to open file: %s!!! Exiting\n");
    exit(1);
  }
  *N = 0;
  while (fgets(buff, 255, f)) {
    if (*N == size) {
      size += 10;
      *R = realloc(*R, size * sizeof(double));
    }
    (*R)[*N] = atof(buff);
    *N += 1;
  }
}


x86 assembly (clang, -O0):
<load_ranking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xa,-0x124(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11bb <load_ranking+0x4b>
movslq -0x124(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    11f6 <load_ranking+0x86>
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x120(%rbp),%rdi
mov    -0x130(%rbp),%rdx
mov    $0xff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1295 <load_ranking+0x125>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x124(%rbp),%eax
jne    1266 <load_ranking+0xf6>
mov    -0x124(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x124(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
movslq -0x124(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x120(%rbp),%rdi
call   1030 <atof@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1200 <load_ranking+0x90>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_ranking>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,0x8(%rsp)
cmpq   $0x0,(%rdx)
jne    11a4 <load_ranking+0x34>
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1278 <load_ranking+0x108>
mov    %rax,%r12
movl   $0x0,(%r14)
lea    0x10(%rsp),%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1266 <load_ranking+0xf6>
mov    $0xa,%r13d
lea    0x10(%rsp),%rbp
jmp    1254 <load_ranking+0xe4>
xchg   %ax,%ax
mov    %r14,%r15
mov    0x8(%rsp),%r14
mov    (%r14),%rdi
mov    %r12,%rbp
mov    %r13d,%r12d
add    $0xa,%r12d
lea    0x50(,%r13,8),%esi
call   1070 <realloc@plt>
mov    %rax,%rbx
mov    %rax,(%r14)
mov    %r15,%r14
mov    (%r15),%r15d
mov    %r12d,%r13d
mov    %rbp,%r12
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <atof@plt>
movslq %r15d,%rax
movsd  %xmm0,(%rbx,%rax,8)
add    $0x1,%eax
mov    %eax,(%r14)
mov    %rbp,%rdi
mov    $0xff,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1266 <load_ranking+0xf6>
mov    (%r14),%r15d
cmp    %r13d,%r15d
je     11f0 <load_ranking+0x80>
mov    0x8(%rsp),%rax
mov    (%rax),%rbx
jmp    1229 <load_ranking+0xb9>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd83(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [36 x i8] c"Unable to open file: %s!!! Exiting\0A\00"
define void @load_ranking(i8* %0, i32* %1, double** %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca double**
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
store double** %2, double*** %6
store i32 10, i32* %8
%10 = load double**, double*** %6
%11 = load double*, double** %10
%12 = icmp eq double* %11, null
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 8
%17 = trunc i64 %16 to i32
%18 = call double* @malloc(i32 %17)
%19 = load double**, double*** %6
store double* %18, double** %19
br label %20
20: ; preds = %13, %3
%21 = load i8*, i8** %4
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %9
%23 = load i32*, i32** %9
%24 = icmp ne i32* %23, null
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = load i32*, i32** %5
store i32 0, i32* %29
br label %30
30: ; preds = %51, %28
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%32 = load i32*, i32** %9
%33 = call i64 @fgets(i8* %31, i32 255, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %63
35: ; preds = %30
%36 = load i32*, i32** %5
%37 = load i32, i32* %36
%38 = load i32, i32* %8
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %51
40: ; preds = %35
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 10
store i32 %42, i32* %8
%43 = load double**, double*** %6
%44 = load double*, double** %43
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = mul i64 %46, 8
%48 = trunc i64 %47 to i32
%49 = call double* @realloc(double* %44, i32 %48)
%50 = load double**, double*** %6
store double* %49, double** %50
br label %51
51: ; preds = %40, %35
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%53 = call double @atof(i8* %52)
%54 = load double**, double*** %6
%55 = load double*, double** %54
%56 = load i32*, i32** %5
%57 = load i32, i32* %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %55, i64 %58
store double %53, double* %59
%60 = load i32*, i32** %5
%61 = load i32, i32* %60
%62 = add nsw i32 %61, 1
store i32 %62, i32* %60
br label %30
63: ; preds = %30
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [36 x i8] c"Unable to open file: %s!!! Exiting\0A\00"
define void @load_ranking(i8* nocapture %0, i32* nocapture %1, double** nocapture %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = load double*, double** %2
%7 = icmp eq double* %6, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call double* @malloc(i32 80)
store double* %9, double** %2
br label %10
10: ; preds = %8, %3
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
store i32 0, i32* %1
%14 = call i64 @fgets(i8* %5, i32 255, i32* %11)
%15 = icmp eq i64 %14, 0
br i1 %15, label %41, label %19
16: ; preds = %10
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %13, %31
%20 = phi i32 [ %34, %31 ], [ 10, %13 ]
%21 = load i32, i32* %1
%22 = icmp eq i32 %21, %20
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = load double*, double** %2
br label %31
25: ; preds = %19
%26 = add nsw i32 %20, 10
%27 = load double*, double** %2
%28 = shl i32 %26, 3
%29 = call double* @realloc(double* %27, i32 %28)
store double* %29, double** %2
%30 = load i32, i32* %1
br label %31
31: ; preds = %23, %25
%32 = phi i32 [ %30, %25 ], [ %21, %23 ]
%33 = phi double* [ %29, %25 ], [ %24, %23 ]
%34 = phi i32 [ %26, %25 ], [ %20, %23 ]
%35 = call double @atof(i8* %5)
%36 = sext i32 %32 to i64
%37 = getelementptr inbounds double, double* %33, i64 %36
store double %35, double* %37
%38 = add nsw i32 %32, 1
store i32 %38, i32* %1
%39 = call i64 @fgets(i8* %5, i32 255, i32* %11)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %19
41: ; preds = %31, %13
ret void
}