#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 fact(int);
int pown(int, double);
double cosmc(double x) {
  double value = 1;
  int sign = -1;
  int i;
  for (i = 2; i < 30; i += 2) {
    value += sign * (pown(i, x) / fact(i));
    sign *= -1;
  }
  return value;
}


x86 assembly (clang, -O0):
<cosmc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xecb(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
cmpl   $0x1e,-0x18(%rbp)
jge    11a3 <cosmc+0x83>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
movsd  -0x8(%rbp),%xmm0
call   1030 <pown@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <fact@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
imul   $0xffffffff,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    1148 <cosmc+0x28>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cosmc>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
movsd  0xeca(%rip),%xmm0
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
nopl   (%rax)
movsd  %xmm0,(%rsp)
add    $0x2,%ebx
mov    %ebx,%edi
movsd  0x8(%rsp),%xmm0
call   1030 <pown@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1040 <fact@plt>
mov    %eax,%ecx
mov    %r14d,%eax
cltd
idiv   %ecx
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
neg    %ebp
cmp    $0x1c,%ebx
jb     1140 <cosmc+0x20>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define double @cosmc(double %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 2, %1 ], [ %13, %2 ]
%4 = phi i32 [ -1, %1 ], [ %12, %2 ]
%5 = phi double [ 1.000000e+00, %1 ], [ %11, %2 ]
%6 = tail call i32 @pown(i32 %3, double %0)
%7 = tail call i32 @fact(i32 %3)
%8 = sdiv i32 %6, %7
%9 = mul nsw i32 %8, %4
%10 = sitofp i32 %9 to double
%11 = fadd double %5, %10
%12 = sub nsw i32 0, %4
%13 = add nuw nsw i32 %3, 2
%14 = icmp ult i32 %3, 28
br i1 %14, label %2, label %15
15: ; preds = %2
ret double %11
}