#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 */
int /*<<< orphan*/ assert(int);
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;
    unsigned sum = 0;
    const unsigned long long start_time = current_time_ns();
#pragma omp parallel for default(none) private(i) reduction(+ : sum)
    for (i = 0; i < 10000; i++) {
      sum += 1;
    }
    const unsigned long long end_time = current_time_ns();
    assert(sum == 10000);
    printf("METRIC recursive_reduction %d %.20f\n", 10000,
           (double)10000 / ((double)(end_time - start_time) / 1000.0));
    printf("METRIC flat_reduction %d %.20f\n", 10000,
           (double)10000 / ((double)(end_time - 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    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <current_time_ns@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2710,-0x18(%rbp)
jge    11ae <main+0x6e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118a <main+0x4a>
xor    %eax,%eax
call   1060 <current_time_ns@plt>
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x2710,%eax
sete   %al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xe2d(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
punpckldq %xmm0,%xmm1
movapd 0xe2d(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xdfa(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xde6(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xe24(%rip),%rdi
mov    $0x2710,%esi
mov    $0x1,%al
call   1030 <printf@plt>
movaps -0x50(%rbp),%xmm2
movaps -0x40(%rbp),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
punpckldq %xmm2,%xmm1
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xda4(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd90(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xdf3(%rip),%rdi
mov    $0x2710,%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    0xede(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <current_time_ns@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <current_time_ns@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1050 <assert@plt>
sub    %r14,%rbx
movq   %rbx,%xmm0
punpckldq 0xe77(%rip),%xmm0
subpd  0xe7f(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  0xe7b(%rip),%xmm1
movsd  0xe7b(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0xe8c(%rip),%rdi
mov    $0x2710,%esi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe9e(%rip),%rdi
mov    $0x2710,%esi
movsd  (%rsp),%xmm0
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 recursive_reduction %d %.20f\0A\00"
@.str.2 = [32 x i8] c"METRIC flat_reduction %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
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)
store i32 0, i32* %8
%14 = call i64 (...) @current_time_ns()
store i64 %14, i64* %9
store i32 0, i32* %7
br label %15
15: ; preds = %21, %2
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 10000
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32, i32* %8
%20 = add i32 %19, 1
store i32 %20, i32* %8
br label %21
21: ; preds = %18
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %15
24: ; preds = %15
%25 = call i64 (...) @current_time_ns()
store i64 %25, i64* %10
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 10000
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i64, i64* %10
%31 = load i64, i64* %9
%32 = sub i64 %30, %31
%33 = uitofp i64 %32 to double
%34 = fdiv double %33, 1.000000e+03
%35 = fdiv double 1.000000e+04, %34
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 10000, double %35)
%37 = load i64, i64* %10
%38 = load i64, i64* %9
%39 = sub i64 %37, %38
%40 = uitofp i64 %39 to double
%41 = fdiv double %40, 1.000000e+03
%42 = fdiv double 1.000000e+04, %41
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 10000, double %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Using %d OpenMP threads\0A\00"
@.str.1 = [37 x i8] c"METRIC recursive_reduction %d %.20f\0A\00"
@.str.2 = [32 x i8] c"METRIC flat_reduction %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 = tail call i32 @assert(i32 1)
%8 = sub i64 %6, %5
%9 = uitofp i64 %8 to double
%10 = fdiv double %9, 1.000000e+03
%11 = fdiv double 1.000000e+04, %10
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 10000, double %11)
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 10000, double %11)
ret i32 0
}