#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_max_threads();
int omp_get_thread_num();
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, double, ...);
int main(int argc, char **argv) {
  int i = 0;
  int n = 0;
  double start = 0.0;
  double middle = 0.0;
  double end = 0.0;
  double for1 = 0.0;
  double for2 = 0.0;
  double total = 0.0;
#pragma omp parallel shared(n) private(i)
  {
    start = omp_get_wtime();
#pragma omp for ordered
    for (i = 0; i < n; i++) {
#pragma omp ordered
      printf("Thread %d of %d - Iteration %d\n", omp_get_thread_num(),
             omp_get_max_threads(), i);
    }
    middle = omp_get_wtime();
#pragma omp for ordered
    for (i = 0; i < n; i++) {
#pragma omp ordered
      printf("Thread %d of %d - Iteration %d\n", omp_get_thread_num(),
             omp_get_max_threads(), i);
    }
    end = omp_get_wtime();
  }
  for1 = middle - start;
  for2 = end - middle;
  total = end - start;
  printf("For Loop 1:  %0.9lf\n", for1);
  printf("For Loop 2:  %0.9lf\n", for2);
  printf("Total Time:  %0.9lf\n", total);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11f0 <main+0xb0>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    $0x0,%al
call   1060 <omp_get_max_threads@plt>
movsd  -0x50(%rbp),%xmm0
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe25(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a7 <main+0x67>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    124c <main+0x10c>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    $0x0,%al
call   1060 <omp_get_max_threads@plt>
movsd  -0x58(%rbp),%xmm0
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xdc9(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1203 <main+0xc3>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xd8f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xd91(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x48(%rbp),%xmm0
lea    0xd93(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movapd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  (%rsp),%xmm1
subsd  %xmm1,%xmm2
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0xe8f(%rip),%rdi
movapd %xmm2,%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe92(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe93(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Thread %d of %d - Iteration %d\0A\00"
@.str.1 = [21 x i8] c"For Loop 1: %0.9lf\0A\00"
@.str.2 = [21 x i8] c"For Loop 2: %0.9lf\0A\00"
@.str.3 = [21 x i8] c"Total Time: %0.9lf\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 double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
%14 = call double (...) @omp_get_wtime()
store double %14, double* %8
store i32 0, i32* %6
br label %15
15: ; preds = %25, %2
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = call i32 (...) @omp_get_thread_num()
%21 = sitofp i32 %20 to double
%22 = call i32 (...) @omp_get_max_threads()
%23 = load i32, i32* %6
%24 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double %21, i32 %22, i32 %23)
br label %25
25: ; preds = %19
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %15
28: ; preds = %15
%29 = call double (...) @omp_get_wtime()
store double %29, double* %9
store i32 0, i32* %6
br label %30
30: ; preds = %40, %28
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %43
34: ; preds = %30
%35 = call i32 (...) @omp_get_thread_num()
%36 = sitofp i32 %35 to double
%37 = call i32 (...) @omp_get_max_threads()
%38 = load i32, i32* %6
%39 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double %36, i32 %37, i32 %38)
br label %40
40: ; preds = %34
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %30
43: ; preds = %30
%44 = call double (...) @omp_get_wtime()
store double %44, double* %10
%45 = load double, double* %9
%46 = load double, double* %8
%47 = fsub double %45, %46
store double %47, double* %11
%48 = load double, double* %10
%49 = load double, double* %9
%50 = fsub double %48, %49
store double %50, double* %12
%51 = load double, double* %10
%52 = load double, double* %8
%53 = fsub double %51, %52
store double %53, double* %13
%54 = load double, double* %11
%55 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %54)
%56 = load double, double* %12
%57 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), double %56)
%58 = load double, double* %13
%59 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), double %58)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"For Loop 1: %0.9lf\0A\00"
@.str.2 = [21 x i8] c"For Loop 2: %0.9lf\0A\00"
@.str.3 = [21 x i8] c"Total Time: %0.9lf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call double (...) @omp_get_wtime()
%4 = tail call double (...) @omp_get_wtime()
%5 = tail call double (...) @omp_get_wtime()
%6 = fsub double %4, %3
%7 = fsub double %5, %4
%8 = fsub double %5, %3
%9 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %6)
%10 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), double %7)
%11 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), double %8)
ret i32 0
}