#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;
int IsPrime(int);
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int i, is_prime, prime_count = 0;
  double cpu_time_used;
  clock_t begin, end;
  printf("List of prime numbers:\n");
  for (i = 1; i > 0; ++i) {
    begin = clock();
    is_prime = IsPrime(i);
    end = clock();
    cpu_time_used = ((double)(end - begin)) / CLOCKS_PER_SEC;
    if (is_prime) {
      printf("%d.\t%d\ttook %f seconds\n", prime_count, i, cpu_time_used);
      prime_count++;
    }
  }
  printf("Done!\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11e2 <main+0xb2>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <IsPrime@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e4e(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11cf <main+0x9f>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
movsd  -0x18(%rbp),%xmm0
lea    0xe59(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d4 <main+0xa4>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115b <main+0x2b>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    0x2e85(%rip),%r13
lea    0xe96(%rip),%r14
xor    %r15d,%r15d
jmp    1173 <main+0x33>
nop
add    $0x1,%ebx
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r12
mov    %ebx,%edi
call   1060 <IsPrime@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <clock@plt>
test   %ebp,%ebp
je     1170 <main+0x30>
sub    %r12,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0x0(%r13),%xmm0
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%r15d
jmp    1170 <main+0x30>

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

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