#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 fact(int);
double mypow(double, int);
double mycos(double x) {
  double e = 0.0;
  int i;
  for (i = 0; i < 10; i++) {
    e += mypow(-1, i) * mypow(x, 2 * i) / fact(2 * i);
  }
  return e;
}


x86 assembly (clang, -O0):
<mycos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11ab <mycos+0x8b>
mov    -0x14(%rbp),%edi
movsd  0xeaf(%rip),%xmm0
call   1030 <mypow@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x14(%rbp),%edi
shl    $0x1,%edi
call   1030 <mypow@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
shl    $0x1,%edi
call   1040 <fact@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113c <mycos+0x1c>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mycos>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x10(%rsp)
movsd  0xeb2(%rip),%xmm0
mov    %ebp,%edi
call   1030 <mypow@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mov    %ebx,%edi
call   1030 <mypow@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %ebx,%edi
call   1040 <fact@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x1,%ebp
add    $0x2,%ebx
cmp    $0xa,%ebp
jne    1140 <mycos+0x20>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define double @mycos(double %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 0, %1 ], [ %12, %2 ]
%4 = phi double [ 0.000000e+00, %1 ], [ %11, %2 ]
%5 = tail call double @mypow(double -1.000000e+00, i32 %3)
%6 = shl nuw nsw i32 %3, 1
%7 = tail call double @mypow(double %0, i32 %6)
%8 = fmul double %5, %7
%9 = tail call double @fact(i32 %6)
%10 = fdiv double %8, %9
%11 = fadd double %4, %10
%12 = add nuw nsw i32 %3, 1
%13 = icmp eq i32 %12, 10
br i1 %13, label %14, label %2
14: ; preds = %2
ret double %11
}