#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 omp_get_thread_num();
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, int, int const, int);
int main(void) {
  const int n = 10000;
  for (int j = 0; j < 20; j++) {
#pragma omp parallel
    {
      double t0 = omp_get_wtime();
      for (int i = 0; i < n; i++) {
#pragma omp barrier
      }
      double t1 = omp_get_wtime();
      if (omp_get_thread_num() == 1)
        printf("round %d: %d barriers took %lf us per call\n", j, n,
               1e6 * (t1 - t0) / n);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2710,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jge    11f3 <main+0xc3>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2710,-0x1c(%rbp)
jge    118a <main+0x5a>
jmp    117c <main+0x4c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <main+0x3a>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
cmp    $0x1,%eax
jne    11e0 <main+0xb0>
mov    -0xc(%rbp),%esi
movsd  -0x28(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xe4d(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe39(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
lea    0xe3a(%rip),%rdi
mov    $0x2710,%edx
call   1050 <printf@plt>
jmp    11e5 <main+0xb5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xed3(%rip),%rbx
xor    %ebp,%ebp
jmp    1158 <main+0x28>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x14,%ebp
je     11af <main+0x7f>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
cmp    $0x1,%eax
jne    1150 <main+0x20>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
mulsd  0xe6e(%rip),%xmm0
divsd  0xe6e(%rip),%xmm0
cvttsd2si %xmm0,%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x2710,%edx
call   1050 <printf@plt>
jmp    1150 <main+0x20>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"round %d: %d barriers took %lf us per call\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
%6 = alloca double
store i32 0, i32* %1
store i32 10000, i32* %2
store i32 0, i32* %3
br label %7
7: ; preds = %33, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 20
br i1 %9, label %10, label %36
10: ; preds = %7
%11 = call double (...) @omp_get_wtime()
store double %11, double* %4
store i32 0, i32* %5
br label %12
12: ; preds = %16, %10
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 10000
br i1 %14, label %15, label %19
15: ; preds = %12
br label %16
16: ; preds = %15
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %12
19: ; preds = %12
%20 = call double (...) @omp_get_wtime()
store double %20, double* %6
%21 = call i32 (...) @omp_get_thread_num()
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i32, i32* %3
%25 = load double, double* %6
%26 = load double, double* %4
%27 = fsub double %25, %26
%28 = fmul double 1.000000e+06, %27
%29 = fdiv double %28, 1.000000e+04
%30 = fptosi double %29 to i32
%31 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %24, i32 10000, i32 %30)
br label %32
32: ; preds = %23, %19
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %7
36: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [44 x i8] c"round %d: %d barriers took %lf us per call\0A\00"
define i32 @main() {
br label %2
1: ; preds = %14
ret i32 0
2: ; preds = %0, %14
%3 = phi i32 [ 0, %0 ], [ %15, %14 ]
%4 = tail call double (...) @omp_get_wtime()
%5 = tail call double (...) @omp_get_wtime()
%6 = tail call i32 (...) @omp_get_thread_num()
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = fsub double %5, %4
%10 = fmul double %9, 1.000000e+06
%11 = fdiv double %10, 1.000000e+04
%12 = fptosi double %11 to i32
%13 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %3, i32 10000, i32 %12)
br label %14
14: ; preds = %8, %2
%15 = add nuw nsw i32 %3, 1
%16 = icmp eq i32 %15, 20
br i1 %16, label %1, label %2
}