#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*/ Proj_sub(double *, double *, int *, int, double *);
double RMSE2(double *, double *, int *, int);
double *alloc_array_z(int, int);
int /*<<< orphan*/ create_omega(int *, int, int *, int, int);
int /*<<< orphan*/ free_array(double *);
int /*<<< orphan*/ ma(double *, int, int, double, double *, int, int, double,
                      int *, int, double *);
int /*<<< orphan*/ printf(char *, double);
double *shrink(double *, double, int, int);
double *test_mat(int, int, int);
int main(void) {
  int nrows = 4;
  int ncols = 4;
  int rank = 1;
  int numIter = 1000;
  int i, j;
  double tau = 1.5 * nrows;
  double delta = 1.4;
  int ku = 2;
  int omega_c[] = {0, 5};
  int kn = (nrows * ncols) - ku;
  int omega[kn];
  create_omega(omega_c, ku, omega, kn, nrows * ncols);
  double *Y = alloc_array_z(nrows, ncols);
  double *Z = alloc_array_z(nrows, ncols);
  double *M = test_mat(rank, nrows, ncols);
  double *dummyMatrix = alloc_array_z(nrows, ncols);
  double *dummy2 = alloc_array_z(nrows, ncols);
  for (i = 0; i < numIter; i++) {
    for (j = 0; j < ncols * nrows; j++) {
      dummy2[j] = Y[j];
    }
    Z = shrink(dummy2, tau, nrows, ncols);
    Proj_sub(M, Z, omega, kn, dummyMatrix);
    ma(Y, ncols, nrows, 1.0, dummyMatrix, ncols, nrows, delta, omega, kn, Y);
  }
  printf("Error = %f\n\n", RMSE2(M, Z, omega_c, ku));
  printf("Known value = %f\n", M[0]);
  printf("Approximation = %f\n", Z[0]);
  free_array(Y);
  free_array(M);
  free_array(dummy2);
  free_array(Z);
  free_array(dummyMatrix);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x3e8,-0x14(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe35(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movabs $0x3ff6666666666666,%rax
66 f6 3f
mov    %rax,-0x30(%rbp)
movl   $0x2,-0x34(%rbp)
mov    0xe20(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   %ecx,%eax
mov    -0x34(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x88(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x58(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x44(%rbp),%ecx
mov    -0x8(%rbp),%r8d
imul   -0xc(%rbp),%r8d
call   1080 <create_omega@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <alloc_array_z@plt>
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <alloc_array_z@plt>
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   10a0 <test_mat@plt>
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <alloc_array_z@plt>
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <alloc_array_z@plt>
mov    %rax,-0x80(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1377 <main+0x1e7>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    12e9 <main+0x159>
mov    -0x60(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x80(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12af <main+0x11f>
mov    -0x80(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <shrink@plt>
mov    -0x88(%rbp),%rdx
mov    %rax,-0x68(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x44(%rbp),%ecx
mov    -0x78(%rbp),%r8
call   1030 <Proj_sub@plt>
mov    -0x88(%rbp),%r11
mov    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x78(%rbp),%rcx
mov    -0xc(%rbp),%r8d
mov    -0x8(%rbp),%r9d
movsd  -0x30(%rbp),%xmm1
mov    -0x44(%rbp),%r10d
mov    -0x60(%rbp),%rax
movsd  0xcba(%rip),%xmm0
sub    $0x20,%rsp
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   10b0 <ma@plt>
add    $0x20,%rsp
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    129c <main+0x10c>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
lea    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%ecx
call   1040 <RMSE2@plt>
lea    0xc86(%rip),%rdi
call   1050 <printf@plt>
mov    -0x70(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xc7f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x68(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xc7d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x60(%rbp),%rdi
call   1060 <free_array@plt>
mov    -0x70(%rbp),%rdi
call   1060 <free_array@plt>
mov    -0x80(%rbp),%rdi
call   1060 <free_array@plt>
mov    -0x68(%rbp),%rdi
call   1060 <free_array@plt>
mov    -0x78(%rbp),%rdi
call   1060 <free_array@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsp,0x18(%rsp)
movabs $0x500000000,%rax
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rdx
mov    $0x2,%esi
mov    $0xe,%ecx
mov    $0x10,%r8d
call   1080 <create_omega@plt>
mov    $0x4,%edi
mov    $0x4,%esi
call   1090 <alloc_array_z@plt>
mov    %rax,%r13
mov    $0x4,%edi
mov    $0x4,%esi
call   1090 <alloc_array_z@plt>
mov    $0x1,%edi
mov    $0x4,%esi
mov    $0x4,%edx
call   10a0 <test_mat@plt>
mov    %rax,0x8(%rsp)
mov    $0x4,%edi
mov    $0x4,%esi
call   1090 <alloc_array_z@plt>
mov    %rax,%r14
mov    $0x4,%edi
mov    $0x4,%esi
call   1090 <alloc_array_z@plt>
mov    %rax,%rbx
mov    $0x3e8,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0x0(%r13),%xmm0
movsd  %xmm0,(%rbx)
movsd  0x8(%r13),%xmm0
movsd  %xmm0,0x8(%rbx)
movsd  0x10(%r13),%xmm0
movsd  %xmm0,0x10(%rbx)
movsd  0x18(%r13),%xmm0
movsd  %xmm0,0x18(%rbx)
movsd  0x20(%r13),%xmm0
movsd  %xmm0,0x20(%rbx)
movsd  0x28(%r13),%xmm0
movsd  %xmm0,0x28(%rbx)
movsd  0x30(%r13),%xmm0
movsd  %xmm0,0x30(%rbx)
movsd  0x38(%r13),%xmm0
movsd  %xmm0,0x38(%rbx)
movsd  0x40(%r13),%xmm0
movsd  %xmm0,0x40(%rbx)
movsd  0x48(%r13),%xmm0
movsd  %xmm0,0x48(%rbx)
movsd  0x50(%r13),%xmm0
movsd  %xmm0,0x50(%rbx)
movsd  0x58(%r13),%xmm0
movsd  %xmm0,0x58(%rbx)
movsd  0x60(%r13),%xmm0
movsd  %xmm0,0x60(%rbx)
movsd  0x68(%r13),%xmm0
movsd  %xmm0,0x68(%rbx)
movsd  0x70(%r13),%xmm0
movsd  %xmm0,0x70(%rbx)
movsd  0x78(%r13),%xmm0
movsd  %xmm0,0x78(%rbx)
mov    %rbx,%rdi
movsd  0xd06(%rip),%xmm0
mov    $0x4,%esi
mov    $0x4,%edx
call   1070 <shrink@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%rdi
mov    %rax,%rsi
lea    0x20(%rsp),%r15
mov    %r15,%rdx
mov    $0xe,%ecx
mov    %r14,%r8
call   1030 <Proj_sub@plt>
sub    $0x8,%rsp
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x4,%edx
movsd  0xcc6(%rip),%xmm0
mov    %r14,%rcx
mov    $0x4,%r8d
mov    $0x4,%r9d
movsd  0xcb7(%rip),%xmm1
push   %r13
push   $0xe
push   %r15
call   10b0 <ma@plt>
add    $0x20,%rsp
add    $0xffffffff,%r12d
jne    1240 <main+0xb0>
lea    0x10(%rsp),%rdx
mov    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x2,%ecx
call   1040 <RMSE2@plt>
lea    0xc85(%rip),%rdi
call   1050 <printf@plt>
movsd  (%r15),%xmm0
lea    0xc81(%rip),%rdi
call   1050 <printf@plt>
movsd  0x0(%rbp),%xmm0
lea    0xc82(%rip),%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
call   1060 <free_array@plt>
mov    %r15,%rdi
call   1060 <free_array@plt>
mov    %rbx,%rdi
call   1060 <free_array@plt>
mov    %rbp,%rdi
call   1060 <free_array@plt>
mov    %r14,%rdi
call   1060 <free_array@plt>
mov    0x18(%rsp),%rsp
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.omega_c = [2 x i32] [i32 0, i32 5]
@.str = [13 x i8] c"Error = %f\0A\0A\00"
@.str.1 = [18 x i8] c"Known value = %f\0A\00"
@.str.2 = [20 x i8] c"Approximation = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca [2 x i32]
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca double*
%16 = alloca double*
%17 = alloca double*
%18 = alloca double*
%19 = alloca double*
store i32 0, i32* %1
store i32 4, i32* %2
store i32 4, i32* %3
store i32 1, i32* %4
store i32 1000, i32* %5
%20 = load i32, i32* %2
%21 = sitofp i32 %20 to double
%22 = fmul double 1.500000e+00, %21
store double %22, double* %8
store double 1.400000e+00, double* %9
store i32 2, i32* %10
%23 = bitcast [2 x i32]* %11 to i8*
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = mul nsw i32 %24, %25
%27 = load i32, i32* %10
%28 = sub nsw i32 %26, %27
store i32 %28, i32* %12
%29 = load i32, i32* %12
%30 = zext i32 %29 to i64
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %13
%32 = alloca i32, i64 %30
store i64 %30, i64* %14
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%34 = load i32, i32* %10
%35 = load i32, i32* %12
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = mul nsw i32 %36, %37
%39 = call i32 @create_omega(i32* %33, i32 %34, i32* %32, i32 %35, i32 %38)
%40 = load i32, i32* %2
%41 = load i32, i32* %3
%42 = call double* @alloc_array_z(i32 %40, i32 %41)
store double* %42, double** %15
%43 = load i32, i32* %2
%44 = load i32, i32* %3
%45 = call double* @alloc_array_z(i32 %43, i32 %44)
store double* %45, double** %16
%46 = load i32, i32* %4
%47 = load i32, i32* %2
%48 = load i32, i32* %3
%49 = call double* @test_mat(i32 %46, i32 %47, i32 %48)
store double* %49, double** %17
%50 = load i32, i32* %2
%51 = load i32, i32* %3
%52 = call double* @alloc_array_z(i32 %50, i32 %51)
store double* %52, double** %18
%53 = load i32, i32* %2
%54 = load i32, i32* %3
%55 = call double* @alloc_array_z(i32 %53, i32 %54)
store double* %55, double** %19
store i32 0, i32* %6
br label %56
56: ; preds = %101, %0
%57 = load i32, i32* %6
%58 = load i32, i32* %5
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %104
60: ; preds = %56
store i32 0, i32* %7
br label %61
61: ; preds = %77, %60
%62 = load i32, i32* %7
%63 = load i32, i32* %3
%64 = load i32, i32* %2
%65 = mul nsw i32 %63, %64
%66 = icmp slt i32 %62, %65
br i1 %66, label %67, label %80
67: ; preds = %61
%68 = load double*, double** %15
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %68, i64 %70
%72 = load double, double* %71
%73 = load double*, double** %19
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
store double %72, double* %76
br label %77
77: ; preds = %67
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
br label %61
80: ; preds = %61
%81 = load double*, double** %19
%82 = load double, double* %8
%83 = load i32, i32* %2
%84 = load i32, i32* %3
%85 = call double* @shrink(double* %81, double %82, i32 %83, i32 %84)
store double* %85, double** %16
%86 = load double*, double** %17
%87 = load double*, double** %16
%88 = load i32, i32* %12
%89 = load double*, double** %18
%90 = call i32 @Proj_sub(double* %86, double* %87, i32* %32, i32 %88, double* %89)
%91 = load double*, double** %15
%92 = load i32, i32* %3
%93 = load i32, i32* %2
%94 = load double*, double** %18
%95 = load i32, i32* %3
%96 = load i32, i32* %2
%97 = load double, double* %9
%98 = load i32, i32* %12
%99 = load double*, double** %15
%100 = call i32 @ma(double* %91, i32 %92, i32 %93, double 1.000000e+00, double* %94, i32 %95, i32 %96, double %97, i32* %32, i32 %98, double* %99)
br label %101
101: ; preds = %80
%102 = load i32, i32* %6
%103 = add nsw i32 %102, 1
store i32 %103, i32* %6
br label %56
104: ; preds = %56
%105 = load double*, double** %17
%106 = load double*, double** %16
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%108 = load i32, i32* %10
%109 = call double @RMSE2(double* %105, double* %106, i32* %107, i32 %108)
%110 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %109)
%111 = load double*, double** %17
%112 = getelementptr inbounds double, double* %111, i64 0
%113 = load double, double* %112
%114 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %113)
%115 = load double*, double** %16
%116 = getelementptr inbounds double, double* %115, i64 0
%117 = load double, double* %116
%118 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %117)
%119 = load double*, double** %15
%120 = call i32 @free_array(double* %119)
%121 = load double*, double** %17
%122 = call i32 @free_array(double* %121)
%123 = load double*, double** %19
%124 = call i32 @free_array(double* %123)
%125 = load double*, double** %16
%126 = call i32 @free_array(double* %125)
%127 = load double*, double** %18
%128 = call i32 @free_array(double* %127)
store i32 0, i32* %1
%129 = load i8*, i8** %13
%130 = load i32, i32* %1
ret i32 %130
}

LLVM IR (-O2):
@.str = [13 x i8] c"Error = %f\0A\0A\00"
@.str.1 = [18 x i8] c"Known value = %f\0A\00"
@.str.2 = [20 x i8] c"Approximation = %f\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
store i64 21474836480, i64* %1
%3 = tail call i8* @llvm.stacksave()
%4 = alloca [14 x i32]
%5 = getelementptr inbounds [14 x i32], [14 x i32]* %4, i64 0, i64 0
%6 = bitcast i64* %1 to i32*
%7 = call i32 @create_omega(i32* %6, i32 2, i32* %5, i32 14, i32 16)
%8 = call double* @alloc_array_z(i32 4, i32 4)
%9 = call double* @alloc_array_z(i32 4, i32 4)
%10 = call double* @test_mat(i32 1, i32 4, i32 4)
%11 = call double* @alloc_array_z(i32 4, i32 4)
%12 = call double* @alloc_array_z(i32 4, i32 4)
%13 = getelementptr inbounds double, double* %8, i64 1
%14 = getelementptr inbounds double, double* %12, i64 1
%15 = getelementptr inbounds double, double* %8, i64 2
%16 = getelementptr inbounds double, double* %12, i64 2
%17 = getelementptr inbounds double, double* %8, i64 3
%18 = getelementptr inbounds double, double* %12, i64 3
%19 = getelementptr inbounds double, double* %8, i64 4
%20 = getelementptr inbounds double, double* %12, i64 4
%21 = getelementptr inbounds double, double* %8, i64 5
%22 = getelementptr inbounds double, double* %12, i64 5
%23 = getelementptr inbounds double, double* %8, i64 6
%24 = getelementptr inbounds double, double* %12, i64 6
%25 = getelementptr inbounds double, double* %8, i64 7
%26 = getelementptr inbounds double, double* %12, i64 7
%27 = getelementptr inbounds double, double* %8, i64 8
%28 = getelementptr inbounds double, double* %12, i64 8
%29 = getelementptr inbounds double, double* %8, i64 9
%30 = getelementptr inbounds double, double* %12, i64 9
%31 = getelementptr inbounds double, double* %8, i64 10
%32 = getelementptr inbounds double, double* %12, i64 10
%33 = getelementptr inbounds double, double* %8, i64 11
%34 = getelementptr inbounds double, double* %12, i64 11
%35 = getelementptr inbounds double, double* %8, i64 12
%36 = getelementptr inbounds double, double* %12, i64 12
%37 = getelementptr inbounds double, double* %8, i64 13
%38 = getelementptr inbounds double, double* %12, i64 13
%39 = getelementptr inbounds double, double* %8, i64 14
%40 = getelementptr inbounds double, double* %12, i64 14
%41 = getelementptr inbounds double, double* %8, i64 15
%42 = getelementptr inbounds double, double* %12, i64 15
br label %43
43: ; preds = %0, %43
%44 = phi i32 [ 0, %0 ], [ %64, %43 ]
%45 = load double, double* %8
store double %45, double* %12
%46 = load double, double* %13
store double %46, double* %14
%47 = load double, double* %15
store double %47, double* %16
%48 = load double, double* %17
store double %48, double* %18
%49 = load double, double* %19
store double %49, double* %20
%50 = load double, double* %21
store double %50, double* %22
%51 = load double, double* %23
store double %51, double* %24
%52 = load double, double* %25
store double %52, double* %26
%53 = load double, double* %27
store double %53, double* %28
%54 = load double, double* %29
store double %54, double* %30
%55 = load double, double* %31
store double %55, double* %32
%56 = load double, double* %33
store double %56, double* %34
%57 = load double, double* %35
store double %57, double* %36
%58 = load double, double* %37
store double %58, double* %38
%59 = load double, double* %39
store double %59, double* %40
%60 = load double, double* %41
store double %60, double* %42
%61 = call double* @shrink(double* %12, double 6.000000e+00, i32 4, i32 4)
%62 = call i32 @Proj_sub(double* %10, double* %61, i32* %5, i32 14, double* %11)
%63 = call i32 @ma(double* %8, i32 4, i32 4, double 1.000000e+00, double* %11, i32 4, i32 4, double 1.400000e+00, i32* %5, i32 14, double* %8)
%64 = add nuw nsw i32 %44, 1
%65 = icmp eq i32 %64, 1000
br i1 %65, label %66, label %43
66: ; preds = %43
%67 = call double @RMSE2(double* %10, double* %61, i32* %6, i32 2)
%68 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %67)
%69 = load double, double* %10
%70 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %69)
%71 = load double, double* %61
%72 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %71)
%73 = call i32 @free_array(double* %8)
%74 = call i32 @free_array(double* %10)
%75 = call i32 @free_array(double* %12)
%76 = call i32 @free_array(double* %61)
%77 = call i32 @free_array(double* %11)
ret i32 0
}