#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double, ...);
int main() {
  clock_t begin, end;
  double time_spent;
  begin = clock();
  int number = 10000, flag, count = 0;
  int i, j;
  for (i = 3; i <= number; i = i + 2) {
    flag = 0;
    for (j = 2; j <= i / 2; j++) {
      if ((i % j) == 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      count++;
    }
  }
  printf("Number of primes upto %d is %d\n", number, count);
  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("%.3lf seconds\n", time_spent);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
movl   $0x2710,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x3,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     11dc <main+0xbc>
movl   $0x0,-0x28(%rbp)
movl   $0x2,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jg     11b6 <main+0x96>
mov    -0x30(%rbp),%eax
cltd
idivl  -0x34(%rbp)
cmp    $0x0,%edx
jne    11a3 <main+0x83>
movl   $0x1,-0x28(%rbp)
jmp    11b6 <main+0x96>
jmp    11a8 <main+0x88>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1169 <main+0x49>
cmpl   $0x0,-0x28(%rbp)
jne    11c9 <main+0xa9>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ce <main+0xae>
mov    -0x30(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x30(%rbp)
jmp    114f <main+0x2f>
cvtsi2sdl -0x24(%rbp),%xmm0
mov    -0x2c(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dd7(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xdfa(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
mov    $0x3,%ecx
mov    $0x1,%esi
jmp    1156 <main+0x36>
xor    %eax,%eax
movzbl %al,%eax
add    %eax,%r15d
add    $0x2,%ecx
add    $0x1,%esi
cmp    $0x1388,%esi
je     119b <main+0x7b>
cmp    $0x3,%esi
mov    $0x2,%edi
cmovae %esi,%edi
mov    $0x1,%al
cmp    $0x4,%ecx
jb     1142 <main+0x22>
test   $0x1,%cl
je     1140 <main+0x20>
mov    %ecx,%r8d
shr    %r8d
mov    $0x2,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%ebx
cmp    %ebp,%edi
je     1193 <main+0x73>
lea    0x1(%rbx),%ebp
mov    %ecx,%eax
xor    %edx,%edx
div    %ebp
test   %edx,%edx
jne    1180 <main+0x60>
cmp    %r8d,%ebx
setae  %al
jmp    1142 <main+0x22>
lea    0xe66(%rip),%rdi
movsd  0xe56(%rip),%xmm0
mov    %r15d,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2e1b(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe50(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Number of primes upto %d is %d\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [15 x i8] c"%.3lf seconds\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i64 (...) @clock()
store i64 %10, i64* %2
store i32 10000, i32* %5
store i32 0, i32* %7
store i32 3, i32* %8
br label %11
11: ; preds = %38, %0
%12 = load i32, i32* %8
%13 = load i32, i32* %5
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %41
15: ; preds = %11
store i32 0, i32* %6
store i32 2, i32* %9
br label %16
16: ; preds = %28, %15
%17 = load i32, i32* %9
%18 = load i32, i32* %8
%19 = sdiv i32 %18, 2
%20 = icmp sle i32 %17, %19
br i1 %20, label %21, label %31
21: ; preds = %16
%22 = load i32, i32* %8
%23 = load i32, i32* %9
%24 = srem i32 %22, %23
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 1, i32* %6
br label %31
27: ; preds = %21
br label %28
28: ; preds = %27
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
br label %16
31: ; preds = %26, %16
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %37
37: ; preds = %34, %31
br label %38
38: ; preds = %37
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 2
store i32 %40, i32* %8
br label %11
41: ; preds = %11
%42 = load i32, i32* %5
%43 = sitofp i32 %42 to double
%44 = load i32, i32* %7
%45 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double %43, i32 %44)
%46 = call i64 (...) @clock()
store i64 %46, i64* %3
%47 = load i64, i64* %3
%48 = load i64, i64* %2
%49 = sub nsw i64 %47, %48
%50 = sitofp i64 %49 to double
%51 = load double, double* @CLOCKS_PER_SEC
%52 = fdiv double %50, %51
store double %52, double* %4
%53 = load double, double* %4
%54 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %53)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Number of primes upto %d is %d\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [15 x i8] c"%.3lf seconds\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @clock()
br label %2
2: ; preds = %0, %21
%3 = phi i32 [ 1, %0 ], [ %26, %21 ]
%4 = phi i32 [ 3, %0 ], [ %25, %21 ]
%5 = phi i32 [ 0, %0 ], [ %24, %21 ]
%6 = call i32 @llvm.umax.i32(i32 %3, i32 2)
%7 = lshr i32 %4, 1
%8 = icmp ult i32 %4, 4
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = and i32 %4, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9, %16
%13 = phi i32 [ %14, %16 ], [ 2, %9 ]
%14 = add nuw nsw i32 %13, 1
%15 = icmp eq i32 %13, %6
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = urem i32 %4, %14
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %12
19: ; preds = %12, %16
%20 = icmp uge i32 %13, %7
br label %21
21: ; preds = %19, %9, %2
%22 = phi i1 [ true, %2 ], [ false, %9 ], [ %20, %19 ]
%23 = zext i1 %22 to i32
%24 = add nuw nsw i32 %5, %23
%25 = add nuw nsw i32 %4, 2
%26 = add nuw nsw i32 %3, 1
%27 = icmp eq i32 %26, 5000
br i1 %27, label %28, label %2
28: ; preds = %21
%29 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 1.000000e+04, i32 %24)
%30 = tail call i64 (...) @clock()
%31 = sub nsw i64 %30, %1
%32 = sitofp i64 %31 to double
%33 = load double, double* @CLOCKS_PER_SEC
%34 = fdiv double %32, %33
%35 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %34)
ret i32 0
}