#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__ IsPrime(unsigned long);
int /*<<< orphan*/ omp_set_num_threads(unsigned long);
unsigned long prime_count(unsigned long a, unsigned long b,
                          unsigned long num_threads, unsigned long chunk_size) {
  unsigned long prime_cnt = 0;
  if (a == 0) {
    a += 2;
  }
  omp_set_num_threads(num_threads);
#pragma omp parallel for schedule(dynamic, chunk_size) reduction(+ : prime_cnt)
  for (unsigned long i = a; i <= b; i++) {
    prime_cnt += IsPrime(i);
  }
  return prime_cnt;
}


x86 assembly (clang, -O0):
<prime_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1157 <prime_count+0x37>
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <omp_set_num_threads@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     1198 <prime_count+0x78>
mov    -0x30(%rbp),%rdi
call   1040 <IsPrime@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1168 <prime_count+0x48>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime_count>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
mov    $0x2,%ebx
cmovne %rdi,%rbx
mov    %rdx,%rdi
call   1030 <omp_set_num_threads@plt>
xor    %r15d,%r15d
cmp    %r14,%rbx
ja     1164 <prime_count+0x44>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <IsPrime@plt>
add    %rax,%r15
add    $0x1,%rbx
cmp    %r14,%rbx
jbe    1150 <prime_count+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @prime_count(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
store i64 0, i64* %9
%11 = load i64, i64* %5
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i64, i64* %5
%15 = add i64 %14, 2
store i64 %15, i64* %5
br label %16
16: ; preds = %13, %4
%17 = load i64, i64* %7
%18 = call i32 @omp_set_num_threads(i64 %17)
%19 = load i64, i64* %5
store i64 %19, i64* %10
br label %20
20: ; preds = %29, %16
%21 = load i64, i64* %10
%22 = load i64, i64* %6
%23 = icmp ule i64 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i64, i64* %10
%26 = call i64 @IsPrime(i64 %25)
%27 = load i64, i64* %9
%28 = add i64 %27, %26
store i64 %28, i64* %9
br label %29
29: ; preds = %24
%30 = load i64, i64* %10
%31 = add i64 %30, 1
store i64 %31, i64* %10
br label %20
32: ; preds = %20
%33 = load i64, i64* %9
ret i64 %33
}

LLVM IR (-O2):
define i64 @prime_count(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = icmp eq i64 %0, 0
%6 = select i1 %5, i64 2, i64 %0
%7 = tail call i32 @omp_set_num_threads(i64 %2)
%8 = icmp ugt i64 %6, %1
br i1 %8, label %9, label %11
9: ; preds = %11, %4
%10 = phi i64 [ 0, %4 ], [ %15, %11 ]
ret i64 %10
11: ; preds = %4, %11
%12 = phi i64 [ %16, %11 ], [ %6, %4 ]
%13 = phi i64 [ %15, %11 ], [ 0, %4 ]
%14 = tail call i64 @IsPrime(i64 %12)
%15 = add i64 %14, %13
%16 = add i64 %12, 1
%17 = icmp ugt i64 %16, %1
br i1 %17, label %9, label %11
}