#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 i;
    const unsigned long long group_start_time = current_time_ns();
    for (i = 0; i < 200000; i++) {
      int incr = 0;
#pragma omp taskgroup
      {
#pragma omp task default(none) firstprivate(incr)
        { incr = incr + 1; }
      }
    }
    const unsigned long long group_end_time = current_time_ns();
    printf("METRIC task_wait_flat %d %.20f\n", 200000,
           (double)200000 /
               ((double)(group_end_time - group_start_time) / 1000.0));
    const unsigned long long wait_start_time = current_time_ns();
    for (i = 0; i < 200000; i++) {
      int incr = 0;
#pragma omp task default(none) firstprivate(incr)
      { incr = incr + 1; }
#pragma omp taskwait
    }
    const unsigned long long wait_end_time = current_time_ns();
    printf("METRIC task_wait_flat %d %.20f\n", 200000,
           (double)200000 /
               ((double)(wait_end_time - wait_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>
mov    $0x0,%al
call   1050 <current_time_ns@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x30d40,-0x18(%rbp)
jge    119e <main+0x6e>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1173 <main+0x43>
xor    %eax,%eax
call   1050 <current_time_ns@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xe50(%rip),%xmm0
punpckldq %xmm0,%xmm1
movapd 0xe54(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe25(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe11(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xe4f(%rip),%rdi
mov    $0x30d40,%esi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <current_time_ns@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x30d40,-0x18(%rbp)
jge    1243 <main+0x113>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1218 <main+0xe8>
xor    %eax,%eax
call   1050 <current_time_ns@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xdab(%rip),%xmm0
punpckldq %xmm0,%xmm1
movapd 0xdaf(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd80(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd6c(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xdaa(%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   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <omp_get_num_threads@plt>
lea    0xeee(%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 0xe94(%rip),%xmm0
subpd  0xe9c(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  0xe98(%rip),%xmm1
movsd  0xe98(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xeae(%rip),%r14
mov    %r14,%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 0xe35(%rip),%xmm0
subpd  0xe3d(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  0xe39(%rip),%xmm1
movsd  0xe39(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    %r14,%rdi
mov    $0x30d40,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Using %d OpenMP threads\0A\00"
@.str.1 = [32 x i8] c"METRIC task_wait_flat %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 i64
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (...) @omp_get_num_threads()
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i64 (...) @current_time_ns()
store i64 %17, i64* %8
store i32 0, i32* %7
br label %18
18: ; preds = %24, %2
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 200000
br i1 %20, label %21, label %27
21: ; preds = %18
store i32 0, i32* %9
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %9
br label %24
24: ; preds = %21
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %18
27: ; preds = %18
%28 = call i64 (...) @current_time_ns()
store i64 %28, i64* %10
%29 = load i64, i64* %10
%30 = load i64, i64* %8
%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 ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 200000, double %34)
%36 = call i64 (...) @current_time_ns()
store i64 %36, i64* %11
store i32 0, i32* %7
br label %37
37: ; preds = %43, %27
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 200000
br i1 %39, label %40, label %46
40: ; preds = %37
store i32 0, i32* %12
%41 = load i32, i32* %12
%42 = add nsw i32 %41, 1
store i32 %42, i32* %12
br label %43
43: ; preds = %40
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %37
46: ; preds = %37
%47 = call i64 (...) @current_time_ns()
store i64 %47, i64* %13
%48 = load i64, i64* %13
%49 = load i64, i64* %11
%50 = sub i64 %48, %49
%51 = uitofp i64 %50 to double
%52 = fdiv double %51, 1.000000e+03
%53 = fdiv double 2.000000e+05, %52
%54 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 200000, double %53)
ret i32 0
}

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