#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_PROCESS_SHARED;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutexattr_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_mutexattr_init(int /*<<< orphan*/ *);
int pthread_mutexattr_setpshared(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int pthread_mutex_init_pshared(pthread_mutex_t *mutex) {
  int ret;
  pthread_mutexattr_t attr;
  pthread_mutexattr_init(&attr);
  if ((ret = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)) !=
      0) {
    fprintf(stderr, "pthread_mutexattr_setpshared failed with code %d\n", ret);
    return ret;
  }
  if ((ret = pthread_mutex_init(mutex, &attr)) != 0) {
    fprintf(stderr, "pthread_mutexattr_init failed with code %d\n", ret);
    return ret;
  }
  pthread_mutexattr_destroy(&attr);
  return 0;
}


x86 assembly (clang, -O0):
<pthread_mutex_init_pshared>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pthread_mutexattr_init@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1040 <pthread_mutexattr_setpshared@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11a6 <pthread_mutex_init_pshared+0x56>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe6a(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f2 <pthread_mutex_init_pshared+0xa2>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <pthread_mutex_init@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11e2 <pthread_mutex_init_pshared+0x92>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe60(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f2 <pthread_mutex_init_pshared+0xa2>
lea    -0x18(%rbp),%rdi
call   1070 <pthread_mutexattr_destroy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pthread_mutex_init_pshared>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <pthread_mutexattr_init@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <pthread_mutexattr_setpshared@plt>
test   %eax,%eax
je     118d <pthread_mutex_init_pshared+0x3d>
mov    %eax,%ebx
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
jmp    11b0 <pthread_mutex_init_pshared+0x60>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   1060 <pthread_mutex_init@plt>
test   %eax,%eax
je     11c1 <pthread_mutex_init_pshared+0x71>
mov    %eax,%ebx
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0x4(%rsp),%rdi
call   1070 <pthread_mutexattr_destroy@plt>
xor    %ebx,%ebx
jmp    11b7 <pthread_mutex_init_pshared+0x67>

LLVM IR (-O0):
@PTHREAD_PROCESS_SHARED = global i32 0
@stderr = global i32 0
@.str = [50 x i8] c"pthread_mutexattr_setpshared failed with code %d\0A\00"
@.str.1 = [44 x i8] c"pthread_mutexattr_init failed with code %d\0A\00"
define i32 @pthread_mutex_init_pshared(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* %5)
%7 = load i32, i32* @PTHREAD_PROCESS_SHARED
%8 = call i32 @pthread_mutexattr_setpshared(i32* %5, i32 %7)
store i32 %8, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* %4
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %4
store i32 %14, i32* %2
br label %26
15: ; preds = %1
%16 = load i32*, i32** %3
%17 = call i32 @pthread_mutex_init(i32* %16, i32* %5)
store i32 %17, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i32, i32* %4
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %26
24: ; preds = %15
%25 = call i32 @pthread_mutexattr_destroy(i32* %5)
store i32 0, i32* %2
br label %26
26: ; preds = %24, %19, %10
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@PTHREAD_PROCESS_SHARED = global i32 0
@stderr = global i32 0
@.str = [50 x i8] c"pthread_mutexattr_setpshared failed with code %d\0A\00"
@.str.1 = [44 x i8] c"pthread_mutexattr_init failed with code %d\0A\00"
define i32 @pthread_mutex_init_pshared(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @pthread_mutexattr_init(i32* %2)
%5 = load i32, i32* @PTHREAD_PROCESS_SHARED
%6 = call i32 @pthread_mutexattr_setpshared(i32* %2, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %19
11: ; preds = %1
%12 = call i32 @pthread_mutex_init(i32* %0, i32* %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %19
17: ; preds = %11
%18 = call i32 @pthread_mutexattr_destroy(i32* %2)
br label %19
19: ; preds = %17, %14, %8
%20 = phi i32 [ %6, %8 ], [ %12, %14 ], [ 0, %17 ]
ret i32 %20
}