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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
unsigned long timediff(void) {
  static struct timeval last;
  struct timeval time;
  unsigned long diff;
  gettimeofday(&time, 0);
  diff = (time.tv_sec - last.tv_sec) * 1000000L + (time.tv_usec - last.tv_usec);
  last.tv_sec = time.tv_sec;
  last.tv_usec = time.tv_usec;
  return diff;
}


x86 assembly (clang, -O0):
<timediff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
sub    0x2f02(%rip),%rax
imul   $0xf4240,%rax,%rax
mov    -0x8(%rbp),%rcx
sub    0x2ef8(%rip),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,0x2ede(%rip)
mov    -0x8(%rbp),%rax
mov    %rax,0x2edb(%rip)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timediff>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%rdx
mov    %rcx,%rsi
sub    0x2efc(%rip),%rsi
mov    %rdx,%rax
sub    0x2efa(%rip),%rax
imul   $0xf4240,%rsi,%rsi
add    %rsi,%rax
mov    %rcx,0x2ee1(%rip)
mov    %rdx,0x2ee2(%rip)
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@timediff.last = internal global %struct.timeval zeroinitializer
define i64 @timediff() {
%1 = alloca %struct.timeval
%2 = alloca i64
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%5 = load i64, i64* %4
%6 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @timediff.last, i32 0, i32 0)
%7 = sub nsw i64 %5, %6
%8 = mul nsw i64 %7, 1000000
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%10 = load i64, i64* %9
%11 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @timediff.last, i32 0, i32 1)
%12 = sub nsw i64 %10, %11
%13 = add nsw i64 %8, %12
store i64 %13, i64* %2
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%15 = load i64, i64* %14
store i64 %15, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @timediff.last, i32 0, i32 0)
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%17 = load i64, i64* %16
store i64 %17, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @timediff.last, i32 0, i32 1)
%18 = load i64, i64* %2
ret i64 %18
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@timediff.last.0 = internal unnamed_addr global i64 0
@timediff.last.1 = internal unnamed_addr global i64 0
define i64 @timediff() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = load i64, i64* @timediff.last.0
%7 = sub nsw i64 %5, %6
%8 = mul nsw i64 %7, 1000000
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = load i64, i64* @timediff.last.1
%12 = sub i64 %10, %11
%13 = add nsw i64 %12, %8
store i64 %5, i64* @timediff.last.0
store i64 %10, i64* @timediff.last.1
ret i64 %13
}