#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*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char const *, int);
float *wbImport(const char *fn, int *inputLength) {
  float *retVal = NULL;
  FILE *fp = fopen(fn, "r");
  if (fp) {
    int i;
    assert(1 == fscanf(fp, "%d", inputLength));
    float *data = (float *)malloc((sizeof(float) * (*inputLength)));
    printf("%s: %d\n", fn, (*inputLength));
    for (i = 0; i < (*inputLength); ++i) {
      assert(1 == fscanf(fp, "%f", &data[i]));
    }
    fclose(fp);
    retVal = data;
  }
  return (retVal);
}


x86 assembly (clang, -O0):
<wbImport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     125b <wbImport+0xfb>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    124a <wbImport+0xea>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f6 <wbImport+0x96>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wbImport>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1218 <wbImport+0xb8>
mov    %rax,%r13
lea    0xe72(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1060 <assert@plt>
mov    (%r14),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    (%r14),%edx
lea    0xe42(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
cmpl   $0x0,(%r14)
jle    120e <wbImport+0xae>
lea    0xe35(%rip),%r12
mov    %r15,%rbx
xor    %ebp,%ebp
nopl   (%rax)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1060 <assert@plt>
add    $0x1,%rbp
movslq (%r14),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     11e0 <wbImport+0x80>
mov    %r13,%rdi
call   1030 <fclose@plt>
jmp    121b <wbImport+0xbb>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%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 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"%s: %d\0A\00"
@.str.3 = [3 x i8] c"%f\00"
define float* @wbImport(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca float*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca float*
store i8* %0, i8** %3
store i32* %1, i32** %4
store float* null, float** %5
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %53
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = load i32*, i32** %4
%16 = call i32 (i32*, i8*, ...) @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%17 = icmp eq i32 1, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32*, i32** %4
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = mul i64 4, %22
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to float*
store float* %26, float** %8
%27 = load i8*, i8** %3
%28 = load i32*, i32** %4
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %27, i32 %29)
store i32 0, i32* %7
br label %31
31: ; preds = %46, %13
%32 = load i32, i32* %7
%33 = load i32*, i32** %4
%34 = load i32, i32* %33
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %49
36: ; preds = %31
%37 = load i32*, i32** %6
%38 = load float*, float** %8
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %38, i64 %40
%42 = call i32 (i32*, i8*, ...) @fscanf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %41)
%43 = icmp eq i32 1, %42
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
br label %46
46: ; preds = %36
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %31
49: ; preds = %31
%50 = load i32*, i32** %6
%51 = call i32 @fclose(i32* %50)
%52 = load float*, float** %8
store float* %52, float** %5
br label %53
53: ; preds = %49, %2
%54 = load float*, float** %5
ret float* %54
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [8 x i8] c"%s: %d\0A\00"
@.str.3 = [3 x i8] c"%f\00"
define float* @wbImport(i8* %0, i32* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %31, label %5
5: ; preds = %2
%6 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = icmp eq i32 %6, 1
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = load i32, i32* %1
%11 = shl i32 %10, 2
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to float*
%14 = load i32, i32* %1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %14)
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %5, %18
%19 = phi i64 [ %25, %18 ], [ 0, %5 ]
%20 = getelementptr inbounds float, float* %13, i64 %19
%21 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %20)
%22 = icmp eq i32 %21, 1
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = add nuw nsw i64 %19, 1
%26 = load i32, i32* %1
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %18, label %29
29: ; preds = %18, %5
%30 = tail call i32 @fclose(i32* %3)
br label %31
31: ; preds = %29, %2
%32 = phi float* [ %13, %29 ], [ null, %2 ]
ret float* %32
}