#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*/ Rprintf(char *);
int /*<<< orphan*/ gcf(double *, double, double, double *);
int /*<<< orphan*/ gser(double *, double, double, double *);
double gammq(double a, double x) {
  double gamser, gammcf, gln;
  if (x < 0.0 || a <= 0.0) {
    Rprintf("[Error]: Invalid arguments in routine gammq.\n");
    return -1.0;
  }
  if (x < (a + 1.0)) {
    gser(&gamser, a, x, &gln);
    return 1.0 - gamser;
  } else {
    gcf(&gammcf, a, x, &gln);
    return gammcf;
  }
}


x86 assembly (clang, -O0):
<gammq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
ja     115e <gammq+0x2e>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     117c <gammq+0x4c>
lea    0xeab(%rip),%rdi
call   1030 <Rprintf@plt>
movsd  0xe96(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e7 <gammq+0xb7>
movsd  -0x18(%rbp),%xmm1
movsd  0xe77(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c6 <gammq+0x96>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <gser@plt>
movsd  0xe49(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e7 <gammq+0xb7>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <gcf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gammq>:
sub    $0x18,%rsp
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
jae    1178 <gammq+0x48>
ucomisd %xmm1,%xmm2
ja     1178 <gammq+0x48>
movsd  0xeb4(%rip),%xmm2
addsd  %xmm0,%xmm2
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
ucomisd %xmm1,%xmm2
jbe    1191 <gammq+0x61>
call   1040 <gser@plt>
movsd  0xe93(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret
lea    0xe91(%rip),%rdi
call   1030 <Rprintf@plt>
movsd  0xe7c(%rip),%xmm0
add    $0x18,%rsp
ret
call   1050 <gcf@plt>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"[Error]: Invalid arguments in routine gammq.\0A\00"
define double @gammq(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
%9 = load double, double* %5
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load double, double* %4
%13 = fcmp ole double %12, 0.000000e+00
br i1 %13, label %14, label %16
14: ; preds = %11, %2
%15 = call i32 @Rprintf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
store double -1.000000e+00, double* %3
br label %32
16: ; preds = %11
%17 = load double, double* %5
%18 = load double, double* %4
%19 = fadd double %18, 1.000000e+00
%20 = fcmp olt double %17, %19
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load double, double* %4
%23 = load double, double* %5
%24 = call i32 @gser(double* %6, double %22, double %23, double* %8)
%25 = load double, double* %6
%26 = fsub double 1.000000e+00, %25
store double %26, double* %3
br label %32
27: ; preds = %16
%28 = load double, double* %4
%29 = load double, double* %5
%30 = call i32 @gcf(double* %7, double %28, double %29, double* %8)
%31 = load double, double* %7
store double %31, double* %3
br label %32
32: ; preds = %27, %21, %14
%33 = load double, double* %3
ret double %33
}

LLVM IR (-O2):
@.str = [46 x i8] c"[Error]: Invalid arguments in routine gammq.\0A\00"
define double @gammq(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = bitcast double* %3 to i8*
%7 = bitcast double* %4 to i8*
%8 = bitcast double* %5 to i8*
%9 = fcmp olt double %1, 0.000000e+00
%10 = fcmp ole double %0, 0.000000e+00
%11 = or i1 %10, %9
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 @Rprintf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %24
14: ; preds = %2
%15 = fadd double %0, 1.000000e+00
%16 = fcmp ogt double %15, %1
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = call i32 @gser(double* %3, double %0, double %1, double* %5)
%19 = load double, double* %3
%20 = fsub double 1.000000e+00, %19
br label %24
21: ; preds = %14
%22 = call i32 @gcf(double* %4, double %0, double %1, double* %5)
%23 = load double, double* %4
br label %24
24: ; preds = %21, %17, %12
%25 = phi double [ -1.000000e+00, %12 ], [ %20, %17 ], [ %23, %21 ]
ret double %25
}