#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, unsigned int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ vExplode(char *, double *, unsigned int);
int main() {
  char sFilename[] = "test.dat";
  const unsigned iLineLen = 1024;
  char sLine[iLineLen];
  FILE *fp = fopen(sFilename, "r");
  if (!fp) {
    printf("error: could not open file \"%s\" for reading\n", sFilename);
    return 1;
  }
  if (feof(fp)) {
    printf("error: to few lines in file\n");
    return 1;
  }
  fgets(sLine, iLineLen, fp);
  unsigned iItemsOnLine = 0;
  char *c = sLine;
  while (*c != 0) {
    if (*c == '\t' || *c == '\n')
      ++iItemsOnLine;
    ++c;
  }
  printf("%u items per line\n", iItemsOnLine);
  double *dArray = (double *)malloc(sizeof(double) * iItemsOnLine);
  ({
    if (dArray == 0) {
      printf("error: got no memory\n");
      return 1;
    }
  });
  while (1) {
    vExplode(sLine, dArray, iItemsOnLine);
    printf("[");
    for (unsigned i = 0; i < iItemsOnLine; ++i) {
      printf("\t%lf", dArray[i]);
    }
    printf("\t]\n");
    if (feof(fp))
      break;
    fgets(sLine, iLineLen, fp);
    if (sLine[0] == 0)
      continue;
  }
  printf("done.\n");
  free(dArray);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0xd(%rbp)
mov    0xe65(%rip),%al
mov    %al,-0x5(%rbp)
movl   $0x400,-0x14(%rbp)
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
lea    -0xd(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f8 <main+0x78>
lea    -0xd(%rbp),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    13d5 <main+0x255>
mov    -0x28(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     122c <main+0xac>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    13d5 <main+0x255>
mov    -0x28(%rbp),%rdx
lea    -0x450(%rbp),%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
movl   $0x0,-0x30(%rbp)
lea    -0x450(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     129d <main+0x11d>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
je     1283 <main+0x103>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    128c <main+0x10c>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1253 <main+0xd3>
mov    -0x30(%rbp),%esi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12ec <main+0x16c>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    13d5 <main+0x255>
jmp    12f1 <main+0x171>
jmp    12f6 <main+0x176>
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%edx
lea    -0x450(%rbp),%rdi
call   1040 <vExplode@plt>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x30(%rbp),%eax
jae    1352 <main+0x1d2>
mov    -0x40(%rbp),%rax
mov    -0x44(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd43(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    131e <main+0x19e>
lea    0xd2c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1378 <main+0x1f8>
jmp    13a7 <main+0x227>
mov    -0x28(%rbp),%rdx
lea    -0x450(%rbp),%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
movsbl -0x450(%rbp),%eax
cmp    $0x0,%eax
jne    13a2 <main+0x222>
jmp    12f1 <main+0x171>
jmp    12f1 <main+0x171>
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rsp,%r14
movabs $0x7461642e74736574,%rax
64 61 74
mov    %rax,(%rsp)
movb   $0x0,0x8(%rsp)
lea    0xe3b(%rip),%rsi
mov    %rsp,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1201 <main+0x61>
mov    %rax,%rbp
mov    %rax,%rdi
call   10a0 <feof@plt>
test   %rax,%rax
je     121c <main+0x7c>
lea    0xe7c(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%eax
jmp    133f <main+0x19f>
lea    0xe03(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%eax
jmp    133f <main+0x19f>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
xor    %r15d,%r15d
jmp    1248 <main+0xa8>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15d
add    $0x1,%rbx
movzbl (%rbx),%eax
lea    -0x9(%rax),%ecx
cmp    $0x2,%cl
jb     1240 <main+0xa0>
test   %al,%al
jne    1244 <main+0xa4>
lea    0xdda(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x0(,%r15,8),%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     1354 <main+0x1b4>
mov    %rax,%rbx
mov    %rbp,0x18(%rsp)
mov    %r14,0x10(%rsp)
mov    %r15d,%r13d
lea    0x20(%rsp),%r12
lea    0xdb1(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r12,%r14
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <vExplode@plt>
mov    $0x5b,%edi
call   1040 <putchar@plt>
test   %r15d,%r15d
je     12e9 <main+0x149>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rbx,%r12,8),%xmm0
mov    %rbp,%rdi
mov    $0x1,%al
call   1080 <printf@plt>
add    $0x1,%r12
cmp    %r12,%r13
jne    12d0 <main+0x130>
lea    0xd60(%rip),%rdi
call   1060 <puts@plt>
mov    0x18(%rsp),%r12
mov    %r12,%rdi
call   10a0 <feof@plt>
test   %rax,%rax
jne    131c <main+0x17c>
mov    %r12,%rdx
mov    %r14,%r12
mov    %r14,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
jmp    12a0 <main+0x100>
lea    0xd30(%rip),%rdi
call   1060 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
mov    0x10(%rsp),%r14
mov    %r14,%rsp
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcfe(%rip),%rdi
jmp    11f2 <main+0x52>

LLVM IR (-O0):
@__const.main.sFilename = [9 x i8] c"test.dat\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [45 x i8] c"error: could not open file \22%s\22 for reading\0A\00"
@.str.2 = [29 x i8] c"error: to few lines in file\0A\00"
@.str.3 = [19 x i8] c"%u items per line\0A\00"
@.str.4 = [22 x i8] c"error: got no memory\0A\00"
@.str.5 = [2 x i8] c"[\00"
@.str.6 = [5 x i8] c"\09%lf\00"
@.str.7 = [4 x i8] c"\09]\0A\00"
@.str.8 = [7 x i8] c"done.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i8]
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca double*
%10 = alloca i32
store i32 0, i32* %1
%11 = bitcast [9 x i8]* %2 to i8*
store i32 1024, i32* %3
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i8, i64 1024
%14 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %0
%19 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %19)
store i32 1, i32* %1
store i32 1, i32* %6
br label %106
21: ; preds = %0
%22 = load i32*, i32** %5
%23 = call i64 @feof(i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
store i32 1, i32* %6
br label %106
27: ; preds = %21
%28 = load i32*, i32** %5
%29 = call i32 @fgets(i8* %13, i32 1024, i32* %28)
store i32 0, i32* %7
store i8* %13, i8** %8
br label %30
30: ; preds = %48, %27
%31 = load i8*, i8** %8
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %51
35: ; preds = %30
%36 = load i8*, i8** %8
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 9
br i1 %39, label %45, label %40
40: ; preds = %35
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 10
br i1 %44, label %45, label %48
45: ; preds = %40, %35
%46 = load i32, i32* %7
%47 = add i32 %46, 1
store i32 %47, i32* %7
br label %48
48: ; preds = %45, %40
%49 = load i8*, i8** %8
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %8
br label %30
51: ; preds = %30
%52 = load i32, i32* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %7
%55 = zext i32 %54 to i64
%56 = mul i64 8, %55
%57 = trunc i64 %56 to i32
%58 = call i64 @malloc(i32 %57)
%59 = inttoptr i64 %58 to double*
store double* %59, double** %9
%60 = load double*, double** %9
%61 = icmp eq double* %60, null
br i1 %61, label %62, label %64
62: ; preds = %51
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
store i32 1, i32* %6
br label %106
64: ; preds = %51
br label %65
65: ; preds = %99, %98, %64
br label %66
66: ; preds = %65
%67 = load double*, double** %9
%68 = load i32, i32* %7
%69 = call i32 @vExplode(i8* %13, double* %67, i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %10
br label %71
71: ; preds = %82, %66
%72 = load i32, i32* %10
%73 = load i32, i32* %7
%74 = icmp ult i32 %72, %73
br i1 %74, label %75, label %85
75: ; preds = %71
%76 = load double*, double** %9
%77 = load i32, i32* %10
%78 = zext i32 %77 to i64
%79 = getelementptr inbounds double, double* %76, i64 %78
%80 = load double, double* %79
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), double %80)
br label %82
82: ; preds = %75
%83 = load i32, i32* %10
%84 = add i32 %83, 1
store i32 %84, i32* %10
br label %71
85: ; preds = %71
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%87 = load i32*, i32** %5
%88 = call i64 @feof(i32* %87)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %91
90: ; preds = %85
br label %100
91: ; preds = %85
%92 = load i32*, i32** %5
%93 = call i32 @fgets(i8* %13, i32 1024, i32* %92)
%94 = getelementptr inbounds i8, i8* %13, i64 0
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %99
98: ; preds = %91
br label %65
99: ; preds = %91
br label %65
100: ; preds = %90
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%102 = load double*, double** %9
%103 = call i32 @free(double* %102)
%104 = load i32*, i32** %5
%105 = call i32 @fclose(i32* %104)
store i32 0, i32* %1
store i32 1, i32* %6
br label %106
106: ; preds = %100, %62, %25, %18
%107 = load i8*, i8** %4
%108 = load i32, i32* %1
ret i32 %108
}

LLVM IR (-O2):
@__const.main.sFilename = [9 x i8] c"test.dat\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [45 x i8] c"error: could not open file \22%s\22 for reading\0A\00"
@.str.3 = [19 x i8] c"%u items per line\0A\00"
@.str.6 = [5 x i8] c"\09%lf\00"
@str = [3 x i8] c"\09]\00"
@str.9 = [6 x i8] c"done.\00"
@str.10 = [21 x i8] c"error: got no memory\00"
@str.11 = [28 x i8] c"error: to few lines in file\00"
define i32 @main() {
%1 = alloca [9 x i8]
%2 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @llvm.stacksave()
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32* @fopen(i8* %2, 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 %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %57
10: ; preds = %0
%11 = tail call i64 @feof(i32* %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0))
br label %57
15: ; preds = %10
%16 = call i32 @fgets(i8* %5, i32 1024, i32* %6)
br label %17
17: ; preds = %23, %15
%18 = phi i32 [ 0, %15 ], [ %24, %23 ]
%19 = phi i8* [ %5, %15 ], [ %25, %23 ]
%20 = load i8, i8* %19
switch i8 %20, label %23 [
i8 0, label %26
i8 9, label %21
i8 10, label %21
]
21: ; preds = %17, %17
%22 = add i32 %18, 1
br label %23
23: ; preds = %17, %21
%24 = phi i32 [ %22, %21 ], [ %18, %17 ]
%25 = getelementptr inbounds i8, i8* %19, i64 1
br label %17
26: ; preds = %17
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%28 = shl i32 %18, 3
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to double*
%31 = icmp eq i64 %29, 0
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = icmp eq i32 %18, 0
%34 = zext i32 %18 to i64
br label %37
35: ; preds = %26
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.10, i64 0, i64 0))
br label %57
37: ; preds = %32, %51
%38 = call i32 @vExplode(i8* %5, double* %30, i32 %18)
%39 = call i32 @putchar(i32 91)
br i1 %33, label %40, label %44
40: ; preds = %44, %37
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%42 = call i64 @feof(i32* %6)
%43 = icmp eq i64 %42, 0
br i1 %43, label %51, label %53
44: ; preds = %37, %44
%45 = phi i64 [ %49, %44 ], [ 0, %37 ]
%46 = getelementptr inbounds double, double* %30, i64 %45
%47 = load double, double* %46
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), double %47)
%49 = add nuw nsw i64 %45, 1
%50 = icmp eq i64 %49, %34
br i1 %50, label %40, label %44
51: ; preds = %40
%52 = call i32 @fgets(i8* %5, i32 1024, i32* %6)
br label %37
53: ; preds = %40
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0))
%55 = call i32 @free(double* %30)
%56 = call i32 @fclose(i32* %6)
br label %57
57: ; preds = %35, %53, %13, %8
%58 = phi i32 [ 1, %13 ], [ 1, %8 ], [ 1, %35 ], [ 0, %53 ]
ret i32 %58
}