#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*/ *hybris_alloc_init_cond();
int /*<<< orphan*/ *hybris_alloc_init_mutex(int);
scalar_t__ hybris_check_android_shared_cond(int);
scalar_t__ hybris_check_android_shared_mutex(int);
int pthread_cond_timedwait(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                           struct timespec const *);
int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
                              const struct timespec *abstime) {
  int cvalue = (*(int *)cond);
  int mvalue = (*(int *)mutex);
  if (hybris_check_android_shared_cond(cvalue) ||
      hybris_check_android_shared_mutex(mvalue)) {
    ;
    return 0;
  }
  pthread_cond_t *realcond = (pthread_cond_t *)cvalue;
  if (cvalue <= 0xFFFF) {
    realcond = hybris_alloc_init_cond();
    *((int *)cond) = (int)realcond;
  }
  pthread_mutex_t *realmutex = (pthread_mutex_t *)mvalue;
  if (mvalue <= 0xFFFF) {
    realmutex = hybris_alloc_init_mutex(mvalue);
    *((int *)mutex) = (int)realmutex;
  }
  return pthread_cond_timedwait(realcond, realmutex, abstime);
}


x86 assembly (clang, -O0):
<my_pthread_cond_timedwait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <hybris_check_android_shared_cond@plt>
cmp    $0x0,%rax
jne    119a <my_pthread_cond_timedwait+0x4a>
mov    -0x28(%rbp),%edi
call   1030 <hybris_check_android_shared_mutex@plt>
cmp    $0x0,%rax
je     11a6 <my_pthread_cond_timedwait+0x56>
movl   $0x0,-0x4(%rbp)
jmp    1213 <my_pthread_cond_timedwait+0xc3>
movslq -0x24(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0xffff,-0x24(%rbp)
jg     11d2 <my_pthread_cond_timedwait+0x82>
mov    $0x0,%al
call   1040 <hybris_alloc_init_cond@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0xffff,-0x28(%rbp)
jg     11ff <my_pthread_cond_timedwait+0xaf>
mov    -0x28(%rbp),%edi
call   1060 <hybris_alloc_init_mutex@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <pthread_cond_timedwait@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_pthread_cond_timedwait>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
mov    (%rdi),%ebp
movslq (%rsi),%r15
mov    %ebp,%edi
call   1050 <hybris_check_android_shared_cond@plt>
test   %rax,%rax
jne    1182 <my_pthread_cond_timedwait+0x32>
mov    %r15d,%edi
call   1030 <hybris_check_android_shared_mutex@plt>
test   %rax,%rax
je     1193 <my_pthread_cond_timedwait+0x43>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0xffff,%ebp
jg     11b3 <my_pthread_cond_timedwait+0x63>
xor    %eax,%eax
call   1040 <hybris_alloc_init_cond@plt>
mov    %rax,%r13
mov    %r13d,(%rbx)
cmp    $0xffff,%r15d
jle    11bf <my_pthread_cond_timedwait+0x6f>
jmp    11ce <my_pthread_cond_timedwait+0x7e>
movslq %ebp,%r13
cmp    $0xffff,%r15d
jg     11ce <my_pthread_cond_timedwait+0x7e>
mov    %r15d,%edi
call   1060 <hybris_alloc_init_mutex@plt>
mov    %rax,%r15
mov    %r15d,(%r12)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <pthread_cond_timedwait@plt>

LLVM IR (-O0):
%struct.timespec = type { i32 }
define i32 @my_pthread_cond_timedwait(i32* %0, i32* %1, %struct.timespec* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca %struct.timespec*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
store i32* %0, i32** %5
store i32* %1, i32** %6
store %struct.timespec* %2, %struct.timespec** %7
%12 = load i32*, i32** %5
%13 = load i32, i32* %12
store i32 %13, i32* %8
%14 = load i32*, i32** %6
%15 = load i32, i32* %14
store i32 %15, i32* %9
%16 = load i32, i32* %8
%17 = call i64 @hybris_check_android_shared_cond(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %3
%20 = load i32, i32* %9
%21 = call i64 @hybris_check_android_shared_mutex(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19, %3
store i32 0, i32* %4
br label %52
24: ; preds = %19
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i32*
store i32* %27, i32** %10
%28 = load i32, i32* %8
%29 = icmp sle i32 %28, 65535
br i1 %29, label %30, label %35
30: ; preds = %24
%31 = call i32* (...) @hybris_alloc_init_cond()
store i32* %31, i32** %10
%32 = load i32*, i32** %10
%33 = ptrtoint i32* %32 to i32
%34 = load i32*, i32** %5
store i32 %33, i32* %34
br label %35
35: ; preds = %30, %24
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i32*
store i32* %38, i32** %11
%39 = load i32, i32* %9
%40 = icmp sle i32 %39, 65535
br i1 %40, label %41, label %47
41: ; preds = %35
%42 = load i32, i32* %9
%43 = call i32* @hybris_alloc_init_mutex(i32 %42)
store i32* %43, i32** %11
%44 = load i32*, i32** %11
%45 = ptrtoint i32* %44 to i32
%46 = load i32*, i32** %6
store i32 %45, i32* %46
br label %47
47: ; preds = %41, %35
%48 = load i32*, i32** %10
%49 = load i32*, i32** %11
%50 = load %struct.timespec*, %struct.timespec** %7
%51 = call i32 @pthread_cond_timedwait(i32* %48, i32* %49, %struct.timespec* %50)
store i32 %51, i32* %4
br label %52
52: ; preds = %47, %23
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
define i32 @my_pthread_cond_timedwait(i32* nocapture %0, i32* nocapture %1, %struct.timespec* %2) {
%4 = load i32, i32* %0
%5 = load i32, i32* %1
%6 = tail call i64 @hybris_check_android_shared_cond(i32 %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %31
8: ; preds = %3
%9 = tail call i64 @hybris_check_android_shared_mutex(i32 %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %8
%12 = sext i32 %4 to i64
%13 = inttoptr i64 %12 to i32*
%14 = icmp slt i32 %4, 65536
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = tail call i32* (...) @hybris_alloc_init_cond()
%17 = ptrtoint i32* %16 to i64
%18 = trunc i64 %17 to i32
store i32 %18, i32* %0
br label %19
19: ; preds = %15, %11
%20 = phi i32* [ %16, %15 ], [ %13, %11 ]
%21 = sext i32 %5 to i64
%22 = inttoptr i64 %21 to i32*
%23 = icmp slt i32 %5, 65536
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = tail call i32* @hybris_alloc_init_mutex(i32 %5)
%26 = ptrtoint i32* %25 to i64
%27 = trunc i64 %26 to i32
store i32 %27, i32* %1
br label %28
28: ; preds = %24, %19
%29 = phi i32* [ %25, %24 ], [ %22, %19 ]
%30 = tail call i32 @pthread_cond_timedwait(i32* %20, i32* %29, %struct.timespec* %2)
br label %31
31: ; preds = %3, %8, %28
%32 = phi i32 [ %30, %28 ], [ 0, %8 ], [ 0, %3 ]
ret i32 %32
}