#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 exp(double);
int factorial(int);
double pow(double, int);
double incompleteGammaFunction(double chi, int n) {
  double sum = 0;
  int k;
  for (k = 0; k < n; k++)
    sum += pow(chi, k) / factorial(k);
  return factorial(n - 1) * (1 - exp(-1.0 * chi) * sum);
}


x86 assembly (clang, -O0):
<incompleteGammaFunction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119a <incompleteGammaFunction+0x6a>
movsd  -0x8(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
call   1050 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <factorial@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <incompleteGammaFunction+0x1f>
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1030 <factorial@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe52(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
movsd  0xe10(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<incompleteGammaFunction>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
test   %edi,%edi
movapd %xmm0,0x10(%rsp)
xorpd  %xmm1,%xmm1
jle    1191 <incompleteGammaFunction+0x61>
movsd  %xmm1,(%rsp)
xor    %ebp,%ebp
nopl   (%rax)
movaps 0x10(%rsp),%xmm0
mov    %ebp,%edi
call   1050 <pow@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <factorial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1150 <incompleteGammaFunction+0x20>
jmp    1196 <incompleteGammaFunction+0x66>
movsd  %xmm1,(%rsp)
add    $0xffffffff,%ebx
mov    %ebx,%edi
call   1030 <factorial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x10(%rsp),%xmm0
xorpd  0xe45(%rip),%xmm0
call   1040 <exp@plt>
mulsd  (%rsp),%xmm0
movsd  0xe43(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define double @incompleteGammaFunction(double %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %14
4: ; preds = %2, %4
%5 = phi i32 [ %12, %4 ], [ 0, %2 ]
%6 = phi double [ %11, %4 ], [ 0.000000e+00, %2 ]
%7 = tail call double @pow(double %0, i32 %5)
%8 = tail call i32 @factorial(i32 %5)
%9 = sitofp i32 %8 to double
%10 = fdiv double %7, %9
%11 = fadd double %6, %10
%12 = add nuw nsw i32 %5, 1
%13 = icmp eq i32 %12, %1
br i1 %13, label %14, label %4
14: ; preds = %4, %2
%15 = phi double [ 0.000000e+00, %2 ], [ %11, %4 ]
%16 = add nsw i32 %1, -1
%17 = tail call i32 @factorial(i32 %16)
%18 = sitofp i32 %17 to double
%19 = fneg double %0
%20 = tail call double @exp(double %19)
%21 = fneg double %20
%22 = tail call double @llvm.fmuladd.f64(double %21, double %15, double 1.000000e+00)
%23 = fmul double %22, %18
ret double %23
}