#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 timespec {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ __NR_clock_gettime;
scalar_t__ syscall(int /*<<< orphan*/, int, void *);
int dx_clock_get_abs_msec(unsigned long long *s_msec_ptr) {
  struct timespec s_timespec;
  if (syscall(__NR_clock_gettime, (int)1, (void *)(&s_timespec)) != 0) {
    return (-1);
  }
  *s_msec_ptr =
      (((unsigned long long)s_timespec.tv_sec) * ((unsigned long long)1000u)) +
      (((unsigned long long)s_timespec.tv_nsec) /
       ((unsigned long long)1000000u));
  return (0);
}


x86 assembly (clang, -O0):
<dx_clock_get_abs_msec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ecd(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
mov    $0x1,%esi
call   1030 <syscall@plt>
cmp    $0x0,%rax
je     1149 <dx_clock_get_abs_msec+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1170 <dx_clock_get_abs_msec+0x60>
imul   $0x3e8,-0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    $0xf4240,%esi
xor    %edx,%edx
div    %rsi
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dx_clock_get_abs_msec>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2ed1(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rdx
mov    $0x1,%esi
call   1030 <syscall@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    115e <dx_clock_get_abs_msec+0x4e>
imul   $0x3e8,0x8(%rsp),%rcx
movabs $0x431bde82d7b634db,%rax
de 1b 43
mulq   (%rsp)
shr    $0x12,%rdx
add    %rcx,%rdx
mov    %rdx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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