#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*/ ts;
typedef scalar_t__ time_t;
struct timespec {
  scalar_t__ tv_sec;
  scalar_t__ tv_nsec;
};
typedef int /*<<< orphan*/ rts;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ TIMER_ABSTIME;
int /*<<< orphan*/ abort();
int clock_nanosleep(int /*<<< orphan*/, int /*<<< orphan*/, struct timespec *,
                    struct timespec *);
int /*<<< orphan*/ memset(struct timespec *, int /*<<< orphan*/, int);
void mt_sleep_until(time_t until) {
  int res;
  struct timespec ts, rts;
  memset(&ts, 0, sizeof(ts));
  ts.tv_sec = until;
  memset(&rts, 0, sizeof(rts));
  while (1) {
    res = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, &rts);
    if (res)
      abort();
    if ((rts.tv_sec == 0) && (rts.tv_nsec == 0))
      break;
  }
}


x86 assembly (clang, -O0):
<mt_sleep_until>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <clock_nanosleep@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1197 <mt_sleep_until+0x67>
mov    $0x0,%al
call   1030 <abort@plt>
cmpq   $0x0,-0x30(%rbp)
jne    11b2 <mt_sleep_until+0x82>
cmpq   $0x0,-0x28(%rbp)
jne    11b2 <mt_sleep_until+0x82>
jmp    11b7 <mt_sleep_until+0x87>
jmp    1164 <mt_sleep_until+0x34>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mt_sleep_until>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    %rbx,0x18(%rsp)
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e6e(%rip),%r12
mov    0x2e6f(%rip),%rbx
nopl   0x0(%rax)
mov    (%r12),%edi
mov    (%rbx),%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <clock_nanosleep@plt>
test   %eax,%eax
jne    11ad <mt_sleep_until+0x7d>
mov    0x8(%rsp),%rax
or     0x10(%rsp),%rax
jne    1180 <mt_sleep_until+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@TIMER_ABSTIME = global i32 0
define void @mt_sleep_until(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
store i64 %0, i64* %2
%6 = call i32 @memset(%struct.timespec* %4, i32 0, i32 16)
%7 = load i64, i64* %2
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i64 %7, i64* %8
%9 = call i32 @memset(%struct.timespec* %5, i32 0, i32 16)
br label %10
10: ; preds = %1, %27
%11 = load i32, i32* @CLOCK_MONOTONIC
%12 = load i32, i32* @TIMER_ABSTIME
%13 = call i32 @clock_nanosleep(i32 %11, i32 %12, %struct.timespec* %4, %struct.timespec* %5)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %10
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%20 = load i64, i64* %19
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%24 = load i64, i64* %23
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
br label %28
27: ; preds = %22, %18
br label %10
28: ; preds = %26
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@TIMER_ABSTIME = global i32 0
define void @mt_sleep_until(i64 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%6 = call i32 @memset(%struct.timespec* %2, i32 0, i32 16)
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i64 %0, i64* %7
%8 = call i32 @memset(%struct.timespec* %3, i32 0, i32 16)
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
br label %11
11: ; preds = %18, %1
%12 = load i32, i32* @CLOCK_MONOTONIC
%13 = load i32, i32* @TIMER_ABSTIME
%14 = call i32 @clock_nanosleep(i32 %12, i32 %13, %struct.timespec* %2, %struct.timespec* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %11
%19 = load i64, i64* %9
%20 = icmp eq i64 %19, 0
%21 = load i64, i64* %10
%22 = icmp eq i64 %21, 0
%23 = select i1 %20, i1 %22, i1 false
br i1 %23, label %24, label %11
24: ; preds = %18
ret void
}