#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;

/* Variables and functions */
int /*<<< orphan*/ *hybris_alloc_init_mutex(int);
scalar_t__ hybris_check_android_shared_mutex(int);
int pthread_mutex_trylock(int /*<<< orphan*/ *);
int my_pthread_mutex_trylock(pthread_mutex_t *__mutex) {
  int value = (*(int *)__mutex);
  if (hybris_check_android_shared_mutex(value)) {
    ;
    return 0;
  }
  pthread_mutex_t *realmutex = (pthread_mutex_t *)value;
  if (value <= 0xFFFF) {
    realmutex = hybris_alloc_init_mutex(value);
    *((int *)__mutex) = (int)realmutex;
  }
  return pthread_mutex_trylock(realmutex);
}


x86 assembly (clang, -O0):
<my_pthread_mutex_trylock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <hybris_check_android_shared_mutex@plt>
cmp    $0x0,%rax
je     1163 <my_pthread_mutex_trylock+0x33>
movl   $0x0,-0x4(%rbp)
jmp    119c <my_pthread_mutex_trylock+0x6c>
movslq -0x14(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0xffff,-0x14(%rbp)
jg     1190 <my_pthread_mutex_trylock+0x60>
mov    -0x14(%rbp),%edi
call   1050 <hybris_alloc_init_mutex@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <pthread_mutex_trylock@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_pthread_mutex_trylock>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%ebp
mov    %ebp,%edi
call   1030 <hybris_check_android_shared_mutex@plt>
test   %rax,%rax
je     114d <my_pthread_mutex_trylock+0x1d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0xffff,%ebp
jg     1163 <my_pthread_mutex_trylock+0x33>
mov    %ebp,%edi
call   1050 <hybris_alloc_init_mutex@plt>
mov    %rax,%rdi
mov    %edi,(%rbx)
jmp    1166 <my_pthread_mutex_trylock+0x36>
movslq %ebp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <pthread_mutex_trylock@plt>

LLVM IR (-O0):
define i32 @my_pthread_mutex_trylock(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = load i32, i32* %6
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = call i64 @hybris_check_android_shared_mutex(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %27
12: ; preds = %1
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %5
%16 = load i32, i32* %4
%17 = icmp sle i32 %16, 65535
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i32, i32* %4
%20 = call i32* @hybris_alloc_init_mutex(i32 %19)
store i32* %20, i32** %5
%21 = load i32*, i32** %5
%22 = ptrtoint i32* %21 to i32
%23 = load i32*, i32** %3
store i32 %22, i32* %23
br label %24
24: ; preds = %18, %12
%25 = load i32*, i32** %5
%26 = call i32 @pthread_mutex_trylock(i32* %25)
store i32 %26, i32* %2
br label %27
27: ; preds = %24, %11
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @my_pthread_mutex_trylock(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = tail call i64 @hybris_check_android_shared_mutex(i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %1
%6 = sext i32 %2 to i64
%7 = inttoptr i64 %6 to i32*
%8 = icmp slt i32 %2, 65536
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = tail call i32* @hybris_alloc_init_mutex(i32 %2)
%11 = ptrtoint i32* %10 to i64
%12 = trunc i64 %11 to i32
store i32 %12, i32* %0
br label %13
13: ; preds = %9, %5
%14 = phi i32* [ %10, %9 ], [ %7, %5 ]
%15 = tail call i32 @pthread_mutex_trylock(i32* %14)
br label %16
16: ; preds = %1, %13
%17 = phi i32 [ %15, %13 ], [ 0, %1 ]
ret i32 %17
}