#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*/ printf(char *, double);
int sqrt(int);
void ramd(int times) {
  double n, pi, term, mult, tmp;
  pi = 1103;
  term = 0;
  mult = 1;
  tmp = 0;
  for (n = 1; n < times; n++) {
    tmp = ((4 * n) * (4 * n - 1) * (4 * n - 2) * (4 * n - 3)) /
          (n * n * n * n * 396 * 396 * 396 * 396);
    mult *= tmp;
    term = mult * (1103 + 26390 * n);
    pi += term;
    printf("term:%16.12g\n", term);
    printf("mult:%16.12g\n", mult);
  }
  pi *= (2 * sqrt(2)) / 9801;
  pi = 1 / pi;
  printf("%16g\n", pi);
}


x86 assembly (clang, -O0):
<ramd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  0xed5(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xeb8(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xea3(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x4(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12b5 <ramd+0x195>
movsd  0xea2(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe90(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe9c(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe6f(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe73(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe4e(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe4a(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  0xe16(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe0a(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xdfe(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xdf2(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xdbc(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xda8(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xdb8(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xdb5(%rip),%rdi
call   1030 <printf@plt>
movsd  0xd5a(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1162 <ramd+0x42>
mov    $0x2,%edi
call   1040 <sqrt@plt>
shl    $0x1,%eax
mov    $0x2649,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xd20(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xd66(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ramd>:
push   %r14
push   %rbx
sub    $0x38,%rsp
cmp    $0x2,%edi
jl     126b <ramd+0x14b>
cvtsi2sd %edi,%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  0xebe(%rip),%xmm0
movsd  0xebe(%rip),%xmm1
lea    0xf0f(%rip),%r14
lea    0xf16(%rip),%rbx
movsd  %xmm1,0x28(%rsp)
movsd  %xmm0,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movapd %xmm1,0x10(%rsp)
movapd 0x10(%rsp),%xmm1
mulsd  0xe8c(%rip),%xmm1
movapd %xmm1,%xmm0
movapd 0x10(%rsp),%xmm2
addsd  0xe82(%rip),%xmm0
movapd %xmm1,%xmm3
mulsd  %xmm2,%xmm2
mulsd  0x10(%rsp),%xmm2
mulsd  0x10(%rsp),%xmm2
movapd 0x10(%rsp),%xmm4
addsd  0xe68(%rip),%xmm3
unpcklpd %xmm2,%xmm4
mulpd  0xe7c(%rip),%xmm4
movapd 0xe84(%rip),%xmm2
shufpd $0x2,%xmm2,%xmm0
addsd  0xe4f(%rip),%xmm1
mulpd  %xmm4,%xmm0
shufpd $0x2,%xmm2,%xmm3
mulpd  %xmm0,%xmm3
shufpd $0x2,%xmm2,%xmm1
mulpd  %xmm3,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
movsd  0x28(%rsp),%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x28(%rsp)
mulsd  0xe17(%rip),%xmm0
addsd  0xddf(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
movsd  0x28(%rsp),%xmm0
call   1030 <printf@plt>
movapd 0x10(%rsp),%xmm1
addsd  0xdaf(%rip),%xmm1
movsd  0x30(%rsp),%xmm0
ucomisd %xmm1,%xmm0
ja     1170 <ramd+0x50>
jmp    1279 <ramd+0x159>
movsd  0xd8d(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
add    %eax,%ecx
movslq %ecx,%rcx
imul   $0xffffffffd5f92819,%rcx,%rcx
shr    $0x20,%rcx
lea    (%rcx,%rax,2),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0xd,%eax
add    %ecx,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0x8(%rsp),%xmm1
movsd  0xd51(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xdba(%rip),%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"term:%16.12g\0A\00"
@.str.1 = [14 x i8] c"mult:%16.12g\0A\00"
@.str.2 = [6 x i8] c"%16g\0A\00"
define void @ramd(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 %0, i32* %2
store double 1.103000e+03, double* %4
store double 0.000000e+00, double* %5
store double 1.000000e+00, double* %6
store double 0.000000e+00, double* %7
store double 1.000000e+00, double* %3
br label %8
8: ; preds = %51, %1
%9 = load double, double* %3
%10 = load i32, i32* %2
%11 = sitofp i32 %10 to double
%12 = fcmp olt double %9, %11
br i1 %12, label %13, label %54
13: ; preds = %8
%14 = load double, double* %3
%15 = fmul double 4.000000e+00, %14
%16 = load double, double* %3
%17 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %16, double -1.000000e+00)
%18 = fmul double %15, %17
%19 = load double, double* %3
%20 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %19, double -2.000000e+00)
%21 = fmul double %18, %20
%22 = load double, double* %3
%23 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %22, double -3.000000e+00)
%24 = fmul double %21, %23
%25 = load double, double* %3
%26 = load double, double* %3
%27 = fmul double %25, %26
%28 = load double, double* %3
%29 = fmul double %27, %28
%30 = load double, double* %3
%31 = fmul double %29, %30
%32 = fmul double %31, 3.960000e+02
%33 = fmul double %32, 3.960000e+02
%34 = fmul double %33, 3.960000e+02
%35 = fmul double %34, 3.960000e+02
%36 = fdiv double %24, %35
store double %36, double* %7
%37 = load double, double* %7
%38 = load double, double* %6
%39 = fmul double %38, %37
store double %39, double* %6
%40 = load double, double* %6
%41 = load double, double* %3
%42 = call double @llvm.fmuladd.f64(double 2.639000e+04, double %41, double 1.103000e+03)
%43 = fmul double %40, %42
store double %43, double* %5
%44 = load double, double* %5
%45 = load double, double* %4
%46 = fadd double %45, %44
store double %46, double* %4
%47 = load double, double* %5
%48 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %47)
%49 = load double, double* %6
%50 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %49)
br label %51
51: ; preds = %13
%52 = load double, double* %3
%53 = fadd double %52, 1.000000e+00
store double %53, double* %3
br label %8
54: ; preds = %8
%55 = call i32 @sqrt(i32 2)
%56 = mul nsw i32 2, %55
%57 = sdiv i32 %56, 9801
%58 = sitofp i32 %57 to double
%59 = load double, double* %4
%60 = fmul double %59, %58
store double %60, double* %4
%61 = load double, double* %4
%62 = fdiv double 1.000000e+00, %61
store double %62, double* %4
%63 = load double, double* %4
%64 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %63)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"term:%16.12g\0A\00"
@.str.1 = [14 x i8] c"mult:%16.12g\0A\00"
@.str.2 = [6 x i8] c"%16g\0A\00"
define void @ramd(i32 %0) {
%2 = sitofp i32 %0 to double
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %34
4: ; preds = %1, %4
%5 = phi double [ %26, %4 ], [ 1.000000e+00, %1 ]
%6 = phi double [ %29, %4 ], [ 1.103000e+03, %1 ]
%7 = phi double [ %32, %4 ], [ 1.000000e+00, %1 ]
%8 = tail call double @llvm.fmuladd.f64(double %7, double 4.000000e+00, double -1.000000e+00)
%9 = tail call double @llvm.fmuladd.f64(double %7, double 4.000000e+00, double -2.000000e+00)
%10 = tail call double @llvm.fmuladd.f64(double %7, double 4.000000e+00, double -3.000000e+00)
%11 = fmul double %7, %7
%12 = fmul double %7, %11
%13 = fmul double %7, %12
%14 = insertelement <2 x double> poison, double %7, i64 0
%15 = insertelement <2 x double> %14, double %13, i64 1
%16 = fmul <2 x double> %15, <double 4.000000e+00, double 3.960000e+02>
%17 = insertelement <2 x double> <double poison, double 3.960000e+02>, double %8, i64 0
%18 = fmul <2 x double> %16, %17
%19 = insertelement <2 x double> <double poison, double 3.960000e+02>, double %9, i64 0
%20 = fmul <2 x double> %19, %18
%21 = insertelement <2 x double> <double poison, double 3.960000e+02>, double %10, i64 0
%22 = fmul <2 x double> %21, %20
%23 = extractelement <2 x double> %22, i64 0
%24 = extractelement <2 x double> %22, i64 1
%25 = fdiv double %23, %24
%26 = fmul double %5, %25
%27 = tail call double @llvm.fmuladd.f64(double %7, double 2.639000e+04, double 1.103000e+03)
%28 = fmul double %27, %26
%29 = fadd double %6, %28
%30 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %28)
%31 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %26)
%32 = fadd double %7, 1.000000e+00
%33 = fcmp olt double %32, %2
br i1 %33, label %4, label %34
34: ; preds = %4, %1
%35 = phi double [ 1.103000e+03, %1 ], [ %29, %4 ]
%36 = tail call i32 @sqrt(i32 2)
%37 = shl nsw i32 %36, 1
%38 = sdiv i32 %37, 9801
%39 = sitofp i32 %38 to double
%40 = fmul double %35, %39
%41 = fdiv double 1.000000e+00, %40
%42 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %41)
ret void
}