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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
unsigned long get_jiffies(void) {
  struct timeval tv;
  static uint64_t start = ~0;
  uint64_t now;
  gettimeofday(&tv, NULL);
  now = (tv.tv_sec * 1000000ULL) + tv.tv_usec;
  if (start == ~0) {
    start = now;
  }
  return (unsigned long)(now - start);
}


x86 assembly (clang, -O0):
<get_jiffies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
imul   $0xf4240,-0x10(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,0x2eeb(%rip)
ff
jne    114e <get_jiffies+0x3e>
mov    -0x18(%rbp),%rax
mov    %rax,0x2eda(%rip)
mov    -0x18(%rbp),%rax
sub    0x2ecf(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_jiffies>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
imul   $0xf4240,0x8(%rsp),%rax
add    0x10(%rsp),%rax
mov    0x2ef3(%rip),%rcx
cmp    $0xffffffffffffffff,%rcx
jne    1145 <get_jiffies+0x35>
mov    %rax,0x2ee6(%rip)
mov    %rax,%rcx
sub    %rcx,%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@get_jiffies.start = internal global i64 -1
define i64 @get_jiffies() {
%1 = alloca %struct.timeval
%2 = alloca i64
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%5 = load i64, i64* %4
%6 = mul i64 %5, 1000000
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%8 = load i64, i64* %7
%9 = add i64 %6, %8
store i64 %9, i64* %2
%10 = load i64, i64* @get_jiffies.start
%11 = icmp eq i64 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = load i64, i64* %2
store i64 %13, i64* @get_jiffies.start
br label %14
14: ; preds = %12, %0
%15 = load i64, i64* %2
%16 = load i64, i64* @get_jiffies.start
%17 = sub nsw i64 %15, %16
ret i64 %17
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@get_jiffies.start = internal unnamed_addr global i64 -1
define i64 @get_jiffies() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = mul i64 %5, 1000000
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%8 = load i64, i64* %7
%9 = add i64 %6, %8
%10 = load i64, i64* @get_jiffies.start
%11 = icmp eq i64 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %0
store i64 %9, i64* @get_jiffies.start
br label %13
13: ; preds = %12, %0
%14 = phi i64 [ %9, %12 ], [ %10, %0 ]
%15 = sub nsw i64 %9, %14
ret i64 %15
}