#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 struct timespec const pthread_cond_t;

/* Variables and functions */
int /*<<< orphan*/ ASSERT(struct timespec const *);
int ETIMEDOUT;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ log_error(int, char *);
int pthread_cond_timedwait(struct timespec const *, int /*<<< orphan*/ *,
                           struct timespec const *);
int conditionTimedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
                       const struct timespec *abs_timeout) {
  ASSERT(cond);
  ASSERT(abs_timeout);
  int retval;
  retval = pthread_cond_timedwait(cond, mutex, abs_timeout);
  if (retval != 0 && retval != ETIMEDOUT) {
    log_error(retval, "Error pthread_cond_timedwait()");
    abort();
  }
  return retval;
}


x86 assembly (clang, -O0):
<conditionTimedwait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ASSERT@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ASSERT@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <pthread_cond_timedwait@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11ac <conditionTimedwait+0x6c>
mov    -0x1c(%rbp),%eax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
je     11ac <conditionTimedwait+0x6c>
mov    -0x1c(%rbp),%edi
lea    0xe60(%rip),%rsi
call   1040 <log_error@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conditionTimedwait>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <ASSERT@plt>
mov    %r15,%rdi
call   1060 <ASSERT@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <pthread_cond_timedwait@plt>
test   %eax,%eax
je     1178 <conditionTimedwait+0x38>
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%eax
jne    117e <conditionTimedwait+0x3e>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe7b(%rip),%rsi
mov    %eax,%edi
call   1040 <log_error@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.timespec = type { i32 }
@ETIMEDOUT = global i32 0
@.str = [31 x i8] c"Error pthread_cond_timedwait()\00"
define i32 @conditionTimedwait(%struct.timespec* %0, i32* %1, %struct.timespec* %2) {
%4 = alloca %struct.timespec*
%5 = alloca i32*
%6 = alloca %struct.timespec*
%7 = alloca i32
store %struct.timespec* %0, %struct.timespec** %4
store i32* %1, i32** %5
store %struct.timespec* %2, %struct.timespec** %6
%8 = load %struct.timespec*, %struct.timespec** %4
%9 = call i32 @ASSERT(%struct.timespec* %8)
%10 = load %struct.timespec*, %struct.timespec** %6
%11 = call i32 @ASSERT(%struct.timespec* %10)
%12 = load %struct.timespec*, %struct.timespec** %4
%13 = load i32*, i32** %5
%14 = load %struct.timespec*, %struct.timespec** %6
%15 = call i32 @pthread_cond_timedwait(%struct.timespec* %12, i32* %13, %struct.timespec* %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %3
%19 = load i32, i32* %7
%20 = load i32, i32* @ETIMEDOUT
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* %7
%24 = call i32 @log_error(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %18, %3
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@ETIMEDOUT = global i32 0
@.str = [31 x i8] c"Error pthread_cond_timedwait()\00"
define i32 @conditionTimedwait(%struct.timespec* %0, i32* %1, %struct.timespec* %2) {
%4 = tail call i32 @ASSERT(%struct.timespec* %0)
%5 = tail call i32 @ASSERT(%struct.timespec* %2)
%6 = tail call i32 @pthread_cond_timedwait(%struct.timespec* %0, i32* %1, %struct.timespec* %2)
%7 = icmp eq i32 %6, 0
%8 = load i32, i32* @ETIMEDOUT
%9 = icmp eq i32 %6, %8
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = tail call i32 @log_error(i32 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %3
ret i32 %6
}