#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 sqrt(int);
int main() {
  int a, b, d = 1;
  for (a = 2;; a++) {
    bool c = 1;
    for (b = 2; b < sqrt(a) + 1; b++) {
      if (a % b == 0) {
        c = 0;
      }
    }
    if (c) {
      d = d + 1;
      if (d % 100000 == 0) {
        printf("Found prime: %d\n", a);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1193 <main+0x73>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1180 <main+0x60>
movl   $0x0,-0x14(%rbp)
jmp    1185 <main+0x65>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <main+0x2b>
cmpl   $0x0,-0x14(%rbp)
je     11ce <main+0xae>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x186a0,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c9 <main+0xa9>
mov    -0x8(%rbp),%esi
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
jmp    11ce <main+0xae>
jmp    11d3 <main+0xb3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113d <main+0x1d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1,%r15d
mov    $0x2,%r12d
lea    0xec5(%rip),%r14
jmp    115e <main+0x3e>
nopl   (%rax)
add    $0x1,%r15d
imul   $0xbcbe61d,%r15d,%eax
add    $0xa7c40,%eax
ror    $0x5,%eax
cmp    $0xa7c4,%eax
jbe    11b0 <main+0x90>
add    $0x1,%r12d
mov    %r12d,%edi
call   1040 <sqrt@plt>
cmp    $0x2,%eax
jl     1140 <main+0x20>
mov    $0x1,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
mov    %r12d,%eax
xor    %edx,%edx
div    %ebp
test   %edx,%edx
cmove  %edx,%ebx
mov    %r12d,%edi
call   1040 <sqrt@plt>
cmp    %eax,%ebp
jl     1180 <main+0x60>
test   %ebx,%ebx
jne    1140 <main+0x20>
jmp    115a <main+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12d,%esi
call   1030 <printf@plt>
jmp    115a <main+0x3a>

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

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