#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_usec;
  int tv_sec;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
long sync_getdelta() {
  static struct timeval c = {0};
  struct timeval t;
  int s, us;
  gettimeofday(&t, NULL);
  us = t.tv_usec - c.tv_usec;
  s = t.tv_sec - c.tv_sec;
  c = t;
  return (s ? 1000000 + us : us);
}


x86 assembly (clang, -O0):
<sync_getdelta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%eax
sub    0x2efe(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
sub    0x2ef6(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,0x2ee4(%rip)
mov    -0x8(%rbp),%eax
mov    %eax,0x2ee3(%rip)
cmpl   $0x0,-0x14(%rbp)
je     116b <sync_getdelta+0x5b>
mov    -0x18(%rbp),%eax
add    $0xf4240,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <sync_getdelta+0x61>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cltq
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sync_getdelta>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x2efe(%rip),%eax
mov    0x10(%rsp),%edx
mov    %edx,0x2efc(%rip)
mov    0x8(%rsp),%rdx
lea    0xf4240(%rax),%esi
cmp    0x2ee7(%rip),%ecx
mov    %rdx,0x2edc(%rip)
cmove  %eax,%esi
movslq %esi,%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32, i32 }
@sync_getdelta.c = internal global %struct.timeval zeroinitializer
define i64 @sync_getdelta() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%6 = load i32, i32* %5
%7 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @sync_getdelta.c, i32 0, i32 0)
%8 = sub nsw i32 %6, %7
store i32 %8, i32* %3
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%10 = load i32, i32* %9
%11 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @sync_getdelta.c, i32 0, i32 1)
%12 = sub nsw i32 %10, %11
store i32 %12, i32* %2
%13 = bitcast %struct.timeval* %1 to i8*
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = load i32, i32* %3
%18 = add nsw i32 1000000, %17
br label %21
19: ; preds = %0
%20 = load i32, i32* %3
br label %21
21: ; preds = %19, %16
%22 = phi i32 [ %18, %16 ], [ %20, %19 ]
%23 = sext i32 %22 to i64
ret i64 %23
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32, i32 }
@sync_getdelta.c = internal unnamed_addr global %struct.timeval zeroinitializer
define i64 @sync_getdelta() {
%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 i32, i32* %4
%6 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @sync_getdelta.c, i64 0, i32 0)
%7 = sub nsw i32 %5, %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%9 = load i32, i32* %8
%10 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @sync_getdelta.c, i64 0, i32 1)
%11 = icmp eq i32 %9, %10
%12 = add nsw i32 %7, 1000000
%13 = select i1 %11, i32 %7, i32 %12
%14 = sext i32 %13 to i64
ret i64 %14
}