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

/* Variables and functions */
int EINTR;
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ exit(int);
scalar_t__ pthread_barrier_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int);
int pthread_barrier_wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ setup_eintr(int /*<<< orphan*/, int /*<<< orphan*/ *);
int do_test(void) {
  pthread_t self = pthread_self();
  setup_eintr(SIGUSR1, &self);
  pthread_barrier_t b;
  if (pthread_barrier_init(&b, NULL, 2) != 0) {
    puts("barrier_init failed");
    exit(1);
  }
  int e = pthread_barrier_wait(&b);
  if (e == EINTR)
    puts("pthread_join returned with EINTR");
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
call   1080 <setup_eintr@plt>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x2,%edx
call   1030 <pthread_barrier_init@plt>
cmp    $0x0,%rax
je     11b6 <do_test+0x56>
lea    0xe59(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x8(%rbp),%rdi
call   1050 <pthread_barrier_wait@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%eax
jne    11e0 <do_test+0x80>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rax
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,0x4(%rsp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rsi
call   1080 <setup_eintr@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1030 <pthread_barrier_init@plt>
test   %rax,%rax
jne    11b6 <do_test+0x56>
mov    %rsp,%rdi
call   1050 <pthread_barrier_wait@plt>
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%eax
jne    11b2 <do_test+0x52>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe43(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SIGUSR1 = global i32 0
@.str = [20 x i8] c"barrier_init failed\00"
@EINTR = global i32 0
@.str.1 = [33 x i8] c"pthread_join returned with EINTR\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @pthread_self()
store i32 %4, i32* %1
%5 = load i32, i32* @SIGUSR1
%6 = call i32 @setup_eintr(i32 %5, i32* %1)
%7 = call i64 @pthread_barrier_init(i32* %2, i32* null, i32 2)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i32 @pthread_barrier_wait(i32* %2)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = load i32, i32* @EINTR
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
ret i32 0
}

LLVM IR (-O2):
@SIGUSR1 = global i32 0
@.str = [20 x i8] c"barrier_init failed\00"
@EINTR = global i32 0
@.str.1 = [33 x i8] c"pthread_join returned with EINTR\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 (...) @pthread_self()
store i32 %4, i32* %1
%5 = load i32, i32* @SIGUSR1
%6 = call i32 @setup_eintr(i32 %5, i32* %1)
%7 = bitcast i32* %2 to i8*
%8 = call i64 @pthread_barrier_init(i32* %2, i32* null, i32 2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32 @pthread_barrier_wait(i32* %2)
%15 = load i32, i32* @EINTR
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
ret i32 0
}