#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *openFile(char *);
scalar_t__ realloc(float *, int);
int /*<<< orphan*/ sscanf(char *, char *, float *);
int getFloatsFromFile(char *dateiName, float **retVal) {
  FILE *datei = openFile(dateiName);
  if (datei == NULL)
    return -1;
  char line[256];
  int anzZeilen = 0;
  while (fgets(line, 256, datei) != NULL) {
    float temp;
    sscanf(line, "%f\n", &temp);
    *retVal = (float *)realloc(*retVal, (anzZeilen + 1) * sizeof(float));
    (*retVal)[anzZeilen] = temp;
    anzZeilen++;
  }
  fclose(datei);
  return anzZeilen;
}


x86 assembly (clang, -O0):
<getFloatsFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <openFile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1187 <getFloatsFromFile+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    1232 <getFloatsFromFile+0xe2>
movl   $0x0,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1220 <getFloatsFromFile+0xd0>
lea    -0x120(%rbp),%rdi
lea    0xe42(%rip),%rsi
lea    -0x128(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x124(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movss  -0x128(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x124(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    1191 <getFloatsFromFile+0x41>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFloatsFromFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r15
call   1040 <openFile@plt>
test   %rax,%rax
je     11ed <getFloatsFromFile+0x9d>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f5 <getFloatsFromFile+0xa5>
mov    $0x4,%ebp
xor    %r12d,%r12d
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rbx
mov    %r13,%rdi
lea    0xe53(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
mov    (%r15),%rdi
add    $0x1,%r12
mov    %ebp,%esi
call   1070 <realloc@plt>
mov    %rax,(%r15)
movss  0xc(%rsp),%xmm0
movss  %xmm0,(%rax,%rbx,4)
mov    %r13,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
add    $0x4,%ebp
test   %rax,%rax
jne    11a0 <getFloatsFromFile+0x50>
jmp    11f8 <getFloatsFromFile+0xa8>
mov    $0xffffffff,%r12d
jmp    1200 <getFloatsFromFile+0xb0>
xor    %r12d,%r12d
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r12d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%f\0A\00"
define i32 @getFloatsFromFile(i8* %0, float** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca float
%5 = tail call i32* @openFile(i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %31, label %7
7: ; preds = %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = call i32* @fgets(i8* %8, i32 256, i32* %5)
%10 = icmp eq i32* %9, null
br i1 %10, label %28, label %11
11: ; preds = %7
%12 = bitcast float* %4 to i8*
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %17, %13 ]
%15 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), float* %4)
%16 = load float*, float** %1
%17 = add nuw i64 %14, 1
%18 = trunc i64 %17 to i32
%19 = shl i32 %18, 2
%20 = call i64 @realloc(float* %16, i32 %19)
%21 = inttoptr i64 %20 to float*
store float* %21, float** %1
%22 = load float, float* %4
%23 = getelementptr inbounds float, float* %21, i64 %14
store float %22, float* %23
%24 = call i32* @fgets(i8* %8, i32 256, i32* %5)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %13
26: ; preds = %13
%27 = trunc i64 %17 to i32
br label %28
28: ; preds = %26, %7
%29 = phi i32 [ 0, %7 ], [ %27, %26 ]
%30 = call i32 @fclose(i32* %5)
br label %31
31: ; preds = %2, %28
%32 = phi i32 [ %29, %28 ], [ -1, %2 ]
ret i32 %32
}