#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 atoi(char *);
double omp_get_wtime();
unsigned long pf(unsigned long, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  unsigned int q = 0;
  if (argv[2] && atoi(argv[2]) == 1)
    q = 1;
  printf("Prime Finder\n");
  if (q)
    printf("1 is a prime number!\n3 is a prime number!\n");
  double startTime = omp_get_wtime();
  unsigned long primes = 2, limit = atoi(argv[1]), i = 1, j = 0, a, b,
                twinprimes = 0;
#pragma omp parallel for schedule(dynamic) reduction(+ : primes, twinprimes) private (j, a, b)
  for (i = 1; i < (limit + 6) / 6; i++) {
    j = 6 * i;
    a = pf(j + 1, q);
    b = pf(j - 1, q);
    primes += a + b;
    if (a && b)
      twinprimes++;
  }
  printf("Twin prime pairs found: %lu\n", twinprimes);
  printf("Primes found: %lu in %.2f seconds.\n\n", primes,
         omp_get_wtime() - startTime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1189 <main+0x49>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
cmp    $0x1,%eax
jne    1189 <main+0x49>
movl   $0x1,-0x14(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     11af <main+0x6f>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x20(%rbp)
movq   $0x2,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
cltq
mov    %rax,-0x30(%rbp)
movq   $0x1,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rax
add    $0x6,%rax
mov    $0x6,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
cmp    %rcx,%rax
jae    1299 <main+0x159>
imul   $0x6,-0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
add    $0x1,%rdi
mov    -0x14(%rbp),%esi
call   1050 <pf@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
sub    $0x1,%rdi
mov    -0x14(%rbp),%esi
call   1050 <pf@plt>
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
add    -0x50(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1283 <main+0x143>
cmpq   $0x0,-0x50(%rbp)
je     1283 <main+0x143>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1288 <main+0x148>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11f6 <main+0xb6>
mov    -0x58(%rbp),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
mov    -0x68(%rbp),%rsi
subsd  -0x20(%rbp),%xmm0
lea    0xd8c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
test   %rdi,%rdi
je     1191 <main+0x41>
call   1070 <atoi@plt>
mov    %eax,%ebp
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
cmp    $0x1,%ebp
jne    11a0 <main+0x50>
mov    $0x1,%r14d
lea    0xec0(%rip),%rdi
jmp    119b <main+0x4b>
xor    %r14d,%r14d
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,(%rsp)
mov    0x8(%rbx),%rdi
call   1070 <atoi@plt>
cltq
add    $0x6,%rax
cmp    $0xc,%rax
jb     1240 <main+0xf0>
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mul    %rcx
mov    %rdx,%r12
shr    $0x2,%r12
cmp    $0x3,%r12
mov    $0x2,%ebx
cmovb  %rbx,%r12
add    $0xffffffffffffffff,%r12
mov    $0x5,%ebp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x2(%rbp),%rdi
mov    %r14d,%esi
call   1060 <pf@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %r14d,%esi
call   1060 <pf@plt>
add    %r13,%rbx
add    %rax,%rbx
test   %r13,%r13
setne  %cl
test   %rax,%rax
setne  %al
and    %cl,%al
movzbl %al,%eax
add    %rax,%r15
add    $0x6,%rbp
add    $0xffffffffffffffff,%r12
jne    1200 <main+0xb0>
jmp    1245 <main+0xf5>
mov    $0x2,%ebx
lea    0xdb4(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  (%rsp),%xmm0
lea    0xdb4(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Prime Finder\0A\00"
@.str.1 = [43 x i8] c"1 is a prime number!\0A3 is a prime number!\0A\00"
@.str.2 = [29 x i8] c"Twin prime pairs found: %lu\0A\00"
@.str.3 = [37 x i8] c"Primes found: %lu in %.2f seconds.\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 1, i32* %6
br label %26
26: ; preds = %25, %19, %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = call double (...) @omp_get_wtime()
store double %33, double* %7
store i64 2, i64* %8
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
%38 = sext i32 %37 to i64
store i64 %38, i64* %9
store i64 1, i64* %10
store i64 0, i64* %11
store i64 0, i64* %14
store i64 1, i64* %10
br label %39
39: ; preds = %70, %32
%40 = load i64, i64* %10
%41 = load i64, i64* %9
%42 = add i64 %41, 6
%43 = udiv i64 %42, 6
%44 = icmp ult i64 %40, %43
br i1 %44, label %45, label %73
45: ; preds = %39
%46 = load i64, i64* %10
%47 = mul i64 6, %46
store i64 %47, i64* %11
%48 = load i64, i64* %11
%49 = add i64 %48, 1
%50 = load i32, i32* %6
%51 = call i64 @pf(i64 %49, i32 %50)
store i64 %51, i64* %12
%52 = load i64, i64* %11
%53 = sub i64 %52, 1
%54 = load i32, i32* %6
%55 = call i64 @pf(i64 %53, i32 %54)
store i64 %55, i64* %13
%56 = load i64, i64* %12
%57 = load i64, i64* %13
%58 = add i64 %56, %57
%59 = load i64, i64* %8
%60 = add i64 %59, %58
store i64 %60, i64* %8
%61 = load i64, i64* %12
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %45
%64 = load i64, i64* %13
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load i64, i64* %14
%68 = add i64 %67, 1
store i64 %68, i64* %14
br label %69
69: ; preds = %66, %63, %45
br label %70
70: ; preds = %69
%71 = load i64, i64* %10
%72 = add i64 %71, 1
store i64 %72, i64* %10
br label %39
73: ; preds = %39
%74 = load i64, i64* %14
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 %74)
%76 = load i64, i64* %8
%77 = call double (...) @omp_get_wtime()
%78 = load double, double* %7
%79 = fsub double %77, %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 %76, double %79)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [29 x i8] c"Twin prime pairs found: %lu\0A\00"
@.str.3 = [37 x i8] c"Primes found: %lu in %.2f seconds.\0A\0A\00"
@str = [13 x i8] c"Prime Finder\00"
@str.4 = [42 x i8] c"1 is a prime number!\0A3 is a prime number!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 2
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @atoi(i8* %4)
%8 = icmp eq i32 %7, 1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br i1 %8, label %10, label %14
10: ; preds = %6, %2
%11 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @str.4, i64 0, i64 0), %6 ]
%12 = phi i32 [ 0, %2 ], [ 1, %6 ]
%13 = tail call i32 @puts(i8* dereferenceable(1) %11)
br label %14
14: ; preds = %10, %6
%15 = phi i32 [ 0, %6 ], [ %12, %10 ]
%16 = tail call double (...) @omp_get_wtime()
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = sext i32 %19 to i64
%21 = add nsw i64 %20, 6
%22 = icmp ugt i64 %21, 11
br i1 %22, label %23, label %44
23: ; preds = %14
%24 = udiv i64 %21, 6
%25 = call i64 @llvm.umax.i64(i64 %24, i64 2)
br label %26
26: ; preds = %23, %26
%27 = phi i64 [ %41, %26 ], [ 0, %23 ]
%28 = phi i64 [ %36, %26 ], [ 2, %23 ]
%29 = phi i64 [ %42, %26 ], [ 1, %23 ]
%30 = mul nuw i64 %29, 6
%31 = or i64 %30, 1
%32 = tail call i64 @pf(i64 %31, i32 %15)
%33 = add i64 %30, -1
%34 = tail call i64 @pf(i64 %33, i32 %15)
%35 = add i64 %32, %28
%36 = add i64 %35, %34
%37 = icmp ne i64 %32, 0
%38 = icmp ne i64 %34, 0
%39 = select i1 %37, i1 %38, i1 false
%40 = zext i1 %39 to i64
%41 = add i64 %27, %40
%42 = add nuw nsw i64 %29, 1
%43 = icmp eq i64 %42, %25
br i1 %43, label %44, label %26
44: ; preds = %26, %14
%45 = phi i64 [ 2, %14 ], [ %36, %26 ]
%46 = phi i64 [ 0, %14 ], [ %41, %26 ]
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 %46)
%48 = tail call double (...) @omp_get_wtime()
%49 = fsub double %48, %16
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 %45, double %49)
ret i32 0
}