#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*/ EXIT_FAILURE;
float atof(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strtok(char *, char *);
int load_locations(char *fn, float locs[][2], int first) {
  char line[2000], *kwd;
  int nlocs;
  FILE *f;
  if ((f = fopen(fn, "r")) == NULL) {
    fprintf(stderr, "Cannot open %s!\n", fn);
    exit(EXIT_FAILURE);
  }
  fgets(line, 2000, f);
  fgets(line, 2000, f);
  nlocs = first;
  while (fgets(line, 2000, f) != NULL) {
    kwd = strtok(line, " ");
    locs[nlocs][1] = atof(kwd);
    kwd = strtok((char *)NULL, " ");
    locs[nlocs][0] = atof(kwd);
    nlocs += 1;
    if (nlocs >= 200000) {
      fprintf(stderr, "Not enough space to hold all locations: %d!\n", nlocs);
      exit(EXIT_FAILURE);
    }
  }
  fclose(f);
  return nlocs;
}


x86 assembly (clang, -O0):
<load_locations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x808(%rbp)
cmp    $0x0,%rax
jne    11d0 <load_locations+0x60>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x7f0(%rbp),%rdi
mov    -0x808(%rbp),%rdx
mov    $0x7d0,%esi
call   1050 <fgets@plt>
lea    -0x7f0(%rbp),%rdi
mov    -0x808(%rbp),%rdx
mov    $0x7d0,%esi
call   1050 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x7fc(%rbp)
lea    -0x7f0(%rbp),%rdi
mov    -0x808(%rbp),%rdx
mov    $0x7d0,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12e4 <load_locations+0x174>
lea    -0x7f0(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x7f8(%rbp)
mov    -0x7f8(%rbp),%rdi
call   1030 <atof@plt>
mov    -0x10(%rbp),%rax
movslq -0x7fc(%rbp),%rcx
movss  %xmm0,0x4(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xda6(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x7f8(%rbp)
mov    -0x7f8(%rbp),%rdi
call   1030 <atof@plt>
mov    -0x10(%rbp),%rax
movslq -0x7fc(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,8)
mov    -0x7fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7fc(%rbp)
cmpl   $0x30d40,-0x7fc(%rbp)
jl     12df <load_locations+0x16f>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
mov    -0x7fc(%rbp),%edx
lea    0xd4b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1209 <load_locations+0x99>
mov    -0x808(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x7fc(%rbp),%eax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_locations>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7d8,%rsp
mov    %edx,%ebx
mov    %rsi,%r13
mov    %rdi,%rbp
lea    0xe70(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1284 <load_locations+0x114>
mov    %rax,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x7d0,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %r15,%rdi
mov    $0x7d0,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
movslq %ebx,%rax
cmp    $0x30d40,%eax
mov    $0x30d3f,%r12d
cmovge %eax,%r12d
add    $0x1,%r12d
lea    0x4(,%rax,8),%rbp
add    %r13,%rbp
lea    0xe27(%rip),%r13
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x7d0,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1268 <load_locations+0xf8>
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
call   1030 <atof@plt>
movss  %xmm0,0x0(%rbp)
xor    %edi,%edi
mov    %r13,%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x4(%rbp)
add    $0x1,%ebx
add    $0x8,%rbp
cmp    %ebx,%r12d
jne    11f0 <load_locations+0x80>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    125a <load_locations+0xea>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"Cannot open %s!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] c" \00"
@.str.3 = [45 x i8] c"Not enough space to hold all locations: %d!\0A\00"
define i32 @load_locations(i8* %0, [2 x float]* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca [2 x float]*
%6 = alloca i32
%7 = alloca [2000 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
store i8* %0, i8** %4
store [2 x float]* %1, [2 x float]** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %3
%21 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%22 = load i32*, i32** %10
%23 = call i32* @fgets(i8* %21, i32 2000, i32* %22)
%24 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%25 = load i32*, i32** %10
%26 = call i32* @fgets(i8* %24, i32 2000, i32* %25)
%27 = load i32, i32* %6
store i32 %27, i32* %9
br label %28
28: ; preds = %61, %20
%29 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%30 = load i32*, i32** %10
%31 = call i32* @fgets(i8* %29, i32 2000, i32* %30)
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %62
33: ; preds = %28
%34 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%35 = call i8* @strtok(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %35, i8** %8
%36 = load i8*, i8** %8
%37 = call float @atof(i8* %36)
%38 = load [2 x float]*, [2 x float]** %5
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [2 x float], [2 x float]* %38, i64 %40
%42 = getelementptr inbounds [2 x float], [2 x float]* %41, i64 0, i64 1
store float %37, float* %42
%43 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = call float @atof(i8* %44)
%46 = load [2 x float]*, [2 x float]** %5
%47 = load i32, i32* %9
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [2 x float], [2 x float]* %46, i64 %48
%50 = getelementptr inbounds [2 x float], [2 x float]* %49, i64 0, i64 0
store float %45, float* %50
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = icmp sge i32 %53, 200000
br i1 %54, label %55, label %61
55: ; preds = %33
%56 = load i32, i32* @stderr
%57 = load i32, i32* %9
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %33
br label %28
62: ; preds = %28
%63 = load i32*, i32** %10
%64 = call i32 @fclose(i32* %63)
%65 = load i32, i32* %9
ret i32 %65
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"Cannot open %s!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] c" \00"
@.str.3 = [45 x i8] c"Not enough space to hold all locations: %d!\0A\00"
define i32 @load_locations(i8* %0, [2 x float]* nocapture writeonly %1, i32 %2) {
%4 = alloca [2000 x i8]
%5 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %3
%14 = call i32* @fgets(i8* %5, i32 2000, i32* %6)
%15 = call i32* @fgets(i8* %5, i32 2000, i32* %6)
%16 = sext i32 %2 to i64
%17 = call i32 @llvm.smax.i32(i32 %2, i32 199999)
%18 = add nuw i32 %17, 1
br label %19
19: ; preds = %23, %13
%20 = phi i64 [ %30, %23 ], [ %16, %13 ]
%21 = call i32* @fgets(i8* %5, i32 2000, i32* %6)
%22 = icmp eq i32* %21, null
br i1 %22, label %38, label %23
23: ; preds = %19
%24 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = call float @atof(i8* %24)
%26 = getelementptr inbounds [2 x float], [2 x float]* %1, i64 %20, i64 1
store float %25, float* %26
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = call float @atof(i8* %27)
%29 = getelementptr inbounds [2 x float], [2 x float]* %1, i64 %20, i64 0
store float %28, float* %29
%30 = add nsw i64 %20, 1
%31 = trunc i64 %30 to i32
%32 = icmp eq i32 %18, %31
br i1 %32, label %33, label %19
33: ; preds = %23
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %19
%39 = trunc i64 %20 to i32
%40 = call i32 @fclose(i32* %6)
ret i32 %39
}