#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() {
  int num, i = 1, j, count;
  printf("Enter Num value To Print Prime Numbers between 1 and Num: ");
  scanf("%d", &num);
  printf("Prime Numbers upto %d :\n \n", num);
  while (i <= num) {
    count = 0;
    for (j = 1; j <= i; j++) {
      if (i % j == 0)
        count++;
    }
    if (count == 2)
      printf("%d ", i);
    i++;
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x8(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef7(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%esi
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11d9 <main+0xb9>
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11b0 <main+0x90>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    119d <main+0x7d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a2 <main+0x82>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <main+0x58>
cmpl   $0x2,-0x10(%rbp)
jne    11cb <main+0xab>
mov    -0x8(%rbp),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115e <main+0x3e>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeef(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
lea    0xedd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%r8d
test   %r8d,%r8d
jle    122f <main+0xff>
mov    $0x1,%ebx
lea    0xed7(%rip),%r14
xor    %r15d,%r15d
jmp    119e <main+0x6e>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%eax
cmp    %r8d,%ebx
mov    %eax,%ebx
jge    122f <main+0xff>
mov    %r15d,%eax
lea    0x1(%rax),%r15d
test   %eax,%eax
je     1220 <main+0xf0>
mov    %ebx,%edi
and    $0xfffffffe,%edi
neg    %edi
mov    $0x1,%ecx
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
cmp    $0x1,%edx
adc    $0x0,%esi
lea    0x1(%rcx),%ebp
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
cmp    $0x1,%edx
adc    $0x0,%esi
mov    %ecx,%ebp
add    $0x2,%ebp
lea    (%rdi,%rcx,1),%eax
add    $0x2,%eax
mov    %ebp,%ecx
cmp    $0x1,%eax
jne    11c0 <main+0x90>
test   $0x1,%r15b
je     11ff <main+0xcf>
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
cmp    $0x1,%edx
adc    $0x0,%esi
cmp    $0x2,%esi
jne    1190 <main+0x60>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%r8d
jmp    1190 <main+0x60>
nopw   0x0(%rax,%rax,1)
xor    %esi,%esi
mov    $0x1,%ebp
test   $0x1,%r15b
jne    11f3 <main+0xc3>
jmp    11ff <main+0xcf>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"Enter Num value To Print Prime Numbers between 1 and Num: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Prime Numbers upto %d :\0A \0A\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [3 x i8] c"\0A\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 1, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %36, %0
%10 = load i32, i32* %2
%11 = load i32, i32* %1
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %39
13: ; preds = %9
store i32 0, i32* %4
store i32 1, i32* %3
br label %14
14: ; preds = %27, %13
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %14
%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 %26
23: ; preds = %18
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %23, %18
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %14
30: ; preds = %14
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 2
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %9
39: ; preds = %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [59 x i8] c"Enter Num value To Print Prime Numbers between 1 and Num: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Prime Numbers upto %d :\0A \0A\00"
@.str.3 = [4 x i8] c"%d \00"
@str = [2 x i8] c"\0A\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %55, label %9
9: ; preds = %0, %50
%10 = phi i32 [ %54, %50 ], [ 0, %0 ]
%11 = phi i32 [ %51, %50 ], [ %7, %0 ]
%12 = phi i32 [ %52, %50 ], [ 1, %0 ]
%13 = add i32 %10, 1
%14 = and i32 %13, 1
%15 = icmp eq i32 %10, 0
br i1 %15, label %34, label %16
16: ; preds = %9
%17 = and i32 %13, -2
br label %18
18: ; preds = %18, %16
%19 = phi i32 [ 0, %16 ], [ %30, %18 ]
%20 = phi i32 [ 1, %16 ], [ %31, %18 ]
%21 = phi i32 [ 0, %16 ], [ %32, %18 ]
%22 = urem i32 %12, %20
%23 = icmp eq i32 %22, 0
%24 = zext i1 %23 to i32
%25 = add nuw nsw i32 %19, %24
%26 = add nuw i32 %20, 1
%27 = urem i32 %12, %26
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = add nuw nsw i32 %25, %29
%31 = add nuw i32 %20, 2
%32 = add i32 %21, 2
%33 = icmp eq i32 %32, %17
br i1 %33, label %34, label %18
34: ; preds = %18, %9
%35 = phi i32 [ undef, %9 ], [ %30, %18 ]
%36 = phi i32 [ 0, %9 ], [ %30, %18 ]
%37 = phi i32 [ 1, %9 ], [ %31, %18 ]
%38 = icmp eq i32 %14, 0
br i1 %38, label %44, label %39
39: ; preds = %34
%40 = urem i32 %12, %37
%41 = icmp eq i32 %40, 0
%42 = zext i1 %41 to i32
%43 = add nuw nsw i32 %36, %42
br label %44
44: ; preds = %34, %39
%45 = phi i32 [ %35, %34 ], [ %43, %39 ]
%46 = icmp eq i32 %45, 2
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%49 = load i32, i32* %1
br label %50
50: ; preds = %47, %44
%51 = phi i32 [ %49, %47 ], [ %11, %44 ]
%52 = add nuw nsw i32 %12, 1
%53 = icmp slt i32 %12, %51
%54 = add i32 %10, 1
br i1 %53, label %9, label %55
55: ; preds = %50, %0
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}