#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 class;
  int n, i = 3, count, c;
  printf("Enter the number of prime numbers required\n");
  scanf("%d", &n);
  if (n >= 1) {
    printf("First %d prime numbers are :\n", n);
    printf("2\n");
  }
  for (count = 2; count <= n;) {
    for (c = 2; c <= i - 1; c++) {
      if (i % c == 0)
        break;
    }
    if (c == i) {
      printf("%d\n", i);
      count++;
    }
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0xc(%rbp)
jl     117d <main+0x5d>
mov    -0xc(%rbp),%esi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1204 <main+0xe4>
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11d0 <main+0xb0>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cmp    $0x0,%edx
jne    11bd <main+0x9d>
jmp    11d0 <main+0xb0>
jmp    11c2 <main+0xa2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1197 <main+0x77>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11f6 <main+0xd6>
mov    -0x10(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1184 <main+0x64>
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    0xee7(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    117f <main+0x4f>
lea    0xea0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%ecx
cmp    $0x2,%ecx
jge    118c <main+0x5c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x3,%ebx
mov    $0x2,%r15d
mov    $0xffffffff,%ebp
lea    0xe7e(%rip),%r14
jmp    11cf <main+0x9f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15d
mov    0x4(%rsp),%ecx
add    $0x1,%ebx
add    $0xffffffff,%ebp
cmp    %ecx,%r15d
jg     117f <main+0x4f>
mov    $0x2,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
test   %edx,%edx
je     1200 <main+0xd0>
lea    (%rsi,%rbp,1),%eax
add    $0x1,%eax
mov    %esi,%edx
add    $0x1,%edx
mov    %edx,%esi
cmp    $0x2,%eax
jne    11e0 <main+0xb0>
jmp    11b0 <main+0x80>
xchg   %ax,%ax
add    %ebp,%esi
cmp    $0x2,%esi
je     11b0 <main+0x80>
jmp    11c4 <main+0x94>

LLVM IR (-O0):
@.str = [44 x i8] c"Enter the number of prime numbers required\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [30 x i8] c"First %d prime numbers are :\0A\00"
@.str.3 = [3 x i8] c"2\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 3, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 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* %3)
%9 = load i32, i32* %3
%10 = icmp sge i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 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, %0
store i32 2, i32* %5
br label %16
16: ; preds = %45, %15
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %48
20: ; preds = %16
store i32 2, i32* %6
br label %21
21: ; preds = %33, %20
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%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* %4
%28 = load i32, i32* %6
%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* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %21
36: ; preds = %31, %21
%37 = load i32, i32* %6
%38 = load i32, i32* %4
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i32, i32* %4
%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* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %45
45: ; preds = %40, %36
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %16
48: ; preds = %16
ret i32 0
}

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