#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 is_prime(int);
int /*<<< orphan*/ printf(char *, double);
int main(void) {
  clock_t t = clock();
  int num = 10001;
  int current = 2, counter = 0;
  while (counter < num) {
    if (is_prime(current) == 1)
      counter++;
    current++;
  }
  printf("%d\n\n", current - 1);
  t = clock() - t;
  double time_taken = ((double)t) / CLOCKS_PER_SEC;
  printf("--- %f seconds ---\n", time_taken);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
movl   $0x2711,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1193 <main+0x63>
mov    -0x18(%rbp),%edi
call   1050 <is_prime@plt>
cmp    $0x1,%eax
jne    1185 <main+0x55>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115f <main+0x2f>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cvtsi2sdq -0x10(%rbp),%xmm0
mov    0x2e23(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
mov    %ebp,%edi
call   1050 <is_prime@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
add    %ecx,%ebx
cmp    $0x2711,%ebx
jb     1150 <main+0x20>
cvtsi2sd %ebp,%xmm0
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2e53(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d\0A\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [20 x i8] c"--- %f seconds ---\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store i32 0, i32* %1
%7 = call i64 (...) @clock()
store i64 %7, i64* %2
store i32 10001, i32* %3
store i32 2, i32* %4
store i32 0, i32* %5
br label %8
8: ; preds = %19, %0
%9 = load i32, i32* %5
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i32, i32* %4
%14 = call i32 @is_prime(i32 %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %19
19: ; preds = %16, %12
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %8
22: ; preds = %8
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
%25 = sitofp i32 %24 to double
%26 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %25)
%27 = call i64 (...) @clock()
%28 = load i64, i64* %2
%29 = sub nsw i64 %27, %28
store i64 %29, i64* %2
%30 = load i64, i64* %2
%31 = sitofp i64 %30 to double
%32 = load double, double* @CLOCKS_PER_SEC
%33 = fdiv double %31, %32
store double %33, double* %6
%34 = load double, double* %6
%35 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), double %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d\0A\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [20 x i8] c"--- %f seconds ---\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @clock()
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %9, %2 ]
%4 = phi i32 [ 2, %0 ], [ %7, %2 ]
%5 = tail call i32 @is_prime(i32 %4)
%6 = icmp eq i32 %5, 1
%7 = add nuw nsw i32 %4, 1
%8 = zext i1 %6 to i32
%9 = add nuw nsw i32 %3, %8
%10 = icmp ult i32 %9, 10001
br i1 %10, label %2, label %11
11: ; preds = %2
%12 = sitofp i32 %4 to double
%13 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %12)
%14 = tail call i64 (...) @clock()
%15 = sub nsw i64 %14, %1
%16 = sitofp i64 %15 to double
%17 = load double, double* @CLOCKS_PER_SEC
%18 = fdiv double %16, %17
%19 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), double %18)
ret i32 0
}