#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__ isPrime(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int num = 0, count = 0, i = 0;
  printf("Please enter the upper bound.\n");
  scanf("%d", &num);
  for (i = 1; i <= num; i++) {
    if (isPrime(i))
      count++;
  }
  printf("The number of primes till %d is %d.\n", num, count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11b3 <main+0x83>
mov    -0x10(%rbp),%edi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     11a0 <main+0x70>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a5 <main+0x75>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1179 <main+0x49>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xed6(%rip),%rdi
call   1030 <puts@plt>
lea    0xea2(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    119b <main+0x5b>
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
mov    %ebp,%edi
call   1050 <isPrime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
mov    0x4(%rsp),%esi
cmp    %esi,%ebp
jl     1180 <main+0x40>
jmp    119d <main+0x5d>
xor    %ebx,%ebx
lea    0xe5f(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Please enter the upper bound.\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [37 x i8] c"The number of primes till %d is %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 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* %2)
store i32 1, i32* %4
br label %7
7: ; preds = %19, %0
%8 = load i32, i32* %4
%9 = load i32, i32* %2
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %22
11: ; preds = %7
%12 = load i32, i32* %4
%13 = call i64 @isPrime(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %18
18: ; preds = %15, %11
br label %19
19: ; preds = %18
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %7
22: ; preds = %7
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [37 x i8] c"The number of primes till %d is %d.\0A\00"
@str = [30 x i8] c"Please enter the upper bound.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 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 slt i32 %5, 1
br i1 %6, label %17, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %14, %7 ], [ 1, %0 ]
%9 = phi i32 [ %13, %7 ], [ 0, %0 ]
%10 = call i64 @isPrime(i32 %8)
%11 = icmp ne i64 %10, 0
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %9, %12
%14 = add nuw nsw i32 %8, 1
%15 = load i32, i32* %1
%16 = icmp slt i32 %8, %15
br i1 %16, label %7, label %17
17: ; preds = %7, %0
%18 = phi i32 [ 0, %0 ], [ %13, %7 ]
%19 = phi i32 [ %5, %0 ], [ %15, %7 ]
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %18)
ret i32 0
}