#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 */
double _pow(double, int);
double fac(int);
double cos(double x) {
  double y = 0;
  x *= 3.14159265358979323846 / 180;
  for (unsigned int i = 0; i != 8; i++)
    y += _pow(-1.0, i) / fac(2 * i) * _pow(x, 2 * i);
  return y;
}


x86 assembly (clang, -O0):
<cos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xec3(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
je     11c1 <cos+0xa1>
mov    -0x14(%rbp),%edi
movsd  0xea5(%rip),%xmm0
call   1030 <_pow@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%edi
shl    $0x1,%edi
call   1040 <fac@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x14(%rbp),%edi
shl    $0x1,%edi
call   1030 <_pow@plt>
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114e <cos+0x2e>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cos>:
sub    $0x18,%rsp
mulsd  0xed4(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xece(%rip),%xmm0
xor    %edi,%edi
call   1030 <_pow@plt>
movsd  %xmm0,(%rsp)
xor    %edi,%edi
call   1040 <fac@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
xor    %edi,%edi
call   1030 <_pow@plt>
mulsd  (%rsp),%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe85(%rip),%xmm0
mov    $0x1,%edi
call   1030 <_pow@plt>
movsd  %xmm0,(%rsp)
mov    $0x2,%edi
call   1040 <fac@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1030 <_pow@plt>
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe35(%rip),%xmm0
mov    $0x2,%edi
call   1030 <_pow@plt>
movsd  %xmm0,(%rsp)
mov    $0x4,%edi
call   1040 <fac@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x4,%edi
call   1030 <_pow@plt>
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xde5(%rip),%xmm0
mov    $0x3,%edi
call   1030 <_pow@plt>
movsd  %xmm0,(%rsp)
mov    $0x6,%edi
call   1040 <fac@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x6,%edi
call   1030 <_pow@plt>
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xd95(%rip),%xmm0
mov    $0x4,%edi
call   1030 <_pow@plt>
movsd  %xmm0,(%rsp)
mov    $0x8,%edi
call   1040 <fac@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x8,%edi
call   1030 <_pow@plt>
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xd45(%rip),%xmm0
mov    $0x5,%edi
call   1030 <_pow@plt>
movsd  %xmm0,(%rsp)
mov    $0xa,%edi
call   1040 <fac@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0xa,%edi
call   1030 <_pow@plt>
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xcf5(%rip),%xmm0
mov    $0x6,%edi
call   1030 <_pow@plt>
movsd  %xmm0,(%rsp)
mov    $0xc,%edi
call   1040 <fac@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0xc,%edi
call   1030 <_pow@plt>
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xca5(%rip),%xmm0
mov    $0x7,%edi
call   1030 <_pow@plt>
movsd  %xmm0,(%rsp)
mov    $0xe,%edi
call   1040 <fac@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0xe,%edi
call   1030 <_pow@plt>
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @cos(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
store double %0, double* %2
store double 0.000000e+00, double* %3
%5 = load double, double* %2
%6 = fmul double %5, 0x3F91DF46A2529D39
store double %6, double* %2
store i32 0, i32* %4
br label %7
7: ; preds = %23, %1
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 8
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = load i32, i32* %4
%12 = call double @_pow(double -1.000000e+00, i32 %11)
%13 = load i32, i32* %4
%14 = mul i32 2, %13
%15 = call double @fac(i32 %14)
%16 = fdiv double %12, %15
%17 = load double, double* %2
%18 = load i32, i32* %4
%19 = mul i32 2, %18
%20 = call double @_pow(double %17, i32 %19)
%21 = load double, double* %3
%22 = call double @llvm.fmuladd.f64(double %16, double %20, double %21)
store double %22, double* %3
br label %23
23: ; preds = %10
%24 = load i32, i32* %4
%25 = add i32 %24, 1
store i32 %25, i32* %4
br label %7
26: ; preds = %7
%27 = load double, double* %3
ret double %27
}

LLVM IR (-O2):
define double @cos(double %0) {
%2 = fmul double %0, 0x3F91DF46A2529D39
%3 = tail call double @_pow(double -1.000000e+00, i32 0)
%4 = tail call double @fac(i32 0)
%5 = fdiv double %3, %4
%6 = tail call double @_pow(double %2, i32 0)
%7 = tail call double @llvm.fmuladd.f64(double %5, double %6, double 0.000000e+00)
%8 = tail call double @_pow(double -1.000000e+00, i32 1)
%9 = tail call double @fac(i32 2)
%10 = fdiv double %8, %9
%11 = tail call double @_pow(double %2, i32 2)
%12 = tail call double @llvm.fmuladd.f64(double %10, double %11, double %7)
%13 = tail call double @_pow(double -1.000000e+00, i32 2)
%14 = tail call double @fac(i32 4)
%15 = fdiv double %13, %14
%16 = tail call double @_pow(double %2, i32 4)
%17 = tail call double @llvm.fmuladd.f64(double %15, double %16, double %12)
%18 = tail call double @_pow(double -1.000000e+00, i32 3)
%19 = tail call double @fac(i32 6)
%20 = fdiv double %18, %19
%21 = tail call double @_pow(double %2, i32 6)
%22 = tail call double @llvm.fmuladd.f64(double %20, double %21, double %17)
%23 = tail call double @_pow(double -1.000000e+00, i32 4)
%24 = tail call double @fac(i32 8)
%25 = fdiv double %23, %24
%26 = tail call double @_pow(double %2, i32 8)
%27 = tail call double @llvm.fmuladd.f64(double %25, double %26, double %22)
%28 = tail call double @_pow(double -1.000000e+00, i32 5)
%29 = tail call double @fac(i32 10)
%30 = fdiv double %28, %29
%31 = tail call double @_pow(double %2, i32 10)
%32 = tail call double @llvm.fmuladd.f64(double %30, double %31, double %27)
%33 = tail call double @_pow(double -1.000000e+00, i32 6)
%34 = tail call double @fac(i32 12)
%35 = fdiv double %33, %34
%36 = tail call double @_pow(double %2, i32 12)
%37 = tail call double @llvm.fmuladd.f64(double %35, double %36, double %32)
%38 = tail call double @_pow(double -1.000000e+00, i32 7)
%39 = tail call double @fac(i32 14)
%40 = fdiv double %38, %39
%41 = tail call double @_pow(double %2, i32 14)
%42 = tail call double @llvm.fmuladd.f64(double %40, double %41, double %37)
ret double %42
}