#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("Test FAILED: Error while initialize attribute object\n");
    return 1;
  }
  if (pthread_barrierattr_getpshared(&ba, &pshared) != 0) {
    printf("Error at pthread_barrierattr_getpshared()\n");
    return 2;
  }
  if (pshared != PTHREAD_PROCESS_PRIVATE) {
    printf("Test FAILED: The process shared attribute was not set to "
           "default value\n");
    return 1;
  }
  rc = pthread_barrierattr_destroy(&ba);
  if (rc != 0) {
    printf("Error at pthread_barrierattr_destroy() "
           "return code: %d, %s\n",
           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   $0x1,-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    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1245 <main+0xf5>
mov    -0x10(%rbp),%eax
mov    0x2e16(%rip),%rcx
cmp    (%rcx),%eax
je     11ec <main+0x9c>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-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    0xe8c(%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    0xf3f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%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    0xeee(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0xc(%rsp),%eax
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
jne    11ec <main+0x8c>
lea    0x8(%rsp),%rdi
call   1050 <pthread_barrierattr_destroy@plt>
test   %eax,%eax
je     11f5 <main+0x95>
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>
jmp    11a6 <main+0x46>
lea    0xe55(%rip),%rdi
jmp    117a <main+0x1a>
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11ab <main+0x4b>

LLVM IR (-O0):
@.str = [54 x i8] c"Test FAILED: 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 = [72 x i8] c"Test FAILED: The process shared attribute was not set to default value\0A\00"
@.str.3 = [60 x i8] c"Error at pthread_barrierattr_destroy() return code: %d, %s\0A\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 ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
store i32 1, 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 2, 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 ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0))
store i32 1, 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 ([60 x i8], [60 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 = [60 x i8] c"Error at pthread_barrierattr_destroy() return code: %d, %s\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.5 = [71 x i8] c"Test FAILED: The process shared attribute was not set to default value\00"
@str.6 = [42 x i8] c"Error at pthread_barrierattr_getpshared()\00"
@str.7 = [53 x i8] c"Test FAILED: 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 ([53 x i8], [53 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 ([71 x i8], [71 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 ([60 x i8], [60 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 [ 1, %7 ], [ 2, %12 ], [ 1, %18 ], [ 2, %23 ], [ 0, %26 ]
ret i32 %29
}