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


x86 assembly (clang, -O0):
<gser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1070 <gammln@plt>
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     11b7 <gser+0x67>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    119d <gser+0x4d>
lea    0xe78(%rip),%rdi
call   1050 <error@plt>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12f9 <gser+0x1a9>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe37(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    12e0 <gser+0x190>
movsd  0xe0f(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%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),%xmm0
call   1030 <fabs@plt>
mov    %eax,-0x4c(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
mov    0x2da7(%rip),%rdx
imul   (%rdx),%ecx
cmp    %ecx,%eax
jge    12cd <gser+0x17d>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movsd  -0x68(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x48(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12f9 <gser+0x1a9>
jmp    12d2 <gser+0x182>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11df <gser+0x8f>
lea    0xd47(%rip),%rdi
call   1050 <error@plt>
movsd  0xd14(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gser>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movsd  %xmm1,0x10(%rsp)
mov    %rdi,%r14
movsd  %xmm0,0x20(%rsp)
call   1070 <gammln@plt>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd 0x10(%rsp),%xmm0
jae    1227 <gser+0xd7>
movsd  %xmm1,0x8(%rsp)
movsd  0xe70(%rip),%xmm0
movsd  0x20(%rsp),%xmm1
divsd  %xmm1,%xmm0
mov    $0x64,%ebx
mov    0x2e42(%rip),%r15
movsd  %xmm0,0x18(%rsp)
nopl   0x0(%rax)
movapd %xmm0,%xmm2
addsd  0xe44(%rip),%xmm1
movsd  0x10(%rsp),%xmm0
movsd  %xmm1,0x30(%rsp)
divsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x28(%rsp)
call   1030 <fabs@plt>
mov    %eax,%ebp
movsd  0x18(%rsp),%xmm0
call   1030 <fabs@plt>
imul   (%r15),%eax
cmp    %eax,%ebp
jl     124a <gser+0xfa>
add    $0xffffffff,%ebx
movsd  0x30(%rsp),%xmm1
movsd  0x28(%rsp),%xmm0
jne    11b0 <gser+0x60>
lea    0xe16(%rip),%rdi
call   1050 <error@plt>
movsd  0xde3(%rip),%xmm1
jmp    1281 <gser+0x131>
jbe    1241 <gser+0xf1>
lea    0xde0(%rip),%rdi
movsd  %xmm1,0x8(%rsp)
call   1050 <error@plt>
movsd  0x8(%rsp),%xmm1
movq   $0x0,(%r14)
jmp    1281 <gser+0x131>
movsd  0x10(%rsp),%xmm0
call   1060 <log@plt>
mulsd  0x20(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
call   1040 <exp@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,(%r14)
movapd %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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