#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;
int /*<<< orphan*/ PTHREAD_PRIO_INHERIT;
int /*<<< orphan*/ PTHREAD_PROCESS_PRIVATE;
int pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int pthread_mutexattr_init(int /*<<< orphan*/ *);
int pthread_mutexattr_setprioceiling(int /*<<< orphan*/ *, int);
int pthread_mutexattr_setprotocol(int /*<<< orphan*/ *, int /*<<< orphan*/);
int pthread_mutexattr_setpshared(int /*<<< orphan*/ *, int /*<<< orphan*/);
int pthread_mutexattr_settype(int /*<<< orphan*/ *, int /*<<< orphan*/);
int mutex_init(pthread_mutex_t *mutex) {
  pthread_mutexattr_t attr;
  int rc;
  rc = pthread_mutexattr_init(&attr);
  if (rc != 0)
    return rc;
  rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
  if (rc != 0)
    return rc;
  rc = pthread_mutexattr_setprioceiling(&attr, 99);
  if (rc != 0)
    return rc;
  rc = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
  if (rc != 0)
    return rc;
  rc = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE);
  if (rc != 0)
    return rc;
  rc = pthread_mutex_init(mutex, &attr);
  if (rc != 0)
    return rc;
  return 0;
}


x86 assembly (clang, -O0):
<mutex_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <pthread_mutexattr_init@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     118d <mutex_init+0x2d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <mutex_init+0xfd>
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1030 <pthread_mutexattr_settype@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11b7 <mutex_init+0x57>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <mutex_init+0xfd>
lea    -0x14(%rbp),%rdi
mov    $0x63,%esi
call   1050 <pthread_mutexattr_setprioceiling@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11dd <mutex_init+0x7d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <mutex_init+0xfd>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1070 <pthread_mutexattr_setprotocol@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1207 <mutex_init+0xa7>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <mutex_init+0xfd>
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1040 <pthread_mutexattr_setpshared@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1231 <mutex_init+0xd1>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <mutex_init+0xfd>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <pthread_mutex_init@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1256 <mutex_init+0xf6>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <mutex_init+0xfd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mutex_init>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
call   1060 <pthread_mutexattr_init@plt>
test   %eax,%eax
jne    11db <mutex_init+0x7b>
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdi
call   1030 <pthread_mutexattr_settype@plt>
test   %eax,%eax
jne    11db <mutex_init+0x7b>
lea    0xc(%rsp),%rdi
mov    $0x63,%esi
call   1050 <pthread_mutexattr_setprioceiling@plt>
test   %eax,%eax
jne    11db <mutex_init+0x7b>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdi
call   1070 <pthread_mutexattr_setprotocol@plt>
test   %eax,%eax
jne    11db <mutex_init+0x7b>
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdi
call   1040 <pthread_mutexattr_setpshared@plt>
test   %eax,%eax
jne    11db <mutex_init+0x7b>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <pthread_mutex_init@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@PTHREAD_MUTEX_ERRORCHECK = global i32 0
@PTHREAD_PRIO_INHERIT = global i32 0
@PTHREAD_PROCESS_PRIVATE = global i32 0
define i32 @mutex_init(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 %46
11: ; preds = %1
%12 = load i32, i32* @PTHREAD_MUTEX_ERRORCHECK
%13 = call i32 @pthread_mutexattr_settype(i32* %4, i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i32, i32* %5
store i32 %17, i32* %2
br label %46
18: ; preds = %11
%19 = call i32 @pthread_mutexattr_setprioceiling(i32* %4, i32 99)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load i32, i32* %5
store i32 %23, i32* %2
br label %46
24: ; preds = %18
%25 = load i32, i32* @PTHREAD_PRIO_INHERIT
%26 = call i32 @pthread_mutexattr_setprotocol(i32* %4, i32 %25)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i32, i32* %5
store i32 %30, i32* %2
br label %46
31: ; preds = %24
%32 = load i32, i32* @PTHREAD_PROCESS_PRIVATE
%33 = call i32 @pthread_mutexattr_setpshared(i32* %4, i32 %32)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = load i32, i32* %5
store i32 %37, i32* %2
br label %46
38: ; preds = %31
%39 = load i32*, i32** %3
%40 = call i32 @pthread_mutex_init(i32* %39, i32* %4)
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = load i32, i32* %5
store i32 %44, i32* %2
br label %46
45: ; preds = %38
store i32 0, i32* %2
br label %46
46: ; preds = %45, %43, %36, %29, %22, %16, %9
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
@PTHREAD_MUTEX_ERRORCHECK = global i32 0
@PTHREAD_PRIO_INHERIT = global i32 0
@PTHREAD_PROCESS_PRIVATE = global i32 0
define i32 @mutex_init(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 %23
6: ; preds = %1
%7 = load i32, i32* @PTHREAD_MUTEX_ERRORCHECK
%8 = call i32 @pthread_mutexattr_settype(i32* %2, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %6
%11 = call i32 @pthread_mutexattr_setprioceiling(i32* %2, i32 99)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i32, i32* @PTHREAD_PRIO_INHERIT
%15 = call i32 @pthread_mutexattr_setprotocol(i32* %2, i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* @PTHREAD_PROCESS_PRIVATE
%19 = call i32 @pthread_mutexattr_setpshared(i32* %2, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @pthread_mutex_init(i32* %0, i32* %2)
br label %23
23: ; preds = %21, %17, %13, %10, %6, %1
%24 = phi i32 [ %4, %1 ], [ %8, %6 ], [ %11, %10 ], [ %15, %13 ], [ %19, %17 ], [ %22, %21 ]
ret i32 %24
}