#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 */
double find_max(double *, int);
double find_min(double *, int);
int /*<<< orphan*/ merge_sort(int *, int /*<<< orphan*/, int);
int omp_get_num_threads();
size_t omp_get_thread_num();
double omp_get_wtime();
int /*<<< orphan*/ print_list(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  double start, end, max, min;
  int tnum, data[1000000];
#pragma omp parallel
  { tnum = omp_get_num_threads(); }
  double alg_start[tnum], alg_end[tnum];
  printf("No. of threads = %d\n", tnum);
  int i;
  for (i = 0; i < 1000000; i++) {
    data[i] = 1000000 - i;
  }
  printf("List before sorting\n");
  print_list(data, 1000000);
  start = omp_get_wtime();
#pragma omp parallel
  {
    alg_start[omp_get_thread_num()] = omp_get_wtime();
#pragma omp single
    { merge_sort(data, 0, 1000000 - 1); }
    alg_end[omp_get_thread_num()] = omp_get_wtime();
  }
  end = omp_get_wtime();
  printf("List after sorting\n");
  print_list(data, 1000000);
  max = find_max(alg_end, tnum);
  min = find_min(alg_start, tnum);
  printf("Stage 1 total runtime = %f\n", end - start);
  printf("Stage 1 alg runtime = %f\n", max - min);
  printf("Stage 1 overhead = %f\n", (end - start) - (max - min));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0970,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
call   1070 <omp_get_num_threads@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x3d0938(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x3d0960(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x3d0940(%rbp)
mov    -0x2c(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x3d0958(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x3d0948(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x3d094c(%rbp)
cmpl   $0xf4240,-0x3d094c(%rbp)
jge    124a <main+0xca>
mov    $0xf4240,%ecx
sub    -0x3d094c(%rbp),%ecx
movslq -0x3d094c(%rbp),%rax
mov    %ecx,-0x3d0930(%rbp,%rax,4)
mov    -0x3d094c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d094c(%rbp)
jmp    120d <main+0x8d>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x3d0930(%rbp),%rdi
mov    $0xf4240,%esi
call   1050 <print_list@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x3d0970(%rbp)
ff
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
movsd  -0x3d0970(%rbp),%xmm0
ff
mov    %rax,%rcx
mov    -0x3d0960(%rbp),%rax
movsd  %xmm0,(%rax,%rcx,8)
lea    -0x3d0930(%rbp),%rdi
xor    %esi,%esi
mov    $0xf423f,%edx
call   1080 <merge_sort@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x3d0968(%rbp)
ff
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
movsd  -0x3d0968(%rbp),%xmm0
ff
mov    %rax,%rcx
mov    -0x3d0958(%rbp),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x18(%rbp)
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x3d0930(%rbp),%rdi
mov    $0xf4240,%esi
call   1050 <print_list@plt>
mov    -0x3d0958(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   10a0 <find_max@plt>
mov    -0x3d0960(%rbp),%rdi
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%esi
call   1090 <find_min@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
lea    0xcf8(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  -0x20(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
lea    0xcfc(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
lea    0xcf0(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x3d0938(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3d0928,%rsp
xor    %eax,%eax
call   1080 <omp_get_num_threads@plt>
mov    %eax,%r14d
mov    %rsp,%r13
mov    %eax,%eax
mov    %rsp,%r15
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xec8(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movdqa 0xe16(%rip),%xmm0
mov    $0x1c,%eax
movdqa 0xe18(%rip),%xmm8
movdqa 0xe1f(%rip),%xmm9
movdqa 0xe26(%rip),%xmm10
movdqa 0xe2d(%rip),%xmm11
movdqa 0xe35(%rip),%xmm5
movdqa 0xe3d(%rip),%xmm6
movdqa 0xe45(%rip),%xmm7
movdqa 0xe4d(%rip),%xmm1
movdqa 0xe55(%rip),%xmm2
nopl   0x0(%rax,%rax,1)
movdqa %xmm8,%xmm3
psubd  %xmm0,%xmm3
movdqa %xmm9,%xmm4
psubd  %xmm0,%xmm4
movdqa %xmm3,-0x3d09c0(%rbp,%rax,4)
c2 ff
movdqa %xmm4,-0x3d09b0(%rbp,%rax,4)
c2 ff
movdqa %xmm10,%xmm3
psubd  %xmm0,%xmm3
movdqa %xmm11,%xmm4
psubd  %xmm0,%xmm4
movdqa %xmm3,-0x3d09a0(%rbp,%rax,4)
c2 ff
movdqa %xmm4,-0x3d0990(%rbp,%rax,4)
c2 ff
movdqa %xmm5,%xmm3
psubd  %xmm0,%xmm3
movdqa %xmm6,%xmm4
psubd  %xmm0,%xmm4
movdqa %xmm3,-0x3d0980(%rbp,%rax,4)
c2 ff
movdqa %xmm4,-0x3d0970(%rbp,%rax,4)
c2 ff
movdqa %xmm7,%xmm3
psubd  %xmm0,%xmm3
movdqa %xmm1,%xmm4
psubd  %xmm0,%xmm4
movdqa %xmm3,-0x3d0960(%rbp,%rax,4)
c2 ff
movdqa %xmm4,-0x3d0950(%rbp,%rax,4)
c2 ff
paddd  %xmm2,%xmm0
add    $0x20,%rax
cmp    $0xf425c,%rax
jne    1240 <main+0xb0>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
lea    -0x3d0950(%rbp),%r12
mov    %r12,%rdi
mov    $0xf4240,%esi
call   1060 <print_list@plt>
xor    %eax,%eax
call   1050 <omp_get_wtime@plt>
movq   %xmm0,-0x48(%rbp)
xor    %eax,%eax
call   1050 <omp_get_wtime@plt>
movq   %xmm0,-0x30(%rbp)
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,(%r15,%rax,8)
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xf423f,%edx
call   1090 <merge_sort@plt>
xor    %eax,%eax
call   1050 <omp_get_wtime@plt>
movsd  %xmm0,-0x30(%rbp)
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
xor    %eax,%eax
call   1050 <omp_get_wtime@plt>
movsd  %xmm0,-0x30(%rbp)
lea    0xdad(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    $0xf4240,%esi
call   1060 <print_list@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   10b0 <find_max@plt>
movsd  %xmm0,-0x38(%rbp)
mov    %r15,%rdi
mov    %r14d,%esi
call   10a0 <find_min@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xd04(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
lea    0xd03(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
lea    0xd05(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    %r13,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"No. of threads = %d\0A\00"
@.str.1 = [21 x i8] c"List before sorting\0A\00"
@.str.2 = [20 x i8] c"List after sorting\0A\00"
@.str.3 = [28 x i8] c"Stage 1 total runtime = %f\0A\00"
@.str.4 = [26 x i8] c"Stage 1 alg runtime = %f\0A\00"
@.str.5 = [23 x i8] c"Stage 1 overhead = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca [1000000 x i32]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %1
%12 = call i32 (...) @omp_get_num_threads()
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %8
%16 = alloca double, i64 %14
store i64 %14, i64* %9
%17 = load i32, i32* %6
%18 = zext i32 %17 to i64
%19 = alloca double, i64 %18
store i64 %18, i64* %10
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 0, i32* %11
br label %22
22: ; preds = %31, %0
%23 = load i32, i32* %11
%24 = icmp slt i32 %23, 1000000
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i32, i32* %11
%27 = sub nsw i32 1000000, %26
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %7, i64 0, i64 %29
store i32 %27, i32* %30
br label %31
31: ; preds = %25
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
store i32 %33, i32* %11
br label %22
34: ; preds = %22
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%36 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %7, i64 0, i64 0
%37 = call i32 @print_list(i32* %36, i32 1000000)
%38 = call double (...) @omp_get_wtime()
store double %38, double* %2
%39 = call double (...) @omp_get_wtime()
%40 = call i64 (...) @omp_get_thread_num()
%41 = getelementptr inbounds double, double* %16, i64 %40
store double %39, double* %41
%42 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %7, i64 0, i64 0
%43 = call i32 @merge_sort(i32* %42, i32 0, i32 999999)
%44 = call double (...) @omp_get_wtime()
%45 = call i64 (...) @omp_get_thread_num()
%46 = getelementptr inbounds double, double* %19, i64 %45
store double %44, double* %46
%47 = call double (...) @omp_get_wtime()
store double %47, double* %3
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%49 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %7, i64 0, i64 0
%50 = call i32 @print_list(i32* %49, i32 1000000)
%51 = load i32, i32* %6
%52 = call double @find_max(double* %19, i32 %51)
store double %52, double* %4
%53 = load i32, i32* %6
%54 = call double @find_min(double* %16, i32 %53)
store double %54, double* %5
%55 = load double, double* %3
%56 = load double, double* %2
%57 = fsub double %55, %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), double %57)
%59 = load double, double* %4
%60 = load double, double* %5
%61 = fsub double %59, %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), double %61)
%63 = load double, double* %3
%64 = load double, double* %2
%65 = fsub double %63, %64
%66 = load double, double* %4
%67 = load double, double* %5
%68 = fsub double %66, %67
%69 = fsub double %65, %68
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), double %69)
store i32 0, i32* %1
%71 = load i8*, i8** %8
%72 = load i32, i32* %1
ret i32 %72
}

LLVM IR (-O2):
@.str = [21 x i8] c"No. of threads = %d\0A\00"
@.str.3 = [28 x i8] c"Stage 1 total runtime = %f\0A\00"
@.str.4 = [26 x i8] c"Stage 1 alg runtime = %f\0A\00"
@.str.5 = [23 x i8] c"Stage 1 overhead = %f\0A\00"
@str = [20 x i8] c"List before sorting\00"
@str.6 = [19 x i8] c"List after sorting\00"
define i32 @main() {
%1 = alloca [1000000 x i32]
%2 = bitcast [1000000 x i32]* %1 to i8*
%3 = tail call i32 (...) @omp_get_num_threads()
%4 = zext i32 %3 to i64
%5 = tail call i8* @llvm.stacksave()
%6 = alloca double, i64 %4
%7 = alloca double, i64 %4
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %9
9: ; preds = %9, %0
%10 = phi i64 [ 0, %0 ], [ %39, %9 ]
%11 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %40, %9 ]
%12 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %10
%13 = sub <4 x i32> <i32 1000000, i32 1000000, i32 1000000, i32 1000000>, %11
%14 = sub <4 x i32> <i32 999996, i32 999996, i32 999996, i32 999996>, %11
%15 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> %13, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %12, i64 4
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %14, <4 x i32>* %17
%18 = or i64 %10, 8
%19 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %18
%20 = sub <4 x i32> <i32 999992, i32 999992, i32 999992, i32 999992>, %11
%21 = sub <4 x i32> <i32 999988, i32 999988, i32 999988, i32 999988>, %11
%22 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> %20, <4 x i32>* %22
%23 = getelementptr inbounds i32, i32* %19, i64 4
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %21, <4 x i32>* %24
%25 = or i64 %10, 16
%26 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %25
%27 = sub <4 x i32> <i32 999984, i32 999984, i32 999984, i32 999984>, %11
%28 = sub <4 x i32> <i32 999980, i32 999980, i32 999980, i32 999980>, %11
%29 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> %27, <4 x i32>* %29
%30 = getelementptr inbounds i32, i32* %26, i64 4
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %31
%32 = or i64 %10, 24
%33 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %32
%34 = sub <4 x i32> <i32 999976, i32 999976, i32 999976, i32 999976>, %11
%35 = sub <4 x i32> <i32 999972, i32 999972, i32 999972, i32 999972>, %11
%36 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> %34, <4 x i32>* %36
%37 = getelementptr inbounds i32, i32* %33, i64 4
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> %35, <4 x i32>* %38
%39 = add nuw nsw i64 %10, 32
%40 = add <4 x i32> %11, <i32 32, i32 32, i32 32, i32 32>
%41 = icmp eq i64 %39, 1000000
br i1 %41, label %42, label %9
42: ; preds = %9
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%44 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 0
%45 = call i32 @print_list(i32* %44, i32 1000000)
%46 = call double (...) @omp_get_wtime()
%47 = call double (...) @omp_get_wtime()
%48 = call i64 (...) @omp_get_thread_num()
%49 = getelementptr inbounds double, double* %6, i64 %48
store double %47, double* %49
%50 = call i32 @merge_sort(i32* %44, i32 0, i32 999999)
%51 = call double (...) @omp_get_wtime()
%52 = call i64 (...) @omp_get_thread_num()
%53 = getelementptr inbounds double, double* %7, i64 %52
store double %51, double* %53
%54 = call double (...) @omp_get_wtime()
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%56 = call i32 @print_list(i32* %44, i32 1000000)
%57 = call double @find_max(double* %7, i32 %3)
%58 = call double @find_min(double* %6, i32 %3)
%59 = fsub double %54, %46
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), double %59)
%61 = fsub double %57, %58
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), double %61)
%63 = fsub double %59, %61
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), double %63)
ret i32 0
}