#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 uint32_t;
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
uint32_t time_elapsed(struct timeval start, struct timeval end) {
  uint32_t start_us, end_us, diff_us = 0;
  start_us = (uint32_t)start.tv_sec * 1000000 + (uint32_t)start.tv_usec;
  end_us = (uint32_t)end.tv_sec * 1000000 + (uint32_t)end.tv_usec;
  diff_us = end_us - start_us;
  return diff_us;
}


x86 assembly (clang, -O0):
<time_elapsed>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
imul   $0xf4240,%eax,%eax
mov    -0x10(%rbp),%rcx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
imul   $0xf4240,%eax,%eax
mov    -0x20(%rbp),%rcx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_elapsed>:
sub    %esi,%ecx
imul   $0xf4240,%ecx,%eax
sub    %edi,%edx
add    %edx,%eax
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define i32 @time_elapsed(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = bitcast %struct.timeval* %5 to { i64, i64 }*
%11 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %10, i32 0, i32 0
store i64 %0, i64* %11
%12 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %10, i32 0, i32 1
store i64 %1, i64* %12
%13 = bitcast %struct.timeval* %6 to { i64, i64 }*
%14 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %13, i32 0, i32 0
store i64 %2, i64* %14
%15 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %13, i32 0, i32 1
store i64 %3, i64* %15
store i32 0, i32* %9
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%17 = load i64, i64* %16
%18 = trunc i64 %17 to i32
%19 = mul nsw i32 %18, 1000000
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%21 = load i64, i64* %20
%22 = trunc i64 %21 to i32
%23 = add nsw i32 %19, %22
store i32 %23, i32* %7
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%25 = load i64, i64* %24
%26 = trunc i64 %25 to i32
%27 = mul nsw i32 %26, 1000000
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%29 = load i64, i64* %28
%30 = trunc i64 %29 to i32
%31 = add nsw i32 %27, %30
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = load i32, i32* %7
%34 = sub nsw i32 %32, %33
store i32 %34, i32* %9
%35 = load i32, i32* %9
ret i32 %35
}

LLVM IR (-O2):
define i32 @time_elapsed(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = trunc i64 %1 to i32
%6 = trunc i64 %0 to i32
%7 = trunc i64 %3 to i32
%8 = trunc i64 %2 to i32
%9 = sub i32 %7, %5
%10 = mul i32 %9, 1000000
%11 = sub i32 %8, %6
%12 = add i32 %11, %10
ret i32 %12
}