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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
scalar_t__ EINVAL;
int /*<<< orphan*/ PTHREAD_COND_INITIALIZER;
int /*<<< orphan*/ PTHREAD_MUTEX_INITIALIZER;
int /*<<< orphan*/ assert(int);
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
scalar_t__ pthread_cond_timedwait(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  struct timespec *);
scalar_t__ pthread_mutex_lock(int /*<<< orphan*/ *);
scalar_t__ pthread_mutex_unlock(int /*<<< orphan*/ *);
int main() {
  struct timespec abstime;
  pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
  pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
  assert(clock_gettime(CLOCK_REALTIME, &abstime) == 0);
  abstime.tv_nsec += 1000000000;
  assert(pthread_mutex_lock(&mutex) == 0);
  assert(pthread_cond_timedwait(&cond, &mutex, &abstime) == EINVAL);
  assert(pthread_mutex_unlock(&mutex) == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%eax
add    $0x3b9aca00,%eax
mov    %eax,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pthread_mutex_lock@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x10(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1060 <pthread_cond_timedwait@plt>
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0xc(%rbp),%rdi
call   1050 <pthread_mutex_unlock@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
addl   $0x3b9aca00,0x8(%rsp)
3b
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <pthread_mutex_lock@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <pthread_cond_timedwait@plt>
mov    0x2e01(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1050 <pthread_mutex_unlock@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@PTHREAD_MUTEX_INITIALIZER = global i32 0
@PTHREAD_COND_INITIALIZER = global i32 0
@CLOCK_REALTIME = global i32 0
@EINVAL = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @PTHREAD_MUTEX_INITIALIZER
store i32 %5, i32* %3
%6 = load i32, i32* @PTHREAD_COND_INITIALIZER
store i32 %6, i32* %4
%7 = load i32, i32* @CLOCK_REALTIME
%8 = call i64 @clock_gettime(i32 %7, %struct.timespec* %2)
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1000000000
store i32 %14, i32* %12
%15 = call i64 @pthread_mutex_lock(i32* %3)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i64 @pthread_cond_timedwait(i32* %4, i32* %3, %struct.timespec* %2)
%20 = load i64, i64* @EINVAL
%21 = icmp eq i64 %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i64 @pthread_mutex_unlock(i32* %3)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@PTHREAD_MUTEX_INITIALIZER = global i32 0
@PTHREAD_COND_INITIALIZER = global i32 0
@CLOCK_REALTIME = global i32 0
@EINVAL = global i64 0
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca i32
%3 = alloca i32
%4 = bitcast %struct.timespec* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = load i32, i32* @PTHREAD_MUTEX_INITIALIZER
store i32 %6, i32* %2
%7 = bitcast i32* %3 to i8*
%8 = load i32, i32* @PTHREAD_COND_INITIALIZER
store i32 %8, i32* %3
%9 = load i32, i32* @CLOCK_REALTIME
%10 = call i64 @clock_gettime(i32 %9, %struct.timespec* %1)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1000000000
store i32 %16, i32* %14
%17 = call i64 @pthread_mutex_lock(i32* %2)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i64 @pthread_cond_timedwait(i32* %3, i32* %2, %struct.timespec* %1)
%22 = load i64, i64* @EINVAL
%23 = icmp eq i64 %21, %22
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = call i64 @pthread_mutex_unlock(i32* %2)
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
ret i32 0
}