#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 /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ system(char *);
int main(void) {
  int i, flag, prime_counter = 0, nth_prime;
  printf("Enter an ordinal number: ");
  scanf("%d", &nth_prime);
  i = 2;
  flag = 1;
  while (flag && prime_counter < nth_prime) {
    if (IsPrime(i))
      prime_counter++;
    i++;
  }
  printf("The %dth prime is %d.\n", prime_counter, --i);
  system("PAUSE");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeaf(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x2,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x15(%rbp)
je     119d <main+0x5d>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11ad <main+0x6d>
jmp    11d6 <main+0x96>
mov    -0x8(%rbp),%edi
call   1060 <IsPrime@plt>
cmp    $0x0,%rax
je     11c8 <main+0x88>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1182 <main+0x42>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
add    $0xffffffff,%edx
mov    %edx,-0x8(%rbp)
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3d(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec0(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    1199 <main+0x59>
xor    %ebx,%ebx
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %ebp,%edi
call   1060 <IsPrime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
cmp    0x4(%rsp),%ebx
jl     1180 <main+0x40>
jmp    119e <main+0x5e>
mov    $0x1,%ebp
lea    0xe78(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7d(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter an ordinal number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"The %dth prime is %d.\0A\00"
@.str.3 = [6 x i8] c"PAUSE\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 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
store i32 2, i32* %2
store i32 1, i32* %3
br label %8
8: ; preds = %24, %0
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br label %15
15: ; preds = %11, %8
%16 = phi i1 [ false, %8 ], [ %14, %11 ]
br i1 %16, label %17, label %27
17: ; preds = %15
%18 = load i32, i32* %2
%19 = call i64 @IsPrime(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %24
24: ; preds = %21, %17
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %8
27: ; preds = %15
%28 = load i32, i32* %4
%29 = load i32, i32* %2
%30 = add nsw i32 %29, -1
store i32 %30, i32* %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %30)
%32 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"Enter an ordinal number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"The %dth prime is %d.\0A\00"
@.str.3 = [6 x i8] c"PAUSE\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %0, %7
%8 = phi i32 [ %13, %7 ], [ 0, %0 ]
%9 = phi i32 [ %14, %7 ], [ 2, %0 ]
%10 = call i64 @IsPrime(i32 %9)
%11 = icmp ne i64 %10, 0
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %8, %12
%14 = add nuw nsw i32 %9, 1
%15 = load i32, i32* %1
%16 = icmp slt i32 %13, %15
br i1 %16, label %7, label %17
17: ; preds = %7, %0
%18 = phi i32 [ 1, %0 ], [ %9, %7 ]
%19 = phi i32 [ 0, %0 ], [ %13, %7 ]
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %18)
%21 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}