#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 dandc_sum(const double *a, const size_t lo, const size_t hi) {
  return (hi - lo) < 2 ? a[lo]
                       : dandc_sum(a, lo, (hi + lo) / 2) +
                             dandc_sum(a, (hi + lo) / 2, hi);
}


x86 assembly (clang, -O0):
<dandc_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cmp    $0x2,%rax
jae    114d <dandc_sum+0x3d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1195 <dandc_sum+0x85>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    -0x10(%rbp),%rdx
shr    $0x1,%rdx
call   1030 <dandc_sum@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    -0x10(%rbp),%rsi
shr    $0x1,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <dandc_sum@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dandc_sum>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    %rdx,%rax
sub    %rsi,%rax
cmp    $0x1,%rax
ja     1130 <dandc_sum+0x20>
movsd  (%r14,%rsi,8),%xmm0
jmp    115f <dandc_sum+0x4f>
mov    %rdx,%r15
lea    (%rdx,%rsi,1),%rbx
shr    %rbx
mov    %r14,%rdi
mov    %rbx,%rdx
call   1030 <dandc_sum@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <dandc_sum@plt>
addsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @dandc_sum(double* %0, i64 %1, i64 %2) {
%4 = alloca double*
%5 = alloca i64
%6 = alloca i64
store double* %0, double** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%7 = load i64, i64* %6
%8 = load i64, i64* %5
%9 = sub i64 %7, %8
%10 = icmp ult i64 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = load double*, double** %4
%13 = load i64, i64* %5
%14 = getelementptr inbounds double, double* %12, i64 %13
%15 = load double, double* %14
br label %32
16: ; preds = %3
%17 = load double*, double** %4
%18 = load i64, i64* %5
%19 = load i64, i64* %6
%20 = load i64, i64* %5
%21 = add i64 %19, %20
%22 = udiv i64 %21, 2
%23 = call double @dandc_sum(double* %17, i64 %18, i64 %22)
%24 = load double*, double** %4
%25 = load i64, i64* %6
%26 = load i64, i64* %5
%27 = add i64 %25, %26
%28 = udiv i64 %27, 2
%29 = load i64, i64* %6
%30 = call double @dandc_sum(double* %24, i64 %28, i64 %29)
%31 = fadd double %23, %30
br label %32
32: ; preds = %16, %11
%33 = phi double [ %15, %11 ], [ %31, %16 ]
ret double %33
}

LLVM IR (-O2):
define double @dandc_sum(double* %0, i64 %1, i64 %2) {
%4 = sub i64 %2, %1
%5 = icmp ult i64 %4, 2
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = getelementptr inbounds double, double* %0, i64 %1
%8 = load double, double* %7
br label %9
9: ; preds = %6, %11
%10 = phi double [ %16, %11 ], [ %8, %6 ]
ret double %10
11: ; preds = %3
%12 = add i64 %2, %1
%13 = lshr i64 %12, 1
%14 = tail call double @dandc_sum(double* %0, i64 %1, i64 %13)
%15 = tail call double @dandc_sum(double* %0, i64 %13, i64 %2)
%16 = fadd double %14, %15
br label %9
}