#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 dep_arr[1];
    dep_arr[0] = dep_arr[0];
    const unsigned long long start_time = current_time_ns();
#pragma omp taskgroup
    {
      int incr = 0;
#pragma omp task default(none) firstprivate(incr) depend(out : dep_arr[0])
      { incr = incr + 1; }
      int i;
      for (i = 0; i < 100000; i++) {
#pragma omp task default(none) firstprivate(incr) depend(in : dep_arr[0])
        { incr = incr + 1; }
      }
    }
    const unsigned long long end_time = current_time_ns();
    printf("METRIC fan_out %d %.20f\n", 100000,
           (double)100000 / ((double)(end_time - start_time) / 1000.0));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <current_time_ns@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x186a0,-0x28(%rbp)
jge    11ad <main+0x7d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1189 <main+0x59>
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 0xe41(%rip),%xmm0
punpckldq %xmm0,%xmm1
movapd 0xe45(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe16(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe02(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xe40(%rip),%rdi
mov    $0x186a0,%esi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%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    $0x186a0,%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 = [25 x i8] c"METRIC fan_out %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 i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (...) @omp_get_num_threads()
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
store i32 %16, i32* %17
%18 = call i64 (...) @current_time_ns()
store i64 %18, i64* %8
store i32 0, i32* %9
%19 = load i32, i32* %9
%20 = add nsw i32 %19, 1
store i32 %20, i32* %9
store i32 0, i32* %10
br label %21
21: ; preds = %27, %2
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 100000
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
store i32 %26, i32* %9
br label %27
27: ; preds = %24
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
br label %21
30: ; preds = %21
%31 = call i64 (...) @current_time_ns()
store i64 %31, i64* %11
%32 = load i64, i64* %11
%33 = load i64, i64* %8
%34 = sub i64 %32, %33
%35 = uitofp i64 %34 to double
%36 = fdiv double %35, 1.000000e+03
%37 = fdiv double 1.000000e+05, %36
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 100000, double %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Using %d OpenMP threads\0A\00"
@.str.1 = [25 x i8] c"METRIC fan_out %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 1.000000e+05, %9
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 100000, double %10)
ret i32 0
}