#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 check_prime(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  printf("which number prime to find?\n");
  int max_prime;
  scanf("%d", &max_prime);
  printf("\n");
  int count = 0, number = 0;
  while (count < max_prime) {
    number++;
    if (number == 1)
      continue;
    printf("%d...", number);
    if (check_prime(number) == 1) {
      count++;
      printf("prime\n");
    };
    printf("\n");
  }
  printf("the %d prime is %d\n", max_prime, number);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e9 <main+0xb9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    119d <main+0x6d>
jmp    1179 <main+0x49>
mov    -0x10(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
call   1030 <check_prime@plt>
cmp    $0x1,%eax
jne    11d6 <main+0xa6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1179 <main+0x49>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeba(%rip),%rdi
call   1050 <puts@plt>
lea    0xe91(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
lea    0xe83(%rip),%r15
lea    0xeb2(%rip),%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
mov    %ebp,%r12d
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%esi
mov    %r12d,%eax
nop
cmp    %esi,%ebx
jge    11da <main+0x8a>
mov    %eax,%ebp
mov    $0x1,%eax
test   %ebp,%ebp
je     11a0 <main+0x50>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1040 <check_prime@plt>
mov    %ebp,%r12d
cmp    $0x1,%eax
jne    118e <main+0x3e>
add    $0x1,%ebx
mov    %r14,%rdi
call   1050 <puts@plt>
jmp    118b <main+0x3b>
lea    0xe28(%rip),%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c"%d...\00"
@.str.5 = [20 x i8] c"the %d prime is %d\0A\00"
@str = [28 x i8] c"which number prime to find?\00"
@str.6 = [6 x i8] c"prime\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %5
5: ; preds = %22, %0
%6 = phi i32 [ %23, %22 ], [ 0, %0 ]
%7 = phi i32 [ %18, %22 ], [ 0, %0 ]
br label %8
8: ; preds = %5, %17
%9 = phi i32 [ %18, %17 ], [ %7, %5 ]
%10 = call i32 @putchar(i32 10)
%11 = load i32, i32* %1
%12 = icmp slt i32 %6, %11
br label %13
13: ; preds = %8, %15
%14 = phi i32 [ 1, %15 ], [ %9, %8 ]
br i1 %12, label %15, label %25
15: ; preds = %13
%16 = icmp eq i32 %14, 0
br i1 %16, label %13, label %17
17: ; preds = %15
%18 = add nsw i32 %14, 1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = call i32 @check_prime(i32 %18)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %8
22: ; preds = %17
%23 = add nuw nsw i32 %6, 1
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.6, i64 0, i64 0))
br label %5
25: ; preds = %13
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %11, i32 %9)
ret i32 0
}