#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 double uint64_t;

/* Variables and functions */
double empty_loop(double);
double notempty_loop(double);
int /*<<< orphan*/ printf(char *, double);
int main(int argc, char **argv) {
  uint64_t empty, notempty;
  uint64_t iterations = 1000000ul;
  double instructions_per_second = 0;
  empty = empty_loop(iterations);
  notempty = notempty_loop(iterations);
  printf("Empty loop=%ld nanoseconds\n", empty);
  printf("Nonempty loop=%ld nanoseconds\n", notempty);
  instructions_per_second = (notempty * 1.0 - empty * 1.0);
  printf("Time taken by the instructions = %f nanoseconds\n",
         instructions_per_second);
  instructions_per_second = instructions_per_second / (10.0 * iterations);
  printf("Time taken by one instruction  = %f nanoseconds \n",
         instructions_per_second);
  instructions_per_second = 1000000000.0 / instructions_per_second;
  printf("Instuctions per second = %f \n", instructions_per_second);
  printf("MIPS = %f \n", instructions_per_second / 1000000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <empty_loop@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <notempty_loop@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  0xe70(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
movsd  0xe25(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
movsd  0xdf6(%rip),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
movsd  0xdc6(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movsd  0xec4(%rip),%xmm0
call   1050 <empty_loop@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0xeb1(%rip),%xmm0
call   1040 <notempty_loop@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xeb7(%rip),%rdi
movsd  0x10(%rsp),%xmm0
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
divsd  0xe5e(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xecd(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe4c(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xedf(%rip),%rdi
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
divsd  0xe16(%rip),%xmm0
lea    0xee3(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Empty loop=%ld nanoseconds\0A\00"
@.str.1 = [31 x i8] c"Nonempty loop=%ld nanoseconds\0A\00"
@.str.2 = [49 x i8] c"Time taken by the instructions = %f nanoseconds\0A\00"
@.str.3 = [50 x i8] c"Time taken by one instruction = %f nanoseconds \0A\00"
@.str.4 = [30 x i8] c"Instuctions per second = %f \0A\00"
@.str.5 = [12 x i8] c"MIPS = %f \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 1.000000e+06, double* %8
store double 0.000000e+00, double* %9
%10 = load double, double* %8
%11 = call double @empty_loop(double %10)
store double %11, double* %6
%12 = load double, double* %8
%13 = call double @notempty_loop(double %12)
store double %13, double* %7
%14 = load double, double* %6
%15 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %14)
%16 = load double, double* %7
%17 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), double %16)
%18 = load double, double* %7
%19 = load double, double* %6
%20 = fmul double %19, 1.000000e+00
%21 = fneg double %20
%22 = call double @llvm.fmuladd.f64(double %18, double 1.000000e+00, double %21)
store double %22, double* %9
%23 = load double, double* %9
%24 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), double %23)
%25 = load double, double* %9
%26 = load double, double* %8
%27 = fmul double 1.000000e+01, %26
%28 = fdiv double %25, %27
store double %28, double* %9
%29 = load double, double* %9
%30 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), double %29)
%31 = load double, double* %9
%32 = fdiv double 1.000000e+09, %31
store double %32, double* %9
%33 = load double, double* %9
%34 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), double %33)
%35 = load double, double* %9
%36 = fdiv double %35, 1.000000e+06
%37 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), double %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Empty loop=%ld nanoseconds\0A\00"
@.str.1 = [31 x i8] c"Nonempty loop=%ld nanoseconds\0A\00"
@.str.2 = [49 x i8] c"Time taken by the instructions = %f nanoseconds\0A\00"
@.str.3 = [50 x i8] c"Time taken by one instruction = %f nanoseconds \0A\00"
@.str.4 = [30 x i8] c"Instuctions per second = %f \0A\00"
@.str.5 = [12 x i8] c"MIPS = %f \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call double @empty_loop(double 1.000000e+06)
%4 = tail call double @notempty_loop(double 1.000000e+06)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %3)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), double %4)
%7 = fsub double %4, %3
%8 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), double %7)
%9 = fdiv double %7, 1.000000e+07
%10 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), double %9)
%11 = fdiv double 1.000000e+09, %9
%12 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), double %11)
%13 = fdiv double %11, 1.000000e+06
%14 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), double %13)
ret i32 0
}