#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 int /*<<< orphan*/ pthread_mutex_t;

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_MUTEX_RECURSIVE;
int pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutexattr_destroy(int /*<<< orphan*/ *);
int pthread_mutexattr_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutexattr_settype(int /*<<< orphan*/ *,
                                             int /*<<< orphan*/);
int mutexCreateRecursive(pthread_mutex_t *lockToCreate) {
  pthread_mutexattr_t lockAttributes;
  int pthreadErrorCode = pthread_mutexattr_init(&lockAttributes);
  if (pthreadErrorCode != 0)
    return pthreadErrorCode;
  pthread_mutexattr_settype(&lockAttributes, PTHREAD_MUTEX_RECURSIVE);
  pthreadErrorCode = pthread_mutex_init(lockToCreate, &lockAttributes);
  pthread_mutexattr_destroy(&lockAttributes);
  return pthreadErrorCode;
}


x86 assembly (clang, -O0):
<mutexCreateRecursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <pthread_mutexattr_init@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     116d <mutexCreateRecursive+0x2d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119e <mutexCreateRecursive+0x5e>
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1030 <pthread_mutexattr_settype@plt>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <pthread_mutex_init@plt>
mov    %eax,-0x18(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <pthread_mutexattr_destroy@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mutexCreateRecursive>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
call   1040 <pthread_mutexattr_init@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1186 <mutexCreateRecursive+0x46>
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1030 <pthread_mutexattr_settype@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <pthread_mutex_init@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <pthread_mutexattr_destroy@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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