#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_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int sys_elapsed(struct timeval *prev) {
  struct timeval tv;
  int secs, usecs;
  gettimeofday(&tv, NULL);
  secs = tv.tv_sec - prev->tv_sec;
  usecs = tv.tv_usec - prev->tv_usec;
  *prev = tv;
  if (!secs)
    return usecs;
  return 1000000 + usecs;
}


x86 assembly (clang, -O0):
<sys_elapsed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
sub    0x4(%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,(%rax)
cmpl   $0x0,-0x1c(%rbp)
jne    1162 <sys_elapsed+0x52>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    116d <sys_elapsed+0x5d>
mov    -0x20(%rbp),%eax
add    $0xf4240,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_elapsed>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0xc(%rsp),%ecx
sub    0x4(%rbx),%ecx
mov    0x8(%rsp),%eax
mov    0x8(%rsp),%rdx
cmp    (%rbx),%eax
lea    0xf4240(%rcx),%eax
mov    %rdx,(%rbx)
cmove  %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @sys_elapsed(%struct.timeval* %0) {
%2 = alloca i32
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
%7 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load %struct.timeval*, %struct.timeval** %3
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = sub nsw i32 %9, %12
store i32 %13, i32* %5
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%15 = load i32, i32* %14
%16 = load %struct.timeval*, %struct.timeval** %3
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = sub nsw i32 %15, %18
store i32 %19, i32* %6
%20 = load %struct.timeval*, %struct.timeval** %3
%21 = bitcast %struct.timeval* %20 to i8*
%22 = bitcast %struct.timeval* %4 to i8*
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %1
%26 = load i32, i32* %6
store i32 %26, i32* %2
br label %30
27: ; preds = %1
%28 = load i32, i32* %6
%29 = add nsw i32 1000000, %28
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %25
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @sys_elapsed(%struct.timeval* nocapture %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.timeval*
%4 = bitcast i64* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = bitcast i64* %2 to i32*
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%13 = load i32, i32* %12
%14 = sub nsw i32 %11, %13
%15 = bitcast %struct.timeval* %0 to i64*
%16 = load i64, i64* %2
store i64 %16, i64* %15
%17 = icmp eq i32 %7, %9
%18 = add nsw i32 %14, 1000000
%19 = select i1 %17, i32 %14, i32 %18
ret i32 %19
}