#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_lock(int /*<<< orphan*/ *);
int my_pthread_mutex_lock(pthread_mutex_t *__mutex) {
  if (!__mutex) {
    ;
    return 0;
  }
  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_lock(realmutex);
}


x86 assembly (clang, -O0):
<my_pthread_mutex_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <my_pthread_mutex_lock+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <my_pthread_mutex_lock+0x83>
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     117a <my_pthread_mutex_lock+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <my_pthread_mutex_lock+0x83>
movslq -0x14(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0xffff,-0x14(%rbp)
jg     11a7 <my_pthread_mutex_lock+0x77>
mov    -0x14(%rbp),%edi
call   1040 <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   1050 <pthread_mutex_lock@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_pthread_mutex_lock>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1149 <my_pthread_mutex_lock+0x19>
mov    %rdi,%rbx
mov    (%rdi),%ebp
mov    %ebp,%edi
call   1030 <hybris_check_android_shared_mutex@plt>
test   %rax,%rax
je     1152 <my_pthread_mutex_lock+0x22>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0xffff,%ebp
jg     1168 <my_pthread_mutex_lock+0x38>
mov    %ebp,%edi
call   1040 <hybris_alloc_init_mutex@plt>
mov    %rax,%rdi
mov    %edi,(%rbx)
jmp    116b <my_pthread_mutex_lock+0x3b>
movslq %ebp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <pthread_mutex_lock@plt>

LLVM IR (-O0):
define i32 @my_pthread_mutex_lock(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 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 0, i32* %2
br label %31
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = load i32, i32* %10
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = call i64 @hybris_check_android_shared_mutex(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 0, i32* %2
br label %31
16: ; preds = %9
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %5
%20 = load i32, i32* %4
%21 = icmp sle i32 %20, 65535
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i32, i32* %4
%24 = call i32* @hybris_alloc_init_mutex(i32 %23)
store i32* %24, i32** %5
%25 = load i32*, i32** %5
%26 = ptrtoint i32* %25 to i32
%27 = load i32*, i32** %3
store i32 %26, i32* %27
br label %28
28: ; preds = %22, %16
%29 = load i32*, i32** %5
%30 = call i32 @pthread_mutex_lock(i32* %29)
store i32 %30, i32* %2
br label %31
31: ; preds = %28, %15, %8
%32 = load i32, i32* %2
ret i32 %32
}

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