#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 single_prob(int, int, int, int, double, int);
double quad_recur(int n, int A, int n0, int A0, double psi) {
  int area_ratio, q;
  double total = 0;
  area_ratio = A0 / A;
  if (area_ratio == 4) {
    return single_prob(n, A, n0, A0, psi, 4);
  } else {
    A = A * 4;
    for (q = n; q < (n0 + 1); q++) {
      total += quad_recur(q, A, n0, A0, psi) * single_prob(n, A, q, A0, psi, 4);
    }
    return total;
  }
}


x86 assembly (clang, -O0):
<quad_recur>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jne    117b <quad_recur+0x5b>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
movsd  -0x20(%rbp),%xmm0
mov    $0x4,%r8d
call   1030 <single_prob@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1204 <quad_recur+0xe4>
mov    -0x10(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11fa <quad_recur+0xda>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
movsd  -0x20(%rbp),%xmm0
call   1040 <quad_recur@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x18(%rbp),%ecx
movsd  -0x20(%rbp),%xmm0
mov    $0x4,%r8d
call   1030 <single_prob@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    118a <quad_recur+0x6a>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quad_recur>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
mov    %ecx,%eax
cltd
idiv   %esi
cmp    $0x4,%eax
jne    1167 <quad_recur+0x47>
mov    %r15d,%edi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %r12d,%ecx
mov    $0x4,%r8d
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <single_prob@plt>
xorpd  %xmm1,%xmm1
cmp    %r14d,%r15d
jg     11e2 <quad_recur+0xc2>
shl    $0x2,%ebp
lea    0x1(%r14),%r13d
xorpd  %xmm1,%xmm1
mov    %r15d,%ebx
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm1,0x10(%rsp)
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %r12d,%ecx
movsd  (%rsp),%xmm0
call   1040 <quad_recur@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
movsd  (%rsp),%xmm0
mov    $0x4,%r8d
call   1030 <single_prob@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm1
add    $0x1,%ebx
cmp    %ebx,%r13d
jne    1190 <quad_recur+0x70>
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @quad_recur(i32 %0, i32 %1, i32 %2, i32 %3, double %4) {
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store double %4, double* %11
store double 0.000000e+00, double* %14
%15 = load i32, i32* %10
%16 = load i32, i32* %8
%17 = sdiv i32 %15, %16
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = icmp eq i32 %18, 4
br i1 %19, label %20, label %27
20: ; preds = %5
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = load i32, i32* %9
%24 = load i32, i32* %10
%25 = load double, double* %11
%26 = call double @single_prob(i32 %21, i32 %22, i32 %23, i32 %24, double %25, i32 4)
store double %26, double* %6
br label %56
27: ; preds = %5
%28 = load i32, i32* %8
%29 = mul nsw i32 %28, 4
store i32 %29, i32* %8
%30 = load i32, i32* %7
store i32 %30, i32* %13
br label %31
31: ; preds = %51, %27
%32 = load i32, i32* %13
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %54
36: ; preds = %31
%37 = load i32, i32* %13
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = load i32, i32* %10
%41 = load double, double* %11
%42 = call double @quad_recur(i32 %37, i32 %38, i32 %39, i32 %40, double %41)
%43 = load i32, i32* %7
%44 = load i32, i32* %8
%45 = load i32, i32* %13
%46 = load i32, i32* %10
%47 = load double, double* %11
%48 = call double @single_prob(i32 %43, i32 %44, i32 %45, i32 %46, double %47, i32 4)
%49 = load double, double* %14
%50 = call double @llvm.fmuladd.f64(double %42, double %48, double %49)
store double %50, double* %14
br label %51
51: ; preds = %36
%52 = load i32, i32* %13
%53 = add nsw i32 %52, 1
store i32 %53, i32* %13
br label %31
54: ; preds = %31
%55 = load double, double* %14
store double %55, double* %6
br label %56
56: ; preds = %54, %20
%57 = load double, double* %6
ret double %57
}

LLVM IR (-O2):
define double @quad_recur(i32 %0, i32 %1, i32 %2, i32 %3, double %4) {
%6 = sdiv i32 %3, %1
%7 = icmp eq i32 %6, 4
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call double @single_prob(i32 %0, i32 %1, i32 %2, i32 %3, double %4, i32 4)
br label %21
10: ; preds = %5
%11 = shl nsw i32 %1, 2
%12 = icmp sgt i32 %0, %2
br i1 %12, label %21, label %13
13: ; preds = %10, %13
%14 = phi double [ %18, %13 ], [ 0.000000e+00, %10 ]
%15 = phi i32 [ %19, %13 ], [ %0, %10 ]
%16 = tail call double @quad_recur(i32 %15, i32 %11, i32 %2, i32 %3, double %4)
%17 = tail call double @single_prob(i32 %0, i32 %11, i32 %15, i32 %3, double %4, i32 4)
%18 = tail call double @llvm.fmuladd.f64(double %16, double %17, double %14)
%19 = add i32 %15, 1
%20 = icmp eq i32 %15, %2
br i1 %20, label %21, label %13
21: ; preds = %13, %10, %8
%22 = phi double [ %9, %8 ], [ 0.000000e+00, %10 ], [ %18, %13 ]
ret double %22
}