#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 */
struct timeval {
  long long tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ isPrime(long long);
int /*<<< orphan*/ printf(char *, long long);
int main(void) {
  struct timeval stop, start;
  gettimeofday(&start, NULL);
  int numberofprimes = 1;
  long long number = 2;
  while (numberofprimes < 10001) {
    if (isPrime(number)) {
      numberofprimes++;
      printf("\n%d", numberofprimes);
    }
    number++;
  }
  printf("\nprime = %lu", number - 1);
  gettimeofday(&stop, NULL);
  printf("\ntook %lu usec\n", stop.tv_usec - start.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movl   $0x1,-0x1c(%rbp)
movq   $0x2,-0x28(%rbp)
cmpl   $0x2711,-0x1c(%rbp)
jge    11a5 <main+0x75>
mov    -0x28(%rbp),%rdi
call   1050 <isPrime@plt>
cmp    $0x0,%rax
je     1194 <main+0x64>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    115b <main+0x2b>
mov    -0x28(%rbp),%rsi
sub    $0x1,%rsi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rsi
sub    -0x18(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x1,%ebp
mov    $0x1,%ebx
lea    0xead(%rip),%r14
jmp    1168 <main+0x38>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x2711,%ebp
jge    1189 <main+0x59>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <isPrime@plt>
test   %rax,%rax
je     1160 <main+0x30>
add    $0x1,%ebp
movslq %ebp,%rsi
mov    %r14,%rdi
call   1030 <printf@plt>
jmp    1160 <main+0x30>
lea    0xe74(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%rsi
sub    (%rsp),%rsi
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [4 x i8] c"\0A%d\00"
@.str.1 = [13 x i8] c"\0Aprime = %lu\00"
@.str.2 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
store i32 1, i32* %4
store i64 2, i64* %5
br label %7
7: ; preds = %20, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 10001
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = load i64, i64* %5
%12 = call i64 @isPrime(i64 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %18)
br label %20
20: ; preds = %14, %10
%21 = load i64, i64* %5
%22 = add nsw i64 %21, 1
store i64 %22, i64* %5
br label %7
23: ; preds = %7
%24 = load i64, i64* %5
%25 = sub nsw i64 %24, 1
%26 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %25)
%27 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%31 = load i64, i64* %30
%32 = sub nsw i64 %29, %31
%33 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 %32)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [4 x i8] c"\0A%d\00"
@.str.1 = [13 x i8] c"\0Aprime = %lu\00"
@.str.2 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %6
6: ; preds = %0, %15
%7 = phi i64 [ 2, %0 ], [ %17, %15 ]
%8 = phi i32 [ 1, %0 ], [ %16, %15 ]
%9 = tail call i64 @isPrime(i64 %7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = add nsw i32 %8, 1
%13 = sext i32 %12 to i64
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %13)
br label %15
15: ; preds = %11, %6
%16 = phi i32 [ %12, %11 ], [ %8, %6 ]
%17 = add nuw nsw i64 %7, 1
%18 = icmp slt i32 %16, 10001
br i1 %18, label %6, label %19
19: ; preds = %15
%20 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %7)
%21 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%25 = load i64, i64* %24
%26 = sub nsw i64 %23, %25
%27 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 %26)
ret i32 0
}