#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 *);
int main() {
  int n, i = 3, count, c;
  while (1) {
    printf("How many prime numbers?\n");
    scanf("%d", &n);
    if (n >= 1) {
      printf("First %d prime numbers:\n", n);
      printf("2 ");
    }
    for (count = 2; count <= n;) {
      for (c = 2; c <= i - 1; c++) {
        if (i % c == 0)
          break;
      }
      if (c == i) {
        printf("%d ", i);
        count++;
      }
      i++;
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0xc(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jl     117d <main+0x5d>
mov    -0x8(%rbp),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1204 <main+0xe4>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11d0 <main+0xb0>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    11bd <main+0x9d>
jmp    11d0 <main+0xb0>
jmp    11c2 <main+0xa2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1197 <main+0x77>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11f6 <main+0xd6>
mov    -0xc(%rbp),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1184 <main+0x64>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1136 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x3,%ebx
lea    0xecc(%rip),%r14
lea    0xea2(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xeb5(%rip),%r13
jmp    117a <main+0x3a>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    1170 <main+0x30>
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%ecx
cmp    $0x2,%ecx
jl     1170 <main+0x30>
mov    $0x2,%ebp
jmp    11ea <main+0xaa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
mov    0x4(%rsp),%ecx
add    $0x1,%ebx
cmp    %ecx,%ebp
jg     1170 <main+0x30>
mov    $0x2,%esi
cmp    $0x3,%ebx
jl     1220 <main+0xe0>
mov    $0x2,%esi
nopl   0x0(%rax)
mov    %ebx,%eax
cltd
idiv   %esi
test   %edx,%edx
je     1220 <main+0xe0>
add    $0x1,%esi
cmp    %esi,%ebx
jne    1200 <main+0xc0>
jmp    11d0 <main+0x90>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %ebx,%esi
je     11d0 <main+0x90>
jmp    11e3 <main+0xa3>

LLVM IR (-O0):
@.str = [25 x i8] c"How many prime numbers?\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"First %d prime numbers:\0A\00"
@.str.3 = [3 x i8] c"2 \00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [2 x i8] c"\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 3, i32* %3
br label %6
6: ; preds = %0, %48
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 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)
%9 = load i32, i32* %2
%10 = icmp sge i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %11, %6
store i32 2, i32* %4
br label %16
16: ; preds = %45, %15
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %48
20: ; preds = %16
store i32 2, i32* %5
br label %21
21: ; preds = %33, %20
%22 = load i32, i32* %5
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 1
%25 = icmp sle i32 %22, %24
br i1 %25, label %26, label %36
26: ; preds = %21
%27 = load i32, i32* %3
%28 = load i32, i32* %5
%29 = srem i32 %27, %28
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
br label %36
32: ; preds = %26
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %21
36: ; preds = %31, %21
%37 = load i32, i32* %5
%38 = load i32, i32* %3
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i32, i32* %3
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %45
45: ; preds = %40, %36
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %16
48: ; preds = %16
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %6
}

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