#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 twin_primes(int n) {
  int del, printed_twin_primes = 1, prime = 3, twin_prime = 3, flag_prime;
  while (printed_twin_primes <= n) {
    flag_prime = 1;
    for (del = 2; del <= prime / 2; del++) {
      if (prime % del == 0) {
        flag_prime = 0;
        break;
      }
    }
    if (flag_prime == 1) {
      if (prime == twin_prime + 2) {
        printf("(%d,%d)\n", twin_prime, prime);
        printed_twin_primes++;
      }
      twin_prime = prime;
    }
    prime++;
  }
}


x86 assembly (clang, -O0):
<twin_primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x3,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11e1 <twin_primes+0xd1>
movl   $0x1,-0x1c(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jg     1197 <twin_primes+0x87>
mov    -0x14(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1184 <twin_primes+0x74>
movl   $0x0,-0x1c(%rbp)
jmp    1197 <twin_primes+0x87>
jmp    1189 <twin_primes+0x79>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <twin_primes+0x3a>
cmpl   $0x1,-0x1c(%rbp)
jne    11d3 <twin_primes+0xc3>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jne    11cd <twin_primes+0xbd>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1130 <twin_primes+0x20>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twin_primes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    11b2 <twin_primes+0xa2>
mov    %edi,%r15d
mov    $0x1,%ebx
mov    $0x3,%esi
mov    $0x2,%r12d
lea    0xec6(%rip),%r14
mov    $0x3,%ebp
jmp    115a <twin_primes+0x4a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%esi
add    $0x1,%ebp
cmp    %r15d,%ebx
jg     11b2 <twin_primes+0xa2>
mov    %ebp,%ecx
shr    %ecx
cmp    $0x3,%ecx
cmovb  %r12d,%ecx
cmp    $0x4,%ebp
jb     119c <twin_primes+0x8c>
neg    %ecx
mov    $0x2,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
xor    %edx,%edx
div    %edi
test   %edx,%edx
je     1152 <twin_primes+0x42>
lea    (%rcx,%rdi,1),%eax
add    $0x1,%eax
mov    %edi,%edx
add    $0x1,%edx
mov    %edx,%edi
cmp    $0x1,%eax
jne    1180 <twin_primes+0x70>
lea    0x2(%rsi),%eax
cmp    %eax,%ebp
jne    1150 <twin_primes+0x40>
mov    %r14,%rdi
mov    %ebp,%edx
call   1030 <printf@plt>
add    $0x1,%ebx
jmp    1150 <twin_primes+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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