#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int tv_sec;
  int tv_usec;
};
struct input_event {
  int value;
  TYPE_1__ time;
};

/* Variables and functions */
double calcualte_velocity(struct input_event event1,
                          struct input_event event2) {
  int distance = event2.value - event1.value;
  double time_delta = event2.time.tv_sec * 1000 + event2.time.tv_usec / 1000 -
                      event1.time.tv_sec * 1000 - event1.time.tv_usec / 1000;
  return distance / time_delta;
}


x86 assembly (clang, -O0):
<calcualte_velocity>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x20(%rbp)
mov    %esi,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %ecx,-0x38(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
imul   $0x3e8,-0x2c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
add    %ecx,%eax
imul   $0x3e8,-0xc(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdl -0x44(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcualte_velocity>:
mov    %rdi,%r8
shr    $0x20,%r8
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x26,%rcx
add    %eax,%ecx
movslq %esi,%rax
imul   $0xffffffffef9db22d,%rax,%rax
mov    %rax,%rsi
shr    $0x3f,%rsi
sar    $0x26,%rax
add    %esi,%eax
mov    %rdx,%rsi
shr    $0x20,%rsi
add    %ecx,%eax
sub    %r8d,%esi
imul   $0x3e8,%esi,%ecx
add    %eax,%ecx
cvtsi2sd %ecx,%xmm1
sub    %edi,%edx
cvtsi2sd %edx,%xmm0
divsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
%struct.input_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i32 }
define double @calcualte_velocity(i64 %0, i32 %1, i64 %2, i32 %3) {
%5 = alloca %struct.input_event
%6 = alloca { i64, i32 }
%7 = alloca %struct.input_event
%8 = alloca { i64, i32 }
%9 = alloca i32
%10 = alloca double
%11 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %6, i32 0, i32 0
store i64 %0, i64* %11
%12 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %6, i32 0, i32 1
store i32 %1, i32* %12
%13 = bitcast %struct.input_event* %5 to i8*
%14 = bitcast { i64, i32 }* %6 to i8*
%15 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %8, i32 0, i32 0
store i64 %2, i64* %15
%16 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %8, i32 0, i32 1
store i32 %3, i32* %16
%17 = bitcast %struct.input_event* %7 to i8*
%18 = bitcast { i64, i32 }* %8 to i8*
%19 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 0
%22 = load i32, i32* %21
%23 = sub nsw i32 %20, %22
store i32 %23, i32* %9
%24 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = mul nsw i32 %26, 1000
%28 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = sdiv i32 %30, 1000
%32 = add nsw i32 %27, %31
%33 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = mul nsw i32 %35, 1000
%37 = sub nsw i32 %32, %36
%38 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 1
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = sdiv i32 %40, 1000
%42 = sub nsw i32 %37, %41
%43 = sitofp i32 %42 to double
store double %43, double* %10
%44 = load i32, i32* %9
%45 = sitofp i32 %44 to double
%46 = load double, double* %10
%47 = fdiv double %45, %46
ret double %47
}

LLVM IR (-O2):
define double @calcualte_velocity(i64 %0, i32 %1, i64 %2, i32 %3) {
%5 = trunc i64 %0 to i32
%6 = lshr i64 %0, 32
%7 = trunc i64 %6 to i32
%8 = trunc i64 %2 to i32
%9 = lshr i64 %2, 32
%10 = trunc i64 %9 to i32
%11 = sub nsw i32 %8, %5
%12 = sdiv i32 %3, 1000
%13 = sdiv i32 %1, -1000
%14 = sub i32 %10, %7
%15 = mul i32 %14, 1000
%16 = add nsw i32 %12, %13
%17 = add i32 %16, %15
%18 = sitofp i32 %17 to double
%19 = sitofp i32 %11 to double
%20 = fdiv double %19, %18
ret double %20
}