#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 {
  unsigned int tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ rtc_get_epoch(unsigned int *);
__attribute__((used)) int _gettimeofday(struct timeval *tp, void *tzp) {
  if (tp) {
    unsigned int milliseconds = 0;
    tp->tv_sec = rtc_get_epoch(&milliseconds);
    tp->tv_usec = milliseconds * 1000;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_gettimeofday>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1151 <_gettimeofday+0x41>
movl   $0x0,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <rtc_get_epoch@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
imul   $0x3e8,-0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_gettimeofday>:
test   %rdi,%rdi
je     1141 <_gettimeofday+0x31>
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <rtc_get_epoch@plt>
mov    %eax,0x4(%rbx)
imul   $0x3e8,0xc(%rsp),%eax
mov    %eax,(%rbx)
add    $0x10,%rsp
pop    %rbx
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.timeval*, i8*)* @_gettimeofday to i8*)], section "llvm.metadata"
define i32 @_gettimeofday(%struct.timeval* %0, i8* %1) {
%3 = alloca %struct.timeval*
%4 = alloca i8*
%5 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store i8* %1, i8** %4
%6 = load %struct.timeval*, %struct.timeval** %3
%7 = icmp ne %struct.timeval* %6, null
br i1 %7, label %8, label %16
8: ; preds = %2
store i32 0, i32* %5
%9 = call i32 @rtc_get_epoch(i32* %5)
%10 = load %struct.timeval*, %struct.timeval** %3
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
store i32 %9, i32* %11
%12 = load i32, i32* %5
%13 = mul i32 %12, 1000
%14 = load %struct.timeval*, %struct.timeval** %3
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
store i32 %13, i32* %15
br label %16
16: ; preds = %8, %2
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.timeval*, i8*)* @_gettimeofday to i8*)], section "llvm.metadata"
define i32 @_gettimeofday(%struct.timeval* writeonly %0, i8* nocapture readnone %1) {
%3 = alloca i32
%4 = icmp eq %struct.timeval* %0, null
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = call i32 @rtc_get_epoch(i32* %3)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* %3
%10 = mul i32 %9, 1000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store i32 %10, i32* %11
br label %12
12: ; preds = %5, %2
ret i32 0
}