#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 {
  int tv_sec;
  int tv_nsec;
};
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ perror(char *);
int64_t time_monotonic_ms(void) {
  struct timespec t;
  int64_t ret;
  if (clock_gettime(CLOCK_MONOTONIC, &t)) {
    perror("time_monotonic_ms clock_gettime");
    return -1;
  }
  ret = (t.tv_sec + 604800) * (int64_t)1000;
  ret += t.tv_nsec / 1000000;
  return ret;
}


x86 assembly (clang, -O0):
<time_monotonic_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     115c <time_monotonic_ms+0x3c>
lea    0xeb5(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <time_monotonic_ms+0x64>
mov    -0x10(%rbp),%eax
add    $0x93a80,%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_monotonic_ms>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
jne    1160 <time_monotonic_ms+0x40>
imul   $0x3e8,(%rsp),%eax
movslq 0x4(%rsp),%rcx
imul   $0x431bde83,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
add    %ecx,%eax
add    $0x240c8400,%eax
pop    %rcx
ret
lea    0xe99(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [32 x i8] c"time_monotonic_ms clock_gettime\00"
define i32 @time_monotonic_ms() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca i32
%4 = load i32, i32* @CLOCK_MONOTONIC
%5 = call i64 @clock_gettime(i32 %4, %struct.timespec* %2)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %20
9: ; preds = %0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 604800
%13 = mul nsw i32 %12, 1000
store i32 %13, i32* %3
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%15 = load i32, i32* %14
%16 = sdiv i32 %15, 1000000
%17 = load i32, i32* %3
%18 = add nsw i32 %17, %16
store i32 %18, i32* %3
%19 = load i32, i32* %3
store i32 %19, i32* %1
br label %20
20: ; preds = %9, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [32 x i8] c"time_monotonic_ms clock_gettime\00"
define i32 @time_monotonic_ms() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i64 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %17
8: ; preds = %0
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = mul i32 %10, 1000
%12 = add i32 %11, 604800000
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 1000000
%16 = add nsw i32 %12, %15
br label %17
17: ; preds = %8, %6
%18 = phi i32 [ -1, %6 ], [ %16, %8 ]
ret i32 %18
}