#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 int time_t;
typedef int suseconds_t;
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ mpw_time(struct timeval *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
const double mpw_show_speed(struct timeval startTime,
                            const unsigned int iterations,
                            const char *operation) {
  struct timeval endTime;
  mpw_time(&endTime);
  const time_t dsec = (endTime.tv_sec - startTime.tv_sec);
  const suseconds_t dusec = (endTime.tv_usec - startTime.tv_usec);
  const double elapsed = dsec + dusec / 1000000.;
  const double speed = iterations / elapsed;
  fprintf(stderr, " done.  ");
  fprintf(stdout, "%d %s iterations in %lus %uµs -> %.2f/s\n", iterations,
          operation, dsec, dusec, speed);
  return speed;
}


x86 assembly (clang, -O0):
<mpw_show_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <mpw_time@plt>
mov    -0x20(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
movsd  0xe9c(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
movsd  -0x38(%rbp),%xmm0
lea    0xe53(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpw_show_speed>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
mov    %rdi,%rbx
shr    $0x20,%rbx
lea    0x10(%rsp),%rdi
call   1030 <mpw_time@plt>
mov    0x10(%rsp),%r13d
mov    0x14(%rsp),%ebp
sub    %r12d,%r13d
sub    %ebx,%ebp
cvtsi2sd %r13d,%xmm0
cvtsi2sd %ebp,%xmm1
divsd  0xe99(%rip),%xmm1
mov    %r15d,%eax
cvtsi2sd %rax,%xmm2
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
mov    %r15d,%edx
mov    %r14,%rcx
mov    %r13d,%r8d
mov    %ebp,%r9d
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@.str = [9 x i8] c" done. \00"
@stdout = global i32 0
@.str.1 = [42 x i8] c"%d %s iterations in %lus %u\C2\B5s -> %.2f/s\0A\00"
define double @mpw_show_speed(i64 %0, i32 %1, i8* %2) {
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.timeval
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = bitcast %struct.timeval* %4 to i64*
store i64 %0, i64* %12
store i32 %1, i32* %5
store i8* %2, i8** %6
%13 = call i32 @mpw_time(%struct.timeval* %7)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%17 = load i32, i32* %16
%18 = sub nsw i32 %15, %17
store i32 %18, i32* %8
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%22 = load i32, i32* %21
%23 = sub nsw i32 %20, %22
store i32 %23, i32* %9
%24 = load i32, i32* %8
%25 = sitofp i32 %24 to double
%26 = load i32, i32* %9
%27 = sitofp i32 %26 to double
%28 = fdiv double %27, 1.000000e+06
%29 = fadd double %25, %28
store double %29, double* %10
%30 = load i32, i32* %5
%31 = uitofp i32 %30 to double
%32 = load double, double* %10
%33 = fdiv double %31, %32
store double %33, double* %11
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* @stdout
%37 = load i32, i32* %5
%38 = load i8*, i8** %6
%39 = load i32, i32* %8
%40 = load i32, i32* %9
%41 = load double, double* %11
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %37, i8* %38, i32 %39, i32 %40, double %41)
%43 = load double, double* %11
ret double %43
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@.str = [9 x i8] c" done. \00"
@stdout = global i32 0
@.str.1 = [42 x i8] c"%d %s iterations in %lus %u\C2\B5s -> %.2f/s\0A\00"
define double @mpw_show_speed(i64 %0, i32 %1, i8* %2) {
%4 = alloca %struct.timeval
%5 = trunc i64 %0 to i32
%6 = lshr i64 %0, 32
%7 = trunc i64 %6 to i32
%8 = bitcast %struct.timeval* %4 to i8*
%9 = call i32 @mpw_time(%struct.timeval* %4)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%11 = load i32, i32* %10
%12 = sub nsw i32 %11, %5
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%14 = load i32, i32* %13
%15 = sub nsw i32 %14, %7
%16 = sitofp i32 %12 to double
%17 = sitofp i32 %15 to double
%18 = fdiv double %17, 1.000000e+06
%19 = fadd double %18, %16
%20 = uitofp i32 %1 to double
%21 = fdiv double %20, %19
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @stdout
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %2, i32 %12, i32 %15, double %21)
ret double %21
}