#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 */
scalar_t__ omp_get_active_level();
scalar_t__ omp_get_max_active_levels();
double sum(double *, int, int);
double sum_omp_fixed_depth(double *v, int low, int high) {
  if (low == high)
    return v[low];
  double sum_left, sum_right;
  int mid = (low + high) / 2;
  if (omp_get_active_level() >= omp_get_max_active_levels()) {
    return sum(v, low, high);
  }
#pragma omp parallel num_threads(2)
  {
#pragma omp sections
    {
#pragma omp section
      sum_left = sum_omp_fixed_depth(v, low, mid);
#pragma omp section
      sum_right = sum_omp_fixed_depth(v, mid + 1, high);
    }
  }
  return sum_left + sum_right;
}


x86 assembly (clang, -O0):
<sum_omp_fixed_depth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1175 <sum_omp_fixed_depth+0x35>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11fb <sum_omp_fixed_depth+0xbb>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1060 <omp_get_active_level@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <omp_get_max_active_levels@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jl     11c1 <sum_omp_fixed_depth+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <sum@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11fb <sum_omp_fixed_depth+0xbb>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1050 <sum_omp_fixed_depth@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
call   1050 <sum_omp_fixed_depth@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_omp_fixed_depth>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
cmp    %edx,%esi
jne    1160 <sum_omp_fixed_depth+0x20>
movslq %ebx,%rax
movsd  (%r14,%rax,8),%xmm0
jmp    11ae <sum_omp_fixed_depth+0x6e>
mov    %edx,%r15d
xor    %eax,%eax
call   1060 <omp_get_active_level@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <omp_get_max_active_levels@plt>
cmp    %rax,%r12
jge    11bb <sum_omp_fixed_depth+0x7b>
lea    (%r15,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1050 <sum_omp_fixed_depth@plt>
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1050 <sum_omp_fixed_depth@plt>
addsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sum@plt>

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

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