#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 */
scalar_t__ fact(int);
float pow(int, int);
float cos_x(int x) {
  float acu = 2, sum = 0;
  int i = 1, n = 0;
  while (acu > 0.0001) {
    sum += (i * pow(x, n)) / (float)fact(n);
    acu = (pow(x, n)) / (float)fact(n);
    i = -i;
    n += 2;
  }
  return sum;
}


x86 assembly (clang, -O0):
<cos_x>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movss  0xecd(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea9(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f0 <cos_x+0xd0>
cvtsi2ssl -0x10(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movss  -0x20(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <fact@plt>
movss  -0x1c(%rbp),%xmm0
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <pow@plt>
movss  %xmm0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <fact@plt>
movss  -0x18(%rbp),%xmm0
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
xor    %eax,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    114e <cos_x+0x2e>
movss  -0xc(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cos_x>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
mov    $0x1,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
movss  %xmm0,0x8(%rsp)
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
mulss  0x8(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <fact@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  0x8(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
movss  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <fact@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  0x8(%rsp),%xmm1
divss  %xmm0,%xmm1
neg    %ebx
add    $0x2,%ebp
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
ucomisd 0xe37(%rip),%xmm0
ja     1140 <cos_x+0x20>
movss  0xc(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define float @cos_x(i32 %0) {
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store float 2.000000e+00, float* %3
store float 0.000000e+00, float* %4
store i32 1, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %11, %1
%8 = load float, float* %3
%9 = fpext float %8 to double
%10 = fcmp ogt double %9, 1.000000e-04
br i1 %10, label %11, label %35
11: ; preds = %7
%12 = load i32, i32* %5
%13 = sitofp i32 %12 to float
%14 = load i32, i32* %2
%15 = load i32, i32* %6
%16 = call float @pow(i32 %14, i32 %15)
%17 = fmul float %13, %16
%18 = load i32, i32* %6
%19 = call i64 @fact(i32 %18)
%20 = sitofp i64 %19 to float
%21 = fdiv float %17, %20
%22 = load float, float* %4
%23 = fadd float %22, %21
store float %23, float* %4
%24 = load i32, i32* %2
%25 = load i32, i32* %6
%26 = call float @pow(i32 %24, i32 %25)
%27 = load i32, i32* %6
%28 = call i64 @fact(i32 %27)
%29 = sitofp i64 %28 to float
%30 = fdiv float %26, %29
store float %30, float* %3
%31 = load i32, i32* %5
%32 = sub nsw i32 0, %31
store i32 %32, i32* %5
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 2
store i32 %34, i32* %6
br label %7
35: ; preds = %7
%36 = load float, float* %4
ret float %36
}

LLVM IR (-O2):
define float @cos_x(i32 %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 0, %1 ], [ %18, %2 ]
%4 = phi i32 [ 1, %1 ], [ %17, %2 ]
%5 = phi float [ 0.000000e+00, %1 ], [ %12, %2 ]
%6 = sitofp i32 %4 to float
%7 = tail call float @pow(i32 %0, i32 %3)
%8 = fmul float %7, %6
%9 = tail call i64 @fact(i32 %3)
%10 = sitofp i64 %9 to float
%11 = fdiv float %8, %10
%12 = fadd float %5, %11
%13 = tail call float @pow(i32 %0, i32 %3)
%14 = tail call i64 @fact(i32 %3)
%15 = sitofp i64 %14 to float
%16 = fdiv float %13, %15
%17 = sub nsw i32 0, %4
%18 = add nuw nsw i32 %3, 2
%19 = fpext float %16 to double
%20 = fcmp ogt double %19, 1.000000e-04
br i1 %20, label %2, label %21
21: ; preds = %2
ret float %12
}