#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 /*<<< orphan*/ us;
struct timespec {
  int /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ mqd_t;
typedef int /*<<< orphan*/ int64_t;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int mq_send(int /*<<< orphan*/, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int ticks_delta(struct timespec, struct timespec);
void get_delta(int64_t sec, int32_t nsec, mqd_t mq) {
  struct timespec now;
  clock_gettime(CLOCK_MONOTONIC, &now);
  struct timespec ts = {.tv_sec = sec, .tv_nsec = nsec};
  double us = ticks_delta(ts, now) * 1e6;
  ssize_t r = mq_send(mq, (char *)&us, sizeof(us), 0);
  if (sizeof(us) == r) {
    perror("mq send failed \n");
  }
}


x86 assembly (clang, -O0):
<get_delta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <ticks_delta@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe78(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <mq_send@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rcx
mov    $0x8,%eax
cmp    %rcx,%rax
jne    11c5 <get_delta+0x85>
lea    0xe48(%rip),%rdi
call   1050 <perror@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_delta>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
shl    $0x20,%rbx
mov    %ebp,%edi
or     %rbx,%rdi
mov    0x8(%rsp),%rsi
call   1060 <ticks_delta@plt>
cvtsi2sd %eax,%xmm0
mulsd  0xe7f(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <mq_send@plt>
cmp    $0x8,%eax
je     11a6 <get_delta+0x66>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe5b(%rip),%rdi
call   1050 <perror@plt>
jmp    119d <get_delta+0x5d>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [17 x i8] c"mq send failed \0A\00"
define void @get_delta(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec
%9 = alloca double
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* @CLOCK_MONOTONIC
%12 = call i32 @clock_gettime(i32 %11, %struct.timespec* %7)
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%14 = load i32, i32* %5
store i32 %14, i32* %13
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
%16 = load i32, i32* %4
store i32 %16, i32* %15
%17 = bitcast %struct.timespec* %8 to i64*
%18 = load i64, i64* %17
%19 = bitcast %struct.timespec* %7 to i64*
%20 = load i64, i64* %19
%21 = call i32 @ticks_delta(i64 %18, i64 %20)
%22 = sitofp i32 %21 to double
%23 = fmul double %22, 1.000000e+06
store double %23, double* %9
%24 = load i32, i32* %6
%25 = bitcast double* %9 to i8*
%26 = call i32 @mq_send(i32 %24, i8* %25, i32 8, i32 0)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = icmp eq i64 8, %28
br i1 %29, label %30, label %32
30: ; preds = %3
%31 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %3
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [17 x i8] c"mq send failed \0A\00"
define void @get_delta(i32 %0, i32 %1, i32 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to %struct.timespec*
%6 = alloca double
%7 = bitcast i64* %4 to i8*
%8 = load i32, i32* @CLOCK_MONOTONIC
%9 = call i32 @clock_gettime(i32 %8, %struct.timespec* %5)
%10 = bitcast double* %6 to i8*
%11 = zext i32 %0 to i64
%12 = shl nuw i64 %11, 32
%13 = zext i32 %1 to i64
%14 = or i64 %12, %13
%15 = load i64, i64* %4
%16 = call i32 @ticks_delta(i64 %14, i64 %15)
%17 = sitofp i32 %16 to double
%18 = fmul double %17, 1.000000e+06
store double %18, double* %6
%19 = call i32 @mq_send(i32 %2, i8* %10, i32 8, i32 0)
%20 = icmp eq i32 %19, 8
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %3
ret void
}