#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_ERRORCHECK_NP;
int pthread_mutex_init(int /*<<< orphan*/ *, 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*/);
int d_pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *pattr) {
  pthread_mutexattr_t attr;
  if (pattr == NULL) {
    pattr = &attr;
    pthread_mutexattr_init(&attr);
  }
  pthread_mutexattr_settype(pattr, PTHREAD_MUTEX_ERRORCHECK_NP);
  int res = pthread_mutex_init(mutex, pattr);
  if (pattr == &attr)
    pthread_mutexattr_destroy(&attr);
  return res;
}


x86 assembly (clang, -O0):
<d_pthread_mutex_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116c <d_pthread_mutex_init+0x2c>
lea    -0x14(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <pthread_mutexattr_init@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
call   1030 <pthread_mutexattr_settype@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <pthread_mutex_init@plt>
mov    %eax,-0x18(%rbp)
lea    -0x14(%rbp),%rax
cmp    %rax,-0x10(%rbp)
jne    11a5 <d_pthread_mutex_init+0x65>
lea    -0x14(%rbp),%rdi
call   1060 <pthread_mutexattr_destroy@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d_pthread_mutex_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
jne    1160 <d_pthread_mutex_init+0x20>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <pthread_mutexattr_init@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <pthread_mutexattr_settype@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <pthread_mutex_init@plt>
mov    %eax,%ebp
lea    0xc(%rsp),%rax
cmp    %rax,%rbx
jne    1192 <d_pthread_mutex_init+0x52>
lea    0xc(%rsp),%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_ERRORCHECK_NP = global i32 0
define i32 @d_pthread_mutex_init(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
store i32* %5, i32** %4
%10 = call i32 @pthread_mutexattr_init(i32* %5)
br label %11
11: ; preds = %9, %2
%12 = load i32*, i32** %4
%13 = load i32, i32* @PTHREAD_MUTEX_ERRORCHECK_NP
%14 = call i32 @pthread_mutexattr_settype(i32* %12, i32 %13)
%15 = load i32*, i32** %3
%16 = load i32*, i32** %4
%17 = call i32 @pthread_mutex_init(i32* %15, i32* %16)
store i32 %17, i32* %6
%18 = load i32*, i32** %4
%19 = icmp eq i32* %18, %5
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 @pthread_mutexattr_destroy(i32* %5)
br label %22
22: ; preds = %20, %11
%23 = load i32, i32* %6
ret i32 %23
}

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