#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 /*<<< orphan*/ printf(char *, ...);
int pthread_barrierattr_destroy(int /*<<< orphan*/ *);
int pthread_barrierattr_init(int /*<<< orphan*/ *);
char *strerror(int);
int main(void) {
  int rc;
  pthread_barrierattr_t ba;
  if (pthread_barrierattr_init(&ba) != 0) {
    printf("Error at pthread_barrierattr_init()\n");
    return 2;
  }
  rc = pthread_barrierattr_destroy(&ba);
  if (rc != 0) {
    printf("Test FAILED: Error at pthread_barrierattr_destroy() "
           "return code: %d, %s",
           rc, strerror(rc));
    return 1;
  }
  rc = pthread_barrierattr_init(&ba);
  if (rc != 0) {
    printf(
        "Test FAILED: Error while re-initializing barrier attribute object\n");
    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    -0xc(%rbp),%rdi
call   1050 <pthread_barrierattr_init@plt>
cmp    $0x0,%eax
je     117b <main+0x3b>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1204 <main+0xc4>
lea    -0xc(%rbp),%rdi
call   1040 <pthread_barrierattr_destroy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11bf <main+0x7f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%esi
mov    %rax,%rdx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1204 <main+0xc4>
lea    -0xc(%rbp),%rdi
call   1050 <pthread_barrierattr_init@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11ef <main+0xaf>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1204 <main+0xc4>
lea    0xeba(%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   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
call   1060 <pthread_barrierattr_init@plt>
test   %eax,%eax
je     1176 <main+0x26>
lea    0xf2c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
jmp    11d6 <main+0x86>
lea    0xc(%rsp),%rdi
call   1050 <pthread_barrierattr_destroy@plt>
test   %eax,%eax
je     11a7 <main+0x57>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <strerror@plt>
lea    0xe6c(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    11d6 <main+0x86>
lea    0xc(%rsp),%rdi
call   1060 <pthread_barrierattr_init@plt>
test   %eax,%eax
je     11c8 <main+0x78>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    11d6 <main+0x86>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Error at pthread_barrierattr_init()\0A\00"
@.str.1 = [72 x i8] c"Test FAILED: Error at pthread_barrierattr_destroy() return code: %d, %s\00"
@.str.2 = [67 x i8] c"Test FAILED: Error while re-initializing barrier attribute object\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 i32 @pthread_barrierattr_init(i32* %3)
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %25
8: ; preds = %0
%9 = call i32 @pthread_barrierattr_destroy(i32* %3)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* %2
%14 = load i32, i32* %2
%15 = call i8* @strerror(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %15)
store i32 1, i32* %1
br label %25
17: ; preds = %8
%18 = call i32 @pthread_barrierattr_init(i32* %3)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %25
23: ; preds = %17
%24 = 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 %25
25: ; preds = %23, %21, %12, %6
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str.1 = [72 x i8] c"Test FAILED: Error at pthread_barrierattr_destroy() return code: %d, %s\00"
@str = [12 x i8] c"Test PASSED\00"
@str.4 = [66 x i8] c"Test FAILED: Error while re-initializing barrier attribute object\00"
@str.5 = [36 x i8] c"Error at pthread_barrierattr_init()\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @pthread_barrierattr_init(i32* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0))
br label %20
7: ; preds = %0
%8 = call i32 @pthread_barrierattr_destroy(i32* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = call i8* @strerror(i32 %8)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i32 %8, i8* %11)
br label %20
13: ; preds = %7
%14 = call i32 @pthread_barrierattr_init(i32* %1)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.4, i64 0, i64 0))
br label %20
18: ; preds = %13
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %16, %10, %5
%21 = phi i32 [ 2, %5 ], [ 1, %10 ], [ 1, %16 ], [ 0, %18 ]
ret i32 %21
}