#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 *, int, int, double);
int sqrt(int);
int liuhui(int n) {
  int i;
  double k, y2;
  for (i = 0, k = 3.0, y2 = 1.0; i < n; ++i, k *= 2.0) {
    printf("sides = %d\tpi(%d) = %.51f\n", 3 * (1 << i), i, k * sqrt(y2));
    y2 = 2 - sqrt(4 - y2);
  }
  return i;
}


x86 assembly (clang, -O0):
<liuhui>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movsd  0xece(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xeb9(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e9 <liuhui+0xc9>
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
imul   $0x3,%eax,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvttsd2si -0x18(%rbp),%edi
call   1040 <sqrt@plt>
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe67(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    $0x2,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movsd  0xe3e(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    114c <liuhui+0x2c>
mov    -0x8(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<liuhui>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    11d0 <liuhui+0xb0>
mov    %edi,%r15d
xor    %ebp,%ebp
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xebb(%rip),%xmm0
lea    0xec4(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x10(%rsp)
mov    $0x3,%ebx
mov    %ebp,%ecx
shl    %cl,%ebx
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x8(%rsp),%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
movsd  0xe77(%rip),%xmm0
subsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
mov    $0x2,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
add    $0x1,%ebp
movsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
cmp    %ebp,%r15d
jne    1160 <liuhui+0x40>
jmp    11d3 <liuhui+0xb3>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"sides = %d\09pi(%d) = %.51f\0A\00"
define i32 @liuhui(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store i32 %0, i32* %2
store i32 0, i32* %3
store double 3.000000e+00, double* %4
store double 1.000000e+00, double* %5
br label %6
6: ; preds = %28, %1
%7 = load i32, i32* %3
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %33
10: ; preds = %6
%11 = load i32, i32* %3
%12 = shl i32 1, %11
%13 = mul nsw i32 3, %12
%14 = load i32, i32* %3
%15 = load double, double* %4
%16 = load double, double* %5
%17 = fptosi double %16 to i32
%18 = call i32 @sqrt(i32 %17)
%19 = sitofp i32 %18 to double
%20 = fmul double %15, %19
%21 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14, double %20)
%22 = load double, double* %5
%23 = fsub double 4.000000e+00, %22
%24 = fptosi double %23 to i32
%25 = call i32 @sqrt(i32 %24)
%26 = sub nsw i32 2, %25
%27 = sitofp i32 %26 to double
store double %27, double* %5
br label %28
28: ; preds = %10
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
%31 = load double, double* %4
%32 = fmul double %31, 2.000000e+00
store double %32, double* %4
br label %6
33: ; preds = %6
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [27 x i8] c"sides = %d\09pi(%d) = %.51f\0A\00"
define i32 @liuhui(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %21
3: ; preds = %1, %3
%4 = phi double [ %17, %3 ], [ 1.000000e+00, %1 ]
%5 = phi double [ %19, %3 ], [ 3.000000e+00, %1 ]
%6 = phi i32 [ %18, %3 ], [ 0, %1 ]
%7 = shl i32 3, %6
%8 = fptosi double %4 to i32
%9 = tail call i32 @sqrt(i32 %8)
%10 = sitofp i32 %9 to double
%11 = fmul double %5, %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %6, double %11)
%13 = fsub double 4.000000e+00, %4
%14 = fptosi double %13 to i32
%15 = tail call i32 @sqrt(i32 %14)
%16 = sub nsw i32 2, %15
%17 = sitofp i32 %16 to double
%18 = add nuw nsw i32 %6, 1
%19 = fmul double %5, 2.000000e+00
%20 = icmp eq i32 %18, %0
br i1 %20, label %21, label %3
21: ; preds = %3, %1
%22 = phi i32 [ 0, %1 ], [ %0, %3 ]
ret i32 %22
}