#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;
typedef int /*<<< orphan*/ pthread_barrier_t;

/* Variables and functions */
int PTHREAD_BARRIER_SERIAL_THREAD;
int /*<<< orphan*/ printf(char *, ...);
int pthread_barrier_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_barrier_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int);
int pthread_barrier_wait(int /*<<< orphan*/ *);
int pthread_barrierattr_destroy(int /*<<< orphan*/ *);
int pthread_barrierattr_init(int /*<<< orphan*/ *);
char *strerror(int);
int main(void) {
  int rc;
  pthread_barrierattr_t ba;
  pthread_barrier_t barriers[100];
  int cnt;
  rc = pthread_barrierattr_init(&ba);
  if (rc != 0) {
    printf("Test FAILED: Error while initialize attribute object\n");
    return 1;
  }
  for (cnt = 0; cnt < 100; cnt++) {
    if (pthread_barrier_init(&barriers[cnt], &ba, 1) != 0) {
      printf("Error at %dth initialization\n", cnt);
      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;
  }
  for (cnt = 0; cnt < 100; cnt++) {
    rc = pthread_barrier_wait(&barriers[cnt]);
    if (rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) {
      printf("Test Fail: Error at %dth wait, %s\n", cnt, strerror(rc));
      return 1;
    }
  }
  for (cnt = 0; cnt < 100; cnt++) {
    rc = pthread_barrier_destroy(&barriers[cnt]);
    if (rc != 0) {
      printf("Error at %dth destruction, %s\n", cnt, strerror(rc));
      return 2;
    }
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1080 <pthread_barrierattr_init@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11b2 <main+0x42>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bc <main+0x24c>
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x64,-0x1a4(%rbp)
jge    122f <main+0xbf>
movslq -0x1a4(%rbp),%rax
lea    -0x1a0(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1030 <pthread_barrier_init@plt>
cmp    $0x0,%rax
je     1216 <main+0xa6>
mov    -0x1a4(%rbp),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    13bc <main+0x24c>
jmp    121b <main+0xab>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    11bc <main+0x4c>
lea    -0xc(%rbp),%rdi
call   1070 <pthread_barrierattr_destroy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1279 <main+0x109>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1a8(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x1a8(%rbp),%esi
mov    %rax,%rdx
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    13bc <main+0x24c>
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x64,-0x1a4(%rbp)
jge    1319 <main+0x1a9>
movslq -0x1a4(%rbp),%rax
lea    -0x1a0(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
call   1040 <pthread_barrier_wait@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1300 <main+0x190>
mov    -0x8(%rbp),%eax
mov    0x2d27(%rip),%rcx
cmp    (%rcx),%eax
je     1300 <main+0x190>
mov    -0x1a4(%rbp),%eax
mov    %eax,-0x1ac(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x1ac(%rbp),%esi
mov    %rax,%rdx
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bc <main+0x24c>
jmp    1305 <main+0x195>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1283 <main+0x113>
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x64,-0x1a4(%rbp)
jge    13a7 <main+0x237>
movslq -0x1a4(%rbp),%rax
lea    -0x1a0(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
call   1060 <pthread_barrier_destroy@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     138e <main+0x21e>
mov    -0x1a4(%rbp),%eax
mov    %eax,-0x1b0(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x1b0(%rbp),%esi
mov    %rax,%rdx
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    13bc <main+0x24c>
jmp    1393 <main+0x223>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1323 <main+0x1b3>
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xc(%rsp),%rdi
call   1090 <pthread_barrierattr_init@plt>
test   %eax,%eax
je     11ad <main+0x2d>
lea    0xf06(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1225 <main+0xa5>
lea    0x10(%rsp),%rbx
xor    %r14d,%r14d
lea    0xc(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <pthread_barrier_init@plt>
test   %rax,%rax
jne    120f <main+0x8f>
add    $0x1,%r14
add    $0x4,%rbx
cmp    $0x64,%r14
jne    11c0 <main+0x40>
lea    0xc(%rsp),%rdi
call   1080 <pthread_barrierattr_destroy@plt>
test   %eax,%eax
je     1232 <main+0xb2>
mov    %eax,%ebx
mov    %eax,%edi
call   10a0 <strerror@plt>
lea    0xe1d(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1220 <main+0xa0>
lea    0xdea(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x2,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0x10(%rsp),%rbx
xor    %r14d,%r14d
mov    0x2da7(%rip),%r15
jmp    125e <main+0xde>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14
add    $0x4,%rbx
cmp    $0x64,%r14
je     1291 <main+0x111>
mov    %rbx,%rdi
call   1050 <pthread_barrier_wait@plt>
test   %eax,%eax
je     1250 <main+0xd0>
cmp    (%r15),%eax
je     1250 <main+0xd0>
mov    %eax,%edi
call   10a0 <strerror@plt>
lea    0xddc(%rip),%rdi
mov    %r14d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
jmp    1225 <main+0xa5>
lea    0x10(%rsp),%rbx
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <pthread_barrier_destroy@plt>
test   %eax,%eax
jne    12cd <main+0x14d>
add    $0x1,%r14
add    $0x4,%rbx
cmp    $0x64,%r14
jne    12a0 <main+0x120>
lea    0xdda(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    1225 <main+0xa5>
mov    %eax,%edi
call   10a0 <strerror@plt>
lea    0xda1(%rip),%rdi
mov    %r14d,%esi
jmp    1203 <main+0x83>

LLVM IR (-O0):
@.str = [54 x i8] c"Test FAILED: Error while initialize attribute object\0A\00"
@.str.1 = [30 x i8] c"Error at %dth initialization\0A\00"
@.str.2 = [59 x i8] c"Error at pthread_barrierattr_destroy() return code: %d, %s\00"
@PTHREAD_BARRIER_SERIAL_THREAD = global i32 0
@.str.3 = [35 x i8] c"Test Fail: Error at %dth wait, %s\0A\00"
@.str.4 = [31 x i8] c"Error at %dth destruction, %s\0A\00"
@.str.5 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i32]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @pthread_barrierattr_init(i32* %3)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = 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 %83
11: ; preds = %0
store i32 0, i32* %5
br label %12
12: ; preds = %25, %11
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 100
br i1 %14, label %15, label %28
15: ; preds = %12
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %17
%19 = call i64 @pthread_barrier_init(i32* %18, i32* %3, i32 1)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %22)
store i32 2, i32* %1
br label %83
24: ; preds = %15
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %12
28: ; preds = %12
%29 = call i32 @pthread_barrierattr_destroy(i32* %3)
store i32 %29, i32* %2
%30 = load i32, i32* %2
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* %2
%34 = load i32, i32* %2
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %33, i8* %35)
store i32 2, i32* %1
br label %83
37: ; preds = %28
store i32 0, i32* %5
br label %38
38: ; preds = %58, %37
%39 = load i32, i32* %5
%40 = icmp slt i32 %39, 100
br i1 %40, label %41, label %61
41: ; preds = %38
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %43
%45 = call i32 @pthread_barrier_wait(i32* %44)
store i32 %45, i32* %2
%46 = load i32, i32* %2
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %57
48: ; preds = %41
%49 = load i32, i32* %2
%50 = load i32, i32* @PTHREAD_BARRIER_SERIAL_THREAD
%51 = icmp ne i32 %49, %50
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = load i32, i32* %5
%54 = load i32, i32* %2
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %53, i8* %55)
store i32 1, i32* %1
br label %83
57: ; preds = %48, %41
br label %58
58: ; preds = %57
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
br label %38
61: ; preds = %38
store i32 0, i32* %5
br label %62
62: ; preds = %78, %61
%63 = load i32, i32* %5
%64 = icmp slt i32 %63, 100
br i1 %64, label %65, label %81
65: ; preds = %62
%66 = load i32, i32* %5
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %67
%69 = call i32 @pthread_barrier_destroy(i32* %68)
store i32 %69, i32* %2
%70 = load i32, i32* %2
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %65
%73 = load i32, i32* %5
%74 = load i32, i32* %2
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %73, i8* %75)
store i32 2, i32* %1
br label %83
77: ; preds = %65
br label %78
78: ; preds = %77
%79 = load i32, i32* %5
%80 = add nsw i32 %79, 1
store i32 %80, i32* %5
br label %62
81: ; preds = %62
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %83
83: ; preds = %81, %72, %52, %32, %21, %9
%84 = load i32, i32* %1
ret i32 %84
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"Error at %dth initialization\0A\00"
@.str.2 = [59 x i8] c"Error at pthread_barrierattr_destroy() return code: %d, %s\00"
@PTHREAD_BARRIER_SERIAL_THREAD = global i32 0
@.str.3 = [35 x i8] c"Test Fail: Error at %dth wait, %s\0A\00"
@.str.4 = [31 x i8] c"Error at %dth destruction, %s\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.6 = [53 x i8] c"Test FAILED: Error while initialize attribute object\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [100 x 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.6, i64 0, i64 0))
br label %55
9: ; preds = %0, %17
%10 = phi i64 [ %18, %17 ], [ 0, %0 ]
%11 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %10
%12 = call i64 @pthread_barrier_init(i32* %11, i32* %1, i32 1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = trunc i64 %10 to i32
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %55
17: ; preds = %9
%18 = add nuw nsw i64 %10, 1
%19 = icmp eq i64 %18, 100
br i1 %19, label %20, label %9
20: ; preds = %17
%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.2, i64 0, i64 0), i32 %21, i8* %24)
br label %55
26: ; preds = %20, %38
%27 = phi i64 [ %39, %38 ], [ 0, %20 ]
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %27
%29 = call i32 @pthread_barrier_wait(i32* %28)
%30 = icmp eq i32 %29, 0
%31 = load i32, i32* @PTHREAD_BARRIER_SERIAL_THREAD
%32 = icmp eq i32 %29, %31
%33 = select i1 %30, i1 true, i1 %32
br i1 %33, label %38, label %34
34: ; preds = %26
%35 = trunc i64 %27 to i32
%36 = call i8* @strerror(i32 %29)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %35, i8* %36)
br label %55
38: ; preds = %26
%39 = add nuw nsw i64 %27, 1
%40 = icmp eq i64 %39, 100
br i1 %40, label %41, label %26
41: ; preds = %38, %50
%42 = phi i64 [ %51, %50 ], [ 0, %38 ]
%43 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %42
%44 = call i32 @pthread_barrier_destroy(i32* %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %41
%47 = trunc i64 %42 to i32
%48 = call i8* @strerror(i32 %44)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %47, i8* %48)
br label %55
50: ; preds = %41
%51 = add nuw nsw i64 %42, 1
%52 = icmp eq i64 %51, 100
br i1 %52, label %53, label %41
53: ; preds = %50
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %55
55: ; preds = %53, %46, %34, %23, %14, %7
%56 = phi i32 [ 1, %7 ], [ 2, %14 ], [ 2, %23 ], [ 1, %34 ], [ 2, %46 ], [ 0, %53 ]
ret i32 %56
}