#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 *sieve(int, int *);
int main() {
  printf("Enter a number\n");
  int n;
  scanf("%d", &n);
  int prime[n + 1];
  int *arr = sieve(n, prime);
  printf("Prime numbers upto n\n");
  int i;
  for (i = 0; i <= n; i++) {
    if (arr[i])
      printf("%d\t", i);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <sieve@plt>
mov    %rax,-0x20(%rbp)
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11e6 <main+0xb6>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11d3 <main+0xa3>
mov    -0x24(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d8 <main+0xa8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a4 <main+0x74>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8e(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1070 <scanf@plt>
mov    %rsp,%r12
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rsi
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rsi
mov    %rsi,%rsp
mov    -0x24(%rbp),%edi
call   1060 <sieve@plt>
mov    %rax,%r15
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
mov    -0x24(%rbp),%eax
test   %eax,%eax
js     11f7 <main+0xa7>
lea    0xe45(%rip),%r14
xor    %ebx,%ebx
jmp    11df <main+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbx),%rcx
movslq %eax,%rdx
cmp    %rdx,%rbx
mov    %rcx,%rbx
jge    11f7 <main+0xa7>
cmpl   $0x0,(%r15,%rbx,4)
je     11d0 <main+0x80>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
jmp    11d0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Enter a number\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"Prime numbers upto n\0A\00"
@.str.3 = [4 x i8] c"%d\09\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 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 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i32, i64 %11
store i64 %11, i64* %4
%14 = load i32, i32* %2
%15 = call i32* @sieve(i32 %14, i32* %13)
store i32* %15, i32** %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %6
br label %17
17: ; preds = %32, %0
%18 = load i32, i32* %6
%19 = load i32, i32* %2
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i32*, i32** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i32, i32* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28, %21
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %17
35: ; preds = %17
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
%37 = load i8*, i8** %3
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\09\00"
@str = [15 x i8] c"Enter a number\00"
@str.5 = [21 x i8] c"Prime numbers upto n\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
%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 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
%9 = alloca i32, i64 %7
%10 = load i32, i32* %1
%11 = call i32* @sieve(i32 %10, i32* %9)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 0
br i1 %14, label %30, label %15
15: ; preds = %0, %25
%16 = phi i32 [ %26, %25 ], [ %13, %0 ]
%17 = phi i64 [ %27, %25 ], [ 0, %0 ]
%18 = getelementptr inbounds i32, i32* %11, i64 %17
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %15
%22 = trunc i64 %17 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %1
br label %25
25: ; preds = %15, %21
%26 = phi i32 [ %16, %15 ], [ %24, %21 ]
%27 = add nuw nsw i64 %17, 1
%28 = sext i32 %26 to i64
%29 = icmp slt i64 %17, %28
br i1 %29, label %15, label %30
30: ; preds = %25, %0
%31 = call i32 @putchar(i32 10)
ret i32 0
}