#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_mutexattr_t;
typedef void pthread_mutex_t;

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_MUTEX_RECURSIVE;
int /*<<< orphan*/ free(void *);
void *malloc(int);
int pthread_mutex_init(void *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutexattr_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutexattr_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutexattr_settype(int /*<<< orphan*/ *,
                                             int /*<<< orphan*/);
void *LockCreate() {
  pthread_mutexattr_t attr;
  pthread_mutex_t *p_mutex = malloc(sizeof(pthread_mutex_t));
  int i_result;
  pthread_mutexattr_init(&attr);
  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  i_result = pthread_mutex_init(p_mutex, &attr);
  pthread_mutexattr_destroy(&attr);
  if (i_result) {
    free(p_mutex);
    return NULL;
  }
  return p_mutex;
}


x86 assembly (clang, -O0):
<LockCreate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pthread_mutexattr_init@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1040 <pthread_mutexattr_settype@plt>
mov    -0x18(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <pthread_mutex_init@plt>
mov    %eax,-0x1c(%rbp)
lea    -0xc(%rbp),%rdi
call   1080 <pthread_mutexattr_destroy@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11ca <LockCreate+0x6a>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <LockCreate+0x72>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LockCreate>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1060 <pthread_mutexattr_init@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1040 <pthread_mutexattr_settype@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <pthread_mutex_init@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1080 <pthread_mutexattr_destroy@plt>
test   %ebp,%ebp
je     11b6 <LockCreate+0x56>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PTHREAD_MUTEX_RECURSIVE = global i32 0
define i8* @LockCreate() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = call i8* @malloc(i32 1)
store i8* %5, i8** %3
%6 = call i32 @pthread_mutexattr_init(i32* %2)
%7 = load i32, i32* @PTHREAD_MUTEX_RECURSIVE
%8 = call i32 @pthread_mutexattr_settype(i32* %2, i32 %7)
%9 = load i8*, i8** %3
%10 = call i32 @pthread_mutex_init(i8* %9, i32* %2)
store i32 %10, i32* %4
%11 = call i32 @pthread_mutexattr_destroy(i32* %2)
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i8*, i8** %3
%16 = call i32 @free(i8* %15)
store i8* null, i8** %1
br label %19
17: ; preds = %0
%18 = load i8*, i8** %3
store i8* %18, i8** %1
br label %19
19: ; preds = %17, %14
%20 = load i8*, i8** %1
ret i8* %20
}

LLVM IR (-O2):
@PTHREAD_MUTEX_RECURSIVE = global i32 0
define i8* @LockCreate() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%4 = call i32 @pthread_mutexattr_init(i32* %1)
%5 = load i32, i32* @PTHREAD_MUTEX_RECURSIVE
%6 = call i32 @pthread_mutexattr_settype(i32* %1, i32 %5)
%7 = call i32 @pthread_mutex_init(i8* %3, i32* %1)
%8 = call i32 @pthread_mutexattr_destroy(i32* %1)
%9 = icmp eq i32 %7, 0
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @free(i8* %3)
br label %12
12: ; preds = %0, %10
%13 = phi i8* [ null, %10 ], [ %3, %0 ]
ret i8* %13
}