#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 scalar_t__ time_t;
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ select(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/,
                          struct timeval *);
scalar_t__ time(int /*<<< orphan*/);
void sleep_until(time_t stoptime) {
  struct timeval tv;
  while (1) {
    time_t current = time(0);
    if (current >= stoptime)
      break;
    tv.tv_sec = stoptime - current;
    tv.tv_usec = 0;
    select(0, 0, 0, 0, &tv);
  }
}


x86 assembly (clang, -O0):
<sleep_until>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %edi,%edi
call   1030 <time@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jl     114a <sleep_until+0x2a>
jmp    1174 <sleep_until+0x54>
mov    -0x8(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
xor    %ecx,%ecx
lea    -0x18(%rbp),%r8
mov    %ecx,%edi
mov    %ecx,%esi
mov    %ecx,%edx
call   1040 <select@plt>
jmp    112c <sleep_until+0xc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleep_until>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
call   1030 <time@plt>
cmp    %rbx,%rax
jge    1170 <sleep_until+0x50>
lea    0x8(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rcx
sub    %rax,%rcx
mov    %rcx,0x10(%rsp)
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
xor    %edi,%edi
call   1030 <time@plt>
cmp    %rbx,%rax
jl     1140 <sleep_until+0x20>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define void @sleep_until(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.timeval
%4 = alloca i64
store i64 %0, i64* %2
br label %5
5: ; preds = %1, %11
%6 = call i64 @time(i32 0)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = load i64, i64* %2
%9 = icmp sge i64 %7, %8
br i1 %9, label %10, label %11
10: ; preds = %5
br label %18
11: ; preds = %5
%12 = load i64, i64* %2
%13 = load i64, i64* %4
%14 = sub nsw i64 %12, %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i64 %14, i64* %15
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i64 0, i64* %16
%17 = call i32 @select(i32 0, i32 0, i32 0, i32 0, %struct.timeval* %3)
br label %5
18: ; preds = %10
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @sleep_until(i64 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i64 @time(i32 0)
%5 = icmp slt i64 %4, %0
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ %4, %6 ], [ %13, %9 ]
%11 = sub nsw i64 %0, %10
store i64 %11, i64* %7
store i64 0, i64* %8
%12 = call i32 @select(i32 0, i32 0, i32 0, i32 0, %struct.timeval* %2)
%13 = call i64 @time(i32 0)
%14 = icmp slt i64 %13, %0
br i1 %14, label %9, label %15
15: ; preds = %9, %1
ret void
}