#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 */

/* Variables and functions */
int read_datafile(char *, double ***, int *);
double *xmalloc(int);
int read_column(char *fname, int ncol, double **data) {
  int i, n, ncols;
  double **datafile;
  n = read_datafile(fname, &datafile, &ncols);
  if (n < 0)
    return -1;
  if (ncol - 1 < 0 || ncol - 1 > ncols - 1)
    return -2;
  *data = xmalloc(sizeof(double) * n);
  for (i = 0; i < n; i++)
    (*data)[i] = datafile[i][ncol - 1];
  return n;
}


x86 assembly (clang, -O0):
<read_column>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <read_datafile@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    115d <read_column+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <read_column+0xd6>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cmp    $0x0,%eax
jl     1180 <read_column+0x60>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    118c <read_column+0x6c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11f6 <read_column+0xd6>
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <xmalloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11f0 <read_column+0xd0>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ac <read_column+0x8c>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_column>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1040 <read_datafile@plt>
test   %eax,%eax
js     1191 <read_column+0x71>
mov    %eax,%r15d
mov    $0xfffffffe,%eax
test   %ebp,%ebp
jle    122b <read_column+0x10b>
cmp    %ebp,0xc(%rsp)
jl     122b <read_column+0x10b>
lea    0x0(,%r15,8),%edi
call   1030 <xmalloc@plt>
mov    %rax,(%r14)
test   %r15d,%r15d
je     119b <read_column+0x7b>
add    $0xffffffff,%ebp
mov    0x10(%rsp),%rsi
mov    %ebp,%ecx
mov    %r15d,%edi
lea    -0x1(%rdi),%rbp
mov    %edi,%edx
and    $0x3,%edx
cmp    $0x3,%rbp
jae    11a2 <read_column+0x82>
xor    %ebp,%ebp
jmp    11f7 <read_column+0xd7>
mov    $0xffffffff,%eax
jmp    122b <read_column+0x10b>
xor    %eax,%eax
jmp    122b <read_column+0x10b>
and    $0xfffffffc,%edi
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%rsi,%rbp,8),%rbx
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rbp,8)
mov    0x8(%rsi,%rbp,8),%rbx
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x8(%rax,%rbp,8)
mov    0x10(%rsi,%rbp,8),%rbx
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x10(%rax,%rbp,8)
mov    0x18(%rsi,%rbp,8),%rbx
movsd  (%rbx,%rcx,8),%xmm0
movsd  %xmm0,0x18(%rax,%rbp,8)
add    $0x4,%rbp
cmp    %rbp,%rdi
jne    11b0 <read_column+0x90>
test   %rdx,%rdx
je     1228 <read_column+0x108>
lea    (%rax,%rbp,8),%rax
lea    (%rsi,%rbp,8),%rsi
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
mov    (%rsi,%rdi,8),%rbp
movsd  0x0(%rbp,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rdi,8)
add    $0x1,%rdi
cmp    %rdi,%rdx
jne    1210 <read_column+0xf0>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_column(i8* %0, i32 %1, double** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca double**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double**
store i8* %0, i8** %5
store i32 %1, i32* %6
store double** %2, double*** %7
%12 = load i8*, i8** %5
%13 = call i32 @read_datafile(i8* %12, double*** %11, i32* %10)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %60
17: ; preds = %3
%18 = load i32, i32* %6
%19 = sub nsw i32 %18, 1
%20 = icmp slt i32 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %17
%22 = load i32, i32* %6
%23 = sub nsw i32 %22, 1
%24 = load i32, i32* %10
%25 = sub nsw i32 %24, 1
%26 = icmp sgt i32 %23, %25
br i1 %26, label %27, label %28
27: ; preds = %21, %17
store i32 -2, i32* %4
br label %60
28: ; preds = %21
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = mul i64 8, %30
%32 = trunc i64 %31 to i32
%33 = call double* @xmalloc(i32 %32)
%34 = load double**, double*** %7
store double* %33, double** %34
store i32 0, i32* %8
br label %35
35: ; preds = %55, %28
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %58
39: ; preds = %35
%40 = load double**, double*** %11
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double*, double** %40, i64 %42
%44 = load double*, double** %43
%45 = load i32, i32* %6
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %44, i64 %47
%49 = load double, double* %48
%50 = load double**, double*** %7
%51 = load double*, double** %50
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
store double %49, double* %54
br label %55
55: ; preds = %39
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %35
58: ; preds = %35
%59 = load i32, i32* %9
store i32 %59, i32* %4
br label %60
60: ; preds = %58, %27, %16
%61 = load i32, i32* %4
ret i32 %61
}

LLVM IR (-O2):
define i32 @read_column(i8* %0, i32 %1, double** nocapture %2) {
%4 = alloca i32
%5 = alloca double**
%6 = bitcast i32* %4 to i8*
%7 = bitcast double*** %5 to i8*
%8 = call i32 @read_datafile(i8* %0, double*** %5, i32* %4)
%9 = icmp slt i32 %8, 0
br i1 %9, label %72, label %10
10: ; preds = %3
%11 = add nsw i32 %1, -1
%12 = icmp slt i32 %1, 1
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, %1
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %72, label %16
16: ; preds = %10
%17 = shl i32 %8, 3
%18 = call double* @xmalloc(i32 %17)
store double* %18, double** %2
%19 = icmp eq i32 %8, 0
br i1 %19, label %72, label %20
20: ; preds = %16
%21 = load double**, double*** %5
%22 = zext i32 %11 to i64
%23 = zext i32 %8 to i64
%24 = add nsw i64 %23, -1
%25 = and i64 %23, 3
%26 = icmp ult i64 %24, 3
br i1 %26, label %58, label %27
27: ; preds = %20
%28 = and i64 %23, 4294967292
br label %29
29: ; preds = %29, %27
%30 = phi i64 [ 0, %27 ], [ %55, %29 ]
%31 = phi i64 [ 0, %27 ], [ %56, %29 ]
%32 = getelementptr inbounds double*, double** %21, i64 %30
%33 = load double*, double** %32
%34 = getelementptr inbounds double, double* %33, i64 %22
%35 = load double, double* %34
%36 = getelementptr inbounds double, double* %18, i64 %30
store double %35, double* %36
%37 = or i64 %30, 1
%38 = getelementptr inbounds double*, double** %21, i64 %37
%39 = load double*, double** %38
%40 = getelementptr inbounds double, double* %39, i64 %22
%41 = load double, double* %40
%42 = getelementptr inbounds double, double* %18, i64 %37
store double %41, double* %42
%43 = or i64 %30, 2
%44 = getelementptr inbounds double*, double** %21, i64 %43
%45 = load double*, double** %44
%46 = getelementptr inbounds double, double* %45, i64 %22
%47 = load double, double* %46
%48 = getelementptr inbounds double, double* %18, i64 %43
store double %47, double* %48
%49 = or i64 %30, 3
%50 = getelementptr inbounds double*, double** %21, i64 %49
%51 = load double*, double** %50
%52 = getelementptr inbounds double, double* %51, i64 %22
%53 = load double, double* %52
%54 = getelementptr inbounds double, double* %18, i64 %49
store double %53, double* %54
%55 = add nuw nsw i64 %30, 4
%56 = add i64 %31, 4
%57 = icmp eq i64 %56, %28
br i1 %57, label %58, label %29
58: ; preds = %29, %20
%59 = phi i64 [ 0, %20 ], [ %55, %29 ]
%60 = icmp eq i64 %25, 0
br i1 %60, label %72, label %61
61: ; preds = %58, %61
%62 = phi i64 [ %69, %61 ], [ %59, %58 ]
%63 = phi i64 [ %70, %61 ], [ 0, %58 ]
%64 = getelementptr inbounds double*, double** %21, i64 %62
%65 = load double*, double** %64
%66 = getelementptr inbounds double, double* %65, i64 %22
%67 = load double, double* %66
%68 = getelementptr inbounds double, double* %18, i64 %62
store double %67, double* %68
%69 = add nuw nsw i64 %62, 1
%70 = add i64 %63, 1
%71 = icmp eq i64 %70, %25
br i1 %71, label %72, label %61
72: ; preds = %58, %61, %16, %10, %3
%73 = phi i32 [ -1, %3 ], [ -2, %10 ], [ 0, %16 ], [ %8, %61 ], [ %8, %58 ]
ret i32 %73
}