#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 incr = 0;
      int nlaunched = 0;
      const unsigned long long spawn_start_time = current_time_ns();
      do {
#pragma omp task default(none) firstprivate(incr)
        { incr = incr + 1; }
        nlaunched++;
      } while (nlaunched < 200000);
      const unsigned long long spawn_end_time = current_time_ns();
      printf("METRIC task_create %d %.20f\n", 200000,
             (double)200000 /
                 ((double)(spawn_end_time - spawn_start_time) / 1000.0));
    }
    int incr = 0;
    int nlaunched = 0;
    const unsigned long long schedule_start_time = current_time_ns();
#pragma omp taskgroup
    {
      nlaunched = 0;
      do {
#pragma omp task default(none) firstprivate(incr)
        { incr = incr + 1; }
        nlaunched++;
      } while (nlaunched < 200000);
    }
    const unsigned long long schedule_end_time = current_time_ns();
    printf("METRIC task_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    $0x50,%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,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <current_time_ns@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x30d40,-0x1c(%rbp)
jl     117a <main+0x4a>
xor    %eax,%eax
call   1050 <current_time_ns@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xe55(%rip),%xmm0
punpckldq %xmm0,%xmm1
movapd 0xe59(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe2a(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe16(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xe54(%rip),%rdi
mov    $0x30d40,%esi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    $0x0,%al
call   1050 <current_time_ns@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x30d40,-0x38(%rbp)
jl     1221 <main+0xf1>
xor    %eax,%eax
call   1050 <current_time_ns@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xdae(%rip),%xmm0
punpckldq %xmm0,%xmm1
movapd 0xdb2(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd83(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd6f(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xdca(%rip),%rdi
mov    $0x30d40,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%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    0xe72(%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 = [29 x i8] c"METRIC task_create %d %.20f\0A\00"
@.str.2 = [26 x i8] c"METRIC task_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 i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32 (...) @omp_get_num_threads()
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 0, i32* %7
store i32 0, i32* %8
%18 = call i64 (...) @current_time_ns()
store i64 %18, i64* %9
br label %19
19: ; preds = %24, %2
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
br label %24
24: ; preds = %19
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 200000
br i1 %26, label %19, label %27
27: ; preds = %24
%28 = call i64 (...) @current_time_ns()
store i64 %28, i64* %10
%29 = load i64, i64* %10
%30 = load i64, i64* %9
%31 = sub i64 %29, %30
%32 = uitofp i64 %31 to double
%33 = fdiv double %32, 1.000000e+03
%34 = fdiv double 2.000000e+05, %33
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 200000, double %34)
store i32 0, i32* %11
store i32 0, i32* %12
%36 = call i64 (...) @current_time_ns()
store i64 %36, i64* %13
store i32 0, i32* %12
br label %37
37: ; preds = %42, %27
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
store i32 %39, i32* %11
%40 = load i32, i32* %12
%41 = add nsw i32 %40, 1
store i32 %41, i32* %12
br label %42
42: ; preds = %37
%43 = load i32, i32* %12
%44 = icmp slt i32 %43, 200000
br i1 %44, label %37, label %45
45: ; preds = %42
%46 = call i64 (...) @current_time_ns()
store i64 %46, i64* %14
%47 = load i64, i64* %14
%48 = load i64, i64* %13
%49 = sub i64 %47, %48
%50 = uitofp i64 %49 to double
%51 = fdiv double %50, 1.000000e+03
%52 = fdiv double 2.000000e+05, %51
%53 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 200000, double %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Using %d OpenMP threads\0A\00"
@.str.1 = [29 x i8] c"METRIC task_create %d %.20f\0A\00"
@.str.2 = [26 x i8] c"METRIC task_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 ([29 x i8], [29 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 ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 200000, double %17)
ret i32 0
}