#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 fabs(double);
int /*<<< orphan*/ printf(char *, int, double);
void calculateA(double *A, double z, int M) {
  int n;
  A[M] = 0.0;
  double k;
  for (n = M - 1; n >= 0; n--) {
    k = ((n + 1.0) / z) + A[n + 1];
    if (fabs(k) > 1.0e-6) {
      A[n] = (n + 1.0) / z - 1.0 / k;
    } else {
      A[n] = (n + 1.0) / z - 1.0;
    }
    printf("A[%d] = %f\n", n, A[n]);
  }
}


x86 assembly (clang, -O0):
<calculateA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1228 <calculateA+0x118>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xeb4(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movaps 0xe90(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe74(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11cf <calculateA+0xbf>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xe65(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  0xe54(%rip),%xmm1
divsd  -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11fe <calculateA+0xee>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xe2c(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    113d <calculateA+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateA>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
movslq %esi,%rax
movq   $0x0,(%rdi,%rax,8)
test   %eax,%eax
jle    11ad <calculateA+0x9d>
mov    %rdi,%r15
mov    %esi,%eax
lea    0xee6(%rip),%r14
jmp    116a <calculateA+0x5a>
nopl   0x0(%rax)
addsd  0xed0(%rip),%xmm0
mov    %ebx,%eax
movsd  %xmm0,(%r15,%rax,8)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %rbx,%rcx
add    $0x1,%rcx
mov    %rbx,%rax
cmp    $0x1,%rcx
jbe    11ad <calculateA+0x9d>
lea    -0x1(%rax),%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x8(%rsp),%xmm0
movsd  (%r15,%rax,8),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm2
andpd  0xe6f(%rip),%xmm2
ucomisd 0xe77(%rip),%xmm2
jbe    1140 <calculateA+0x30>
movsd  0xe75(%rip),%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
jmp    1148 <calculateA+0x38>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"A[%d] = %f\0A\00"
define void @calculateA(double* %0, double %1, i32 %2) {
%4 = alloca double*
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store double* %0, double** %4
store double %1, double* %5
store i32 %2, i32* %6
%9 = load double*, double** %4
%10 = load i32, i32* %6
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds double, double* %9, i64 %11
store double 0.000000e+00, double* %12
%13 = load i32, i32* %6
%14 = sub nsw i32 %13, 1
store i32 %14, i32* %7
br label %15
15: ; preds = %66, %3
%16 = load i32, i32* %7
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %69
18: ; preds = %15
%19 = load i32, i32* %7
%20 = sitofp i32 %19 to double
%21 = fadd double %20, 1.000000e+00
%22 = load double, double* %5
%23 = fdiv double %21, %22
%24 = load double*, double** %4
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %24, i64 %27
%29 = load double, double* %28
%30 = fadd double %23, %29
store double %30, double* %8
%31 = load double, double* %8
%32 = call double @llvm.fabs.f64(double %31)
%33 = fcmp ogt double %32, 0x3EB0C6F7A0B5ED8D
br i1 %33, label %34, label %47
34: ; preds = %18
%35 = load i32, i32* %7
%36 = sitofp i32 %35 to double
%37 = fadd double %36, 1.000000e+00
%38 = load double, double* %5
%39 = fdiv double %37, %38
%40 = load double, double* %8
%41 = fdiv double 1.000000e+00, %40
%42 = fsub double %39, %41
%43 = load double*, double** %4
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
store double %42, double* %46
br label %58
47: ; preds = %18
%48 = load i32, i32* %7
%49 = sitofp i32 %48 to double
%50 = fadd double %49, 1.000000e+00
%51 = load double, double* %5
%52 = fdiv double %50, %51
%53 = fsub double %52, 1.000000e+00
%54 = load double*, double** %4
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
store double %53, double* %57
br label %58
58: ; preds = %47, %34
%59 = load i32, i32* %7
%60 = load double*, double** %4
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load double, double* %63
%65 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %59, double %64)
br label %66
66: ; preds = %58
%67 = load i32, i32* %7
%68 = add nsw i32 %67, -1
store i32 %68, i32* %7
br label %15
69: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"A[%d] = %f\0A\00"
define void @calculateA(double* nocapture %0, double %1, i32 %2) {
%4 = sext i32 %2 to i64
%5 = getelementptr inbounds double, double* %0, i64 %4
store double 0.000000e+00, double* %5
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %32
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %26
%10 = phi i64 [ %8, %7 ], [ %11, %26 ]
%11 = add nsw i64 %10, -1
%12 = trunc i64 %11 to i32
%13 = trunc i64 %10 to i32
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, %1
%16 = getelementptr inbounds double, double* %0, i64 %10
%17 = load double, double* %16
%18 = fadd double %15, %17
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = fcmp ogt double %19, 0x3EB0C6F7A0B5ED8D
br i1 %20, label %21, label %24
21: ; preds = %9
%22 = fdiv double 1.000000e+00, %18
%23 = fsub double %15, %22
br label %26
24: ; preds = %9
%25 = fadd double %15, -1.000000e+00
br label %26
26: ; preds = %24, %21
%27 = phi double [ %25, %24 ], [ %23, %21 ]
%28 = and i64 %11, 4294967295
%29 = getelementptr inbounds double, double* %0, i64 %28
store double %27, double* %29
%30 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %12, double %27)
%31 = icmp ugt i64 %10, 1
br i1 %31, label %9, label %32
32: ; preds = %26, %3
ret void
}