#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*/ fmtstr;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, char *, char const *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
float strtof(char *, char **);
int ai_common_load_func(const char *header, float **values,
                        const char *filename) {
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    fprintf(stderr, "Couldn't open file %s\n", filename);
    return 1;
  }
  char buf[1024];
  memset(buf, 0x00, sizeof(buf));
  int ret = fread(buf, 1, 1024, fp);
  if (ret < 3) {
    fprintf(stderr, "Couldn't read file %s\n", filename);
    fclose(fp);
    return 1;
  }
  fclose(fp);
  char fmtstr[1024];
  memset(fmtstr, 0x00, sizeof(fmtstr));
  if (strncmp(header, buf, strlen(header))) {
    fprintf(stderr, "Couldn't parse header in %s\n", filename);
    printf("'%s' '%s'\n", buf, header);
    assert(0);
    return 1;
  }
  char *pos = &buf[0] + strlen(header) + 1;
  char *endptr;
  while (*values) {
    float val = strtof(pos, &endptr);
    if (pos == endptr) {
      fprintf(stderr, "Error parsing float in %s\n", filename);
      return 1;
    }
    pos = endptr;
    **values = val;
    values++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ai_common_load_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11fb <ai_common_load_func+0x5b>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe18(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d5 <ai_common_load_func+0x235>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x3,-0x434(%rbp)
jge    1269 <ai_common_load_func+0xc9>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdca(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d5 <ai_common_load_func+0x235>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x840(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x868(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x860(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x868(%rbp),%rdi
mov    -0x860(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1309 <ai_common_load_func+0x169>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd56(%rip),%rsi
call   10b0 <fprintf@plt>
lea    -0x430(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xd5c(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <assert@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d5 <ai_common_load_func+0x235>
lea    -0x430(%rbp),%rax
mov    %rax,-0x870(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x870(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x848(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     13ce <ai_common_load_func+0x22e>
mov    -0x848(%rbp),%rdi
lea    -0x850(%rbp),%rsi
call   1080 <strtof@plt>
movss  %xmm0,-0x854(%rbp)
ff
mov    -0x848(%rbp),%rax
cmp    -0x850(%rbp),%rax
jne    139c <ai_common_load_func+0x1fc>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xccd(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d5 <ai_common_load_func+0x235>
mov    -0x850(%rbp),%rax
mov    %rax,-0x848(%rbp)
movss  -0x854(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movss  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    133a <ai_common_load_func+0x19a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ai_common_load_func>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0xe3f(%rip),%rsi
mov    %rdx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     122a <ai_common_load_func+0x8a>
mov    %rax,%rbx
lea    0x10(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
mov    $0x1,%r14d
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x2,%eax
jg     1244 <ai_common_load_func+0xa4>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
mov    %r12,%rdx
call   10b0 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    12b8 <ai_common_load_func+0x118>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    %r12,%rdx
call   10b0 <fprintf@plt>
jmp    12b2 <ai_common_load_func+0x112>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0x410(%rsp),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12cd <ai_common_load_func+0x12d>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
mov    %r12,%rdx
call   10b0 <fprintf@plt>
lea    0xdaf(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %r15,%rdx
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <assert@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1060 <strlen@plt>
cmpq   $0x0,0x0(%rbp)
je     12b8 <ai_common_load_func+0x118>
cltq
add    %rsp,%rax
add    $0x11,%rax
add    $0x8,%rbp
lea    0x8(%rsp),%r15
xchg   %ax,%ax
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1080 <strtof@plt>
mov    0x8(%rsp),%rax
cmp    %rax,%rbx
je     131d <ai_common_load_func+0x17d>
mov    -0x8(%rbp),%rcx
movss  %xmm0,(%rcx)
cmpq   $0x0,0x0(%rbp)
lea    0x8(%rbp),%rbp
jne    12f0 <ai_common_load_func+0x150>
jmp    12b8 <ai_common_load_func+0x118>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
lea    0xd2b(%rip),%rsi
jmp    123a <ai_common_load_func+0x9a>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Couldn't open file %s\0A\00"
@.str.2 = [23 x i8] c"Couldn't read file %s\0A\00"
@.str.3 = [29 x i8] c"Couldn't parse header in %s\0A\00"
@.str.4 = [11 x i8] c"'%s' '%s'\0A\00"
@.str.5 = [27 x i8] c"Error parsing float in %s\0A\00"
define i32 @ai_common_load_func(i8* %0, float** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca float**
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [1024 x i8]
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca float
store i8* %0, i8** %5
store float** %1, float*** %6
store i8* %2, i8** %7
%15 = load i8*, i8** %7
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %8
%17 = load i32*, i32** %8
%18 = icmp ne i32* %17, null
br i1 %18, label %23, label %19
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %7
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 1, i32* %4
br label %85
23: ; preds = %3
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 1024)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%27 = load i32*, i32** %8
%28 = call i32 @fread(i8* %26, i32 1, i32 1024, i32* %27)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp slt i32 %29, 3
br i1 %30, label %31, label %37
31: ; preds = %23
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %7
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32*, i32** %8
%36 = call i32 @fclose(i32* %35)
store i32 1, i32* %4
br label %85
37: ; preds = %23
%38 = load i32*, i32** %8
%39 = call i32 @fclose(i32* %38)
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%41 = call i32 @memset(i8* %40, i32 0, i32 1024)
%42 = load i8*, i8** %5
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%44 = load i8*, i8** %5
%45 = call i32 @strlen(i8* %44)
%46 = call i64 @strncmp(i8* %42, i8* %43, i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %37
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %7
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %50)
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%53 = load i8*, i8** %5
%54 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %52, i8* %53)
%55 = call i32 @assert(i32 0)
store i32 1, i32* %4
br label %85
56: ; preds = %37
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%58 = load i8*, i8** %5
%59 = call i32 @strlen(i8* %58)
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
%62 = getelementptr inbounds i8, i8* %61, i64 1
store i8* %62, i8** %12
br label %63
63: ; preds = %77, %56
%64 = load float**, float*** %6
%65 = load float*, float** %64
%66 = icmp ne float* %65, null
br i1 %66, label %67, label %84
67: ; preds = %63
%68 = load i8*, i8** %12
%69 = call float @strtof(i8* %68, i8** %13)
store float %69, float* %14
%70 = load i8*, i8** %12
%71 = load i8*, i8** %13
%72 = icmp eq i8* %70, %71
br i1 %72, label %73, label %77
73: ; preds = %67
%74 = load i32, i32* @stderr
%75 = load i8*, i8** %7
%76 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %75)
store i32 1, i32* %4
br label %85
77: ; preds = %67
%78 = load i8*, i8** %13
store i8* %78, i8** %12
%79 = load float, float* %14
%80 = load float**, float*** %6
%81 = load float*, float** %80
store float %79, float* %81
%82 = load float**, float*** %6
%83 = getelementptr inbounds float*, float** %82, i32 1
store float** %83, float*** %6
br label %63
84: ; preds = %63
store i32 0, i32* %4
br label %85
85: ; preds = %84, %73, %48, %31, %19
%86 = load i32, i32* %4
ret i32 %86
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Couldn't open file %s\0A\00"
@.str.2 = [23 x i8] c"Couldn't read file %s\0A\00"
@.str.3 = [29 x i8] c"Couldn't parse header in %s\0A\00"
@.str.4 = [11 x i8] c"'%s' '%s'\0A\00"
@.str.5 = [27 x i8] c"Error parsing float in %s\0A\00"
define i32 @ai_common_load_func(i8* %0, float** nocapture %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %62
12: ; preds = %3
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 1024)
%15 = call i32 @fread(i8* %13, i32 1, i32 1024, i32* %7)
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%20 = call i32 @fclose(i32* %7)
br label %60
21: ; preds = %12
%22 = call i32 @fclose(i32* %7)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%24 = call i32 @memset(i8* %23, i32 0, i32 1024)
%25 = call i32 @strlen(i8* %0)
%26 = call i64 @strncmp(i8* %0, i8* %13, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%31 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %13, i8* %0)
%32 = call i32 @assert(i32 0)
br label %58
33: ; preds = %21
%34 = call i32 @strlen(i8* %0)
%35 = bitcast i8** %6 to i8*
%36 = load float*, float** %1
%37 = icmp eq float* %36, null
br i1 %37, label %56, label %38
38: ; preds = %33
%39 = sext i32 %34 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %39
%41 = getelementptr inbounds i8, i8* %40, i64 1
br label %42
42: ; preds = %38, %51
%43 = phi i8* [ %46, %51 ], [ %41, %38 ]
%44 = phi float** [ %53, %51 ], [ %1, %38 ]
%45 = call float @strtof(i8* %43, i8** %6)
%46 = load i8*, i8** %6
%47 = icmp eq i8* %43, %46
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %2)
br label %56
51: ; preds = %42
%52 = load float*, float** %44
store float %45, float* %52
%53 = getelementptr inbounds float*, float** %44, i64 1
%54 = load float*, float** %53
%55 = icmp eq float* %54, null
br i1 %55, label %56, label %42
56: ; preds = %51, %33, %48
%57 = phi i32 [ 1, %48 ], [ 0, %33 ], [ 0, %51 ]
br label %58
58: ; preds = %56, %28
%59 = phi i32 [ 1, %28 ], [ %57, %56 ]
br label %60
60: ; preds = %58, %17
%61 = phi i32 [ 1, %17 ], [ %59, %58 ]
br label %62
62: ; preds = %60, %9
%63 = phi i32 [ %61, %60 ], [ 1, %9 ]
ret i32 %63
}