#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
  {
#pragma omp taskgroup
    {
      int dep_arr[3];
      int incr = 0;
      int nlaunched = 0;
      dep_arr[1] = dep_arr[0];
      const unsigned long long spawn_start_time = current_time_ns();
      do {
        if (nlaunched == 0) {
#pragma omp task default(none) firstprivate(incr) depend(out : dep_arr[1])
          { incr = incr + 1; }
        } else {
#pragma omp task default(none) firstprivate(incr) depend(in                    \
                                                         : dep_arr[nlaunched]) \
    depend(out                                                                 \
           : dep_arr[nlaunched + 1])
          { incr = incr + 1; }
        }
        nlaunched++;
      } while (nlaunched < 200000);
      const unsigned long long spawn_end_time = current_time_ns();
      printf("METRIC future_create %d %.20f\n", 200000,
             (double)200000 /
                 ((double)(spawn_end_time - spawn_start_time) / 1000.0));
    }
    const unsigned long long schedule_start_time = current_time_ns();
#pragma omp taskgroup
    {
      int dep_arr[3];
      int incr = 0;
      int nlaunched = 0;
      dep_arr[1] = dep_arr[0];
      do {
        if (nlaunched == 0) {
#pragma omp task default(none) firstprivate(incr) depend(out : dep_arr[1])
          { incr = incr + 1; }
        } else {
#pragma omp task default(none) firstprivate(incr) depend(in                    \
                                                         : dep_arr[nlaunched]) \
    depend(out                                                                 \
           : dep_arr[nlaunched + 1])
          { incr = incr + 1; }
        }
        nlaunched++;
      } while (nlaunched < 200000);
    }
    const unsigned long long schedule_end_time = current_time_ns();
    printf("METRIC future_run %d %.20f\n", 200000,
           (double)200000 /
               ((double)(schedule_end_time - schedule_start_time) / 1000.0));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <current_time_ns@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1198 <main+0x68>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a1 <main+0x71>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x30d40,-0x28(%rbp)
jl     1180 <main+0x50>
xor    %eax,%eax
call   1050 <current_time_ns@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xe37(%rip),%xmm0
punpckldq %xmm0,%xmm1
movapd 0xe3b(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe0c(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xdf8(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xe36(%rip),%rdi
mov    $0x30d40,%esi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <current_time_ns@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x54(%rbp)
jne    1256 <main+0x126>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    125f <main+0x12f>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x30d40,-0x54(%rbp)
jl     123e <main+0x10e>
xor    %eax,%eax
call   1050 <current_time_ns@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xd79(%rip),%xmm0
punpckldq %xmm0,%xmm1
movapd 0xd7d(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd4e(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd3a(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xd97(%rip),%rdi
mov    $0x30d40,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%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    $0x30d40,%esi
mov    $0x1,%al
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 0xe3b(%rip),%xmm0
subpd  0xe43(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  0xe3f(%rip),%xmm1
movsd  0xe3f(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xe74(%rip),%rdi
mov    $0x30d40,%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 = [31 x i8] c"METRIC future_create %d %.20f\0A\00"
@.str.2 = [28 x i8] c"METRIC future_run %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 [3 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca [3 x 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)
store i32 0, i32* %8
store i32 0, i32* %9
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 1
store i32 %21, i32* %22
%23 = call i64 (...) @current_time_ns()
store i64 %23, i64* %10
br label %24
24: ; preds = %36, %2
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %33
30: ; preds = %24
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %33
33: ; preds = %30, %27
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %36
36: ; preds = %33
%37 = load i32, i32* %9
%38 = icmp slt i32 %37, 200000
br i1 %38, label %24, label %39
39: ; preds = %36
%40 = call i64 (...) @current_time_ns()
store i64 %40, i64* %11
%41 = load i64, i64* %11
%42 = load i64, i64* %10
%43 = sub i64 %41, %42
%44 = uitofp i64 %43 to double
%45 = fdiv double %44, 1.000000e+03
%46 = fdiv double 2.000000e+05, %45
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 200000, double %46)
%48 = call i64 (...) @current_time_ns()
store i64 %48, i64* %12
store i32 0, i32* %14
store i32 0, i32* %15
%49 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 0
%50 = load i32, i32* %49
%51 = getelementptr inbounds [3 x i32], [3 x i32]* %13, i64 0, i64 1
store i32 %50, i32* %51
br label %52
52: ; preds = %64, %39
%53 = load i32, i32* %15
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* %14
%57 = add nsw i32 %56, 1
store i32 %57, i32* %14
br label %61
58: ; preds = %52
%59 = load i32, i32* %14
%60 = add nsw i32 %59, 1
store i32 %60, i32* %14
br label %61
61: ; preds = %58, %55
%62 = load i32, i32* %15
%63 = add nsw i32 %62, 1
store i32 %63, i32* %15
br label %64
64: ; preds = %61
%65 = load i32, i32* %15
%66 = icmp slt i32 %65, 200000
br i1 %66, label %52, label %67
67: ; preds = %64
%68 = call i64 (...) @current_time_ns()
store i64 %68, i64* %16
%69 = load i64, i64* %16
%70 = load i64, i64* %12
%71 = sub i64 %69, %70
%72 = uitofp i64 %71 to double
%73 = fdiv double %72, 1.000000e+03
%74 = fdiv double 2.000000e+05, %73
%75 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 200000, double %74)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Using %d OpenMP threads\0A\00"
@.str.1 = [31 x i8] c"METRIC future_create %d %.20f\0A\00"
@.str.2 = [28 x i8] c"METRIC future_run %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 2.000000e+05, %9
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 200000, double %10)
%12 = tail call i64 (...) @current_time_ns()
%13 = tail call i64 (...) @current_time_ns()
%14 = sub i64 %13, %12
%15 = uitofp i64 %14 to double
%16 = fdiv double %15, 1.000000e+03
%17 = fdiv double 2.000000e+05, %16
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 200000, double %17)
ret i32 0
}