#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 {
  int tv_usec;
  int tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, int, long long);
void sp(char *msg, struct timeval *s) {
  struct timeval e;
  gettimeofday(&e, NULL);
  long long delta;
  delta = (e.tv_usec - s->tv_usec) / 1000;
  delta += (e.tv_sec - s->tv_sec) * 1000;
  printf("c: %s: %d ops took %d ms\n", msg, (10 * 1000 * 1000), delta);
}


x86 assembly (clang, -O0):
<sp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
sub    0x4(%rcx),%eax
imul   $0x3e8,%eax,%eax
cltq
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    0xe83(%rip),%rdi
mov    $0x989680,%edx
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sp>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rsp),%eax
sub    (%rbx),%eax
cltq
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
cltq
movslq 0x4(%rsp),%rcx
movslq 0x4(%rbx),%rdx
sub    %rdx,%rcx
imul   $0x3e8,%rcx,%rcx
add    %rax,%rcx
lea    0xe92(%rip),%rdi
mov    %r14,%rsi
mov    $0x989680,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [26 x i8] c"c: %s: %d ops took %d ms\0A\00"
define void @sp(i8* %0, %struct.timeval* %1) {
%3 = alloca i8*
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval
%6 = alloca i64
store i8* %0, i8** %3
store %struct.timeval* %1, %struct.timeval** %4
%7 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load %struct.timeval*, %struct.timeval** %4
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = sub nsw i32 %9, %12
%14 = sdiv i32 %13, 1000
%15 = sext i32 %14 to i64
store i64 %15, i64* %6
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%17 = load i32, i32* %16
%18 = load %struct.timeval*, %struct.timeval** %4
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = sub nsw i32 %17, %20
%22 = mul nsw i32 %21, 1000
%23 = sext i32 %22 to i64
%24 = load i64, i64* %6
%25 = add nsw i64 %24, %23
store i64 %25, i64* %6
%26 = load i8*, i8** %3
%27 = load i64, i64* %6
%28 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %26, i32 10000000, i64 %27)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [26 x i8] c"c: %s: %d ops took %d ms\0A\00"
define void @sp(i8* %0, %struct.timeval* nocapture %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = sub nsw i32 %7, %9
%11 = sdiv i32 %10, 1000
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%16 = load i32, i32* %15
%17 = sub nsw i32 %14, %16
%18 = mul nsw i32 %17, 1000
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, %12
%21 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0, i32 10000000, i64 %20)
ret void
}