#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(int);
int /*<<< orphan*/ printf(char *, int, int);
main() {
  int targetPrime = 1000000;
  int currentPrime = 6;
  int currentNum = 13;
  while (currentPrime < targetPrime) {
    currentNum += 2;
    if (isPrime(currentNum)) {
      currentPrime += 1;
      printf("Prime number #%i found: %i\n", currentPrime, currentNum);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf4240,-0x8(%rbp)
movl   $0x6,-0xc(%rbp)
movl   $0xd,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    118b <main+0x6b>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     1186 <main+0x66>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
jmp    1144 <main+0x24>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x6,%ebx
mov    $0xf,%ebp
lea    0xecb(%rip),%r14
jmp    114b <main+0x2b>
nopw   0x0(%rax,%rax,1)
add    $0x2,%ebp
cmp    $0xf4240,%ebx
jge    1168 <main+0x48>
mov    %ebp,%edi
call   1040 <isPrime@plt>
test   %rax,%rax
je     1140 <main+0x20>
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
jmp    1140 <main+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Prime number #%i found: %i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1000000, i32* %2
store i32 6, i32* %3
store i32 13, i32* %4
br label %5
5: ; preds = %21, %0
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %22
9: ; preds = %5
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 2
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = call i64 @isPrime(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
br label %21
21: ; preds = %15, %9
br label %5
22: ; preds = %5
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [28 x i8] c"Prime number #%i found: %i\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %10
%2 = phi i32 [ 13, %0 ], [ %4, %10 ]
%3 = phi i32 [ 6, %0 ], [ %11, %10 ]
%4 = add nuw nsw i32 %2, 2
%5 = tail call i64 @isPrime(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = add nsw i32 %3, 1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %4)
br label %10
10: ; preds = %7, %1
%11 = phi i32 [ %8, %7 ], [ %3, %1 ]
%12 = icmp slt i32 %11, 1000000
br i1 %12, label %1, label %13
13: ; preds = %10
ret i32 0
}