#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, ...);
void primeLessThan(int n) {
  printf("Finding number of prime numbers less than %d\n", n);
  int *arr;
  int i;
  int count = 0;
  arr = (int *)malloc(sizeof(int) * (n + 1));
  for (i = 2; i < (n + 1); i++) {
    if (arr[i] == 1) {
      continue;
    }
    count += 1;
    int j = 2 * i;
    while (j < (n + 1)) {
      arr[j] = 1;
      j += i;
    }
  }
  printf("Number of prime numbers less than %d is : %d\n", n, count);
}


x86 assembly (clang, -O0):
<primeLessThan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11dc <primeLessThan+0xbc>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1189 <primeLessThan+0x69>
jmp    11ce <primeLessThan+0xae>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11c9 <primeLessThan+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    119b <primeLessThan+0x7b>
jmp    11ce <primeLessThan+0xae>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <primeLessThan+0x41>
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<primeLessThan>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    0xed3(%rip),%rdi
xor    %r14d,%r14d
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(,%rbx,4),%edi
call   1040 <malloc@plt>
cmp    $0x2,%ebx
jge    1161 <primeLessThan+0x41>
lea    0xedd(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>
lea    0x1(%rbx),%r8d
mov    %rax,%r9
add    $0x10,%r9
xor    %r14d,%r14d
mov    $0x2,%esi
mov    $0x8,%edi
mov    $0x4,%ecx
jmp    1194 <primeLessThan+0x74>
add    $0x1,%rsi
add    $0x8,%r9
add    $0x4,%rdi
add    $0x2,%ecx
cmp    %r8,%rsi
je     114a <primeLessThan+0x2a>
cmpl   $0x1,(%rax,%rsi,4)
je     1180 <primeLessThan+0x60>
add    $0x1,%r14d
lea    (%rsi,%rsi,1),%edx
cmp    %ebx,%edx
jg     1180 <primeLessThan+0x60>
mov    %ecx,%ebp
mov    %r9,%rdx
nopw   0x0(%rax,%rax,1)
movl   $0x1,(%rdx)
add    %rdi,%rdx
add    %esi,%ebp
cmp    %ebx,%ebp
jle    11b0 <primeLessThan+0x90>
jmp    1180 <primeLessThan+0x60>

LLVM IR (-O0):
@.str = [46 x i8] c"Finding number of prime numbers less than %d\0A\00"
@.str.1 = [46 x i8] c"Number of prime numbers less than %d is : %d\0A\00"
define void @primeLessThan(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 0, i32* %5
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 4, %11
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %3
store i32 2, i32* %4
br label %16
16: ; preds = %48, %1
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %51
21: ; preds = %16
%22 = load i32*, i32** %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %21
br label %48
29: ; preds = %21
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
%32 = load i32, i32* %4
%33 = mul nsw i32 2, %32
store i32 %33, i32* %6
br label %34
34: ; preds = %39, %29
%35 = load i32, i32* %6
%36 = load i32, i32* %2
%37 = add nsw i32 %36, 1
%38 = icmp slt i32 %35, %37
br i1 %38, label %39, label %47
39: ; preds = %34
%40 = load i32*, i32** %3
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 1, i32* %43
%44 = load i32, i32* %4
%45 = load i32, i32* %6
%46 = add nsw i32 %45, %44
store i32 %46, i32* %6
br label %34
47: ; preds = %34
br label %48
48: ; preds = %47, %28
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
store i32 %50, i32* %4
br label %16
51: ; preds = %16
%52 = load i32, i32* %2
%53 = load i32, i32* %5
%54 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %52, i32 %53)
ret void
}

LLVM IR (-O2):
@.str = [46 x i8] c"Finding number of prime numbers less than %d\0A\00"
@.str.1 = [46 x i8] c"Number of prime numbers less than %d is : %d\0A\00"
define void @primeLessThan(i32 %0) {
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = shl i32 %0, 2
%4 = add i32 %3, 4
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i32*
%7 = icmp slt i32 %0, 2
br i1 %7, label %34, label %8
8: ; preds = %1
%9 = add nuw nsw i32 %0, 1
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %8, %29
%12 = phi i64 [ 2, %8 ], [ %31, %29 ]
%13 = phi i64 [ 4, %8 ], [ %32, %29 ]
%14 = phi i32 [ 0, %8 ], [ %30, %29 ]
%15 = getelementptr inbounds i32, i32* %6, i64 %12
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 1
br i1 %17, label %29, label %18
18: ; preds = %11
%19 = add nsw i32 %14, 1
%20 = trunc i64 %12 to i32
%21 = shl i32 %20, 1
%22 = icmp sgt i32 %21, %0
br i1 %22, label %29, label %23
23: ; preds = %18, %23
%24 = phi i64 [ %26, %23 ], [ %13, %18 ]
%25 = getelementptr inbounds i32, i32* %6, i64 %24
store i32 1, i32* %25
%26 = add nuw nsw i64 %24, %12
%27 = trunc i64 %26 to i32
%28 = icmp sgt i32 %27, %0
br i1 %28, label %29, label %23
29: ; preds = %23, %18, %11
%30 = phi i32 [ %14, %11 ], [ %19, %18 ], [ %19, %23 ]
%31 = add nuw nsw i64 %12, 1
%32 = add nuw nsw i64 %13, 2
%33 = icmp eq i64 %31, %10
br i1 %33, label %34, label %11
34: ; preds = %29, %1
%35 = phi i32 [ 0, %1 ], [ %30, %29 ]
%36 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %35)
ret void
}