#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 */
scalar_t__ is_prime_number(int);
int omp_get_thread_num();
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, int, double);
int count_prime_numbers_omp(int a, int b) {
  int nprimes = 0;
  if (a <= 2) {
    nprimes = 1;
    a = 2;
  }
  if (a % 2 == 0)
    a++;
#pragma omp parallel
  {
    double t = omp_get_wtime();
    int nloc = 0;
#pragma omp for nowait
    for (int i = a; i <= b; i += 2) {
      if (is_prime_number(i))
        nloc++;
    }
#pragma omp atomic
    nprimes += nloc;
    t = omp_get_wtime() - t;
    printf("Thread %d execution time: %.6f sec.\n", omp_get_thread_num(), t);
  }
  return nprimes;
}


x86 assembly (clang, -O0):
<count_prime_numbers_omp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x2,-0x4(%rbp)
jg     116d <count_prime_numbers_omp+0x2d>
movl   $0x1,-0xc(%rbp)
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118a <count_prime_numbers_omp+0x4a>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11dd <count_prime_numbers_omp+0x9d>
mov    -0x20(%rbp),%edi
call   1060 <is_prime_number@plt>
cmp    $0x0,%rax
je     11ca <count_prime_numbers_omp+0x8a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cf <count_prime_numbers_omp+0x8f>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    11a3 <count_prime_numbers_omp+0x63>
mov    -0x1c(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,%esi
movsd  -0x18(%rbp),%xmm0
lea    0xdf4(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_prime_numbers_omp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
cmp    $0x3,%edi
mov    $0x2,%eax
cmovge %edi,%eax
mov    %esi,%r15d
mov    %eax,%ebx
not    %ebx
and    $0x1,%ebx
add    %eax,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,(%rsp)
cmp    %r15d,%ebx
jg     1196 <count_prime_numbers_omp+0x56>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1060 <is_prime_number@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0x2,%ebx
cmp    %r15d,%ebx
jle    1180 <count_prime_numbers_omp+0x40>
xor    %ebx,%ebx
cmp    $0x3,%r14d
setl   %bl
add    %ebp,%ebx
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
lea    0xe40(%rip),%rdi
mov    %eax,%esi
movsd  (%rsp),%xmm0
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Thread %d execution time: %.6f sec.\0A\00"
define i32 @count_prime_numbers_omp(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%9 = load i32, i32* %3
%10 = icmp sle i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %5
store i32 2, i32* %3
br label %12
12: ; preds = %11, %2
%13 = load i32, i32* %3
%14 = srem i32 %13, 2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %12
%20 = call double (...) @omp_get_wtime()
store double %20, double* %6
store i32 0, i32* %7
%21 = load i32, i32* %3
store i32 %21, i32* %8
br label %22
22: ; preds = %34, %19
%23 = load i32, i32* %8
%24 = load i32, i32* %4
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = load i32, i32* %8
%28 = call i64 @is_prime_number(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %33
33: ; preds = %30, %26
br label %34
34: ; preds = %33
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 2
store i32 %36, i32* %8
br label %22
37: ; preds = %22
%38 = load i32, i32* %7
%39 = load i32, i32* %5
%40 = add nsw i32 %39, %38
store i32 %40, i32* %5
%41 = call double (...) @omp_get_wtime()
%42 = load double, double* %6
%43 = fsub double %41, %42
store double %43, double* %6
%44 = call i32 (...) @omp_get_thread_num()
%45 = load double, double* %6
%46 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %44, double %45)
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
@.str = [37 x i8] c"Thread %d execution time: %.6f sec.\0A\00"
define i32 @count_prime_numbers_omp(i32 %0, i32 %1) {
%3 = icmp slt i32 %0, 3
%4 = select i1 %3, i32 2, i32 %0
%5 = and i32 %4, 1
%6 = xor i32 %5, 1
%7 = add nuw nsw i32 %6, %4
%8 = tail call double (...) @omp_get_wtime()
%9 = icmp sgt i32 %7, %1
br i1 %9, label %10, label %18
10: ; preds = %18, %2
%11 = phi i32 [ 0, %2 ], [ %24, %18 ]
%12 = zext i1 %3 to i32
%13 = add nuw nsw i32 %11, %12
%14 = tail call double (...) @omp_get_wtime()
%15 = fsub double %14, %8
%16 = tail call i32 (...) @omp_get_thread_num()
%17 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %16, double %15)
ret i32 %13
18: ; preds = %2, %18
%19 = phi i32 [ %25, %18 ], [ %7, %2 ]
%20 = phi i32 [ %24, %18 ], [ 0, %2 ]
%21 = tail call i64 @is_prime_number(i32 %19)
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i32
%24 = add nuw nsw i32 %20, %23
%25 = add nsw i32 %19, 2
%26 = icmp sgt i32 %25, %1
br i1 %26, label %10, label %18
}