#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 */
unsigned long long current_time_ns();
int omp_get_num_threads();
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char **argv) {
  int nthreads;
#pragma omp parallel default(none) shared(nthreads)
#pragma omp master
  { nthreads = omp_get_num_threads(); }
  printf("Using %d OpenMP threads\n", nthreads);
#pragma omp parallel default(none)
#pragma omp master
  {
    int initial_dep[1];
    int dep_arr[1][50000];
    dep_arr[0][0] = dep_arr[0][0];
    initial_dep[0] = initial_dep[0];
    int incr = 0;
    const unsigned long long start_time = current_time_ns();
#pragma omp taskgroup
    {
#pragma omp task default(none) depend(out : initial_dep[0])
      {}
      int i;
      for (i = 0; i < 50000; i++) {
#pragma omp task default(none) firstprivate(incr) depend(in                    \
                                                         : initial_dep[0])     \
    depend(out                                                                 \
           : dep_arr[0][i])
        { incr = incr + 1; }
      }
      int wavefront = 1;
      int nfutures = 50000;
      while (nfutures > 1) {
        int next_nfutures = 0;
        for (i = 0; i < nfutures; i += 4) {
          int this_n_futures = nfutures - i;
          if (this_n_futures > 4)
            this_n_futures = 4;
#pragma omp task default(none)                                                 \
    depend(in                                                                  \
           : dep_arr[wavefront - 1] [i:this_n_futures])                        \
        depend(out                                                             \
               : dep_arr[wavefront][i]) firstprivate(incr)
          { incr = incr + 1; }
        }
        nfutures = next_nfutures;
        wavefront++;
      }
    }
    const unsigned long long end_time = current_time_ns();
    printf("METRIC fan_out_and_in %d %.20f\n", 50000,
           (double)50000 / ((double)(end_time - start_time) / 1000.0));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30d90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <omp_get_num_threads@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30d60(%rbp),%eax
mov    %eax,-0x30d60(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x30d64(%rbp)
mov    $0x0,%al
call   1050 <current_time_ns@plt>
mov    %rax,-0x30d70(%rbp)
movl   $0x0,-0x30d74(%rbp)
cmpl   $0xc350,-0x30d74(%rbp)
jge    11cb <main+0x9b>
mov    -0x30d64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30d64(%rbp)
mov    -0x30d74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30d74(%rbp)
jmp    1198 <main+0x68>
movl   $0x1,-0x30d78(%rbp)
movl   $0xc350,-0x30d7c(%rbp)
cmpl   $0x1,-0x30d7c(%rbp)
jle    127e <main+0x14e>
movl   $0x0,-0x30d80(%rbp)
movl   $0x0,-0x30d74(%rbp)
mov    -0x30d74(%rbp),%eax
cmp    -0x30d7c(%rbp),%eax
jge    125e <main+0x12e>
mov    -0x30d7c(%rbp),%eax
sub    -0x30d74(%rbp),%eax
mov    %eax,-0x30d84(%rbp)
cmpl   $0x4,-0x30d84(%rbp)
jle    123b <main+0x10b>
movl   $0x4,-0x30d84(%rbp)
mov    -0x30d64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30d64(%rbp)
mov    -0x30d74(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x30d74(%rbp)
jmp    1200 <main+0xd0>
mov    -0x30d80(%rbp),%eax
mov    %eax,-0x30d7c(%rbp)
mov    -0x30d78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30d78(%rbp)
jmp    11df <main+0xaf>
xor    %eax,%eax
call   1050 <current_time_ns@plt>
mov    %rax,-0x30d90(%rbp)
mov    -0x30d90(%rbp),%rax
mov    -0x30d70(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xd67(%rip),%xmm0
punpckldq %xmm0,%xmm1
movapd 0xd6b(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd3c(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd28(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xd66(%rip),%rdi
mov    $0xc350,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30d90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
lea    0xef1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <current_time_ns@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <current_time_ns@plt>
sub    %rbx,%rax
movq   %rax,%xmm0
punpckldq 0xe97(%rip),%xmm0
subpd  0xe9f(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  0xe9b(%rip),%xmm1
movsd  0xe9b(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xeb1(%rip),%rdi
mov    $0xc350,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Using %d OpenMP threads\0A\00"
@.str.1 = [32 x i8] c"METRIC fan_out_and_in %d %.20f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1 x i32]
%8 = alloca [1 x [50000 x i32]]
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = call i32 (...) @omp_get_num_threads()
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [1 x [50000 x i32]], [1 x [50000 x i32]]* %8, i64 0, i64 0
%21 = getelementptr inbounds [50000 x i32], [50000 x i32]* %20, i64 0, i64 0
%22 = load i32, i32* %21
%23 = getelementptr inbounds [1 x [50000 x i32]], [1 x [50000 x i32]]* %8, i64 0, i64 0
%24 = getelementptr inbounds [50000 x i32], [50000 x i32]* %23, i64 0, i64 0
store i32 %22, i32* %24
%25 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
store i32 %26, i32* %27
store i32 0, i32* %9
%28 = call i64 (...) @current_time_ns()
store i64 %28, i64* %10
store i32 0, i32* %11
br label %29
29: ; preds = %35, %2
%30 = load i32, i32* %11
%31 = icmp slt i32 %30, 50000
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %35
35: ; preds = %32
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 1
store i32 %37, i32* %11
br label %29
38: ; preds = %29
store i32 1, i32* %12
store i32 50000, i32* %13
br label %39
39: ; preds = %60, %38
%40 = load i32, i32* %13
%41 = icmp sgt i32 %40, 1
br i1 %41, label %42, label %64
42: ; preds = %39
store i32 0, i32* %14
store i32 0, i32* %11
br label %43
43: ; preds = %57, %42
%44 = load i32, i32* %11
%45 = load i32, i32* %13
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %60
47: ; preds = %43
%48 = load i32, i32* %13
%49 = load i32, i32* %11
%50 = sub nsw i32 %48, %49
store i32 %50, i32* %15
%51 = load i32, i32* %15
%52 = icmp sgt i32 %51, 4
br i1 %52, label %53, label %54
53: ; preds = %47
store i32 4, i32* %15
br label %54
54: ; preds = %53, %47
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %57
57: ; preds = %54
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 4
store i32 %59, i32* %11
br label %43
60: ; preds = %43
%61 = load i32, i32* %14
store i32 %61, i32* %13
%62 = load i32, i32* %12
%63 = add nsw i32 %62, 1
store i32 %63, i32* %12
br label %39
64: ; preds = %39
%65 = call i64 (...) @current_time_ns()
store i64 %65, i64* %16
%66 = load i64, i64* %16
%67 = load i64, i64* %10
%68 = sub i64 %66, %67
%69 = uitofp i64 %68 to double
%70 = fdiv double %69, 1.000000e+03
%71 = fdiv double 5.000000e+04, %70
%72 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 50000, double %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Using %d OpenMP threads\0A\00"
@.str.1 = [32 x i8] c"METRIC fan_out_and_in %d %.20f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @omp_get_num_threads()
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i64 (...) @current_time_ns()
%6 = tail call i64 (...) @current_time_ns()
%7 = sub i64 %6, %5
%8 = uitofp i64 %7 to double
%9 = fdiv double %8, 1.000000e+03
%10 = fdiv double 5.000000e+04, %9
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 50000, double %10)
ret i32 0
}