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

/* Variables and functions */
int PTHREAD_PROCESS_PRIVATE;
int /*<<< orphan*/ printf(char *, ...);
int pthread_barrierattr_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_barrierattr_getpshared(int /*<<< orphan*/ *, int *);
int pthread_barrierattr_init(int /*<<< orphan*/ *);
char *strerror(int);
int main(void) {
  int rc;
  pthread_barrierattr_t ba;
  int pshared;
  rc = pthread_barrierattr_init(&ba);
  if (rc != 0) {
    printf("Error while initialize attribute object\n");
    return 2;
  }
  if (pthread_barrierattr_getpshared(&ba, &pshared) != 0) {
    printf("Error at pthread_barrierattr_getpshared()\n");
    return 1;
  }
  if (pshared != PTHREAD_PROCESS_PRIVATE) {
    printf("The process shared attribute was not set to "
           "default value of PTHREAD_PROCESS_PRIVATE\n");
    return 2;
  }
  rc = pthread_barrierattr_destroy(&ba);
  if (rc != 0) {
    printf("Error at pthread_barrierattr_destroy() "
           "return code: %d, %s",
           rc, strerror(rc));
    return 2;
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pthread_barrierattr_init@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     118f <main+0x3f>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1245 <main+0xf5>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <pthread_barrierattr_getpshared@plt>
cmp    $0x0,%rax
je     11c0 <main+0x70>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1245 <main+0xf5>
mov    -0x10(%rbp),%eax
mov    0x2e16(%rip),%rcx
cmp    (%rcx),%eax
je     11ec <main+0x9c>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1245 <main+0xf5>
lea    -0xc(%rbp),%rdi
call   1040 <pthread_barrierattr_destroy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1230 <main+0xe0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x14(%rbp),%esi
mov    %rax,%rdx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1245 <main+0xf5>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pthread_barrierattr_init@plt>
test   %eax,%eax
je     1186 <main+0x26>
lea    0xf4c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
jmp    11ab <main+0x4b>
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1070 <pthread_barrierattr_getpshared@plt>
test   %rax,%rax
je     11b1 <main+0x51>
lea    0xefb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0xc(%rsp),%eax
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
jne    11f1 <main+0x91>
lea    0x8(%rsp),%rdi
call   1050 <pthread_barrierattr_destroy@plt>
test   %eax,%eax
je     11fa <main+0x9a>
mov    %eax,%ebx
mov    %eax,%edi
call   1080 <strerror@plt>
lea    0xe22(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%eax
jmp    11ab <main+0x4b>
lea    0xe4f(%rip),%rdi
jmp    117a <main+0x1a>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11ab <main+0x4b>

LLVM IR (-O0):
@.str = [41 x i8] c"Error while initialize attribute object\0A\00"
@.str.1 = [43 x i8] c"Error at pthread_barrierattr_getpshared()\0A\00"
@PTHREAD_PROCESS_PRIVATE = global i32 0
@.str.2 = [86 x i8] c"The process shared attribute was not set to default value of PTHREAD_PROCESS_PRIVATE\0A\00"
@.str.3 = [59 x i8] c"Error at pthread_barrierattr_destroy() return code: %d, %s\00"
@.str.4 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @pthread_barrierattr_init(i32* %3)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %32
10: ; preds = %0
%11 = call i64 @pthread_barrierattr_getpshared(i32* %3, i32* %4)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %32
15: ; preds = %10
%16 = load i32, i32* %4
%17 = load i32, i32* @PTHREAD_PROCESS_PRIVATE
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %32
21: ; preds = %15
%22 = call i32 @pthread_barrierattr_destroy(i32* %3)
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i32, i32* %2
%27 = load i32, i32* %2
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i32 %26, i8* %28)
store i32 2, i32* %1
br label %32
30: ; preds = %21
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %32
32: ; preds = %30, %25, %19, %13, %8
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@PTHREAD_PROCESS_PRIVATE = global i32 0
@.str.3 = [59 x i8] c"Error at pthread_barrierattr_destroy() return code: %d, %s\00"
@str = [12 x i8] c"Test PASSED\00"
@str.5 = [85 x i8] c"The process shared attribute was not set to default value of PTHREAD_PROCESS_PRIVATE\00"
@str.6 = [42 x i8] c"Error at pthread_barrierattr_getpshared()\00"
@str.7 = [40 x i8] c"Error while initialize attribute object\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @pthread_barrierattr_init(i32* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.7, i64 0, i64 0))
br label %28
9: ; preds = %0
%10 = call i64 @pthread_barrierattr_getpshared(i32* %1, i32* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.6, i64 0, i64 0))
br label %28
14: ; preds = %9
%15 = load i32, i32* %2
%16 = load i32, i32* @PTHREAD_PROCESS_PRIVATE
%17 = icmp eq i32 %15, %16
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.5, i64 0, i64 0))
br label %28
20: ; preds = %14
%21 = call i32 @pthread_barrierattr_destroy(i32* %1)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = call i8* @strerror(i32 %21)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* %24)
br label %28
26: ; preds = %20
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %26, %23, %18, %12, %7
%29 = phi i32 [ 2, %7 ], [ 1, %12 ], [ 2, %18 ], [ 2, %23 ], [ 0, %26 ]
ret i32 %29
}