#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*/ free(double *);
int /*<<< orphan*/ log_message(char *, size_t);
int /*<<< orphan*/ printf(char *, double);
size_t read_data_single_col(int /*<<< orphan*/, size_t, double **);
int /*<<< orphan*/ *safe_fopen(char const *, char *);
int /*<<< orphan*/ stdin;
int main() {
  size_t i, j, col_n = 4, N;
  double *data;
  const char *big_file_name = "test_big_data.dat";
  FILE *f_in = safe_fopen(big_file_name, "r");
  N = read_data_single_col(stdin, col_n, &data);
  log_message("read %d lines\n", N);
  for (i = 0; i < N; i++)
    printf("%f\n", data[i]);
  free(data);
  fclose(f_in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x4,-0x20(%rbp)
lea    0xe82(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <safe_fopen@plt>
mov    %rax,-0x40(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <read_data_single_col@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1070 <log_message@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1200 <main+0xa0>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe39(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11c8 <main+0x68>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe91(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1080 <safe_fopen@plt>
mov    %rax,%r14
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rdx
mov    $0x4,%esi
call   1050 <read_data_single_col@plt>
mov    %rax,%r12
lea    0xe76(%rip),%rdi
mov    %rax,%rsi
call   1070 <log_message@plt>
test   %r12,%r12
je     11da <main+0x7a>
xor    %ebx,%ebx
lea    0xe6f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsp),%rax
movsd  (%rax,%rbx,8),%xmm0
mov    %r15,%rdi
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11c0 <main+0x60>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"test_big_data.dat\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [15 x i8] c"read %d lines\0A\00"
@.str.3 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca double*
%7 = alloca i8*
%8 = alloca i32*
store i32 0, i32* %1
store i64 4, i64* %4
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i8*, i8** %7
%10 = call i32* @safe_fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32, i32* @stdin
%12 = load i64, i64* %4
%13 = call i64 @read_data_single_col(i32 %11, i64 %12, double** %6)
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = call i32 @log_message(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 %14)
store i64 0, i64* %2
br label %16
16: ; preds = %26, %0
%17 = load i64, i64* %2
%18 = load i64, i64* %5
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load double*, double** %6
%22 = load i64, i64* %2
%23 = getelementptr inbounds double, double* %21, i64 %22
%24 = load double, double* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %24)
br label %26
26: ; preds = %20
%27 = load i64, i64* %2
%28 = add i64 %27, 1
store i64 %28, i64* %2
br label %16
29: ; preds = %16
%30 = load double*, double** %6
%31 = call i32 @free(double* %30)
%32 = load i32*, i32** %8
%33 = call i32 @fclose(i32* %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"test_big_data.dat\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [15 x i8] c"read %d lines\0A\00"
@.str.3 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca double*
%2 = bitcast double** %1 to i8*
%3 = tail call i32* @safe_fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i64 @read_data_single_col(i32 %4, i64 4, double** %1)
%6 = call i32 @log_message(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 %5)
%7 = icmp eq i64 %5, 0
br i1 %7, label %16, label %8
8: ; preds = %0, %8
%9 = phi i64 [ %14, %8 ], [ 0, %0 ]
%10 = load double*, double** %1
%11 = getelementptr inbounds double, double* %10, i64 %9
%12 = load double, double* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %12)
%14 = add nuw i64 %9, 1
%15 = icmp eq i64 %14, %5
br i1 %15, label %16, label %8
16: ; preds = %8, %0
%17 = load double*, double** %1
%18 = call i32 @free(double* %17)
%19 = call i32 @fclose(i32* %3)
ret i32 0
}