#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 == 10001) {
      printf("Found prime: %d\n", a);
      break;
    }
  }
}


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     11a6 <main+0x86>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x2711,-0x10(%rbp)
jne    11c7 <main+0xa7>
mov    -0x8(%rbp),%esi
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
jmp    11da <main+0xba>
jmp    11cc <main+0xac>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113d <main+0x1d>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%r14d
mov    $0x2,%eax
jmp    1154 <main+0x34>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x1,%ebp
sbb    $0xffffffff,%r14d
lea    0x1(%r15),%eax
cmp    $0x2711,%r14d
je     119d <main+0x7d>
mov    %eax,%r15d
mov    %eax,%edi
call   1040 <sqrt@plt>
mov    $0x1,%ebp
cmp    $0x2,%eax
jl     1140 <main+0x20>
mov    $0x1,%ebx
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebx
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
test   %edx,%edx
cmove  %edx,%ebp
mov    %r15d,%edi
call   1040 <sqrt@plt>
cmp    %eax,%ebx
jl     1180 <main+0x60>
jmp    1140 <main+0x20>
lea    0xe5c(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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 = %36, %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 %29
26: ; preds = %23
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 10001
br i1 %31, label %32, label %35
32: ; preds = %29
%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 %39
35: ; preds = %29
br label %36
36: ; preds = %35
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %6
39: ; preds = %32
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [17 x i8] c"Found prime: %d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %15, %0
%2 = phi i32 [ 2, %0 ], [ %21, %15 ]
%3 = phi i32 [ 1, %0 ], [ %19, %15 ]
%4 = tail call i32 @sqrt(i32 %2)
%5 = icmp slt i32 %4, 2
br i1 %5, label %15, 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, %1
%16 = phi i32 [ 1, %1 ], [ %11, %6 ]
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %3, %18
%20 = icmp eq i32 %19, 10001
%21 = add nuw nsw i32 %2, 1
br i1 %20, label %22, label %1
22: ; preds = %15
%23 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %2)
ret i32 0
}