#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;
};
typedef int /*<<< orphan*/ pthread_mutex_t;
typedef int /*<<< orphan*/ pthread_cond_t;

/* Variables and functions */
int /*<<< orphan*/ pthread_cond_init(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_cond_timedwait(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ *,
                                          struct timespec *);
int /*<<< orphan*/ pthread_mutex_init(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutex_lock(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutex_unlock(int /*<<< orphan*/ *);
int /*<<< orphan*/ set_timeout(long long, struct timespec *);
void wait(long long timeout) {
  struct timespec time;
  pthread_mutex_t mutex;
  pthread_cond_t cond;
  if (timeout <= 0)
    return;
  pthread_mutex_init(&mutex, NULL);
  pthread_cond_init(&cond, NULL);
  set_timeout(timeout, &time);
  pthread_mutex_lock(&mutex);
  pthread_cond_timedwait(&cond, &mutex, &time);
  pthread_mutex_unlock(&mutex);
}


x86 assembly (clang, -O0):
<wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jg     117c <wait+0x1c>
jmp    11c6 <wait+0x66>
lea    -0x14(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <pthread_mutex_init@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_cond_init@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <set_timeout@plt>
lea    -0x14(%rbp),%rdi
call   1080 <pthread_mutex_lock@plt>
lea    -0x18(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1060 <pthread_cond_timedwait@plt>
lea    -0x14(%rbp),%rdi
call   1050 <pthread_mutex_unlock@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait>:
test   %rdi,%rdi
jle    11ca <wait+0x6a>
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x14(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <pthread_mutex_init@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <pthread_cond_init@plt>
lea    0x8(%rsp),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <set_timeout@plt>
mov    %r14,%rdi
call   1080 <pthread_mutex_lock@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <pthread_cond_timedwait@plt>
mov    %r14,%rdi
call   1050 <pthread_mutex_unlock@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
define void @wait(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.timespec
%4 = alloca i32
%5 = alloca i32
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = icmp sle i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
br label %17
9: ; preds = %1
%10 = call i32 @pthread_mutex_init(i32* %4, i32* null)
%11 = call i32 @pthread_cond_init(i32* %5, i32* null)
%12 = load i64, i64* %2
%13 = call i32 @set_timeout(i64 %12, %struct.timespec* %3)
%14 = call i32 @pthread_mutex_lock(i32* %4)
%15 = call i32 @pthread_cond_timedwait(i32* %5, i32* %4, %struct.timespec* %3)
%16 = call i32 @pthread_mutex_unlock(i32* %4)
br label %17
17: ; preds = %9, %8
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
define void @wait(i64 %0) {
%2 = alloca %struct.timespec
%3 = alloca i32
%4 = alloca i32
%5 = bitcast %struct.timespec* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = icmp slt i64 %0, 1
br i1 %8, label %16, label %9
9: ; preds = %1
%10 = call i32 @pthread_mutex_init(i32* %3, i32* null)
%11 = call i32 @pthread_cond_init(i32* %4, i32* null)
%12 = call i32 @set_timeout(i64 %0, %struct.timespec* %2)
%13 = call i32 @pthread_mutex_lock(i32* %3)
%14 = call i32 @pthread_cond_timedwait(i32* %4, i32* %3, %struct.timespec* %2)
%15 = call i32 @pthread_mutex_unlock(i32* %3)
br label %16
16: ; preds = %1, %9
ret void
}