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

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_RWLOCK_PREFER_READER_NP;
int /*<<< orphan*/ PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP;
int /*<<< orphan*/ PTHREAD_RWLOCK_PREFER_WRITER_NP;
scalar_t__ pthread_rwlockattr_setkind_np(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/);
scalar_t__ rwlock_reinit(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int test_setkind_np(pthread_rwlock_t *rwlock, pthread_rwlockattr_t *attr) {
  int result = 1;
  if (pthread_rwlockattr_setkind_np(attr, PTHREAD_RWLOCK_PREFER_READER_NP) ==
          0 &&
      rwlock_reinit(rwlock, attr) == 0 &&
      pthread_rwlockattr_setkind_np(attr, PTHREAD_RWLOCK_PREFER_WRITER_NP) ==
          0 &&
      rwlock_reinit(rwlock, attr) == 0 &&
      pthread_rwlockattr_setkind_np(
          attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) == 0 &&
      rwlock_reinit(rwlock, attr) == 0)
    result = 0;
  return result;
}


x86 assembly (clang, -O0):
<test_setkind_np>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
call   1040 <pthread_rwlockattr_setkind_np@plt>
cmp    $0x0,%rax
jne    11d7 <test_setkind_np+0xb7>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <rwlock_reinit@plt>
cmp    $0x0,%rax
jne    11d7 <test_setkind_np+0xb7>
mov    -0x10(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1040 <pthread_rwlockattr_setkind_np@plt>
cmp    $0x0,%rax
jne    11d7 <test_setkind_np+0xb7>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <rwlock_reinit@plt>
cmp    $0x0,%rax
jne    11d7 <test_setkind_np+0xb7>
mov    -0x10(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1040 <pthread_rwlockattr_setkind_np@plt>
cmp    $0x0,%rax
jne    11d7 <test_setkind_np+0xb7>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <rwlock_reinit@plt>
cmp    $0x0,%rax
jne    11d7 <test_setkind_np+0xb7>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_setkind_np>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2eb7(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <pthread_rwlockattr_setkind_np@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11a5 <test_setkind_np+0x85>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <rwlock_reinit@plt>
test   %rax,%rax
jne    11a5 <test_setkind_np+0x85>
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <pthread_rwlockattr_setkind_np@plt>
test   %rax,%rax
jne    11a5 <test_setkind_np+0x85>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <rwlock_reinit@plt>
test   %rax,%rax
jne    11a5 <test_setkind_np+0x85>
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <pthread_rwlockattr_setkind_np@plt>
test   %rax,%rax
jne    11a5 <test_setkind_np+0x85>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <rwlock_reinit@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PTHREAD_RWLOCK_PREFER_READER_NP = global i32 0
@PTHREAD_RWLOCK_PREFER_WRITER_NP = global i32 0
@PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP = global i32 0
define i32 @test_setkind_np(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 1, i32* %5
%6 = load i32*, i32** %4
%7 = load i32, i32* @PTHREAD_RWLOCK_PREFER_READER_NP
%8 = call i64 @pthread_rwlockattr_setkind_np(i32* %6, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %36
10: ; preds = %2
%11 = load i32*, i32** %3
%12 = load i32*, i32** %4
%13 = call i64 @rwlock_reinit(i32* %11, i32* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %10
%16 = load i32*, i32** %4
%17 = load i32, i32* @PTHREAD_RWLOCK_PREFER_WRITER_NP
%18 = call i64 @pthread_rwlockattr_setkind_np(i32* %16, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %15
%21 = load i32*, i32** %3
%22 = load i32*, i32** %4
%23 = call i64 @rwlock_reinit(i32* %21, i32* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %20
%26 = load i32*, i32** %4
%27 = load i32, i32* @PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
%28 = call i64 @pthread_rwlockattr_setkind_np(i32* %26, i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i32*, i32** %3
%32 = load i32*, i32** %4
%33 = call i64 @rwlock_reinit(i32* %31, i32* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 0, i32* %5
br label %36
36: ; preds = %35, %30, %25, %20, %15, %10, %2
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@PTHREAD_RWLOCK_PREFER_READER_NP = global i32 0
@PTHREAD_RWLOCK_PREFER_WRITER_NP = global i32 0
@PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP = global i32 0
define i32 @test_setkind_np(i32* %0, i32* %1) {
%3 = load i32, i32* @PTHREAD_RWLOCK_PREFER_READER_NP
%4 = tail call i64 @pthread_rwlockattr_setkind_np(i32* %1, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %24
6: ; preds = %2
%7 = tail call i64 @rwlock_reinit(i32* %0, i32* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i32, i32* @PTHREAD_RWLOCK_PREFER_WRITER_NP
%11 = tail call i64 @pthread_rwlockattr_setkind_np(i32* %1, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = tail call i64 @rwlock_reinit(i32* %0, i32* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i32, i32* @PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
%18 = tail call i64 @pthread_rwlockattr_setkind_np(i32* %1, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = tail call i64 @rwlock_reinit(i32* %0, i32* %1)
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %20, %16, %13, %9, %6, %2
%25 = phi i32 [ 1, %16 ], [ 1, %13 ], [ 1, %9 ], [ 1, %6 ], [ 1, %2 ], [ %23, %20 ]
ret i32 %25
}