#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__ factorielle(int, int);
double pow(double, int);
double dl_cosinus(double x, long ordre) {
  size_t i = 0;
  double value = 0;
  short int coef = 1;
  for (i = 1; i <= ordre; i++) {
    coef *= -1;
    value += coef * (pow(x, 2 * i) / (double)factorielle(2 * i, 1));
  }
  value += 1;
  return value;
}


x86 assembly (clang, -O0):
<dl_cosinus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movw   $0x1,-0x22(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     11d8 <dl_cosinus+0xb8>
movswl -0x22(%rbp),%eax
imul   $0xffffffff,%eax,%eax
mov    %ax,-0x22(%rbp)
movswl -0x22(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1030 <pow@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <factorielle@plt>
movsd  -0x38(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114f <dl_cosinus+0x2f>
movsd  0xe20(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dl_cosinus>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
je     11d6 <dl_cosinus+0xb6>
mov    %rdi,%r14
movapd %xmm0,%xmm1
mov    $0x1,%r15d
xorpd  %xmm0,%xmm0
mov    $0x1,%ebx
mov    $0x2,%ebp
movsd  %xmm1,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x20(%rsp)
movswl %bx,%ebx
neg    %ebx
movswl %bx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x18(%rsp)
movapd %xmm1,%xmm0
mov    %ebp,%edi
call   1030 <pow@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebp,%edi
mov    $0x1,%esi
call   1040 <factorielle@plt>
movsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x10(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  0x20(%rsp),%xmm0
mulsd  0x18(%rsp),%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%r15
add    $0x2,%ebp
cmp    %r14,%r15
jbe    1160 <dl_cosinus+0x40>
addsd  0xe2c(%rip),%xmm0
jmp    11de <dl_cosinus+0xbe>
movsd  0xe22(%rip),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @dl_cosinus(double %0, i64 %1) {
%3 = alloca double
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
%7 = alloca i16
store double %0, double* %3
store i64 %1, i64* %4
store i64 0, i64* %5
store double 0.000000e+00, double* %6
store i16 1, i16* %7
store i64 1, i64* %5
br label %8
8: ; preds = %33, %2
%9 = load i64, i64* %5
%10 = load i64, i64* %4
%11 = icmp ule i64 %9, %10
br i1 %11, label %12, label %36
12: ; preds = %8
%13 = load i16, i16* %7
%14 = sext i16 %13 to i32
%15 = mul nsw i32 %14, -1
%16 = trunc i32 %15 to i16
store i16 %16, i16* %7
%17 = load i16, i16* %7
%18 = sext i16 %17 to i32
%19 = sitofp i32 %18 to double
%20 = load double, double* %3
%21 = load i64, i64* %5
%22 = mul i64 2, %21
%23 = trunc i64 %22 to i32
%24 = call double @pow(double %20, i32 %23)
%25 = load i64, i64* %5
%26 = mul i64 2, %25
%27 = trunc i64 %26 to i32
%28 = call i64 @factorielle(i32 %27, i32 1)
%29 = sitofp i64 %28 to double
%30 = fdiv double %24, %29
%31 = load double, double* %6
%32 = call double @llvm.fmuladd.f64(double %19, double %30, double %31)
store double %32, double* %6
br label %33
33: ; preds = %12
%34 = load i64, i64* %5
%35 = add i64 %34, 1
store i64 %35, i64* %5
br label %8
36: ; preds = %8
%37 = load double, double* %6
%38 = fadd double %37, 1.000000e+00
store double %38, double* %6
%39 = load double, double* %6
ret double %39
}

LLVM IR (-O2):
define double @dl_cosinus(double %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %25, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %10, %4 ], [ 1, %2 ]
%6 = phi double [ %20, %4 ], [ 0.000000e+00, %2 ]
%7 = phi i64 [ %21, %4 ], [ 1, %2 ]
%8 = shl i32 %5, 16
%9 = ashr exact i32 %8, 16
%10 = sub nsw i32 0, %9
%11 = shl i32 %10, 16
%12 = ashr exact i32 %11, 16
%13 = sitofp i32 %12 to double
%14 = trunc i64 %7 to i32
%15 = shl i32 %14, 1
%16 = tail call double @pow(double %0, i32 %15)
%17 = tail call i64 @factorielle(i32 %15, i32 1)
%18 = sitofp i64 %17 to double
%19 = fdiv double %16, %18
%20 = tail call double @llvm.fmuladd.f64(double %13, double %19, double %6)
%21 = add i64 %7, 1
%22 = icmp ugt i64 %21, %1
br i1 %22, label %23, label %4
23: ; preds = %4
%24 = fadd double %20, 1.000000e+00
br label %25
25: ; preds = %23, %2
%26 = phi double [ 1.000000e+00, %2 ], [ %24, %23 ]
ret double %26
}