#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 */
scalar_t__ M_PI;
int /*<<< orphan*/ printf(char *, int, long, double, double, scalar_t__);
int sqrt(double);
int main() {
  int i;
  long n;
  double s, p;
  i = 0;
  n = 4;
  s = 1. / sqrt(2.);
  p = n * s;
  printf("%3d   %10ld   %.14f    % .14f    % .14f\n", i, n, s, p, M_PI - p);
  for (i = 1; i < 28; i++) {
    s = sqrt(s * s / (2 + 2 * sqrt(1 - s * s)));
    n *= 2;
    p = n * s;
    printf("%3d   %10ld   %.14f    % .14f    % .14f\n", i, n, s, p, M_PI - p);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x4,-0x10(%rbp)
movsd  0xec2(%rip),%xmm0
call   1040 <sqrt@plt>
cvtsi2sd %eax,%xmm1
movsd  0xea9(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdq -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    0x2e60(%rip),%rax
cvtsi2sdq (%rax),%xmm2
subsd  -0x20(%rbp),%xmm2
cvttsd2si %xmm2,%rcx
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x1c,-0x8(%rbp)
jge    1277 <main+0x157>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe10(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  -0x28(%rbp),%xmm0
shl    $0x1,%eax
add    $0x2,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
cvtsi2sdq -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    0x2d9a(%rip),%rax
cvtsi2sdq (%rax),%xmm2
subsd  -0x20(%rbp),%xmm2
cvttsd2si %xmm2,%rcx
lea    0xdac(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11aa <main+0x8a>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movsd  0xed1(%rip),%xmm0
call   1040 <sqrt@plt>
cvtsi2sd %eax,%xmm2
movsd  0xec8(%rip),%xmm0
divsd  %xmm2,%xmm0
movsd  0xec4(%rip),%xmm1
mov    0x2e95(%rip),%r15
xorps  %xmm2,%xmm2
cvtsi2sdq (%r15),%xmm2
mulsd  %xmm0,%xmm1
subsd  %xmm1,%xmm2
cvttsd2si %xmm2,%rcx
lea    0xea9(%rip),%r14
mov    $0x4,%ebx
mov    $0x4,%edx
mov    %r14,%rdi
xor    %esi,%esi
movsd  %xmm0,(%rsp)
call   1030 <printf@plt>
mov    $0x1,%ebp
nopl   (%rax)
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
movsd  0xe62(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
add    %eax,%eax
add    $0x2,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  (%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    %rbx,%rbx
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sdq (%r15),%xmm2
mulsd  %xmm0,%xmm1
subsd  %xmm1,%xmm2
cvttsd2si %xmm2,%rcx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
movsd  %xmm0,(%rsp)
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    $0x1c,%ebp
jne    1190 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"%3d %10ld %.14f % .14f % .14f\0A\00"
@M_PI = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
store i32 0, i32* %2
store i64 4, i64* %3
%6 = call i32 @sqrt(double 2.000000e+00)
%7 = sitofp i32 %6 to double
%8 = fdiv double 1.000000e+00, %7
store double %8, double* %4
%9 = load i64, i64* %3
%10 = sitofp i64 %9 to double
%11 = load double, double* %4
%12 = fmul double %10, %11
store double %12, double* %5
%13 = load i32, i32* %2
%14 = load i64, i64* %3
%15 = load double, double* %4
%16 = load double, double* %5
%17 = load i64, i64* @M_PI
%18 = sitofp i64 %17 to double
%19 = load double, double* %5
%20 = fsub double %18, %19
%21 = fptosi double %20 to i64
%22 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %13, i64 %14, double %15, double %16, i64 %21)
store i32 1, i32* %2
br label %23
23: ; preds = %57, %0
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, 28
br i1 %25, label %26, label %60
26: ; preds = %23
%27 = load double, double* %4
%28 = load double, double* %4
%29 = fmul double %27, %28
%30 = load double, double* %4
%31 = load double, double* %4
%32 = fneg double %30
%33 = call double @llvm.fmuladd.f64(double %32, double %31, double 1.000000e+00)
%34 = call i32 @sqrt(double %33)
%35 = mul nsw i32 2, %34
%36 = add nsw i32 2, %35
%37 = sitofp i32 %36 to double
%38 = fdiv double %29, %37
%39 = call i32 @sqrt(double %38)
%40 = sitofp i32 %39 to double
store double %40, double* %4
%41 = load i64, i64* %3
%42 = mul nsw i64 %41, 2
store i64 %42, i64* %3
%43 = load i64, i64* %3
%44 = sitofp i64 %43 to double
%45 = load double, double* %4
%46 = fmul double %44, %45
store double %46, double* %5
%47 = load i32, i32* %2
%48 = load i64, i64* %3
%49 = load double, double* %4
%50 = load double, double* %5
%51 = load i64, i64* @M_PI
%52 = sitofp i64 %51 to double
%53 = load double, double* %5
%54 = fsub double %52, %53
%55 = fptosi double %54 to i64
%56 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %47, i64 %48, double %49, double %50, i64 %55)
br label %57
57: ; preds = %26
%58 = load i32, i32* %2
%59 = add nsw i32 %58, 1
store i32 %59, i32* %2
br label %23
60: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"%3d %10ld %.14f % .14f % .14f\0A\00"
@M_PI = global i64 0
define i32 @main() {
%1 = tail call i32 @sqrt(double 2.000000e+00)
%2 = sitofp i32 %1 to double
%3 = fdiv double 1.000000e+00, %2
%4 = fmul double %3, 4.000000e+00
%5 = load i64, i64* @M_PI
%6 = sitofp i64 %5 to double
%7 = fsub double %6, %4
%8 = fptosi double %7 to i64
%9 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 0, i64 4, double %3, double %4, i64 %8)
br label %10
10: ; preds = %0, %10
%11 = phi double [ %3, %0 ], [ %23, %10 ]
%12 = phi i64 [ 4, %0 ], [ %24, %10 ]
%13 = phi i32 [ 1, %0 ], [ %32, %10 ]
%14 = fmul double %11, %11
%15 = fneg double %11
%16 = tail call double @llvm.fmuladd.f64(double %15, double %11, double 1.000000e+00)
%17 = tail call i32 @sqrt(double %16)
%18 = shl nsw i32 %17, 1
%19 = add nsw i32 %18, 2
%20 = sitofp i32 %19 to double
%21 = fdiv double %14, %20
%22 = tail call i32 @sqrt(double %21)
%23 = sitofp i32 %22 to double
%24 = shl nsw i64 %12, 1
%25 = sitofp i64 %24 to double
%26 = fmul double %25, %23
%27 = load i64, i64* @M_PI
%28 = sitofp i64 %27 to double
%29 = fsub double %28, %26
%30 = fptosi double %29 to i64
%31 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %13, i64 %24, double %23, double %26, i64 %30)
%32 = add nuw nsw i32 %13, 1
%33 = icmp eq i32 %32, 28
br i1 %33, label %34, label %10
34: ; preds = %10
ret i32 0
}