#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;
  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,-0xc(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jl     117d <main+0x5d>
mov    -0x8(%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,-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    0xe6a(%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>
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
store i32 0, i32* %1
store i32 3, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 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* %2)
%8 = load i32, i32* %2
%9 = icmp sge i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %10, %0
store i32 2, i32* %4
br label %15
15: ; preds = %44, %14
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %47
19: ; preds = %15
store i32 2, i32* %5
br label %20
20: ; preds = %32, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, 1
%24 = icmp sle i32 %21, %23
br i1 %24, label %25, label %35
25: ; preds = %20
%26 = load i32, i32* %3
%27 = load i32, i32* %5
%28 = srem i32 %26, %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
br label %35
31: ; preds = %25
br label %32
32: ; preds = %31
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %20
35: ; preds = %30, %20
%36 = load i32, i32* %5
%37 = load i32, i32* %3
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i32, i32* %3
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %44
44: ; preds = %39, %35
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %15
47: ; preds = %15
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
}