#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 sum(double *, int, int);
double sum_omp_tasks_maxthreads(double *v, int low, int high, int nthreads) {
  if (low == high)
    return v[low];
  if (nthreads <= 1)
    return sum(v, low, high);
  double sum_left, sum_right;
  int mid = (low + high) / 2;
#pragma omp task shared(sum_left)
  sum_left = sum_omp_tasks_maxthreads(v, low, mid, nthreads / 2);
#pragma omp task shared(sum_right)
  sum_right =
      sum_omp_tasks_maxthreads(v, mid + 1, high, nthreads - nthreads / 2);
#pragma omp taskwait
  return sum_left + sum_right;
}


x86 assembly (clang, -O0):
<sum_omp_tasks_maxthreads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1158 <sum_omp_tasks_maxthreads+0x38>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f1 <sum_omp_tasks_maxthreads+0xd1>
cmpl   $0x1,-0x1c(%rbp)
jg     117b <sum_omp_tasks_maxthreads+0x5b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <sum@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11f1 <sum_omp_tasks_maxthreads+0xd1>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x3c(%rbp),%edx
mov    %eax,%ecx
call   1040 <sum_omp_tasks_maxthreads@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x1c(%rbp),%eax
mov    $0x2,%r8d
cltd
idiv   %r8d
mov    -0x38(%rbp),%edx
sub    %eax,%ecx
call   1040 <sum_omp_tasks_maxthreads@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_omp_tasks_maxthreads>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
cmp    %edx,%esi
jne    113e <sum_omp_tasks_maxthreads+0x1e>
movslq %esi,%rax
movsd  (%r14,%rax,8),%xmm0
jmp    119e <sum_omp_tasks_maxthreads+0x7e>
mov    %ecx,%r15d
mov    %edx,%ebx
cmp    $0x1,%ecx
jg     115e <sum_omp_tasks_maxthreads+0x3e>
mov    %r14,%rdi
mov    %ebx,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sum@plt>
lea    (%rbx,%rsi,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r15d,%r12d
shr    %r12d
mov    %r14,%rdi
mov    %ebp,%edx
mov    %r12d,%ecx
call   1040 <sum_omp_tasks_maxthreads@plt>
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebp
sub    %r12d,%r15d
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
call   1040 <sum_omp_tasks_maxthreads@plt>
addsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @sum_omp_tasks_maxthreads(double* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca double
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store double* %0, double** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %22
16: ; preds = %4
%17 = load double*, double** %6
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
store double %21, double* %5
br label %53
22: ; preds = %4
%23 = load i32, i32* %9
%24 = icmp sle i32 %23, 1
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load double*, double** %6
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = call double @sum(double* %26, i32 %27, i32 %28)
store double %29, double* %5
br label %53
30: ; preds = %22
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = add nsw i32 %31, %32
%34 = sdiv i32 %33, 2
store i32 %34, i32* %12
%35 = load double*, double** %6
%36 = load i32, i32* %7
%37 = load i32, i32* %12
%38 = load i32, i32* %9
%39 = sdiv i32 %38, 2
%40 = call double @sum_omp_tasks_maxthreads(double* %35, i32 %36, i32 %37, i32 %39)
store double %40, double* %10
%41 = load double*, double** %6
%42 = load i32, i32* %12
%43 = add nsw i32 %42, 1
%44 = load i32, i32* %8
%45 = load i32, i32* %9
%46 = load i32, i32* %9
%47 = sdiv i32 %46, 2
%48 = sub nsw i32 %45, %47
%49 = call double @sum_omp_tasks_maxthreads(double* %41, i32 %43, i32 %44, i32 %48)
store double %49, double* %11
%50 = load double, double* %10
%51 = load double, double* %11
%52 = fadd double %50, %51
store double %52, double* %5
br label %53
53: ; preds = %30, %25, %16
%54 = load double, double* %5
ret double %54
}

LLVM IR (-O2):
define double @sum_omp_tasks_maxthreads(double* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %1, %2
br i1 %5, label %6, label %10
6: ; preds = %4
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds double, double* %0, i64 %7
%9 = load double, double* %8
br label %14
10: ; preds = %4
%11 = icmp slt i32 %3, 2
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = tail call double @sum(double* %0, i32 %1, i32 %2)
br label %14
14: ; preds = %6, %12, %16
%15 = phi double [ %24, %16 ], [ %9, %6 ], [ %13, %12 ]
ret double %15
16: ; preds = %10
%17 = add nsw i32 %2, %1
%18 = sdiv i32 %17, 2
%19 = lshr i32 %3, 1
%20 = tail call double @sum_omp_tasks_maxthreads(double* %0, i32 %1, i32 %18, i32 %19)
%21 = add nsw i32 %18, 1
%22 = sub nsw i32 %3, %19
%23 = tail call double @sum_omp_tasks_maxthreads(double* %0, i32 %21, i32 %2, i32 %22)
%24 = fadd double %20, %23
br label %14
}