#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 /*<<< orphan*/ calc_cov(double *, int, int, double *);
int /*<<< orphan*/ calc_sdev(double *, int);
int /*<<< orphan*/ calc_x(double *, double *, int, int);
int /*<<< orphan*/ diagonalize(double *, int, int, double *, double *);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int nb_cols_lfmm(char *);
int nb_lines(char *, int);
int /*<<< orphan*/ normalize_cov_I(double *, int, int);
int /*<<< orphan*/ normalize_mean_I(double *, int, int);
int /*<<< orphan*/ print_summary_pca(int, int, int, int, int, char *, char *,
                                     char *, char *, char *);
int /*<<< orphan*/ read_data_double(char *, int, int, double *);
int /*<<< orphan*/ write_data_double(char *, int, int, double *);
void pca(char *input_file, char *output_eva_file, char *output_eve_file,
         char *output_sdev_file, char *output_x_file, int *n, int *L, int *K,
         int c, int s) {
  double *data;
  double *cov, *val, *vect;
  int N, M, tmp;
  M = nb_cols_lfmm(input_file);
  N = nb_lines(input_file, M);
  *L = M;
  *n = N;
  if (N < M)
    tmp = N;
  else
    tmp = M;
  if (!(*K) || *K > tmp)
    *K = tmp;
  print_summary_pca(N, M, *K, c, s, input_file, output_eva_file,
                    output_eve_file, output_sdev_file, output_x_file);
  data = (double *)malloc(N * M * sizeof(double));
  cov = (double *)malloc(N * N * sizeof(double));
  val = (double *)malloc(N * sizeof(double));
  vect = (double *)malloc(N * (*K) * sizeof(double));
  read_data_double(input_file, N, M, data);
  if (s)
    normalize_cov_I(data, N, M);
  else if (c)
    normalize_mean_I(data, N, M);
  calc_cov(data, N, M, cov);
  diagonalize(cov, N, *K, val, vect);
  write_data_double(output_eva_file, N, 1, val);
  write_data_double(output_eve_file, N, *K, vect);
  calc_sdev(val, N);
  write_data_double(output_sdev_file, N, 1, val);
  calc_x(vect, val, N, *K);
  write_data_double(output_x_file, N, *K, vect);
  free(data);
  free(cov);
  free(val);
  free(vect);
}


x86 assembly (clang, -O0):
<pca>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x88,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   10f0 <nb_cols_lfmm@plt>
mov    %eax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x60(%rbp),%esi
call   1060 <nb_lines@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x60(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x5c(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x5c(%rbp),%eax
cmp    -0x60(%rbp),%eax
jge    1246 <pca+0x76>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    124c <pca+0x7c>
mov    -0x60(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     1268 <pca+0x98>
mov    0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x64(%rbp),%eax
jle    1271 <pca+0xa1>
mov    -0x64(%rbp),%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x5c(%rbp),%edi
mov    -0x60(%rbp),%esi
mov    0x18(%rbp),%rax
mov    (%rax),%edx
mov    0x20(%rbp),%ecx
mov    0x28(%rbp),%r8d
mov    -0x10(%rbp),%r9
mov    -0x18(%rbp),%rbx
mov    -0x20(%rbp),%r11
mov    -0x28(%rbp),%r10
mov    -0x30(%rbp),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   10a0 <print_summary_pca@plt>
mov    -0x5c(%rbp),%eax
imul   -0x60(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x5c(%rbp),%eax
imul   -0x5c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
movslq -0x5c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x5c(%rbp),%eax
mov    0x18(%rbp),%rcx
imul   (%rcx),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x60(%rbp),%edx
mov    -0x40(%rbp),%rcx
call   1070 <read_data_double@plt>
cmpl   $0x0,0x28(%rbp)
je     133f <pca+0x16f>
mov    -0x40(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x60(%rbp),%edx
call   1080 <normalize_cov_I@plt>
jmp    135d <pca+0x18d>
cmpl   $0x0,0x20(%rbp)
je     1358 <pca+0x188>
mov    -0x40(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x60(%rbp),%edx
call   10d0 <normalize_mean_I@plt>
jmp    135d <pca+0x18d>
mov    -0x40(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x60(%rbp),%edx
mov    -0x48(%rbp),%rcx
call   1040 <calc_cov@plt>
mov    -0x48(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x50(%rbp),%rcx
mov    -0x58(%rbp),%r8
call   10b0 <diagonalize@plt>
mov    -0x18(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x50(%rbp),%rcx
mov    $0x1,%edx
call   10c0 <write_data_double@plt>
mov    -0x20(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x58(%rbp),%rcx
call   10c0 <write_data_double@plt>
mov    -0x50(%rbp),%rdi
mov    -0x5c(%rbp),%esi
call   10e0 <calc_sdev@plt>
mov    -0x28(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x50(%rbp),%rcx
mov    $0x1,%edx
call   10c0 <write_data_double@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x5c(%rbp),%edx
mov    0x18(%rbp),%rax
mov    (%rax),%ecx
call   1050 <calc_x@plt>
mov    -0x30(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x58(%rbp),%rcx
call   10c0 <write_data_double@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<pca>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%r12
mov    %rcx,0x30(%rsp)
mov    %rdx,0x28(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdi,%r15
mov    0x98(%rsp),%eax
mov    %eax,0xc(%rsp)
mov    0x90(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    0x88(%rsp),%r13
mov    0x80(%rsp),%rbp
call   10f0 <nb_cols_lfmm@plt>
mov    %eax,%r14d
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <nb_lines@plt>
mov    %eax,%ebx
mov    %r14d,0x0(%rbp)
mov    0x10(%rsp),%rax
mov    %ebx,(%rax)
cmp    %r14d,%ebx
mov    %r14d,%eax
cmovl  %ebx,%eax
mov    0x0(%r13),%edx
test   %edx,%edx
je     1252 <pca+0x82>
cmp    %eax,%edx
jle    1258 <pca+0x88>
mov    %eax,0x0(%r13)
mov    %eax,%edx
mov    %ebx,%edi
mov    %r14d,%esi
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    %r15,%r9
mov    %r12,0x10(%rsp)
push   %r12
push   0x38(%rsp)
push   0x38(%rsp)
push   0x38(%rsp)
call   10a0 <print_summary_pca@plt>
add    $0x20,%rsp
mov    %r14d,%edi
imul   %ebx,%edi
shl    $0x3,%edi
call   1090 <malloc@plt>
mov    %rax,0x38(%rsp)
lea    0x0(,%rbx,8),%ebp
mov    %ebx,%edi
imul   %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,0x40(%rsp)
mov    %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
mov    %r13,0x18(%rsp)
imul   0x0(%r13),%ebp
mov    %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    %r15,%rdi
mov    0x38(%rsp),%r15
mov    %ebx,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1070 <read_data_double@plt>
cmpl   $0x0,0xc(%rsp)
je     12fc <pca+0x12c>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1080 <normalize_cov_I@plt>
mov    0x18(%rsp),%rbp
jmp    1315 <pca+0x145>
cmpl   $0x0,0x8(%rsp)
mov    0x18(%rsp),%rbp
je     1315 <pca+0x145>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   10d0 <normalize_mean_I@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    0x40(%rsp),%r14
mov    %r14,%rcx
call   1040 <calc_cov@plt>
mov    0x0(%rbp),%edx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r12,%rcx
mov    %r13,%r8
call   10b0 <diagonalize@plt>
mov    0x20(%rsp),%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10c0 <write_data_double@plt>
mov    0x0(%rbp),%edx
mov    0x28(%rsp),%rdi
mov    %ebx,%esi
mov    %r13,%rcx
call   10c0 <write_data_double@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   10e0 <calc_sdev@plt>
mov    0x30(%rsp),%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10c0 <write_data_double@plt>
mov    0x0(%rbp),%ecx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <calc_x@plt>
mov    0x0(%rbp),%edx
mov    0x10(%rsp),%rdi
mov    %ebx,%esi
mov    %r13,%rcx
call   10c0 <write_data_double@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @pca(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32* %5, i32* %6, i32* %7, i32 %8, i32 %9) {
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32
%20 = alloca i32
%21 = alloca double*
%22 = alloca double*
%23 = alloca double*
%24 = alloca double*
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
store i8* %0, i8** %11
store i8* %1, i8** %12
store i8* %2, i8** %13
store i8* %3, i8** %14
store i8* %4, i8** %15
store i32* %5, i32** %16
store i32* %6, i32** %17
store i32* %7, i32** %18
store i32 %8, i32* %19
store i32 %9, i32* %20
%28 = load i8*, i8** %11
%29 = call i32 @nb_cols_lfmm(i8* %28)
store i32 %29, i32* %26
%30 = load i8*, i8** %11
%31 = load i32, i32* %26
%32 = call i32 @nb_lines(i8* %30, i32 %31)
store i32 %32, i32* %25
%33 = load i32, i32* %26
%34 = load i32*, i32** %17
store i32 %33, i32* %34
%35 = load i32, i32* %25
%36 = load i32*, i32** %16
store i32 %35, i32* %36
%37 = load i32, i32* %25
%38 = load i32, i32* %26
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %10
%41 = load i32, i32* %25
store i32 %41, i32* %27
br label %44
42: ; preds = %10
%43 = load i32, i32* %26
store i32 %43, i32* %27
br label %44
44: ; preds = %42, %40
%45 = load i32*, i32** %18
%46 = load i32, i32* %45
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i32*, i32** %18
%50 = load i32, i32* %49
%51 = load i32, i32* %27
%52 = icmp sgt i32 %50, %51
br i1 %52, label %53, label %56
53: ; preds = %48, %44
%54 = load i32, i32* %27
%55 = load i32*, i32** %18
store i32 %54, i32* %55
br label %56
56: ; preds = %53, %48
%57 = load i32, i32* %25
%58 = load i32, i32* %26
%59 = load i32*, i32** %18
%60 = load i32, i32* %59
%61 = load i32, i32* %19
%62 = load i32, i32* %20
%63 = load i8*, i8** %11
%64 = load i8*, i8** %12
%65 = load i8*, i8** %13
%66 = load i8*, i8** %14
%67 = load i8*, i8** %15
%68 = call i32 @print_summary_pca(i32 %57, i32 %58, i32 %60, i32 %61, i32 %62, i8* %63, i8* %64, i8* %65, i8* %66, i8* %67)
%69 = load i32, i32* %25
%70 = load i32, i32* %26
%71 = mul nsw i32 %69, %70
%72 = sext i32 %71 to i64
%73 = mul i64 %72, 8
%74 = trunc i64 %73 to i32
%75 = call i64 @malloc(i32 %74)
%76 = inttoptr i64 %75 to double*
store double* %76, double** %21
%77 = load i32, i32* %25
%78 = load i32, i32* %25
%79 = mul nsw i32 %77, %78
%80 = sext i32 %79 to i64
%81 = mul i64 %80, 8
%82 = trunc i64 %81 to i32
%83 = call i64 @malloc(i32 %82)
%84 = inttoptr i64 %83 to double*
store double* %84, double** %22
%85 = load i32, i32* %25
%86 = sext i32 %85 to i64
%87 = mul i64 %86, 8
%88 = trunc i64 %87 to i32
%89 = call i64 @malloc(i32 %88)
%90 = inttoptr i64 %89 to double*
store double* %90, double** %23
%91 = load i32, i32* %25
%92 = load i32*, i32** %18
%93 = load i32, i32* %92
%94 = mul nsw i32 %91, %93
%95 = sext i32 %94 to i64
%96 = mul i64 %95, 8
%97 = trunc i64 %96 to i32
%98 = call i64 @malloc(i32 %97)
%99 = inttoptr i64 %98 to double*
store double* %99, double** %24
%100 = load i8*, i8** %11
%101 = load i32, i32* %25
%102 = load i32, i32* %26
%103 = load double*, double** %21
%104 = call i32 @read_data_double(i8* %100, i32 %101, i32 %102, double* %103)
%105 = load i32, i32* %20
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %112
107: ; preds = %56
%108 = load double*, double** %21
%109 = load i32, i32* %25
%110 = load i32, i32* %26
%111 = call i32 @normalize_cov_I(double* %108, i32 %109, i32 %110)
br label %121
112: ; preds = %56
%113 = load i32, i32* %19
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %120
115: ; preds = %112
%116 = load double*, double** %21
%117 = load i32, i32* %25
%118 = load i32, i32* %26
%119 = call i32 @normalize_mean_I(double* %116, i32 %117, i32 %118)
br label %120
120: ; preds = %115, %112
br label %121
121: ; preds = %120, %107
%122 = load double*, double** %21
%123 = load i32, i32* %25
%124 = load i32, i32* %26
%125 = load double*, double** %22
%126 = call i32 @calc_cov(double* %122, i32 %123, i32 %124, double* %125)
%127 = load double*, double** %22
%128 = load i32, i32* %25
%129 = load i32*, i32** %18
%130 = load i32, i32* %129
%131 = load double*, double** %23
%132 = load double*, double** %24
%133 = call i32 @diagonalize(double* %127, i32 %128, i32 %130, double* %131, double* %132)
%134 = load i8*, i8** %12
%135 = load i32, i32* %25
%136 = load double*, double** %23
%137 = call i32 @write_data_double(i8* %134, i32 %135, i32 1, double* %136)
%138 = load i8*, i8** %13
%139 = load i32, i32* %25
%140 = load i32*, i32** %18
%141 = load i32, i32* %140
%142 = load double*, double** %24
%143 = call i32 @write_data_double(i8* %138, i32 %139, i32 %141, double* %142)
%144 = load double*, double** %23
%145 = load i32, i32* %25
%146 = call i32 @calc_sdev(double* %144, i32 %145)
%147 = load i8*, i8** %14
%148 = load i32, i32* %25
%149 = load double*, double** %23
%150 = call i32 @write_data_double(i8* %147, i32 %148, i32 1, double* %149)
%151 = load double*, double** %24
%152 = load double*, double** %23
%153 = load i32, i32* %25
%154 = load i32*, i32** %18
%155 = load i32, i32* %154
%156 = call i32 @calc_x(double* %151, double* %152, i32 %153, i32 %155)
%157 = load i8*, i8** %15
%158 = load i32, i32* %25
%159 = load i32*, i32** %18
%160 = load i32, i32* %159
%161 = load double*, double** %24
%162 = call i32 @write_data_double(i8* %157, i32 %158, i32 %160, double* %161)
%163 = load double*, double** %21
%164 = call i32 @free(double* %163)
%165 = load double*, double** %22
%166 = call i32 @free(double* %165)
%167 = load double*, double** %23
%168 = call i32 @free(double* %167)
%169 = load double*, double** %24
%170 = call i32 @free(double* %169)
ret void
}

LLVM IR (-O2):
define void @pca(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6, i32* nocapture %7, i32 %8, i32 %9) {
%11 = tail call i32 @nb_cols_lfmm(i8* %0)
%12 = tail call i32 @nb_lines(i8* %0, i32 %11)
store i32 %11, i32* %6
store i32 %12, i32* %5
%13 = icmp slt i32 %12, %11
%14 = select i1 %13, i32 %12, i32 %11
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, 0
%17 = icmp sgt i32 %15, %14
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %19, label %20
19: ; preds = %10
store i32 %14, i32* %7
br label %20
20: ; preds = %10, %19
%21 = phi i32 [ %15, %10 ], [ %14, %19 ]
%22 = tail call i32 @print_summary_pca(i32 %12, i32 %11, i32 %21, i32 %8, i32 %9, i8* %0, i8* %1, i8* %2, i8* %3, i8* %4)
%23 = shl i32 %11, 3
%24 = mul i32 %23, %12
%25 = tail call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to double*
%27 = shl i32 %12, 3
%28 = mul i32 %27, %12
%29 = tail call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to double*
%31 = tail call i64 @malloc(i32 %27)
%32 = inttoptr i64 %31 to double*
%33 = load i32, i32* %7
%34 = mul i32 %27, %33
%35 = tail call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to double*
%37 = tail call i32 @read_data_double(i8* %0, i32 %12, i32 %11, double* %26)
%38 = icmp eq i32 %9, 0
br i1 %38, label %41, label %39
39: ; preds = %20
%40 = tail call i32 @normalize_cov_I(double* %26, i32 %12, i32 %11)
br label %45
41: ; preds = %20
%42 = icmp eq i32 %8, 0
br i1 %42, label %45, label %43
43: ; preds = %41
%44 = tail call i32 @normalize_mean_I(double* %26, i32 %12, i32 %11)
br label %45
45: ; preds = %41, %43, %39
%46 = tail call i32 @calc_cov(double* %26, i32 %12, i32 %11, double* %30)
%47 = load i32, i32* %7
%48 = tail call i32 @diagonalize(double* %30, i32 %12, i32 %47, double* %32, double* %36)
%49 = tail call i32 @write_data_double(i8* %1, i32 %12, i32 1, double* %32)
%50 = load i32, i32* %7
%51 = tail call i32 @write_data_double(i8* %2, i32 %12, i32 %50, double* %36)
%52 = tail call i32 @calc_sdev(double* %32, i32 %12)
%53 = tail call i32 @write_data_double(i8* %3, i32 %12, i32 1, double* %32)
%54 = load i32, i32* %7
%55 = tail call i32 @calc_x(double* %36, double* %32, i32 %12, i32 %54)
%56 = load i32, i32* %7
%57 = tail call i32 @write_data_double(i8* %4, i32 %12, i32 %56, double* %36)
%58 = tail call i32 @free(double* %26)
%59 = tail call i32 @free(double* %30)
%60 = tail call i32 @free(double* %32)
%61 = tail call i32 @free(double* %36)
ret void
}