#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 omp_get_wtime();
int /*<<< orphan*/ print(char *, int const, double, double, double);
int /*<<< orphan*/ printf(char *, double);
int main() {
  const int REPS = 1000000;
  int i;
  double balance = 0.0, startTime = 0.0, stopTime = 0.0, atomicTime = 0.0,
         criticalTime = 0.0;
  printf("\nYour starting bank account balance is %0.2f\n", balance);
  startTime = omp_get_wtime();
#pragma omp parallel for
  for (i = 0; i < REPS; i++) {
#pragma omp atomic
    balance += 1.0;
  }
  stopTime = omp_get_wtime();
  atomicTime = stopTime - startTime;
  print("atomic", REPS, balance, atomicTime, atomicTime / REPS);
  balance = 0.0;
  startTime = omp_get_wtime();
#pragma omp parallel for
  for (i = 0; i < REPS; i++) {
#pragma omp critical
    { balance += 1.0; }
  }
  stopTime = omp_get_wtime();
  criticalTime = stopTime - startTime;
  print("critical", REPS, balance, criticalTime, criticalTime / REPS);
  printf("criticalTime / atomicTime ratio: %0.12f\n\n",
         criticalTime / atomicTime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf4240,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-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)
movsd  -0x18(%rbp),%xmm0
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xf4240,-0xc(%rbp)
jge    11bf <main+0x8f>
movsd  0xe61(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1192 <main+0x62>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  0xe0f(%rip),%xmm3
divsd  %xmm3,%xmm2
lea    0xe42(%rip),%rdi
mov    $0xf4240,%esi
call   1050 <print@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xf4240,-0xc(%rbp)
jge    124e <main+0x11e>
movsd  0xdd2(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1221 <main+0xf1>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  0xd80(%rip),%xmm3
divsd  %xmm3,%xmm2
lea    0xdba(%rip),%rdi
mov    $0xf4240,%esi
call   1050 <print@plt>
movsd  -0x38(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
lea    0xda8(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xed4(%rip),%rdi
xorps  %xmm0,%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x10(%rsp)
mov    $0xf4240,%eax
movsd  0xe9e(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
add    $0xfffffff6,%eax
jne    1170 <main+0x40>
xor    %eax,%eax
movsd  %xmm1,0x8(%rsp)
call   1030 <omp_get_wtime@plt>
movapd %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm2
divsd  0xe48(%rip),%xmm2
lea    0xe77(%rip),%rdi
mov    $0xf4240,%ebx
mov    $0xf4240,%esi
movsd  0x8(%rsp),%xmm0
movsd  %xmm1,0x10(%rsp)
call   1050 <print@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe09(%rip),%xmm0
xorpd  %xmm1,%xmm1
nopl   0x0(%rax,%rax,1)
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm0,%xmm1
add    $0xfffffff6,%ebx
jne    1200 <main+0xd0>
xor    %eax,%eax
movsd  %xmm1,0x18(%rsp)
call   1030 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm2
movapd %xmm0,%xmm1
movsd  %xmm0,0x8(%rsp)
divsd  0xdb2(%rip),%xmm2
lea    0xde8(%rip),%rdi
mov    $0xf4240,%esi
movsd  0x18(%rsp),%xmm0
call   1050 <print@plt>
movsd  0x8(%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
lea    0xdce(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [46 x i8] c"\0AYour starting bank account balance is %0.2f\0A\00"
@.str.1 = [7 x i8] c"atomic\00"
@.str.2 = [9 x i8] c"critical\00"
@.str.3 = [42 x i8] c"criticalTime / atomicTime ratio: %0.12f\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
store i32 1000000, i32* %2
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
%9 = load double, double* %4
%10 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), double %9)
%11 = call double (...) @omp_get_wtime()
store double %11, double* %5
store i32 0, i32* %3
br label %12
12: ; preds = %18, %0
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 1000000
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load double, double* %4
%17 = fadd double %16, 1.000000e+00
store double %17, double* %4
br label %18
18: ; preds = %15
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %12
21: ; preds = %12
%22 = call double (...) @omp_get_wtime()
store double %22, double* %6
%23 = load double, double* %6
%24 = load double, double* %5
%25 = fsub double %23, %24
store double %25, double* %7
%26 = load double, double* %4
%27 = load double, double* %7
%28 = load double, double* %7
%29 = fdiv double %28, 1.000000e+06
%30 = call i32 @print(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1000000, double %26, double %27, double %29)
store double 0.000000e+00, double* %4
%31 = call double (...) @omp_get_wtime()
store double %31, double* %5
store i32 0, i32* %3
br label %32
32: ; preds = %38, %21
%33 = load i32, i32* %3
%34 = icmp slt i32 %33, 1000000
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load double, double* %4
%37 = fadd double %36, 1.000000e+00
store double %37, double* %4
br label %38
38: ; preds = %35
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %32
41: ; preds = %32
%42 = call double (...) @omp_get_wtime()
store double %42, double* %6
%43 = load double, double* %6
%44 = load double, double* %5
%45 = fsub double %43, %44
store double %45, double* %8
%46 = load double, double* %4
%47 = load double, double* %8
%48 = load double, double* %8
%49 = fdiv double %48, 1.000000e+06
%50 = call i32 @print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1000000, double %46, double %47, double %49)
%51 = load double, double* %8
%52 = load double, double* %7
%53 = fdiv double %51, %52
%54 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), double %53)
ret i32 0
}

LLVM IR (-O2):
@.str = [46 x i8] c"\0AYour starting bank account balance is %0.2f\0A\00"
@.str.1 = [7 x i8] c"atomic\00"
@.str.2 = [9 x i8] c"critical\00"
@.str.3 = [42 x i8] c"criticalTime / atomicTime ratio: %0.12f\0A\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), double 0.000000e+00)
%2 = tail call double (...) @omp_get_wtime()
br label %3
3: ; preds = %3, %0
%4 = phi double [ 0.000000e+00, %0 ], [ %15, %3 ]
%5 = phi i32 [ 0, %0 ], [ %16, %3 ]
%6 = fadd double %4, 1.000000e+00
%7 = fadd double %6, 1.000000e+00
%8 = fadd double %7, 1.000000e+00
%9 = fadd double %8, 1.000000e+00
%10 = fadd double %9, 1.000000e+00
%11 = fadd double %10, 1.000000e+00
%12 = fadd double %11, 1.000000e+00
%13 = fadd double %12, 1.000000e+00
%14 = fadd double %13, 1.000000e+00
%15 = fadd double %14, 1.000000e+00
%16 = add nuw nsw i32 %5, 10
%17 = icmp eq i32 %16, 1000000
br i1 %17, label %18, label %3
18: ; preds = %3
%19 = tail call double (...) @omp_get_wtime()
%20 = fsub double %19, %2
%21 = fdiv double %20, 1.000000e+06
%22 = tail call i32 @print(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1000000, double %15, double %20, double %21)
%23 = tail call double (...) @omp_get_wtime()
br label %24
24: ; preds = %24, %18
%25 = phi double [ 0.000000e+00, %18 ], [ %36, %24 ]
%26 = phi i32 [ 0, %18 ], [ %37, %24 ]
%27 = fadd double %25, 1.000000e+00
%28 = fadd double %27, 1.000000e+00
%29 = fadd double %28, 1.000000e+00
%30 = fadd double %29, 1.000000e+00
%31 = fadd double %30, 1.000000e+00
%32 = fadd double %31, 1.000000e+00
%33 = fadd double %32, 1.000000e+00
%34 = fadd double %33, 1.000000e+00
%35 = fadd double %34, 1.000000e+00
%36 = fadd double %35, 1.000000e+00
%37 = add nuw nsw i32 %26, 10
%38 = icmp eq i32 %37, 1000000
br i1 %38, label %39, label %24
39: ; preds = %24
%40 = tail call double (...) @omp_get_wtime()
%41 = fsub double %40, %23
%42 = fdiv double %41, 1.000000e+06
%43 = tail call i32 @print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1000000, double %36, double %41, double %42)
%44 = fdiv double %41, %20
%45 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), double %44)
ret i32 0
}