#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 int time_t;
struct timespec {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
time_t rel_time(time_t *ptr) {
  struct timespec reltime;
  clock_gettime(CLOCK_MONOTONIC, &reltime);
  time_t _time = (reltime.tv_sec * 1000) + (reltime.tv_nsec / 1000000);
  if (ptr)
    *ptr = _time;
  return _time;
}


x86 assembly (clang, -O0):
<rel_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ec5(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
imul   $0x3e8,-0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1161 <rel_time+0x51>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rel_time>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
imul   $0x3e8,0x8(%rsp),%ecx
movslq 0xc(%rsp),%rax
imul   $0x431bde83,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rax
add    %edx,%eax
add    %ecx,%eax
test   %rbx,%rbx
je     1155 <rel_time+0x45>
mov    %eax,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

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

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