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

/* Variables and functions */
scalar_t__ EINVAL;
int /*<<< orphan*/ PTHREAD_COND_INITIALIZER;
int /*<<< orphan*/ PTHREAD_MUTEX_INITIALIZER;
int /*<<< orphan*/ assert(int);
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*/ *);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  struct timespec abstime;
  pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
  pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
  abstime.tv_sec = time(NULL) + 2;
  abstime.tv_nsec = 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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x3b9aca00,%rax
mov    %rax,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
call   1070 <pthread_mutex_lock@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x20(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <pthread_cond_timedwait@plt>
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1050 <pthread_mutex_unlock@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
xor    %edi,%edi
call   1040 <time@plt>
add    $0x2,%rax
mov    %rax,0x18(%rsp)
movq   $0x3b9aca00,0x10(%rsp)
9a 3b
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <pthread_mutex_lock@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rdx
mov    %rbx,%rsi
call   1060 <pthread_cond_timedwait@plt>
mov    0x2e14(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1050 <pthread_mutex_unlock@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@PTHREAD_MUTEX_INITIALIZER = global i32 0
@PTHREAD_COND_INITIALIZER = 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 = tail call i64 @time(i32* null)
%10 = add nsw i64 %9, 2
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i64 %10, i64* %11
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i64 1000000000, i64* %12
%13 = call i64 @pthread_mutex_lock(i32* %2)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i64 @pthread_cond_timedwait(i32* %3, i32* %2, %struct.timespec* %1)
%18 = load i64, i64* @EINVAL
%19 = icmp eq i64 %17, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = call i64 @pthread_mutex_unlock(i32* %2)
%23 = icmp eq i64 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
ret i32 0
}