#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 FLT_EPSILON;
int M_PI;
double cos(double);
int fabs(double);
int /*<<< orphan*/ printf(char *, double, double, int);
int main() {
  int i = 0;
  int k = 0;
  double x = 0;
  double s_k = 0;
  double a_k1 = 0;
  for (i = 0; i < 10000; i++) {
    x = 10 * M_PI / 10000 * i;
    a_k1 = 1;
    s_k = 0;
    k = 1;
    do {
      s_k += a_k1;
      a_k1 *= -(x * x) / ((2 * k - 1) * 2 * k);
      k++;
    } while (fabs(a_k1) >= fabs(s_k) * FLT_EPSILON);
    printf("%.10lf %+.10lf %.10lf\n", x, s_k, fabs((s_k - cos(x)) / cos(x)));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jge    12b7 <main+0x187>
mov    0x2e68(%rip),%rax
imul   $0xa,(%rax),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
imul   -0x8(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe60(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0xc(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
sub    $0x1,%eax
shl    $0x1,%eax
imul   -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
mov    0x2da6(%rip),%rdx
imul   (%rdx),%ecx
cmp    %ecx,%eax
jge    11b4 <main+0x84>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1040 <fabs@plt>
movsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mov    %eax,%esi
lea    0xd64(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116c <main+0x3c>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
xor    %r12d,%r12d
mov    0x2e90(%rip),%r13
lea    0xec9(%rip),%r14
nop
mov    0x2e91(%rip),%rax
movslq (%rax),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   %r12d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd %xmm0,%xmm1
xorpd  0xe7b(%rip),%xmm1
movapd %xmm0,0x10(%rsp)
mulsd  %xmm0,%xmm1
movapd %xmm1,0x30(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%ebx
mov    $0x2,%r15d
movsd  0xe5e(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,%eax
imul   %ebx,%eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd 0x30(%rsp),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
add    $0x1,%ebx
call   1040 <fabs@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1040 <fabs@plt>
movaps 0x20(%rsp),%xmm0
imul   0x0(%r13),%eax
add    $0x4,%r15d
cmp    %eax,%ebp
jge    11c0 <main+0x90>
movapd 0x10(%rsp),%xmm0
call   1050 <cos@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
movapd 0x10(%rsp),%xmm0
call   1050 <cos@plt>
movsd  0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <fabs@plt>
mov    %r14,%rdi
movaps 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %eax,%esi
call   1030 <printf@plt>
add    $0x1,%r12d
cmp    $0x2710,%r12d
jne    1150 <main+0x20>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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