#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;

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_PROCESS_PRIVATE;
int /*<<< orphan*/ PTHREAD_PROCESS_SHARED;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ pthread_mutexattr_init(int /*<<< orphan*/ *);
int pthread_mutexattr_setpshared(int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(void) {
  pthread_mutexattr_t mta;
  int ret;
  if (pthread_mutexattr_init(&mta) != 0) {
    perror("Error at pthread_mutexattr_init()\n");
    return 2;
  }
  if ((ret = pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_PRIVATE)) !=
      0) {
    printf("Test FAILED: Cannot set pshared attribute to "
           "PTHREAD_PROCESS_PRIVATE. Error: %d\n",
           ret);
    return 1;
  }
  if ((ret = pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_SHARED)) != 0) {
    printf("Test FAILED: Cannot set pshared attribute to "
           "PTHREAD_PROCESS_SHARED. Error code: %d\n",
           ret);
    return 1;
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1060 <pthread_mutexattr_init@plt>
cmp    $0x0,%rax
je     117a <main+0x3a>
lea    0xe97(%rip),%rdi
call   1050 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1205 <main+0xc5>
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1040 <pthread_mutexattr_setpshared@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     11b5 <main+0x75>
mov    -0xc(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1205 <main+0xc5>
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1040 <pthread_mutexattr_setpshared@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     11f0 <main+0xb0>
mov    -0xc(%rbp),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1205 <main+0xc5>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0x4(%rsp),%rdi
call   1070 <pthread_mutexattr_init@plt>
test   %rax,%rax
jne    11be <main+0x6e>
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1050 <pthread_mutexattr_setpshared@plt>
test   %eax,%eax
je     1180 <main+0x30>
lea    0xea5(%rip),%rdi
jmp    119e <main+0x4e>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1050 <pthread_mutexattr_setpshared@plt>
test   %eax,%eax
je     11ae <main+0x5e>
lea    0xed6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xf14(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe3b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Error at pthread_mutexattr_init()\0A\00"
@PTHREAD_PROCESS_PRIVATE = global i32 0
@.str.1 = [81 x i8] c"Test FAILED: Cannot set pshared attribute to PTHREAD_PROCESS_PRIVATE. Error: %d\0A\00"
@PTHREAD_PROCESS_SHARED = global i32 0
@.str.2 = [85 x i8] c"Test FAILED: Cannot set pshared attribute to PTHREAD_PROCESS_SHARED. Error code: %d\0A\00"
@.str.3 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 @pthread_mutexattr_init(i32* %2)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %24
8: ; preds = %0
%9 = load i32, i32* @PTHREAD_PROCESS_PRIVATE
%10 = call i32 @pthread_mutexattr_setpshared(i32* %2, i32 %9)
store i32 %10, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 1, i32* %1
br label %24
15: ; preds = %8
%16 = load i32, i32* @PTHREAD_PROCESS_SHARED
%17 = call i32 @pthread_mutexattr_setpshared(i32* %2, i32 %16)
store i32 %17, i32* %3
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.2, i64 0, i64 0), i32 %20)
store i32 1, i32* %1
br label %24
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %24
24: ; preds = %22, %19, %12, %6
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [35 x i8] c"Error at pthread_mutexattr_init()\0A\00"
@PTHREAD_PROCESS_PRIVATE = global i32 0
@.str.1 = [81 x i8] c"Test FAILED: Cannot set pshared attribute to PTHREAD_PROCESS_PRIVATE. Error: %d\0A\00"
@PTHREAD_PROCESS_SHARED = global i32 0
@.str.2 = [85 x i8] c"Test FAILED: Cannot set pshared attribute to PTHREAD_PROCESS_SHARED. Error code: %d\0A\00"
@str = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 @pthread_mutexattr_init(i32* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %21
7: ; preds = %0
%8 = load i32, i32* @PTHREAD_PROCESS_PRIVATE
%9 = call i32 @pthread_mutexattr_setpshared(i32* %1, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %21
13: ; preds = %7
%14 = load i32, i32* @PTHREAD_PROCESS_SHARED
%15 = call i32 @pthread_mutexattr_setpshared(i32* %1, i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %21
19: ; preds = %13
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %19, %17, %11, %5
%22 = phi i32 [ 2, %5 ], [ 1, %11 ], [ 1, %17 ], [ 0, %19 ]
ret i32 %22
}