#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*/ printf(char *, int);
void elapsed(struct timeval *t0, struct timeval *t1) {
  printf("elapsed %zdms\n", (1000 * (t1->tv_sec - t0->tv_sec)) +
                                (t1->tv_usec / 1000) - (t0->tv_usec / 1000));
}


x86 assembly (clang, -O0):
<elapsed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
imul   $0x3e8,%eax,%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
add    %eax,%esi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
sub    %eax,%esi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elapsed>:
mov    (%rsi),%eax
sub    (%rdi),%eax
imul   $0x3e8,%eax,%eax
movslq 0x4(%rsi),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %eax,%ecx
movslq 0x4(%rdi),%rax
imul   $0xffffffffef9db22d,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x26,%rsi
add    %eax,%esi
add    %ecx,%esi
lea    0xeab(%rip),%rdi
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [15 x i8] c"elapsed %zdms\0A\00"
define void @elapsed(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = sub nsw i32 %4, %6
%8 = mul nsw i32 %7, 1000
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%10 = load i32, i32* %9
%11 = sdiv i32 %10, 1000
%12 = add nsw i32 %8, %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%14 = load i32, i32* %13
%15 = sdiv i32 %14, -1000
%16 = add i32 %12, %15
%17 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %16)
ret void
}