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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *, long);
int /*<<< orphan*/ timeval_subtract(struct timeval *, struct timeval *,
                                    struct timeval *);
void print_elapsed(const char *name, struct timeval *tv) {
  struct timeval end, result;
  gettimeofday(&end, NULL);
  timeval_subtract(&result, &end, tv);
  long ms = result.tv_sec * 1000 + result.tv_usec / 1000;
  printf("%s completed in %ldms\n", name, ms);
}


x86 assembly (clang, -O0):
<print_elapsed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <timeval_subtract@plt>
imul   $0x3e8,-0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_elapsed>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <timeval_subtract@plt>
movslq (%rsp),%rax
imul   $0x3e8,%rax,%rax
movslq 0x4(%rsp),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
movslq %ecx,%rdx
add    %rax,%rdx
lea    0xe73(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [23 x i8] c"%s completed in %ldms\0A\00"
define void @print_elapsed(i8* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%8 = call i32 @timeval_subtract(%struct.timeval* %4, %struct.timeval* %3, %struct.timeval* %1)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%10 = load i32, i32* %9
%11 = mul nsw i32 %10, 1000
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%13 = load i32, i32* %12
%14 = sdiv i32 %13, 1000
%15 = add nsw i32 %14, %11
%16 = sext i32 %15 to i64
%17 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %16)
ret void
}