#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 */
double *calloc(int, int);
int /*<<< orphan*/ free(double *);
double sqrt(double);
void CompZ(double *y, double *z, int M) {
  double LeftSum;
  double RightSum;
  double *aux;
  int m;
  aux = calloc(M - 1, sizeof(double));
  LeftSum = 0;
  RightSum = 0;
  for (m = 1; m < M; m++) {
    LeftSum = LeftSum + y[m - 1];
    aux[m - 1] =
        (-1) * sqrt((double)(M - m) / ((double)M * (double)m)) * LeftSum;
  }
  for (m = M - 1; m >= 1; m--) {
    RightSum = RightSum + y[m];
    z[m - 1] = aux[m - 1] +
               sqrt((double)m / ((double)(M - m) * (double)(M))) * RightSum;
  }
  free(aux);
}


x86 assembly (clang, -O0):
<CompZ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11eb <CompZ+0xbb>
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x34(%rbp),%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
cvtsi2sdl -0x34(%rbp),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe3e(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116e <CompZ+0x3e>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
jl     127f <CompZ+0x14f>
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm0
mov    -0x14(%rbp),%eax
sub    -0x34(%rbp),%eax
cvtsi2sd %eax,%xmm1
cvtsi2sdl -0x14(%rbp),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    11f4 <CompZ+0xc4>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CompZ>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebp
mov    %rsi,0x20(%rsp)
mov    %rdi,%r15
lea    -0x1(%rbp),%r14d
mov    %r14d,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r13
cmp    $0x2,%ebp
jl     12b0 <CompZ+0x180>
mov    %ebp,%ebx
mov    %rbp,0x8(%rsp)
cvtsi2sd %ebp,%xmm2
xorpd  %xmm3,%xmm3
mov    $0x1,%ebp
movapd 0xe7f(%rip),%xmm4
mov    %r14d,%r12d
xorpd  %xmm5,%xmm5
movsd  %xmm2,0x10(%rsp)
jmp    11cf <CompZ+0x9f>
movsd  %xmm5,0x18(%rsp)
call   1050 <sqrt@plt>
movsd  0x18(%rsp),%xmm5
movapd 0xe57(%rip),%xmm4
xorpd  %xmm3,%xmm3
movsd  0x10(%rsp),%xmm2
xorpd  %xmm4,%xmm0
mulsd  %xmm5,%xmm0
movsd  %xmm0,-0x8(%r13,%rbp,8)
add    $0x1,%rbp
add    $0xffffffff,%r12d
cmp    %rbp,%rbx
je     11f9 <CompZ+0xc9>
addsd  -0x8(%r15,%rbp,8),%xmm5
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
ucomisd %xmm3,%xmm0
jb     1190 <CompZ+0x60>
sqrtsd %xmm0,%xmm0
jmp    11b3 <CompZ+0x83>
cmpl   $0x2,0x8(%rsp)
jl     12b0 <CompZ+0x180>
xorps  %xmm2,%xmm2
cvtsi2sd %ebx,%xmm2
mov    %r14d,%ebx
add    $0x1,%rbx
xorpd  %xmm3,%xmm3
mov    $0x1,%ebp
xorpd  %xmm4,%xmm4
movsd  %xmm2,0x8(%rsp)
jmp    127b <CompZ+0x14b>
nopw   0x0(%rax,%rax,1)
movsd  %xmm4,0x18(%rsp)
movsd  %xmm5,0x10(%rsp)
call   1050 <sqrt@plt>
movsd  0x10(%rsp),%xmm5
movsd  0x18(%rsp),%xmm4
xorpd  %xmm3,%xmm3
movsd  0x8(%rsp),%xmm2
mulsd  %xmm4,%xmm0
addsd  %xmm5,%xmm0
mov    0x20(%rsp),%rax
movsd  %xmm0,(%rax,%r12,8)
add    $0xffffffff,%r14d
add    $0x1,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    12b0 <CompZ+0x180>
addsd  -0x8(%r15,%rbx,8),%xmm4
lea    -0x2(%rbx),%r12d
movsd  0x0(%r13,%r12,8),%xmm5
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
ucomisd %xmm3,%xmm0
jb     1230 <CompZ+0x100>
sqrtsd %xmm0,%xmm0
jmp    1257 <CompZ+0x127>
mov    %r13,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @CompZ(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = sub nsw i32 %11, 1
%13 = call double* @calloc(i32 %12, i32 8)
store double* %13, double** %9
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store i32 1, i32* %10
br label %14
14: ; preds = %46, %3
%15 = load i32, i32* %10
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %49
18: ; preds = %14
%19 = load double, double* %7
%20 = load double*, double** %4
%21 = load i32, i32* %10
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %20, i64 %23
%25 = load double, double* %24
%26 = fadd double %19, %25
store double %26, double* %7
%27 = load i32, i32* %6
%28 = load i32, i32* %10
%29 = sub nsw i32 %27, %28
%30 = sitofp i32 %29 to double
%31 = load i32, i32* %6
%32 = sitofp i32 %31 to double
%33 = load i32, i32* %10
%34 = sitofp i32 %33 to double
%35 = fmul double %32, %34
%36 = fdiv double %30, %35
%37 = call double @sqrt(double %36)
%38 = fmul double -1.000000e+00, %37
%39 = load double, double* %7
%40 = fmul double %38, %39
%41 = load double*, double** %9
%42 = load i32, i32* %10
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %41, i64 %44
store double %40, double* %45
br label %46
46: ; preds = %18
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %14
49: ; preds = %14
%50 = load i32, i32* %6
%51 = sub nsw i32 %50, 1
store i32 %51, i32* %10
br label %52
52: ; preds = %87, %49
%53 = load i32, i32* %10
%54 = icmp sge i32 %53, 1
br i1 %54, label %55, label %90
55: ; preds = %52
%56 = load double, double* %8
%57 = load double*, double** %4
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
%61 = load double, double* %60
%62 = fadd double %56, %61
store double %62, double* %8
%63 = load double*, double** %9
%64 = load i32, i32* %10
%65 = sub nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %63, i64 %66
%68 = load double, double* %67
%69 = load i32, i32* %10
%70 = sitofp i32 %69 to double
%71 = load i32, i32* %6
%72 = load i32, i32* %10
%73 = sub nsw i32 %71, %72
%74 = sitofp i32 %73 to double
%75 = load i32, i32* %6
%76 = sitofp i32 %75 to double
%77 = fmul double %74, %76
%78 = fdiv double %70, %77
%79 = call double @sqrt(double %78)
%80 = load double, double* %8
%81 = call double @llvm.fmuladd.f64(double %79, double %80, double %68)
%82 = load double*, double** %5
%83 = load i32, i32* %10
%84 = sub nsw i32 %83, 1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %82, i64 %85
store double %81, double* %86
br label %87
87: ; preds = %55
%88 = load i32, i32* %10
%89 = add nsw i32 %88, -1
store i32 %89, i32* %10
br label %52
90: ; preds = %52
%91 = load double*, double** %9
%92 = call i32 @free(double* %91)
ret void
}

LLVM IR (-O2):
define void @CompZ(double* nocapture %0, double* nocapture writeonly %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = tail call double* @calloc(i32 %4, i32 8)
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %54
7: ; preds = %3
%8 = sitofp i32 %2 to double
%9 = zext i32 %2 to i64
br label %14
10: ; preds = %14
br i1 %6, label %11, label %54
11: ; preds = %10
%12 = sitofp i32 %2 to double
%13 = zext i32 %4 to i64
br label %34
14: ; preds = %7, %14
%15 = phi i64 [ 1, %7 ], [ %32, %14 ]
%16 = phi double [ 0.000000e+00, %7 ], [ %20, %14 ]
%17 = add nsw i64 %15, -1
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = load double, double* %18
%20 = fadd double %16, %19
%21 = trunc i64 %15 to i32
%22 = sub i32 %2, %21
%23 = sitofp i32 %22 to double
%24 = trunc i64 %15 to i32
%25 = sitofp i32 %24 to double
%26 = fmul double %8, %25
%27 = fdiv double %23, %26
%28 = tail call double @sqrt(double %27)
%29 = fneg double %28
%30 = fmul double %20, %29
%31 = getelementptr inbounds double, double* %5, i64 %17
store double %30, double* %31
%32 = add nuw nsw i64 %15, 1
%33 = icmp eq i64 %32, %9
br i1 %33, label %10, label %14
34: ; preds = %11, %34
%35 = phi i64 [ %13, %11 ], [ %41, %34 ]
%36 = phi double [ 0.000000e+00, %11 ], [ %40, %34 ]
%37 = trunc i64 %35 to i32
%38 = getelementptr inbounds double, double* %0, i64 %35
%39 = load double, double* %38
%40 = fadd double %36, %39
%41 = add nsw i64 %35, -1
%42 = and i64 %41, 4294967295
%43 = getelementptr inbounds double, double* %5, i64 %42
%44 = load double, double* %43
%45 = sitofp i32 %37 to double
%46 = sub nsw i32 %2, %37
%47 = sitofp i32 %46 to double
%48 = fmul double %12, %47
%49 = fdiv double %45, %48
%50 = tail call double @sqrt(double %49)
%51 = tail call double @llvm.fmuladd.f64(double %50, double %40, double %44)
%52 = getelementptr inbounds double, double* %1, i64 %42
store double %51, double* %52
%53 = icmp ugt i64 %35, 1
br i1 %53, label %34, label %54
54: ; preds = %34, %3, %10
%55 = tail call i32 @free(double* %5)
ret void
}