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

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ printf(char *, ...);
int pthread_barrier_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                         int /*<<< orphan*/);
char *strerror(int);
int main(void) {
  int rc;
  pthread_barrier_t barrier;
  rc = pthread_barrier_init(&barrier, NULL, 0);
  if (rc != EINVAL) {
    printf("Test FAILED: pthread_barrier_init() does not return EINVAL when "
           "initializing a barrier with count=0,"
           " return code %d, %s\n",
           rc, strerror(rc));
    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
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <pthread_barrier_init@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%eax
je     1191 <main+0x61>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <strerror@plt>
mov    -0x10(%rbp),%esi
mov    %rax,%rdx
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a6 <main+0x76>
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
lea    0x4(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <pthread_barrier_init@plt>
mov    %eax,%ebp
mov    0x2e84(%rip),%rax
cmp    (%rax),%ebp
jne    116e <main+0x2e>
lea    0xf12(%rip),%rdi
call   1040 <puts@plt>
jmp    118d <main+0x4d>
mov    %ebp,%edi
call   1060 <strerror@plt>
lea    0xe84(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@.str = [121 x i8] c"Test FAILED: pthread_barrier_init() does not return EINVAL when initializing a barrier with count=0, return code %d, %s\0A\00"
@.str.1 = [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_barrier_init(i32* %3, i32* null, i32 0)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @EINVAL
%7 = icmp ne i32 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i32, i32* %2
%10 = load i32, i32* %2
%11 = call i8* @strerror(i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %11)
store i32 1, i32* %1
br label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %15
15: ; preds = %13, %8
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@EINVAL = global i32 0
@.str = [121 x i8] c"Test FAILED: pthread_barrier_init() does not return EINVAL when initializing a barrier with count=0, return code %d, %s\0A\00"
@str = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @pthread_barrier_init(i32* %1, i32* null, i32 0)
%4 = load i32, i32* @EINVAL
%5 = icmp eq i32 %3, %4
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i8* @strerror(i32 %3)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %7)
br label %11
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ 1, %6 ], [ 0, %9 ]
ret i32 %12
}