#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*/ *);
unsigned long mtime(unsigned long *timer) {
  unsigned long mtime;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  mtime = tv.tv_sec * 1000 + tv.tv_usec / 1000;
  if (timer != NULL) {
    *timer = mtime;
  }
  return mtime;
}


x86 assembly (clang, -O0):
<mtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
imul   $0x3e8,-0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1161 <mtime+0x51>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mtime>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movslq 0x8(%rsp),%rax
imul   $0x3e8,%rax,%rcx
movslq 0xc(%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
cltq
add    %rcx,%rax
test   %rbx,%rbx
je     1156 <mtime+0x46>
mov    %rax,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

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

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