#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*/ omp_quiesce();
int /*<<< orphan*/ printf(char *, double);
double read_timer();
void omp_quiesce_overhead(int nthreads) {
  int i;
  int NUM_ITERATIONS = 1000;
  double quiesce_ov = 0.0;
  double quiesce_start_ov = 0.0;
  double cost_all = read_timer();
  for (i = 0; i < NUM_ITERATIONS; i++) {
#pragma omp parallel num_threads(nthreads)
    {}
    double temp2 = read_timer();
    omp_quiesce();
    quiesce_ov += read_timer() - temp2;
  }
  cost_all = read_timer() - cost_all;
  double parallel_overhead = read_timer();
  for (i = 0; i < NUM_ITERATIONS; i++) {
#pragma omp parallel num_threads(nthreads)
    {}
  }
  parallel_overhead = read_timer() - parallel_overhead;
  printf("quiesce overhead      : %f\n", quiesce_ov / NUM_ITERATIONS);
  printf("quiesce_start overhead: %f\n",
         (cost_all - parallel_overhead) / NUM_ITERATIONS);
  printf("Total cost:             %f\n", cost_all / NUM_ITERATIONS);
  return;
}


x86 assembly (clang, -O0):
<omp_quiesce_overhead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x3e8,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <read_timer@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a8 <omp_quiesce_overhead+0x78>
mov    $0x0,%al
call   1040 <read_timer@plt>
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1050 <omp_quiesce@plt>
mov    $0x0,%al
call   1040 <read_timer@plt>
subsd  -0x30(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1165 <omp_quiesce_overhead+0x35>
mov    $0x0,%al
call   1040 <read_timer@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <read_timer@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11eb <omp_quiesce_overhead+0xbb>
jmp    11dd <omp_quiesce_overhead+0xad>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11cc <omp_quiesce_overhead+0x9c>
mov    $0x0,%al
call   1040 <read_timer@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdef(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdec(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdee(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<omp_quiesce_overhead>:
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1040 <read_timer@plt>
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0x3e8,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <read_timer@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <omp_quiesce@plt>
xor    %eax,%eax
call   1040 <read_timer@plt>
subsd  (%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
add    $0xffffffff,%ebx
jne    1160 <omp_quiesce_overhead+0x30>
xor    %eax,%eax
call   1040 <read_timer@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <read_timer@plt>
movsd  %xmm0,0x18(%rsp)
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <read_timer@plt>
subsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
divsd  0xe22(%rip),%xmm0
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
divsd  0xe03(%rip),%xmm0
lea    0xe20(%rip),%rdi
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
divsd  0xdea(%rip),%xmm0
lea    0xe23(%rip),%rdi
add    $0x20,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"quiesce overhead : %f\0A\00"
@.str.1 = [28 x i8] c"quiesce_start overhead: %f\0A\00"
@.str.2 = [28 x i8] c"Total cost: %f\0A\00"
define void @omp_quiesce_overhead(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 %0, i32* %2
store i32 1000, i32* %4
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
%10 = call double (...) @read_timer()
store double %10, double* %7
store i32 0, i32* %3
br label %11
11: ; preds = %23, %1
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = call double (...) @read_timer()
store double %16, double* %8
%17 = call i32 (...) @omp_quiesce()
%18 = call double (...) @read_timer()
%19 = load double, double* %8
%20 = fsub double %18, %19
%21 = load double, double* %5
%22 = fadd double %21, %20
store double %22, double* %5
br label %23
23: ; preds = %15
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %11
26: ; preds = %11
%27 = call double (...) @read_timer()
%28 = load double, double* %7
%29 = fsub double %27, %28
store double %29, double* %7
%30 = call double (...) @read_timer()
store double %30, double* %9
store i32 0, i32* %3
br label %31
31: ; preds = %36, %26
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %39
35: ; preds = %31
br label %36
36: ; preds = %35
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %31
39: ; preds = %31
%40 = call double (...) @read_timer()
%41 = load double, double* %9
%42 = fsub double %40, %41
store double %42, double* %9
%43 = load double, double* %5
%44 = load i32, i32* %4
%45 = sitofp i32 %44 to double
%46 = fdiv double %43, %45
%47 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %46)
%48 = load double, double* %7
%49 = load double, double* %9
%50 = fsub double %48, %49
%51 = load i32, i32* %4
%52 = sitofp i32 %51 to double
%53 = fdiv double %50, %52
%54 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), double %53)
%55 = load double, double* %7
%56 = load i32, i32* %4
%57 = sitofp i32 %56 to double
%58 = fdiv double %55, %57
%59 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), double %58)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"quiesce overhead : %f\0A\00"
@.str.1 = [28 x i8] c"quiesce_start overhead: %f\0A\00"
@.str.2 = [28 x i8] c"Total cost: %f\0A\00"
define void @omp_quiesce_overhead(i32 %0) {
%2 = tail call double (...) @read_timer()
br label %3
3: ; preds = %1, %3
%4 = phi i32 [ 0, %1 ], [ %11, %3 ]
%5 = phi double [ 0.000000e+00, %1 ], [ %10, %3 ]
%6 = tail call double (...) @read_timer()
%7 = tail call i32 (...) @omp_quiesce()
%8 = tail call double (...) @read_timer()
%9 = fsub double %8, %6
%10 = fadd double %5, %9
%11 = add nuw nsw i32 %4, 1
%12 = icmp eq i32 %11, 1000
br i1 %12, label %13, label %3
13: ; preds = %3
%14 = tail call double (...) @read_timer()
%15 = tail call double (...) @read_timer()
%16 = fsub double %14, %2
%17 = tail call double (...) @read_timer()
%18 = fsub double %17, %15
%19 = fdiv double %10, 1.000000e+03
%20 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %19)
%21 = fsub double %16, %18
%22 = fdiv double %21, 1.000000e+03
%23 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), double %22)
%24 = fdiv double %16, 1.000000e+03
%25 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), double %24)
ret void
}