#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ TIMER_ABSTIME;
int /*<<< orphan*/ clock_nanosleep(int /*<<< orphan*/, int /*<<< orphan*/,
                                   struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ time_add_ms(struct timespec *, long);
void wait_for_period_ms(struct timespec *at, struct timespec *dl, long period) {
  clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, at, NULL);
  time_add_ms(at, period);
  time_add_ms(dl, period);
}


x86 assembly (clang, -O0):
<wait_for_period_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <clock_nanosleep@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <time_add_ms@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <time_add_ms@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_period_ms>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1040 <clock_nanosleep@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <time_add_ms@plt>
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <time_add_ms@plt>

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@TIMER_ABSTIME = global i32 0
define void @wait_for_period_ms(%struct.timespec* %0, %struct.timespec* %1, i64 %2) {
%4 = alloca %struct.timespec*
%5 = alloca %struct.timespec*
%6 = alloca i64
store %struct.timespec* %0, %struct.timespec** %4
store %struct.timespec* %1, %struct.timespec** %5
store i64 %2, i64* %6
%7 = load i32, i32* @CLOCK_MONOTONIC
%8 = load i32, i32* @TIMER_ABSTIME
%9 = load %struct.timespec*, %struct.timespec** %4
%10 = call i32 @clock_nanosleep(i32 %7, i32 %8, %struct.timespec* %9, i32* null)
%11 = load %struct.timespec*, %struct.timespec** %4
%12 = load i64, i64* %6
%13 = call i32 @time_add_ms(%struct.timespec* %11, i64 %12)
%14 = load %struct.timespec*, %struct.timespec** %5
%15 = load i64, i64* %6
%16 = call i32 @time_add_ms(%struct.timespec* %14, i64 %15)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@TIMER_ABSTIME = global i32 0
define void @wait_for_period_ms(%struct.timespec* %0, %struct.timespec* %1, i64 %2) {
%4 = load i32, i32* @CLOCK_MONOTONIC
%5 = load i32, i32* @TIMER_ABSTIME
%6 = tail call i32 @clock_nanosleep(i32 %4, i32 %5, %struct.timespec* %0, i32* null)
%7 = tail call i32 @time_add_ms(%struct.timespec* %0, i64 %2)
%8 = tail call i32 @time_add_ms(%struct.timespec* %1, i64 %2)
ret void
}