#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 */
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_wait(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int my_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) {
  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_wait(realcond, realmutex);
}


x86 assembly (clang, -O0):
<my_pthread_cond_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <hybris_check_android_shared_cond@plt>
cmp    $0x0,%rax
jne    1196 <my_pthread_cond_wait+0x46>
mov    -0x20(%rbp),%edi
call   1030 <hybris_check_android_shared_mutex@plt>
cmp    $0x0,%rax
je     11a2 <my_pthread_cond_wait+0x52>
movl   $0x0,-0x4(%rbp)
jmp    120b <my_pthread_cond_wait+0xbb>
movslq -0x1c(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0xffff,-0x1c(%rbp)
jg     11ce <my_pthread_cond_wait+0x7e>
mov    $0x0,%al
call   1050 <hybris_alloc_init_cond@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0xffff,-0x20(%rbp)
jg     11fb <my_pthread_cond_wait+0xab>
mov    -0x20(%rbp),%edi
call   1070 <hybris_alloc_init_mutex@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <pthread_cond_wait@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_pthread_cond_wait>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
mov    (%rdi),%ebp
movslq (%rsi),%r14
mov    %ebp,%edi
call   1060 <hybris_check_android_shared_cond@plt>
test   %rax,%rax
jne    117c <my_pthread_cond_wait+0x2c>
mov    %r14d,%edi
call   1030 <hybris_check_android_shared_mutex@plt>
test   %rax,%rax
je     1187 <my_pthread_cond_wait+0x37>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0xffff,%ebp
jg     11a7 <my_pthread_cond_wait+0x57>
xor    %eax,%eax
call   1050 <hybris_alloc_init_cond@plt>
mov    %rax,%r12
mov    %r12d,(%rbx)
cmp    $0xffff,%r14d
jle    11b3 <my_pthread_cond_wait+0x63>
jmp    11c1 <my_pthread_cond_wait+0x71>
movslq %ebp,%r12
cmp    $0xffff,%r14d
jg     11c1 <my_pthread_cond_wait+0x71>
mov    %r14d,%edi
call   1070 <hybris_alloc_init_mutex@plt>
mov    %rax,%r14
mov    %r14d,(%r15)
mov    %r12,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <pthread_cond_wait@plt>

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

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