#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 PTHREAD_BARRIER_SERIAL_THREAD;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int pthread_barrier_wait(int /*<<< orphan*/ *);
scalar_t__ pthread_self();
void *routine(void *barrier) {
  assert(barrier != NULL);
  printf(" thread id: %lld\n", (long long int)pthread_self());
  int r;
  r = pthread_barrier_wait((pthread_barrier_t *)barrier);
  if (r != PTHREAD_BARRIER_SERIAL_THREAD && r != 0) {
    printf("pthread_barrier_wait failed\n");
  }
  return NULL;
}


x86 assembly (clang, -O0):
<routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %rax,%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <pthread_barrier_wait@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%eax
je     11ac <routine+0x6c>
cmpl   $0x0,-0xc(%rbp)
je     11ac <routine+0x6c>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<routine>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1060 <assert@plt>
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0xe90(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <pthread_barrier_wait@plt>
test   %eax,%eax
je     119d <routine+0x4d>
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%eax
je     119d <routine+0x4d>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c" thread id: %lld\0A\00"
@PTHREAD_BARRIER_SERIAL_THREAD = global i32 0
@.str.1 = [29 x i8] c"pthread_barrier_wait failed\0A\00"
define i8* @routine(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = call i64 (...) @pthread_self()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %8)
%10 = load i8*, i8** %2
%11 = bitcast i8* %10 to i32*
%12 = call i32 @pthread_barrier_wait(i32* %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = load i32, i32* @PTHREAD_BARRIER_SERIAL_THREAD
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %1
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %16, %1
ret i8* null
}

LLVM IR (-O2):
@.str = [18 x i8] c" thread id: %lld\0A\00"
@PTHREAD_BARRIER_SERIAL_THREAD = global i32 0
@str = [28 x i8] c"pthread_barrier_wait failed\00"
define noalias i8* @routine(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i64 (...) @pthread_self()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %5)
%7 = bitcast i8* %0 to i32*
%8 = tail call i32 @pthread_barrier_wait(i32* %7)
%9 = load i32, i32* @PTHREAD_BARRIER_SERIAL_THREAD
%10 = icmp ne i32 %8, %9
%11 = icmp ne i32 %8, 0
%12 = and i1 %11, %10
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
ret i8* null
}