#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();
scalar_t__ isPrime(int);
int pow(int, int);
int /*<<< orphan*/ printf(char *, double, ...);
int main(void) {
  int maxValue = pow(10, 7);
  int count = 0;
  clock_t begin, end;
  double time_spent;
  begin = clock();
  int i;
  for (i = 1; i <= maxValue; i++) {
    if (isPrime(i)) {
      count++;
    }
  }
  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC * 1000;
  printf("There are %d primes up to %d.\n", count, maxValue);
  printf("Took %lf milliseconds.\n", time_spent);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
mov    $0x7,%esi
call   1060 <pow@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11b4 <main+0x74>
mov    -0x2c(%rbp),%edi
call   1050 <isPrime@plt>
cmp    $0x0,%rax
je     11a1 <main+0x61>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a6 <main+0x66>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117a <main+0x3a>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e15(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe21(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
mov    -0x8(%rbp),%esi
lea    0xe11(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xe1d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0xa,%edi
mov    $0x7,%esi
call   1060 <pow@plt>
mov    %eax,%r15d
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    11a7 <main+0x67>
mov    %r15d,%r12d
neg    %r12d
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1050 <isPrime@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
lea    (%r12,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1180 <main+0x40>
cvtsi2sd %ebp,%xmm0
jmp    11ab <main+0x6b>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2e1f(%rip),%rax
divsd  (%rax),%xmm0
mulsd  0xe2b(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe26(%rip),%rdi
movsd  (%rsp),%xmm0
mov    %r15d,%esi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe2f(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [31 x i8] c"There are %d primes up to %d.\0A\00"
@.str.1 = [24 x i8] c"Took %lf milliseconds.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @pow(i32 10, i32 7)
store i32 %8, i32* %2
store i32 0, i32* %3
%9 = call i64 (...) @clock()
store i64 %9, i64* %4
store i32 1, i32* %7
br label %10
10: ; preds = %22, %0
%11 = load i32, i32* %7
%12 = load i32, i32* %2
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* %7
%16 = call i64 @isPrime(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %21
21: ; preds = %18, %14
br label %22
22: ; preds = %21
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %10
25: ; preds = %10
%26 = call i64 (...) @clock()
store i64 %26, i64* %5
%27 = load i64, i64* %5
%28 = load i64, i64* %4
%29 = sub nsw i64 %27, %28
%30 = sitofp i64 %29 to double
%31 = load double, double* @CLOCKS_PER_SEC
%32 = fdiv double %30, %31
%33 = fmul double %32, 1.000000e+03
store double %33, double* %6
%34 = load i32, i32* %3
%35 = sitofp i32 %34 to double
%36 = load i32, i32* %2
%37 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %35, i32 %36)
%38 = load double, double* %6
%39 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %38)
ret i32 0
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [31 x i8] c"There are %d primes up to %d.\0A\00"
@.str.1 = [24 x i8] c"Took %lf milliseconds.\0A\00"
define i32 @main() {
%1 = tail call i32 @pow(i32 10, i32 7)
%2 = tail call i64 (...) @clock()
%3 = icmp slt i32 %1, 1
br i1 %3, label %15, label %4
4: ; preds = %0, %4
%5 = phi i32 [ %11, %4 ], [ 1, %0 ]
%6 = phi i32 [ %10, %4 ], [ 0, %0 ]
%7 = tail call i64 @isPrime(i32 %5)
%8 = icmp ne i64 %7, 0
%9 = zext i1 %8 to i32
%10 = add nuw nsw i32 %6, %9
%11 = add nuw i32 %5, 1
%12 = icmp eq i32 %5, %1
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = sitofp i32 %10 to double
br label %15
15: ; preds = %13, %0
%16 = phi double [ 0.000000e+00, %0 ], [ %14, %13 ]
%17 = tail call i64 (...) @clock()
%18 = sub nsw i64 %17, %2
%19 = sitofp i64 %18 to double
%20 = load double, double* @CLOCKS_PER_SEC
%21 = fdiv double %19, %20
%22 = fmul double %21, 1.000000e+03
%23 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %16, i32 %1)
%24 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), double %22)
ret i32 0
}