#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 /*<<< orphan*/ chiGammaFlagError(char *);
double exp(double);
double fabs(double);
double gammln(double);
double log(double);
void gser(double *gamser, double a, double x, double *gln) {
  int n;
  double sum, del, ap;
  *gln = gammln(a);
  if (x <= 0.0) {
    if (x < 0.0)
      chiGammaFlagError("x less than 0 in routine gser");
    *gamser = 0.0;
    return;
  } else {
    ap = a;
    del = sum = 1.0 / a;
    for (n = 1; n <= 10000000; n++) {
      ++ap;
      del *= x / ap;
      sum += del;
      if (fabs(del) < fabs(sum) * 3.0e-7) {
        *gamser = sum * exp(-x + a * log(x) - (*gln));
        return;
      }
    }
    chiGammaFlagError("a too large, ITMAX too small in routine gser");
    return;
  }
}


x86 assembly (clang, -O0):
<gser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <gammln@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     11a4 <gser+0x64>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1194 <gser+0x54>
lea    0xe91(%rip),%rdi
call   1030 <chiGammaFlagError@plt>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    12dd <gser+0x19d>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe4a(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x989680,-0x24(%rbp)
jg     12d1 <gser+0x191>
movsd  0xe1f(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm1
movaps 0xdf6(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movaps 0xde6(%rip),%xmm2
pand   %xmm2,%xmm0
movsd  0xdd2(%rip),%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    12be <gser+0x17e>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
subsd  (%rax),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    12dd <gser+0x19d>
jmp    12c3 <gser+0x183>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cc <gser+0x8c>
lea    0xd66(%rip),%rdi
call   1030 <chiGammaFlagError@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gser>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
movsd  %xmm1,0x8(%rsp)
mov    %rdi,%r14
movsd  %xmm0,(%rsp)
call   1060 <gammln@plt>
movsd  0x8(%rsp),%xmm7
movsd  %xmm0,(%rbx)
xorpd  %xmm0,%xmm0
ucomisd %xmm7,%xmm0
jae    11fb <gser+0xbb>
movsd  0xe82(%rip),%xmm9
movapd %xmm9,%xmm3
movsd  (%rsp),%xmm8
divsd  %xmm8,%xmm3
mov    $0x989680,%eax
movapd 0xe75(%rip),%xmm1
movsd  0xe65(%rip),%xmm0
movapd %xmm8,%xmm4
movapd %xmm3,%xmm2
nopl   0x0(%rax)
movapd %xmm3,%xmm5
addsd  %xmm9,%xmm4
movapd %xmm7,%xmm3
divsd  %xmm4,%xmm3
mulsd  %xmm5,%xmm3
addsd  %xmm3,%xmm2
movapd %xmm3,%xmm5
andpd  %xmm1,%xmm5
movapd %xmm2,%xmm6
andpd  %xmm1,%xmm6
mulsd  %xmm0,%xmm6
ucomisd %xmm5,%xmm6
ja     1212 <gser+0xd2>
add    $0xffffffff,%eax
jne    11b0 <gser+0x70>
lea    0xe4f(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1030 <chiGammaFlagError@plt>
jbe    1209 <gser+0xc9>
lea    0xe1c(%rip),%rdi
call   1030 <chiGammaFlagError@plt>
movq   $0x0,(%r14)
jmp    1244 <gser+0x104>
movapd %xmm7,%xmm0
movapd %xmm2,0x10(%rsp)
call   1050 <log@plt>
mulsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
subsd  (%rbx),%xmm0
call   1040 <exp@plt>
movapd 0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [30 x i8] c"x less than 0 in routine gser\00"
@.str.1 = [45 x i8] c"a too large, ITMAX too small in routine gser\00"
define void @gser(double* %0, double %1, double %2, double* %3) {
%5 = alloca double*
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
store double* %0, double** %5
store double %1, double* %6
store double %2, double* %7
store double* %3, double** %8
%13 = load double, double* %6
%14 = call double @gammln(double %13)
%15 = load double*, double** %8
store double %14, double* %15
%16 = load double, double* %7
%17 = fcmp ole double %16, 0.000000e+00
br i1 %17, label %18, label %25
18: ; preds = %4
%19 = load double, double* %7
%20 = fcmp olt double %19, 0.000000e+00
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @chiGammaFlagError(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load double*, double** %5
store double 0.000000e+00, double* %24
br label %69
25: ; preds = %4
%26 = load double, double* %6
store double %26, double* %12
%27 = load double, double* %6
%28 = fdiv double 1.000000e+00, %27
store double %28, double* %10
store double %28, double* %11
store i32 1, i32* %9
br label %29
29: ; preds = %64, %25
%30 = load i32, i32* %9
%31 = icmp sle i32 %30, 10000000
br i1 %31, label %32, label %67
32: ; preds = %29
%33 = load double, double* %12
%34 = fadd double %33, 1.000000e+00
store double %34, double* %12
%35 = load double, double* %7
%36 = load double, double* %12
%37 = fdiv double %35, %36
%38 = load double, double* %11
%39 = fmul double %38, %37
store double %39, double* %11
%40 = load double, double* %11
%41 = load double, double* %10
%42 = fadd double %41, %40
store double %42, double* %10
%43 = load double, double* %11
%44 = call double @llvm.fabs.f64(double %43)
%45 = load double, double* %10
%46 = call double @llvm.fabs.f64(double %45)
%47 = fmul double %46, 3.000000e-07
%48 = fcmp olt double %44, %47
br i1 %48, label %49, label %63
49: ; preds = %32
%50 = load double, double* %10
%51 = load double, double* %7
%52 = fneg double %51
%53 = load double, double* %6
%54 = load double, double* %7
%55 = call double @log(double %54)
%56 = call double @llvm.fmuladd.f64(double %53, double %55, double %52)
%57 = load double*, double** %8
%58 = load double, double* %57
%59 = fsub double %56, %58
%60 = call double @exp(double %59)
%61 = fmul double %50, %60
%62 = load double*, double** %5
store double %61, double* %62
br label %69
63: ; preds = %32
br label %64
64: ; preds = %63
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %29
67: ; preds = %29
%68 = call i32 @chiGammaFlagError(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %69
69: ; preds = %67, %49, %23
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"x less than 0 in routine gser\00"
@.str.1 = [45 x i8] c"a too large, ITMAX too small in routine gser\00"
define void @gser(double* nocapture writeonly %0, double %1, double %2, double* nocapture %3) {
%5 = tail call double @gammln(double %1)
store double %5, double* %3
%6 = fcmp ugt double %2, 0.000000e+00
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = fcmp olt double %2, 0.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @chiGammaFlagError(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
store double 0.000000e+00, double* %0
br label %40
12: ; preds = %4
%13 = fdiv double 1.000000e+00, %1
br label %17
14: ; preds = %17
%15 = add nuw nsw i32 %21, 1
%16 = icmp eq i32 %15, 10000001
br i1 %16, label %38, label %17
17: ; preds = %12, %14
%18 = phi double [ %1, %12 ], [ %22, %14 ]
%19 = phi double [ %13, %12 ], [ %24, %14 ]
%20 = phi double [ %13, %12 ], [ %25, %14 ]
%21 = phi i32 [ 1, %12 ], [ %15, %14 ]
%22 = fadd double %18, 1.000000e+00
%23 = fdiv double %2, %22
%24 = fmul double %19, %23
%25 = fadd double %20, %24
%26 = tail call double @llvm.fabs.f64(double %24)
%27 = tail call double @llvm.fabs.f64(double %25)
%28 = fmul double %27, 3.000000e-07
%29 = fcmp olt double %26, %28
br i1 %29, label %30, label %14
30: ; preds = %17
%31 = fneg double %2
%32 = tail call double @log(double %2)
%33 = tail call double @llvm.fmuladd.f64(double %1, double %32, double %31)
%34 = load double, double* %3
%35 = fsub double %33, %34
%36 = tail call double @exp(double %35)
%37 = fmul double %25, %36
store double %37, double* %0
br label %40
38: ; preds = %14
%39 = tail call i32 @chiGammaFlagError(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %30, %11
ret void
}