#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 /*<<< orphan*/ scanf(char *, int *);
float sqrt(float);
int main() {
  int n, accuracy;
  float pi = 0;
  printf("输入精度:\n");
  scanf("%d", &accuracy);
  for (n = 1; n <= accuracy; n++)
    pi += 1.0 / (n * n);
  pi *= 6;
  pi = sqrt(pi);
  printf("pi=%f", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11b3 <main+0x83>
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe7d(%rip),%xmm1
divsd  %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116c <main+0x3c>
movss  0xe45(%rip),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe3e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
xorps  %xmm1,%xmm1
xorps  %xmm0,%xmm0
test   %eax,%eax
jle    1224 <main+0xe4>
cmp    $0x1,%eax
jne    1186 <main+0x46>
mov    $0x1,%ecx
xorps  %xmm2,%xmm2
test   $0x1,%al
jne    11fb <main+0xbb>
jmp    121c <main+0xdc>
mov    %eax,%edx
and    $0xfffffffe,%edx
neg    %edx
mov    $0x1,%ecx
xorps  %xmm0,%xmm0
movsd  0xe63(%rip),%xmm2
nopl   (%rax)
mov    %ecx,%esi
imul   %ecx,%esi
xorps  %xmm3,%xmm3
cvtsi2sd %esi,%xmm3
movapd %xmm2,%xmm4
divsd  %xmm3,%xmm4
cvtss2sd %xmm0,%xmm0
addsd  %xmm4,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0x1(%rcx),%esi
imul   %esi,%esi
xorps  %xmm3,%xmm3
cvtsi2sd %esi,%xmm3
movapd %xmm2,%xmm4
divsd  %xmm3,%xmm4
cvtss2sd %xmm0,%xmm0
addsd  %xmm4,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    %ecx,%esi
add    $0x2,%ecx
add    %edx,%esi
add    $0x2,%esi
cmp    $0x1,%esi
jne    11a0 <main+0x60>
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
test   $0x1,%al
je     121c <main+0xdc>
imul   %ecx,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0xdf3(%rip),%xmm3
divsd  %xmm0,%xmm3
addsd  %xmm2,%xmm3
xorps  %xmm0,%xmm0
cvtsd2ss %xmm3,%xmm0
mulss  0xde4(%rip),%xmm0
ucomiss %xmm1,%xmm0
jb     122f <main+0xef>
sqrtss %xmm0,%xmm0
jmp    1234 <main+0xf4>
call   1060 <sqrt@plt>
cvtss2sd %xmm0,%xmm0
lea    0xdd0(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"\E8\BE\93\E5\85\A5\E7\B2\BE\E5\BA\A6:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"pi=%f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
store i32 1, i32* %2
br label %7
7: ; preds = %21, %0
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = load i32, i32* %2
%13 = load i32, i32* %2
%14 = mul nsw i32 %12, %13
%15 = sitofp i32 %14 to double
%16 = fdiv double 1.000000e+00, %15
%17 = load float, float* %4
%18 = fpext float %17 to double
%19 = fadd double %18, %16
%20 = fptrunc double %19 to float
store float %20, float* %4
br label %21
21: ; preds = %11
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %7
24: ; preds = %7
%25 = load float, float* %4
%26 = fmul float %25, 6.000000e+00
store float %26, float* %4
%27 = load float, float* %4
%28 = call float @sqrt(float %27)
store float %28, float* %4
%29 = load float, float* %4
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %30)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"pi=%f\00"
@str = [14 x i8] c"\E8\BE\93\E5\85\A5\E7\B2\BE\E5\BA\A6:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
br i1 %6, label %48, label %7
7: ; preds = %0
%8 = and i32 %5, 1
%9 = icmp eq i32 %5, 1
br i1 %9, label %34, label %10
10: ; preds = %7
%11 = and i32 %5, -2
br label %12
12: ; preds = %12, %10
%13 = phi float [ 0.000000e+00, %10 ], [ %28, %12 ]
%14 = phi i32 [ 1, %10 ], [ %29, %12 ]
%15 = phi i32 [ 0, %10 ], [ %30, %12 ]
%16 = mul nsw i32 %14, %14
%17 = sitofp i32 %16 to double
%18 = fdiv double 1.000000e+00, %17
%19 = fpext float %13 to double
%20 = fadd double %18, %19
%21 = fptrunc double %20 to float
%22 = add nuw i32 %14, 1
%23 = mul nsw i32 %22, %22
%24 = sitofp i32 %23 to double
%25 = fdiv double 1.000000e+00, %24
%26 = fpext float %21 to double
%27 = fadd double %25, %26
%28 = fptrunc double %27 to float
%29 = add nuw i32 %14, 2
%30 = add i32 %15, 2
%31 = icmp eq i32 %30, %11
br i1 %31, label %32, label %12
32: ; preds = %12
%33 = fpext float %28 to double
br label %34
34: ; preds = %32, %7
%35 = phi float [ undef, %7 ], [ %28, %32 ]
%36 = phi double [ 0.000000e+00, %7 ], [ %33, %32 ]
%37 = phi i32 [ 1, %7 ], [ %29, %32 ]
%38 = icmp eq i32 %8, 0
br i1 %38, label %45, label %39
39: ; preds = %34
%40 = mul nsw i32 %37, %37
%41 = sitofp i32 %40 to double
%42 = fdiv double 1.000000e+00, %41
%43 = fadd double %42, %36
%44 = fptrunc double %43 to float
br label %45
45: ; preds = %34, %39
%46 = phi float [ %35, %34 ], [ %44, %39 ]
%47 = fmul float %46, 6.000000e+00
br label %48
48: ; preds = %45, %0
%49 = phi float [ 0.000000e+00, %0 ], [ %47, %45 ]
%50 = call float @sqrt(float %49)
%51 = fpext float %50 to double
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %51)
ret i32 0
}