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

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
uint64_t get_time(uint64_t *old_t) {
  uint64_t t;
  struct timeval tv;
  if (gettimeofday(&tv, NULL) != 0)
    return 0;
  t = tv.tv_sec * 1000000 + tv.tv_usec;
  if (t < *old_t)
    return *old_t;
  *old_t = t;
  return t;
}


x86 assembly (clang, -O0):
<get_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
je     1140 <get_time+0x30>
movq   $0x0,-0x8(%rbp)
jmp    1185 <get_time+0x75>
imul   $0xf4240,-0x28(%rbp),%eax
cltq
add    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jge    1172 <get_time+0x62>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1185 <get_time+0x75>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
jne    114c <get_time+0x3c>
movslq 0x8(%rsp),%rax
imul   $0xf4240,%rax,%rax
add    0x10(%rsp),%rax
mov    (%r14),%rbx
cmp    %rbx,%rax
jl     114c <get_time+0x3c>
mov    %rax,(%r14)
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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