#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__);
double sqrt(int);
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 = s / sqrt(2. * (1. + 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)
mov    $0x2,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xead(%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    0x2e64(%rip),%rax
cvtsi2sdq (%rax),%xmm2
subsd  -0x20(%rbp),%xmm2
cvttsd2si %xmm2,%rcx
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x1c,-0x8(%rbp)
jge    1283 <main+0x163>
movsd  -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  0xe19(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  0xe04(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0xe00(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%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    0x2d8e(%rip),%rax
cvtsi2sdq (%rax),%xmm2
subsd  -0x20(%rbp),%xmm2
cvttsd2si %xmm2,%rcx
lea    0xda0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a6 <main+0x86>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x2,%edi
call   1040 <sqrt@plt>
movsd  0xec7(%rip),%xmm2
divsd  %xmm0,%xmm2
movsd  0xec3(%rip),%xmm1
mov    0x2e9c(%rip),%r15
xorps  %xmm0,%xmm0
cvtsi2sdq (%r15),%xmm0
mulsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
lea    0xea8(%rip),%r14
mov    $0x4,%ebx
mov    $0x4,%edx
mov    %r14,%rdi
xor    %esi,%esi
movsd  %xmm2,(%rsp)
movapd %xmm2,%xmm0
call   1030 <printf@plt>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
movsd  (%rsp),%xmm0
mulsd  %xmm0,%xmm0
movsd  0xe5f(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <sqrt@plt>
addsd  0xe4a(%rip),%xmm0
addsd  %xmm0,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm2
divsd  %xmm0,%xmm2
add    %rbx,%rbx
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%r15),%xmm0
mulsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
movsd  %xmm2,(%rsp)
movapd %xmm2,%xmm0
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 double @sqrt(i32 2)
%7 = fdiv double 1.000000e+00, %6
store double %7, double* %4
%8 = load i64, i64* %3
%9 = sitofp i64 %8 to double
%10 = load double, double* %4
%11 = fmul double %9, %10
store double %11, double* %5
%12 = load i32, i32* %2
%13 = load i64, i64* %3
%14 = load double, double* %4
%15 = load double, double* %5
%16 = load i64, i64* @M_PI
%17 = sitofp i64 %16 to double
%18 = load double, double* %5
%19 = fsub double %17, %18
%20 = fptosi double %19 to i64
%21 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %12, i64 %13, double %14, double %15, i64 %20)
store i32 1, i32* %2
br label %22
22: ; preds = %54, %0
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 28
br i1 %24, label %25, label %57
25: ; preds = %22
%26 = load double, double* %4
%27 = load double, double* %4
%28 = load double, double* %4
%29 = fneg double %27
%30 = call double @llvm.fmuladd.f64(double %29, double %28, double 1.000000e+00)
%31 = fptosi double %30 to i32
%32 = call double @sqrt(i32 %31)
%33 = fadd double 1.000000e+00, %32
%34 = fmul double 2.000000e+00, %33
%35 = fptosi double %34 to i32
%36 = call double @sqrt(i32 %35)
%37 = fdiv double %26, %36
store double %37, double* %4
%38 = load i64, i64* %3
%39 = mul nsw i64 %38, 2
store i64 %39, i64* %3
%40 = load i64, i64* %3
%41 = sitofp i64 %40 to double
%42 = load double, double* %4
%43 = fmul double %41, %42
store double %43, double* %5
%44 = load i32, i32* %2
%45 = load i64, i64* %3
%46 = load double, double* %4
%47 = load double, double* %5
%48 = load i64, i64* @M_PI
%49 = sitofp i64 %48 to double
%50 = load double, double* %5
%51 = fsub double %49, %50
%52 = fptosi double %51 to i64
%53 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %44, i64 %45, double %46, double %47, i64 %52)
br label %54
54: ; preds = %25
%55 = load i32, i32* %2
%56 = add nsw i32 %55, 1
store i32 %56, i32* %2
br label %22
57: ; preds = %22
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 double @sqrt(i32 2)
%2 = fdiv double 1.000000e+00, %1
%3 = fmul double %2, 4.000000e+00
%4 = load i64, i64* @M_PI
%5 = sitofp i64 %4 to double
%6 = fsub double %5, %3
%7 = fptosi double %6 to i64
%8 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 0, i64 4, double %2, double %3, i64 %7)
br label %9
9: ; preds = %0, %9
%10 = phi double [ %2, %0 ], [ %21, %9 ]
%11 = phi i64 [ 4, %0 ], [ %22, %9 ]
%12 = phi i32 [ 1, %0 ], [ %30, %9 ]
%13 = fneg double %10
%14 = tail call double @llvm.fmuladd.f64(double %13, double %10, double 1.000000e+00)
%15 = fptosi double %14 to i32
%16 = tail call double @sqrt(i32 %15)
%17 = fadd double %16, 1.000000e+00
%18 = fmul double %17, 2.000000e+00
%19 = fptosi double %18 to i32
%20 = tail call double @sqrt(i32 %19)
%21 = fdiv double %10, %20
%22 = shl nsw i64 %11, 1
%23 = sitofp i64 %22 to double
%24 = fmul double %21, %23
%25 = load i64, i64* @M_PI
%26 = sitofp i64 %25 to double
%27 = fsub double %26, %24
%28 = fptosi double %27 to i64
%29 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %12, i64 %22, double %21, double %24, i64 %28)
%30 = add nuw nsw i32 %12, 1
%31 = icmp eq i32 %30, 28
br i1 %31, label %32, label %9
32: ; preds = %9
ret i32 0
}