#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 F_normale_centree_reduite(double);
scalar_t__ calcul_factorielle(int);
scalar_t__ calcul_factorielle_impaire(int);
double exp(double);
double pow(double, double);
double sqrt(double);
double chi_square(double x, int k) {
  int i;
  double resultat;
  if (k % 2 == 0) {
    resultat = 0;
    for (i = 0; i <= k / 2 - 1; i++) {
      resultat += pow(x / 2.0, (double)i) / (double)calcul_factorielle(i);
    }
    resultat *= exp(-x / 2.0);
  } else {
    resultat = 0;
    for (i = 1; i <= (k - 1) / 2; i++) {
      resultat +=
          pow(x, (double)i - 0.5) / (double)calcul_factorielle_impaire(i);
    }
    resultat = 2.0 * (1.0 - F_normale_centree_reduite(sqrt(x))) +
               2.0 / sqrt(2.0 * 3.1415927) * exp(-x / 2.0) * resultat;
  }
  return resultat;
}


x86 assembly (clang, -O0):
<chi_square>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    123e <chi_square+0xde>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1202 <chi_square+0xa2>
movsd  -0x8(%rbp),%xmm0
movsd  0xe3f(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
call   1060 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <calcul_factorielle@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1193 <chi_square+0x33>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdda(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <exp@plt>
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1350 <chi_square+0x1f0>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jg     12bc <chi_square+0x15c>
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  0xd98(%rip),%xmm2
subsd  %xmm2,%xmm1
call   1060 <pow@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <calcul_factorielle_impaire@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    124d <chi_square+0xed>
movsd  -0x8(%rbp),%xmm0
call   1070 <sqrt@plt>
call   1080 <F_normale_centree_reduite@plt>
movaps %xmm0,%xmm1
movsd  0xd3a(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xd21(%rip),%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xd09(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xcdc(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <exp@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm1
mulsd  -0x18(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chi_square>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %edi,%r14d
test   $0x1,%r14b
movsd  %xmm0,0x18(%rsp)
jne    123f <chi_square+0xdf>
xorpd  %xmm0,%xmm0
cmp    $0x2,%r14d
jl     121b <chi_square+0xbb>
mov    %r14d,%ebp
shr    $0x1f,%ebp
add    %r14d,%ebp
sar    %ebp
movsd  0xe7c(%rip),%xmm0
mulsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
xor    %ebx,%ebx
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  0x28(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1060 <pow@plt>
movsd  %xmm0,0x20(%rsp)
mov    %ebx,%edi
call   1050 <calcul_factorielle@plt>
movsd  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x20(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
addsd  %xmm2,%xmm0
addsd  0xdec(%rip),%xmm1
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    11c0 <chi_square+0x60>
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0xdd9(%rip),%xmm0
call   1040 <exp@plt>
mulsd  0x8(%rsp),%xmm0
jmp    1344 <chi_square+0x1e4>
xorpd  %xmm1,%xmm1
cmp    $0x3,%r14d
jl     12e3 <chi_square+0x183>
add    $0xffffffff,%r14d
shr    %r14d
neg    %r14d
mov    $0x1,%ebx
movsd  0xd9c(%rip),%xmm2
xorpd  %xmm1,%xmm1
nopl   0x0(%rax,%rax,1)
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movapd %xmm2,%xmm1
addsd  0xd80(%rip),%xmm1
movsd  0x18(%rsp),%xmm0
call   1060 <pow@plt>
movsd  %xmm0,0x20(%rsp)
mov    %ebx,%edi
call   1030 <calcul_factorielle_impaire@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x20(%rsp),%xmm3
divsd  %xmm0,%xmm3
movsd  0x18(%rsp),%xmm0
addsd  %xmm3,%xmm1
addsd  0xd30(%rip),%xmm2
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1270 <chi_square+0x110>
movsd  %xmm1,0x10(%rsp)
ucomisd 0xd2f(%rip),%xmm0
jb     12f9 <chi_square+0x199>
sqrtsd %xmm0,%xmm0
jmp    12fe <chi_square+0x19e>
call   1070 <sqrt@plt>
call   1080 <F_normale_centree_reduite@plt>
movsd  0xcf5(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0xce5(%rip),%xmm0
call   1040 <exp@plt>
mulsd  0xce0(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @chi_square(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store double %0, double* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = srem i32 %7, 2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %39
10: ; preds = %2
store double 0.000000e+00, double* %6
store i32 0, i32* %5
br label %11
11: ; preds = %29, %10
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = sdiv i32 %13, 2
%15 = sub nsw i32 %14, 1
%16 = icmp sle i32 %12, %15
br i1 %16, label %17, label %32
17: ; preds = %11
%18 = load double, double* %3
%19 = fdiv double %18, 2.000000e+00
%20 = load i32, i32* %5
%21 = sitofp i32 %20 to double
%22 = call double @pow(double %19, double %21)
%23 = load i32, i32* %5
%24 = call i64 @calcul_factorielle(i32 %23)
%25 = sitofp i64 %24 to double
%26 = fdiv double %22, %25
%27 = load double, double* %6
%28 = fadd double %27, %26
store double %28, double* %6
br label %29
29: ; preds = %17
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %11
32: ; preds = %11
%33 = load double, double* %3
%34 = fneg double %33
%35 = fdiv double %34, 2.000000e+00
%36 = call double @exp(double %35)
%37 = load double, double* %6
%38 = fmul double %37, %36
store double %38, double* %6
br label %76
39: ; preds = %2
store double 0.000000e+00, double* %6
store i32 1, i32* %5
br label %40
40: ; preds = %58, %39
%41 = load i32, i32* %5
%42 = load i32, i32* %4
%43 = sub nsw i32 %42, 1
%44 = sdiv i32 %43, 2
%45 = icmp sle i32 %41, %44
br i1 %45, label %46, label %61
46: ; preds = %40
%47 = load double, double* %3
%48 = load i32, i32* %5
%49 = sitofp i32 %48 to double
%50 = fsub double %49, 5.000000e-01
%51 = call double @pow(double %47, double %50)
%52 = load i32, i32* %5
%53 = call i64 @calcul_factorielle_impaire(i32 %52)
%54 = sitofp i64 %53 to double
%55 = fdiv double %51, %54
%56 = load double, double* %6
%57 = fadd double %56, %55
store double %57, double* %6
br label %58
58: ; preds = %46
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
br label %40
61: ; preds = %40
%62 = load double, double* %3
%63 = call double @sqrt(double %62)
%64 = call double @F_normale_centree_reduite(double %63)
%65 = fsub double 1.000000e+00, %64
%66 = call double @sqrt(double 0x401921FB5A7ED197)
%67 = fdiv double 2.000000e+00, %66
%68 = load double, double* %3
%69 = fneg double %68
%70 = fdiv double %69, 2.000000e+00
%71 = call double @exp(double %70)
%72 = fmul double %67, %71
%73 = load double, double* %6
%74 = fmul double %72, %73
%75 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %65, double %74)
store double %75, double* %6
br label %76
76: ; preds = %61, %32
%77 = load double, double* %6
ret double %77
}

LLVM IR (-O2):
define double @chi_square(double %0, i32 %1) {
%3 = and i32 %1, 1
%4 = icmp eq i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = icmp slt i32 %1, 3
br i1 %6, label %43, label %7
7: ; preds = %5
%8 = add nsw i32 %1, -1
%9 = lshr i32 %8, 1
br label %31
10: ; preds = %2
%11 = sdiv i32 %1, 2
%12 = icmp sgt i32 %1, 1
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = fmul double %0, 5.000000e-01
br label %15
15: ; preds = %13, %15
%16 = phi double [ 0.000000e+00, %13 ], [ %23, %15 ]
%17 = phi i32 [ 0, %13 ], [ %24, %15 ]
%18 = sitofp i32 %17 to double
%19 = tail call double @pow(double %14, double %18)
%20 = tail call i64 @calcul_factorielle(i32 %17)
%21 = sitofp i64 %20 to double
%22 = fdiv double %19, %21
%23 = fadd double %16, %22
%24 = add nuw nsw i32 %17, 1
%25 = icmp eq i32 %24, %11
br i1 %25, label %26, label %15
26: ; preds = %15, %10
%27 = phi double [ 0.000000e+00, %10 ], [ %23, %15 ]
%28 = fmul double %0, -5.000000e-01
%29 = tail call double @exp(double %28)
%30 = fmul double %27, %29
br label %53
31: ; preds = %7, %31
%32 = phi double [ %40, %31 ], [ 0.000000e+00, %7 ]
%33 = phi i32 [ %41, %31 ], [ 1, %7 ]
%34 = sitofp i32 %33 to double
%35 = fadd double %34, -5.000000e-01
%36 = tail call double @pow(double %0, double %35)
%37 = tail call i64 @calcul_factorielle_impaire(i32 %33)
%38 = sitofp i64 %37 to double
%39 = fdiv double %36, %38
%40 = fadd double %32, %39
%41 = add nuw nsw i32 %33, 1
%42 = icmp eq i32 %33, %9
br i1 %42, label %43, label %31
43: ; preds = %31, %5
%44 = phi double [ 0.000000e+00, %5 ], [ %40, %31 ]
%45 = tail call double @sqrt(double %0)
%46 = tail call double @F_normale_centree_reduite(double %45)
%47 = fsub double 1.000000e+00, %46
%48 = fmul double %0, -5.000000e-01
%49 = tail call double @exp(double %48)
%50 = fmul double %49, 0x3FE9884530AA3706
%51 = fmul double %44, %50
%52 = tail call double @llvm.fmuladd.f64(double %47, double 2.000000e+00, double %51)
br label %53
53: ; preds = %43, %26
%54 = phi double [ %30, %26 ], [ %52, %43 ]
ret double %54
}