#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*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int sqrt(int);
int main() {
  int numberOfPrimes;
  printf("Quantos números primos quer? ");
  scanf("%d", &numberOfPrimes);
  int lastPrime = 1;
  for (int i = 0; i < numberOfPrimes; ++i) {
    for (;;) {
      char found = 1;
      ++lastPrime;
      for (int i = 2; i <= sqrt(lastPrime); ++i) {
        if (lastPrime % i == 0) {
          found = 0;
          break;
        }
      }
      if (found) {
        break;
      }
    }
    printf("%d ", lastPrime);
  }
  puts("");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121a <main+0xda>
jmp    118c <main+0x4c>
movb   $0x1,-0x11(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <sqrt@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jg     11e7 <main+0xa7>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cmp    $0x0,%edx
jne    11d4 <main+0x94>
movb   $0x0,-0x11(%rbp)
jmp    11e7 <main+0xa7>
jmp    11d9 <main+0x99>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a0 <main+0x60>
cmpb   $0x0,-0x11(%rbp)
je     11f6 <main+0xb6>
jmp    11fb <main+0xbb>
jmp    118c <main+0x4c>
mov    -0xc(%rbp),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117b <main+0x3b>
lea    0xdfd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec3(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11c9 <main+0x89>
mov    $0x1,%ebx
lea    0xea9(%rip),%r14
xor    %r15d,%r15d
jmp    1197 <main+0x57>
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15d
cmp    0x4(%rsp),%r15d
jge    11c9 <main+0x89>
add    $0x1,%ebx
mov    %ebx,%edi
call   1060 <sqrt@plt>
cmp    $0x2,%eax
jl     1180 <main+0x40>
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     1197 <main+0x57>
mov    %ebx,%edi
call   1060 <sqrt@plt>
cmp    %eax,%ebp
jl     11b0 <main+0x70>
jmp    1180 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [31 x i8] c"Quantos n\C3\BAmeros primos quer? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 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 %13
7: ; preds = %0, %29
%8 = phi i32 [ %32, %29 ], [ 0, %0 ]
%9 = phi i32 [ %30, %29 ], [ 1, %0 ]
%10 = add nsw i32 %9, 1
%11 = call i32 @sqrt(i32 %10)
%12 = icmp slt i32 %11, 2
br i1 %12, label %29, label %19
13: ; preds = %29, %0
%14 = call i32 @putchar(i32 10)
ret i32 0
15: ; preds = %25
%16 = add nsw i32 %20, 1
%17 = call i32 @sqrt(i32 %16)
%18 = icmp slt i32 %17, 2
br i1 %18, label %29, label %19
19: ; preds = %7, %15
%20 = phi i32 [ %16, %15 ], [ %10, %7 ]
br label %25
21: ; preds = %25
%22 = add nuw nsw i32 %26, 1
%23 = call i32 @sqrt(i32 %20)
%24 = icmp slt i32 %26, %23
br i1 %24, label %25, label %29
25: ; preds = %19, %21
%26 = phi i32 [ 2, %19 ], [ %22, %21 ]
%27 = srem i32 %20, %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %15, label %21
29: ; preds = %15, %21, %7
%30 = phi i32 [ %10, %7 ], [ %20, %21 ], [ %16, %15 ]
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = add nuw nsw i32 %8, 1
%33 = load i32, i32* %1
%34 = icmp slt i32 %32, %33
br i1 %34, label %7, label %13
}