#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 /*<<< orphan*/ printf(char *, int, int, int);
int twin_primes(const int primes[], int size) {
  int i, twinPrimes = 0;
  for (i = 0; i <= size - 2; ++i) {
    if (primes[i] == 1 && primes[i + 2] == 1) {
      twinPrimes++;
      printf("twin prime #%4i: %4i and %4i\n", twinPrimes, i, i + 2);
    }
  }
  return twinPrimes;
}


x86 assembly (clang, -O0):
<twin_primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jg     119b <twin_primes+0x8b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1188 <twin_primes+0x78>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1188 <twin_primes+0x78>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x10(%rbp),%ecx
add    $0x2,%ecx
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
jmp    118d <twin_primes+0x7d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <twin_primes+0x1d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twin_primes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
cmp    $0x2,%esi
jge    112c <twin_primes+0x1c>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %esi,%r14d
mov    %rdi,%rbx
add    $0xffffffff,%r14d
xor    %ebp,%ebp
lea    0xec1(%rip),%r12
xor    %r15d,%r15d
jmp    1159 <twin_primes+0x49>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbp
cmp    %rbp,%r14
je     1120 <twin_primes+0x10>
cmpl   $0x1,(%rbx,%rbp,4)
jne    1150 <twin_primes+0x40>
cmpl   $0x1,0x8(%rbx,%rbp,4)
jne    1150 <twin_primes+0x40>
lea    0x2(%rbp),%ecx
add    $0x1,%r15d
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
jmp    1150 <twin_primes+0x40>

LLVM IR (-O0):
@.str = [30 x i8] c"twin prime #%4i: %4i and %4i\0A\00"
define i32 @twin_primes(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %7
7: ; preds = %36, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 2
%11 = icmp sle i32 %8, %10
br i1 %11, label %12, label %39
12: ; preds = %7
%13 = load i32*, i32** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %35
19: ; preds = %12
%20 = load i32*, i32** %3
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %20, i64 %23
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %35
27: ; preds = %19
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = load i32, i32* %5
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 2
%34 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31, i32 %33)
br label %35
35: ; preds = %27, %19, %12
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %7
39: ; preds = %7
%40 = load i32, i32* %6
ret i32 %40
}

LLVM IR (-O2):
@.str = [30 x i8] c"twin prime #%4i: %4i and %4i\0A\00"
define i32 @twin_primes(i32* nocapture %0, i32 %1) {
%3 = icmp slt i32 %1, 2
br i1 %3, label %27, label %4
4: ; preds = %2
%5 = add nsw i32 %1, -1
%6 = zext i32 %5 to i64
br label %7
7: ; preds = %4, %23
%8 = phi i64 [ 0, %4 ], [ %25, %23 ]
%9 = phi i32 [ 0, %4 ], [ %24, %23 ]
%10 = trunc i64 %8 to i32
%11 = getelementptr inbounds i32, i32* %0, i64 %8
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %23
14: ; preds = %7
%15 = add nuw nsw i64 %8, 2
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = add nuw nsw i32 %10, 2
%21 = add nsw i32 %9, 1
%22 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %10, i32 %20)
br label %23
23: ; preds = %7, %14, %19
%24 = phi i32 [ %21, %19 ], [ %9, %14 ], [ %9, %7 ]
%25 = add nuw nsw i64 %8, 1
%26 = icmp eq i64 %25, %6
br i1 %26, label %27, label %7
27: ; preds = %23, %2
%28 = phi i32 [ 0, %2 ], [ %24, %23 ]
ret i32 %28
}