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

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_MUTEX_RECURSIVE;
int /*<<< orphan*/ PTHREAD_MUTEX_ROBUST;
int /*<<< orphan*/ PTHREAD_PROCESS_SHARED;
scalar_t__ pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutexattr_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutexattr_init(int /*<<< orphan*/ *);
scalar_t__ pthread_mutexattr_setpshared(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/);
scalar_t__ pthread_mutexattr_setrobust(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/);
scalar_t__ pthread_mutexattr_settype(int /*<<< orphan*/ *, int /*<<< orphan*/);
void shm_mutex_create(key_t key, void *addr, size_t size) {
  pthread_mutex_t *pmutex = (pthread_mutex_t *)addr;
  pthread_mutexattr_t mutexAttr;
  pthread_mutexattr_init(&mutexAttr);
  if (pthread_mutexattr_setpshared(&mutexAttr, PTHREAD_PROCESS_SHARED) < 0) {
    ;
  } else if (pthread_mutexattr_setrobust(&mutexAttr, PTHREAD_MUTEX_ROBUST) <
             0) {
    ;
  } else if (pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE) <
             0) {
    ;
  } else if (pthread_mutex_init(pmutex, &mutexAttr) < 0) {
    ;
  } else {
    ;
  }
  pthread_mutexattr_destroy(&mutexAttr);
}


x86 assembly (clang, -O0):
<shm_mutex_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x24(%rbp),%rdi
call   1060 <pthread_mutexattr_init@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdi
call   1050 <pthread_mutexattr_setpshared@plt>
cmp    $0x0,%rax
jge    11a5 <shm_mutex_create+0x45>
jmp    1217 <shm_mutex_create+0xb7>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdi
call   1040 <pthread_mutexattr_setrobust@plt>
cmp    $0x0,%rax
jge    11c6 <shm_mutex_create+0x66>
jmp    1212 <shm_mutex_create+0xb2>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdi
call   1030 <pthread_mutexattr_settype@plt>
cmp    $0x0,%rax
jge    11e7 <shm_mutex_create+0x87>
jmp    120d <shm_mutex_create+0xad>
mov    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1070 <pthread_mutex_init@plt>
cmp    $0x0,%rax
jge    1203 <shm_mutex_create+0xa3>
jmp    1208 <shm_mutex_create+0xa8>
jmp    1208 <shm_mutex_create+0xa8>
jmp    120d <shm_mutex_create+0xad>
jmp    1212 <shm_mutex_create+0xb2>
jmp    1217 <shm_mutex_create+0xb7>
lea    -0x24(%rbp),%rdi
call   1080 <pthread_mutexattr_destroy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shm_mutex_create>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <pthread_mutexattr_init@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <pthread_mutexattr_setpshared@plt>
test   %rax,%rax
js     11c7 <shm_mutex_create+0x67>
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1040 <pthread_mutexattr_setrobust@plt>
test   %rax,%rax
js     11c7 <shm_mutex_create+0x67>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1030 <pthread_mutexattr_settype@plt>
test   %rax,%rax
js     11c7 <shm_mutex_create+0x67>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   1070 <pthread_mutex_init@plt>
lea    0x4(%rsp),%rdi
call   1080 <pthread_mutexattr_destroy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@PTHREAD_PROCESS_SHARED = global i32 0
@PTHREAD_MUTEX_ROBUST = global i32 0
@PTHREAD_MUTEX_RECURSIVE = global i32 0
define void @shm_mutex_create(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %5
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %7
%11 = call i32 @pthread_mutexattr_init(i32* %8)
%12 = load i32, i32* @PTHREAD_PROCESS_SHARED
%13 = call i64 @pthread_mutexattr_setpshared(i32* %8, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
br label %35
16: ; preds = %3
%17 = load i32, i32* @PTHREAD_MUTEX_ROBUST
%18 = call i64 @pthread_mutexattr_setrobust(i32* %8, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
br label %34
21: ; preds = %16
%22 = load i32, i32* @PTHREAD_MUTEX_RECURSIVE
%23 = call i64 @pthread_mutexattr_settype(i32* %8, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
br label %33
26: ; preds = %21
%27 = load i32*, i32** %7
%28 = call i64 @pthread_mutex_init(i32* %27, i32* %8)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
br label %32
31: ; preds = %26
br label %32
32: ; preds = %31, %30
br label %33
33: ; preds = %32, %25
br label %34
34: ; preds = %33, %20
br label %35
35: ; preds = %34, %15
%36 = call i32 @pthread_mutexattr_destroy(i32* %8)
ret void
}

LLVM IR (-O2):
@PTHREAD_PROCESS_SHARED = global i32 0
@PTHREAD_MUTEX_ROBUST = global i32 0
@PTHREAD_MUTEX_RECURSIVE = global i32 0
define void @shm_mutex_create(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = bitcast i8* %1 to i32*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @pthread_mutexattr_init(i32* %4)
%8 = load i32, i32* @PTHREAD_PROCESS_SHARED
%9 = call i64 @pthread_mutexattr_setpshared(i32* %4, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %3
%12 = load i32, i32* @PTHREAD_MUTEX_ROBUST
%13 = call i64 @pthread_mutexattr_setrobust(i32* %4, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %11
%16 = load i32, i32* @PTHREAD_MUTEX_RECURSIVE
%17 = call i64 @pthread_mutexattr_settype(i32* %4, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i64 @pthread_mutex_init(i32* %5, i32* %4)
br label %21
21: ; preds = %11, %15, %19, %3
%22 = call i32 @pthread_mutexattr_destroy(i32* %4)
ret void
}