#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 EBUSY;
int /*<<< orphan*/ PTHREAD_RWLOCK_PREFER_READER_NP;
scalar_t__ pthread_rwlock_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlock_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int pthread_rwlock_tryrdlock(int /*<<< orphan*/ *);
int pthread_rwlock_trywrlock(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlock_unlock(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlock_wrlock(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlockattr_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlockattr_init(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlockattr_setkind_np(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int do_test(void) {
  pthread_rwlock_t r;
  pthread_rwlockattr_t at;
  int e;
  if (pthread_rwlockattr_init(&at) != 0) {
    puts("rwlockattr_init failed");
    return 1;
  }
  puts("rwlockattr_init succeeded");
  if (pthread_rwlockattr_setkind_np(&at, PTHREAD_RWLOCK_PREFER_READER_NP) !=
      0) {
    puts("rwlockattr_setkind failed");
    return 1;
  }
  puts("rwlockattr_setkind succeeded");
  if (pthread_rwlock_init(&r, &at) != 0) {
    puts("rwlock_init failed");
    return 1;
  }
  puts("rwlock_init succeeded");
  if (pthread_rwlockattr_destroy(&at) != 0) {
    puts("rwlockattr_destroy failed");
    return 1;
  }
  puts("rwlockattr_destroy succeeded");
  if (pthread_rwlock_wrlock(&r) != 0) {
    puts("1st rwlock_wrlock failed");
    return 1;
  }
  puts("1st rwlock_wrlock succeeded");
  e = pthread_rwlock_tryrdlock(&r);
  if (e == 0) {
    puts("rwlock_tryrdlock on rwlock with writer succeeded");
    return 1;
  }
  if (e != EBUSY) {
    puts("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
    return 1;
  }
  puts("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
  e = pthread_rwlock_trywrlock(&r);
  if (e == 0) {
    puts("rwlock_trywrlock on rwlock with writer succeeded");
    return 1;
  }
  if (e != EBUSY) {
    puts("rwlock_trywrlock on rwlock with writer return value != EBUSY");
    return 1;
  }
  puts("rwlock_trywrlock on rwlock with writer failed with EBUSY");
  if (pthread_rwlock_unlock(&r) != 0) {
    puts("1st rwlock_unlock failed");
    return 1;
  }
  puts("1st rwlock_unlock succeeded");
  if (pthread_rwlock_tryrdlock(&r) != 0) {
    puts("rwlock_tryrdlock on unlocked rwlock failed");
    return 1;
  }
  puts("rwlock_tryrdlock on unlocked rwlock succeeded");
  e = pthread_rwlock_trywrlock(&r);
  if (e == 0) {
    puts("rwlock_trywrlock on rwlock with reader succeeded");
    return 1;
  }
  if (e != EBUSY) {
    puts("rwlock_trywrlock on rwlock with reader return value != EBUSY");
    return 1;
  }
  puts("rwlock_trywrlock on rwlock with reader failed with EBUSY");
  if (pthread_rwlock_unlock(&r) != 0) {
    puts("2nd rwlock_unlock failed");
    return 1;
  }
  puts("2nd rwlock_unlock succeeded");
  if (pthread_rwlock_trywrlock(&r) != 0) {
    puts("rwlock_trywrlock on unlocked rwlock failed");
    return 1;
  }
  puts("rwlock_trywrlock on unlocked rwlock succeeded");
  e = pthread_rwlock_tryrdlock(&r);
  if (e == 0) {
    puts("rwlock_tryrdlock on rwlock with writer succeeded");
    return 1;
  }
  if (e != EBUSY) {
    puts("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
    return 1;
  }
  puts("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
  if (pthread_rwlock_unlock(&r) != 0) {
    puts("3rd rwlock_unlock failed");
    return 1;
  }
  puts("3rd rwlock_unlock succeeded");
  if (pthread_rwlock_destroy(&r) != 0) {
    puts("rwlock_destroy failed");
    return 1;
  }
  puts("rwlock_destroy succeeded");
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0xc(%rbp),%rdi
call   1080 <pthread_rwlockattr_init@plt>
cmp    $0x0,%rax
je     11d3 <do_test+0x33>
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1070 <pthread_rwlockattr_setkind_np@plt>
cmp    $0x0,%rax
je     1213 <do_test+0x73>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   10a0 <pthread_rwlock_init@plt>
cmp    $0x0,%rax
je     124e <do_test+0xae>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
lea    -0xc(%rbp),%rdi
call   10c0 <pthread_rwlockattr_destroy@plt>
cmp    $0x0,%rax
je     1285 <do_test+0xe5>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1040 <pthread_rwlock_wrlock@plt>
cmp    $0x0,%rax
je     12bc <do_test+0x11c>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xe1e(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    12f6 <do_test+0x156>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
mov    -0x10(%rbp),%eax
mov    0x2cd8(%rip),%rcx
cmp    (%rcx),%eax
je     1320 <do_test+0x180>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1090 <pthread_rwlock_trywrlock@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    135a <do_test+0x1ba>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
mov    -0x10(%rbp),%eax
mov    0x2c74(%rip),%rcx
cmp    (%rcx),%eax
je     1384 <do_test+0x1e4>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   10b0 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
je     13bb <do_test+0x21b>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
cmp    $0x0,%eax
je     13f1 <do_test+0x251>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1090 <pthread_rwlock_trywrlock@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    142b <do_test+0x28b>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
mov    -0x10(%rbp),%eax
mov    0x2ba3(%rip),%rcx
cmp    (%rcx),%eax
je     1455 <do_test+0x2b5>
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   10b0 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
je     148c <do_test+0x2ec>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xf06(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1090 <pthread_rwlock_trywrlock@plt>
cmp    $0x0,%eax
je     14c2 <do_test+0x322>
lea    0xf04(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xf17(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    14fc <do_test+0x35c>
lea    0xc12(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
mov    -0x10(%rbp),%eax
mov    0x2ad2(%rip),%rcx
cmp    (%rcx),%eax
je     1526 <do_test+0x386>
lea    0xc19(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xc3e(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   10b0 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
je     155d <do_test+0x3bd>
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1050 <pthread_rwlock_destroy@plt>
cmp    $0x0,%rax
je     1594 <do_test+0x3f4>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a7 <do_test+0x407>
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rdi
call   1080 <pthread_rwlockattr_init@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11c7 <do_test+0x27>
lea    0xe3e(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1070 <pthread_rwlockattr_setkind_np@plt>
test   %rax,%rax
je     11f4 <do_test+0x54>
lea    0xe3f(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
lea    0x4(%rsp),%rsi
call   10a0 <pthread_rwlock_init@plt>
test   %rax,%rax
je     121b <do_test+0x7b>
lea    0xe4f(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   10c0 <pthread_rwlockattr_destroy@plt>
test   %rax,%rax
je     123f <do_test+0x9f>
lea    0xe54(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1040 <pthread_rwlock_wrlock@plt>
test   %rax,%rax
je     1274 <do_test+0xd4>
lea    0xe69(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
lea    0xe6e(%rip),%rbx
test   %eax,%eax
je     125f <do_test+0xbf>
mov    0x2d3e(%rip),%r15
lea    0xe8d(%rip),%r14
cmp    (%r15),%eax
jne    13ec <do_test+0x24c>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1090 <pthread_rwlock_trywrlock@plt>
test   %eax,%eax
je     12ec <do_test+0x14c>
cmp    (%r15),%eax
jne    12f8 <do_test+0x158>
lea    0xf44(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   10b0 <pthread_rwlock_unlock@plt>
test   %rax,%rax
je     1304 <do_test+0x164>
lea    0xf64(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0xeb1(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0xed6(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0xf59(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
test   %eax,%eax
je     1328 <do_test+0x188>
lea    0xf5d(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0xf7c(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1090 <pthread_rwlock_trywrlock@plt>
test   %eax,%eax
je     136a <do_test+0x1ca>
cmp    (%r15),%eax
jne    1376 <do_test+0x1d6>
lea    0xffb(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   10b0 <pthread_rwlock_unlock@plt>
test   %rax,%rax
je     1382 <do_test+0x1e2>
lea    0x101b(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0xf68(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0xf8d(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0x1010(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1090 <pthread_rwlock_trywrlock@plt>
test   %eax,%eax
je     13a6 <do_test+0x206>
lea    0x1014(%rip),%rbx
jmp    125f <do_test+0xbf>
lea    0x1033(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
test   %eax,%eax
je     125f <do_test+0xbf>
cmp    (%r15),%eax
jne    13ec <do_test+0x24c>
lea    0xd9d(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   10b0 <pthread_rwlock_unlock@plt>
test   %rax,%rax
je     13f4 <do_test+0x254>
lea    0x1027(%rip),%rbx
jmp    125f <do_test+0xbf>
mov    %r14,%rbx
jmp    125f <do_test+0xbf>
lea    0x102c(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1050 <pthread_rwlock_destroy@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
lea    0x1041(%rip),%rax
lea    0x1024(%rip),%rbx
cmove  %rax,%rbx
jmp    125f <do_test+0xbf>

LLVM IR (-O0):
@.str = [23 x i8] c"rwlockattr_init failed\00"
@.str.1 = [26 x i8] c"rwlockattr_init succeeded\00"
@PTHREAD_RWLOCK_PREFER_READER_NP = global i32 0
@.str.2 = [26 x i8] c"rwlockattr_setkind failed\00"
@.str.3 = [29 x i8] c"rwlockattr_setkind succeeded\00"
@.str.4 = [19 x i8] c"rwlock_init failed\00"
@.str.5 = [22 x i8] c"rwlock_init succeeded\00"
@.str.6 = [26 x i8] c"rwlockattr_destroy failed\00"
@.str.7 = [29 x i8] c"rwlockattr_destroy succeeded\00"
@.str.8 = [25 x i8] c"1st rwlock_wrlock failed\00"
@.str.9 = [28 x i8] c"1st rwlock_wrlock succeeded\00"
@.str.10 = [49 x i8] c"rwlock_tryrdlock on rwlock with writer succeeded\00"
@EBUSY = global i32 0
@.str.11 = [61 x i8] c"rwlock_tryrdlock on rwlock with writer return value != EBUSY\00"
@.str.12 = [57 x i8] c"rwlock_tryrdlock on rwlock with writer failed with EBUSY\00"
@.str.13 = [49 x i8] c"rwlock_trywrlock on rwlock with writer succeeded\00"
@.str.14 = [61 x i8] c"rwlock_trywrlock on rwlock with writer return value != EBUSY\00"
@.str.15 = [57 x i8] c"rwlock_trywrlock on rwlock with writer failed with EBUSY\00"
@.str.16 = [25 x i8] c"1st rwlock_unlock failed\00"
@.str.17 = [28 x i8] c"1st rwlock_unlock succeeded\00"
@.str.18 = [43 x i8] c"rwlock_tryrdlock on unlocked rwlock failed\00"
@.str.19 = [46 x i8] c"rwlock_tryrdlock on unlocked rwlock succeeded\00"
@.str.20 = [49 x i8] c"rwlock_trywrlock on rwlock with reader succeeded\00"
@.str.21 = [61 x i8] c"rwlock_trywrlock on rwlock with reader return value != EBUSY\00"
@.str.22 = [57 x i8] c"rwlock_trywrlock on rwlock with reader failed with EBUSY\00"
@.str.23 = [25 x i8] c"2nd rwlock_unlock failed\00"
@.str.24 = [28 x i8] c"2nd rwlock_unlock succeeded\00"
@.str.25 = [43 x i8] c"rwlock_trywrlock on unlocked rwlock failed\00"
@.str.26 = [46 x i8] c"rwlock_trywrlock on unlocked rwlock succeeded\00"
@.str.27 = [25 x i8] c"3rd rwlock_unlock failed\00"
@.str.28 = [28 x i8] c"3rd rwlock_unlock succeeded\00"
@.str.29 = [22 x i8] c"rwlock_destroy failed\00"
@.str.30 = [25 x i8] c"rwlock_destroy succeeded\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i64 @pthread_rwlockattr_init(i32* %3)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %124
9: ; preds = %0
%10 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @PTHREAD_RWLOCK_PREFER_READER_NP
%12 = call i64 @pthread_rwlockattr_setkind_np(i32* %3, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %124
16: ; preds = %9
%17 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%18 = call i64 @pthread_rwlock_init(i32* %2, i32* %3)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %124
22: ; preds = %16
%23 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%24 = call i64 @pthread_rwlockattr_destroy(i32* %3)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %124
28: ; preds = %22
%29 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%30 = call i64 @pthread_rwlock_wrlock(i32* %2)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %1
br label %124
34: ; preds = %28
%35 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%36 = call i32 @pthread_rwlock_tryrdlock(i32* %2)
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 @puts(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %1
br label %124
41: ; preds = %34
%42 = load i32, i32* %4
%43 = load i32, i32* @EBUSY
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @puts(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %1
br label %124
47: ; preds = %41
%48 = call i32 @puts(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.12, i64 0, i64 0))
%49 = call i32 @pthread_rwlock_trywrlock(i32* %2)
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 @puts(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.13, i64 0, i64 0))
store i32 1, i32* %1
br label %124
54: ; preds = %47
%55 = load i32, i32* %4
%56 = load i32, i32* @EBUSY
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @puts(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.14, i64 0, i64 0))
store i32 1, i32* %1
br label %124
60: ; preds = %54
%61 = call i32 @puts(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.15, i64 0, i64 0))
%62 = call i64 @pthread_rwlock_unlock(i32* %2)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.16, i64 0, i64 0))
store i32 1, i32* %1
br label %124
66: ; preds = %60
%67 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.17, i64 0, i64 0))
%68 = call i32 @pthread_rwlock_tryrdlock(i32* %2)
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.18, i64 0, i64 0))
store i32 1, i32* %1
br label %124
72: ; preds = %66
%73 = call i32 @puts(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.19, i64 0, i64 0))
%74 = call i32 @pthread_rwlock_trywrlock(i32* %2)
store i32 %74, i32* %4
%75 = load i32, i32* %4
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %72
%78 = call i32 @puts(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.20, i64 0, i64 0))
store i32 1, i32* %1
br label %124
79: ; preds = %72
%80 = load i32, i32* %4
%81 = load i32, i32* @EBUSY
%82 = icmp ne i32 %80, %81
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = call i32 @puts(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.21, i64 0, i64 0))
store i32 1, i32* %1
br label %124
85: ; preds = %79
%86 = call i32 @puts(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.22, i64 0, i64 0))
%87 = call i64 @pthread_rwlock_unlock(i32* %2)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %85
%90 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.23, i64 0, i64 0))
store i32 1, i32* %1
br label %124
91: ; preds = %85
%92 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.24, i64 0, i64 0))
%93 = call i32 @pthread_rwlock_trywrlock(i32* %2)
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %91
%96 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.25, i64 0, i64 0))
store i32 1, i32* %1
br label %124
97: ; preds = %91
%98 = call i32 @puts(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.26, i64 0, i64 0))
%99 = call i32 @pthread_rwlock_tryrdlock(i32* %2)
store i32 %99, i32* %4
%100 = load i32, i32* %4
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %97
%103 = call i32 @puts(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %1
br label %124
104: ; preds = %97
%105 = load i32, i32* %4
%106 = load i32, i32* @EBUSY
%107 = icmp ne i32 %105, %106
br i1 %107, label %108, label %110
108: ; preds = %104
%109 = call i32 @puts(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %1
br label %124
110: ; preds = %104
%111 = call i32 @puts(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.12, i64 0, i64 0))
%112 = call i64 @pthread_rwlock_unlock(i32* %2)
%113 = icmp ne i64 %112, 0
br i1 %113, label %114, label %116
114: ; preds = %110
%115 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.27, i64 0, i64 0))
store i32 1, i32* %1
br label %124
116: ; preds = %110
%117 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.28, i64 0, i64 0))
%118 = call i64 @pthread_rwlock_destroy(i32* %2)
%119 = icmp ne i64 %118, 0
br i1 %119, label %120, label %122
120: ; preds = %116
%121 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.29, i64 0, i64 0))
store i32 1, i32* %1
br label %124
122: ; preds = %116
%123 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.30, i64 0, i64 0))
store i32 0, i32* %1
br label %124
124: ; preds = %122, %120, %114, %108, %102, %95, %89, %83, %77, %70, %64, %58, %52, %45, %39, %32, %26, %20, %14, %7
%125 = load i32, i32* %1
ret i32 %125
}

LLVM IR (-O2):
@.str = [23 x i8] c"rwlockattr_init failed\00"
@.str.1 = [26 x i8] c"rwlockattr_init succeeded\00"
@PTHREAD_RWLOCK_PREFER_READER_NP = global i32 0
@.str.2 = [26 x i8] c"rwlockattr_setkind failed\00"
@.str.3 = [29 x i8] c"rwlockattr_setkind succeeded\00"
@.str.4 = [19 x i8] c"rwlock_init failed\00"
@.str.5 = [22 x i8] c"rwlock_init succeeded\00"
@.str.6 = [26 x i8] c"rwlockattr_destroy failed\00"
@.str.7 = [29 x i8] c"rwlockattr_destroy succeeded\00"
@.str.8 = [25 x i8] c"1st rwlock_wrlock failed\00"
@.str.9 = [28 x i8] c"1st rwlock_wrlock succeeded\00"
@.str.10 = [49 x i8] c"rwlock_tryrdlock on rwlock with writer succeeded\00"
@EBUSY = global i32 0
@.str.11 = [61 x i8] c"rwlock_tryrdlock on rwlock with writer return value != EBUSY\00"
@.str.12 = [57 x i8] c"rwlock_tryrdlock on rwlock with writer failed with EBUSY\00"
@.str.13 = [49 x i8] c"rwlock_trywrlock on rwlock with writer succeeded\00"
@.str.14 = [61 x i8] c"rwlock_trywrlock on rwlock with writer return value != EBUSY\00"
@.str.15 = [57 x i8] c"rwlock_trywrlock on rwlock with writer failed with EBUSY\00"
@.str.16 = [25 x i8] c"1st rwlock_unlock failed\00"
@.str.17 = [28 x i8] c"1st rwlock_unlock succeeded\00"
@.str.18 = [43 x i8] c"rwlock_tryrdlock on unlocked rwlock failed\00"
@.str.19 = [46 x i8] c"rwlock_tryrdlock on unlocked rwlock succeeded\00"
@.str.20 = [49 x i8] c"rwlock_trywrlock on rwlock with reader succeeded\00"
@.str.21 = [61 x i8] c"rwlock_trywrlock on rwlock with reader return value != EBUSY\00"
@.str.22 = [57 x i8] c"rwlock_trywrlock on rwlock with reader failed with EBUSY\00"
@.str.23 = [25 x i8] c"2nd rwlock_unlock failed\00"
@.str.24 = [28 x i8] c"2nd rwlock_unlock succeeded\00"
@.str.25 = [43 x i8] c"rwlock_trywrlock on unlocked rwlock failed\00"
@.str.26 = [46 x i8] c"rwlock_trywrlock on unlocked rwlock succeeded\00"
@.str.27 = [25 x i8] c"3rd rwlock_unlock failed\00"
@.str.28 = [28 x i8] c"3rd rwlock_unlock succeeded\00"
@.str.29 = [22 x i8] c"rwlock_destroy failed\00"
@.str.30 = [25 x i8] c"rwlock_destroy succeeded\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i64 @pthread_rwlockattr_init(i32* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %79
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @PTHREAD_RWLOCK_PREFER_READER_NP
%10 = call i64 @pthread_rwlockattr_setkind_np(i32* %2, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %79
12: ; preds = %7
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%14 = call i64 @pthread_rwlock_init(i32* %1, i32* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %79
16: ; preds = %12
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%18 = call i64 @pthread_rwlockattr_destroy(i32* %2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %79
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%22 = call i64 @pthread_rwlock_wrlock(i32* %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %79
24: ; preds = %20
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%26 = call i32 @pthread_rwlock_tryrdlock(i32* %1)
%27 = icmp eq i32 %26, 0
br i1 %27, label %79, label %28
28: ; preds = %24
%29 = load i32, i32* @EBUSY
%30 = icmp eq i32 %26, %29
br i1 %30, label %31, label %79
31: ; preds = %28
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.12, i64 0, i64 0))
%33 = call i32 @pthread_rwlock_trywrlock(i32* %1)
%34 = icmp eq i32 %33, 0
br i1 %34, label %79, label %35
35: ; preds = %31
%36 = load i32, i32* @EBUSY
%37 = icmp eq i32 %33, %36
br i1 %37, label %38, label %79
38: ; preds = %35
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.15, i64 0, i64 0))
%40 = call i64 @pthread_rwlock_unlock(i32* %1)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %79
42: ; preds = %38
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.17, i64 0, i64 0))
%44 = call i32 @pthread_rwlock_tryrdlock(i32* %1)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %79
46: ; preds = %42
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.19, i64 0, i64 0))
%48 = call i32 @pthread_rwlock_trywrlock(i32* %1)
%49 = icmp eq i32 %48, 0
br i1 %49, label %79, label %50
50: ; preds = %46
%51 = load i32, i32* @EBUSY
%52 = icmp eq i32 %48, %51
br i1 %52, label %53, label %79
53: ; preds = %50
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.22, i64 0, i64 0))
%55 = call i64 @pthread_rwlock_unlock(i32* %1)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %79
57: ; preds = %53
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.24, i64 0, i64 0))
%59 = call i32 @pthread_rwlock_trywrlock(i32* %1)
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %79
61: ; preds = %57
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.26, i64 0, i64 0))
%63 = call i32 @pthread_rwlock_tryrdlock(i32* %1)
%64 = icmp eq i32 %63, 0
br i1 %64, label %79, label %65
65: ; preds = %61
%66 = load i32, i32* @EBUSY
%67 = icmp eq i32 %63, %66
br i1 %67, label %68, label %79
68: ; preds = %65
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.12, i64 0, i64 0))
%70 = call i64 @pthread_rwlock_unlock(i32* %1)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %79
72: ; preds = %68
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.28, i64 0, i64 0))
%74 = call i64 @pthread_rwlock_destroy(i32* %1)
%75 = icmp eq i64 %74, 0
%76 = select i1 %75, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.30, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.29, i64 0, i64 0)
%77 = xor i1 %75, true
%78 = zext i1 %77 to i32
br label %79
79: ; preds = %72, %68, %65, %61, %57, %53, %50, %46, %42, %38, %35, %31, %28, %24, %20, %16, %12, %7, %0
%80 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), %12 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), %16 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), %20 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.10, i64 0, i64 0), %24 ], [ getelementptr inbounds ([61 x i8], [61 x i8]* @.str.11, i64 0, i64 0), %28 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.13, i64 0, i64 0), %31 ], [ getelementptr inbounds ([61 x i8], [61 x i8]* @.str.14, i64 0, i64 0), %35 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.16, i64 0, i64 0), %38 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.18, i64 0, i64 0), %42 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.20, i64 0, i64 0), %46 ], [ getelementptr inbounds ([61 x i8], [61 x i8]* @.str.21, i64 0, i64 0), %50 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.23, i64 0, i64 0), %53 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.25, i64 0, i64 0), %57 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.10, i64 0, i64 0), %61 ], [ getelementptr inbounds ([61 x i8], [61 x i8]* @.str.11, i64 0, i64 0), %65 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.27, i64 0, i64 0), %68 ], [ %76, %72 ]
%81 = phi i32 [ 1, %0 ], [ 1, %7 ], [ 1, %12 ], [ 1, %16 ], [ 1, %20 ], [ 1, %24 ], [ 1, %28 ], [ 1, %31 ], [ 1, %35 ], [ 1, %38 ], [ 1, %42 ], [ 1, %46 ], [ 1, %50 ], [ 1, %53 ], [ 1, %57 ], [ 1, %61 ], [ 1, %65 ], [ 1, %68 ], [ %78, %72 ]
%82 = call i32 @puts(i8* dereferenceable(1) %80)
ret i32 %81
}