#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 */
typedef int int64_t;

/* Variables and functions */
int isPrime(int);
int countTwinPrimes(int limit) {
  int count = 0;
  int64_t p3 = true, p2 = true, p1 = false;
  int64_t i;
  for (i = 5; i <= limit; i++) {
    p3 = p2;
    p2 = p1;
    p1 = isPrime(i);
    if (p3 && p1) {
      count++;
    }
  }
  return count;
}


x86 assembly (clang, -O0):
<countTwinPrimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x5,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1191 <countTwinPrimes+0x81>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <isPrime@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117e <countTwinPrimes+0x6e>
cmpl   $0x0,-0x14(%rbp)
je     117e <countTwinPrimes+0x6e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1183 <countTwinPrimes+0x73>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <countTwinPrimes+0x2e>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countTwinPrimes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebp,%ebp
cmp    $0x5,%edi
jl     1172 <countTwinPrimes+0x62>
mov    %edi,%r14d
neg    %r14d
mov    $0x1,%r15d
xor    %eax,%eax
mov    $0x5,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%r12d
mov    %ebx,%edi
call   1030 <isPrime@plt>
test   %r15d,%r15d
setne  %cl
test   %eax,%eax
setne  %dl
and    %cl,%dl
movzbl %dl,%ecx
add    %ecx,%ebp
lea    (%r14,%rbx,1),%ecx
add    $0x1,%ecx
mov    %ebx,%edx
add    $0x1,%edx
mov    %edx,%ebx
mov    %r12d,%r15d
cmp    $0x1,%ecx
jne    1140 <countTwinPrimes+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @countTwinPrimes(i32 %0) {
%2 = icmp slt i32 %0, 5
br i1 %2, label %16, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %14, %3 ], [ 5, %1 ]
%5 = phi i32 [ %8, %3 ], [ 0, %1 ]
%6 = phi i32 [ %5, %3 ], [ 1, %1 ]
%7 = phi i32 [ %13, %3 ], [ 0, %1 ]
%8 = tail call i32 @isPrime(i32 %4)
%9 = icmp ne i32 %6, 0
%10 = icmp ne i32 %8, 0
%11 = select i1 %9, i1 %10, i1 false
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %7, %12
%14 = add nuw i32 %4, 1
%15 = icmp eq i32 %4, %0
br i1 %15, label %16, label %3
16: ; preds = %3, %1
%17 = phi i32 [ 0, %1 ], [ %13, %3 ]
ret i32 %17
}