#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 /*<<< orphan*/ assert(int);
int pthread_barrier_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_barrier_init(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *, unsigned int);
int pthread_barrier_reset(pthread_barrier_t *barrier,
                          pthread_barrierattr_t *attr, unsigned int count) {
  int result_code = -1;
  result_code = pthread_barrier_destroy(barrier);
  assert(result_code == 0);
  pthread_barrier_init(barrier, attr, count);
  assert(result_code == 0);
  return result_code;
}


x86 assembly (clang, -O0):
<pthread_barrier_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <pthread_barrier_destroy@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <pthread_barrier_init@plt>
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pthread_barrier_reset>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
call   1040 <pthread_barrier_destroy@plt>
mov    %eax,%r12d
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %ebx,%edi
call   1050 <assert@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <pthread_barrier_init@plt>
mov    %ebx,%edi
call   1050 <assert@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pthread_barrier_reset(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 -1, i32* %7
%8 = load i32*, i32** %4
%9 = call i32 @pthread_barrier_destroy(i32* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32*, i32** %4
%15 = load i32*, i32** %5
%16 = load i32, i32* %6
%17 = call i32 @pthread_barrier_init(i32* %14, i32* %15, i32 %16)
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %7
ret i32 %22
}

LLVM IR (-O2):
define i32 @pthread_barrier_reset(i32* %0, i32* %1, i32 %2) {
%4 = tail call i32 @pthread_barrier_destroy(i32* %0)
%5 = icmp eq i32 %4, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @pthread_barrier_init(i32* %0, i32* %1, i32 %2)
%9 = tail call i32 @assert(i32 %6)
ret i32 %4
}