#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 /*<<< orphan*/ recursive_group_task(int /*<<< orphan*/);
int /*<<< orphan*/ recursive_wait_task(int /*<<< orphan*/);
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
  {
    const unsigned long long group_start_time = current_time_ns();
    recursive_group_task(0);
    const unsigned long long group_end_time = current_time_ns();
    printf("METRIC task_wait_recursive %d %.20f\n", 1000,
           (double)1000 /
               ((double)(group_end_time - group_start_time) / 1000.0));
    const unsigned long long wait_start_time = current_time_ns();
    recursive_wait_task(0);
    const unsigned long long wait_end_time = current_time_ns();
    printf("METRIC task_wait_recursive %d %.20f\n", 1000,
           (double)1000 / ((double)(wait_end_time - wait_start_time) / 1000.0));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,-0x68(%rbp)
mov    %al,-0x61(%rbp)
call   1050 <omp_get_num_threads@plt>
mov    %eax,%ecx
mov    -0x61(%rbp),%al
mov    %ecx,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    -0x61(%rbp),%al
call   1070 <current_time_ns@plt>
mov    -0x68(%rbp),%edi
mov    %rax,-0x20(%rbp)
call   1060 <recursive_group_task@plt>
mov    -0x61(%rbp),%al
call   1070 <current_time_ns@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xe4f(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
punpckldq %xmm0,%xmm1
movapd 0xe4f(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe14(%rip),%xmm0
divsd  %xmm0,%xmm1
divsd  %xmm1,%xmm0
lea    0xe4e(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x61(%rbp),%al
call   1070 <current_time_ns@plt>
mov    -0x68(%rbp),%edi
mov    %rax,-0x30(%rbp)
call   1040 <recursive_wait_task@plt>
mov    -0x61(%rbp),%al
call   1070 <current_time_ns@plt>
movaps -0x60(%rbp),%xmm2
movaps -0x50(%rbp),%xmm0
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
punpckldq %xmm2,%xmm1
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xda6(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd9a(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xdd8(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
lea    0xec6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <current_time_ns@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1060 <recursive_group_task@plt>
xor    %eax,%eax
call   1070 <current_time_ns@plt>
sub    %rbx,%rax
movq   %rax,%xmm0
punpckldq 0xe6d(%rip),%xmm0
subpd  0xe75(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe71(%rip),%xmm0
divsd  %xmm0,%xmm1
divsd  %xmm1,%xmm0
lea    0xe83(%rip),%r14
mov    %r14,%rdi
mov    $0x3e8,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <current_time_ns@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1040 <recursive_wait_task@plt>
xor    %eax,%eax
call   1070 <current_time_ns@plt>
sub    %rbx,%rax
movq   %rax,%xmm0
punpckldq 0xe0b(%rip),%xmm0
subpd  0xe13(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe0f(%rip),%xmm0
divsd  %xmm0,%xmm1
divsd  %xmm1,%xmm0
mov    %r14,%rdi
mov    $0x3e8,%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 = [37 x i8] c"METRIC task_wait_recursive %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 i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @omp_get_num_threads()
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i64 (...) @current_time_ns()
store i64 %14, i64* %7
%15 = call i32 @recursive_group_task(i32 0)
%16 = call i64 (...) @current_time_ns()
store i64 %16, i64* %8
%17 = load i64, i64* %8
%18 = load i64, i64* %7
%19 = sub i64 %17, %18
%20 = uitofp i64 %19 to double
%21 = fdiv double %20, 1.000000e+03
%22 = fdiv double 1.000000e+03, %21
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 1000, double %22)
%24 = call i64 (...) @current_time_ns()
store i64 %24, i64* %9
%25 = call i32 @recursive_wait_task(i32 0)
%26 = call i64 (...) @current_time_ns()
store i64 %26, i64* %10
%27 = load i64, i64* %10
%28 = load i64, i64* %9
%29 = sub i64 %27, %28
%30 = uitofp i64 %29 to double
%31 = fdiv double %30, 1.000000e+03
%32 = fdiv double 1.000000e+03, %31
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 1000, double %32)
ret i32 0
}

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