#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 /*<<< orphan*/ scanf(char *, int *);
void main(void) {
  int primes_found, i, divisor, is_prime, k;
  printf("How many numbers do you want to find? ");
  scanf("%d", &k);
  primes_found = 0;
  i = 2;
  while (primes_found < k) {
    divisor = 2;
    is_prime = 1;
    while (divisor <= i / 2) {
      if (i % divisor == 0) {
        is_prime = 0;
        break;
      }
      divisor += 1;
    }
    if (is_prime == 1) {
      printf("%d\n", i);
      primes_found += 1;
    }
    i = i + 1;
  }
  scanf("%d", &i);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeea(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e8 <main+0xc8>
movl   $0x2,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jg     11b6 <main+0x96>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11a8 <main+0x88>
movl   $0x0,-0x10(%rbp)
jmp    11b6 <main+0x96>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116e <main+0x4e>
cmpl   $0x1,-0x10(%rbp)
jne    11da <main+0xba>
mov    -0x8(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1154 <main+0x34>
lea    0xe38(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeea(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
movl   $0x2,0xc(%rsp)
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
jle    11be <main+0x9e>
mov    $0x2,%ebx
lea    0xec7(%rip),%r14
xor    %ebp,%ebp
jmp    118e <main+0x6e>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
mov    0x8(%rsp),%ecx
add    $0x1,%ebx
mov    %ebx,0xc(%rsp)
cmp    %ecx,%ebp
jge    11be <main+0x9e>
cmp    $0x4,%ebx
jb     1170 <main+0x50>
mov    %ebx,%esi
shr    %esi
neg    %esi
mov    $0x2,%edi
xchg   %ax,%ax
mov    %ebx,%eax
xor    %edx,%edx
div    %edi
test   %edx,%edx
je     1183 <main+0x63>
lea    (%rsi,%rdi,1),%eax
add    $0x1,%eax
mov    %edi,%edx
add    $0x1,%edx
mov    %edx,%edi
cmp    $0x1,%eax
jne    11a0 <main+0x80>
jmp    1170 <main+0x50>
lea    0xe62(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"How many numbers do you want to find? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 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 0, i32* %1
store i32 2, i32* %2
br label %8
8: ; preds = %35, %0
%9 = load i32, i32* %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %38
12: ; preds = %8
store i32 2, i32* %3
store i32 1, i32* %4
br label %13
13: ; preds = %24, %12
%14 = load i32, i32* %3
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 2
%17 = icmp sle i32 %14, %16
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = srem i32 %19, %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 0, i32* %4
br label %27
24: ; preds = %18
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %13
27: ; preds = %23, %13
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %1
%34 = add nsw i32 %33, 1
store i32 %34, i32* %1
br label %35
35: ; preds = %30, %27
%36 = load i32, i32* %2
%37 = add nsw i32 %36, 1
store i32 %37, i32* %2
br label %8
38: ; preds = %8
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"How many numbers do you want to find? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 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)
store i32 2, i32* %1
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %32
9: ; preds = %0, %27
%10 = phi i32 [ %28, %27 ], [ %7, %0 ]
%11 = phi i32 [ %29, %27 ], [ 0, %0 ]
%12 = phi i32 [ %30, %27 ], [ 2, %0 ]
%13 = icmp ult i32 %12, 4
br i1 %13, label %23, label %14
14: ; preds = %9
%15 = lshr i32 %12, 1
br label %19
16: ; preds = %19
%17 = add nuw nsw i32 %20, 1
%18 = icmp eq i32 %20, %15
br i1 %18, label %23, label %19
19: ; preds = %14, %16
%20 = phi i32 [ %17, %16 ], [ 2, %14 ]
%21 = urem i32 %12, %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %16
23: ; preds = %16, %9
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%25 = add nsw i32 %11, 1
%26 = load i32, i32* %2
br label %27
27: ; preds = %19, %23
%28 = phi i32 [ %26, %23 ], [ %10, %19 ]
%29 = phi i32 [ %25, %23 ], [ %11, %19 ]
%30 = add nuw nsw i32 %12, 1
store i32 %30, i32* %1
%31 = icmp slt i32 %29, %28
br i1 %31, label %9, label %32
32: ; preds = %27, %0
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
ret void
}