#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_rwlock_t;

/* Variables and functions */
int EBUSY;
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*/ *);
int /*<<< orphan*/ puts(char *);
int do_test(void) {
  pthread_rwlock_t r;
  int e;
  if (pthread_rwlock_init(&r, NULL) != 0) {
    puts("rwlock_init failed");
    return 1;
  }
  puts("rwlock_init 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    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <pthread_rwlock_init@plt>
cmp    $0x0,%rax
je     11a7 <do_test+0x37>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1040 <pthread_rwlock_wrlock@plt>
cmp    $0x0,%rax
je     11de <do_test+0x6e>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1218 <do_test+0xa8>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
mov    -0xc(%rbp),%eax
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%eax
je     1242 <do_test+0xd2>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1070 <pthread_rwlock_trywrlock@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    127c <do_test+0x10c>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
mov    -0xc(%rbp),%eax
mov    0x2d5a(%rip),%rcx
cmp    (%rcx),%eax
je     12a6 <do_test+0x136>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1090 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
je     12dd <do_test+0x16d>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
cmp    $0x0,%eax
je     1313 <do_test+0x1a3>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xef2(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1070 <pthread_rwlock_trywrlock@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    134d <do_test+0x1dd>
lea    0xefe(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
mov    -0xc(%rbp),%eax
mov    0x2c89(%rip),%rcx
cmp    (%rcx),%eax
je     1377 <do_test+0x207>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xf2a(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1090 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
je     13ae <do_test+0x23e>
lea    0xf44(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xf45(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1070 <pthread_rwlock_trywrlock@plt>
cmp    $0x0,%eax
je     13e4 <do_test+0x274>
lea    0xf43(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xf56(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    141e <do_test+0x2ae>
lea    0xc51(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
mov    -0xc(%rbp),%eax
mov    0x2bb8(%rip),%rcx
cmp    (%rcx),%eax
je     1448 <do_test+0x2d8>
lea    0xc58(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xc7d(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1090 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
je     147f <do_test+0x30f>
lea    0xf01(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xf02(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rdi
call   1050 <pthread_rwlock_destroy@plt>
cmp    $0x0,%rax
je     14b6 <do_test+0x346>
lea    0xeff(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c9 <do_test+0x359>
lea    0xefd(%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
xor    %esi,%esi
call   1080 <pthread_rwlock_init@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1196 <do_test+0x26>
lea    0xe6c(%rip),%rbx
jmp    11b8 <do_test+0x48>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1040 <pthread_rwlock_wrlock@plt>
test   %rax,%rax
je     11cd <do_test+0x5d>
lea    0xe71(%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    0xe6e(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
lea    0xe74(%rip),%rbx
test   %eax,%eax
je     11b8 <do_test+0x48>
mov    0x2deb(%rip),%r15
lea    0xe93(%rip),%r14
cmp    (%r15),%eax
jne    1357 <do_test+0x1e7>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1070 <pthread_rwlock_trywrlock@plt>
test   %eax,%eax
je     124b <do_test+0xdb>
cmp    (%r15),%eax
jne    1257 <do_test+0xe7>
lea    0xf48(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1090 <pthread_rwlock_unlock@plt>
test   %rax,%rax
je     1263 <do_test+0xf3>
lea    0xf66(%rip),%rbx
jmp    11b8 <do_test+0x48>
lea    0xeb3(%rip),%rbx
jmp    11b8 <do_test+0x48>
lea    0xed8(%rip),%rbx
jmp    11b8 <do_test+0x48>
lea    0xf5b(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
test   %eax,%eax
je     1289 <do_test+0x119>
lea    0xf5d(%rip),%rbx
jmp    11b8 <do_test+0x48>
lea    0xf7c(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1070 <pthread_rwlock_trywrlock@plt>
test   %eax,%eax
je     12cf <do_test+0x15f>
cmp    (%r15),%eax
jne    12db <do_test+0x16b>
lea    0xff9(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1090 <pthread_rwlock_unlock@plt>
test   %rax,%rax
je     12e7 <do_test+0x177>
lea    0x1017(%rip),%rbx
jmp    11b8 <do_test+0x48>
lea    0xf64(%rip),%rbx
jmp    11b8 <do_test+0x48>
lea    0xf89(%rip),%rbx
jmp    11b8 <do_test+0x48>
lea    0x100c(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1070 <pthread_rwlock_trywrlock@plt>
test   %eax,%eax
je     130d <do_test+0x19d>
lea    0x100e(%rip),%rbx
jmp    11b8 <do_test+0x48>
lea    0x102d(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1060 <pthread_rwlock_tryrdlock@plt>
test   %eax,%eax
je     11b8 <do_test+0x48>
cmp    (%r15),%eax
jne    1357 <do_test+0x1e7>
lea    0xd95(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1090 <pthread_rwlock_unlock@plt>
test   %rax,%rax
je     135f <do_test+0x1ef>
lea    0x101d(%rip),%rbx
jmp    11b8 <do_test+0x48>
mov    %r14,%rbx
jmp    11b8 <do_test+0x48>
lea    0x1022(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1050 <pthread_rwlock_destroy@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
lea    0x1035(%rip),%rax
lea    0x1018(%rip),%rbx
cmove  %rax,%rbx
jmp    11b8 <do_test+0x48>

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

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