#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 */
struct timespec {
  int tv_sec;
  scalar_t__ tv_nsec;
};
typedef int /*<<< orphan*/ pthread_rwlock_t;
typedef int /*<<< orphan*/ pthread_mutex_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int pthread_mutex_destroy(int /*<<< orphan*/ *);
int pthread_mutex_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int pthread_mutex_lock(int /*<<< orphan*/ *);
int pthread_mutex_timedlock(int /*<<< orphan*/ *, struct timespec *);
int pthread_mutex_trylock(int /*<<< orphan*/ *);
int pthread_mutex_unlock(int /*<<< orphan*/ *);
int pthread_rwlock_destroy(int /*<<< orphan*/ *);
int pthread_rwlock_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int pthread_rwlock_rdlock(int /*<<< orphan*/ *);
int pthread_rwlock_timedrdlock(int /*<<< orphan*/ *, struct timespec *);
int pthread_rwlock_timedwrlock(int /*<<< orphan*/ *, struct timespec *);
int pthread_rwlock_tryrdlock(int /*<<< orphan*/ *);
int pthread_rwlock_trywrlock(int /*<<< orphan*/ *);
int pthread_rwlock_unlock(int /*<<< orphan*/ *);
int pthread_rwlock_wrlock(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int *);
int main(int argc, char **argv) {
  int r;
  pthread_mutex_t mutex;
  pthread_rwlock_t rwlock;
  struct timespec abs_timeout;
  time(&abs_timeout.tv_sec);
  abs_timeout.tv_nsec = 0;
  abs_timeout.tv_sec += 10;
  r = pthread_rwlock_init(&rwlock, NULL);
  assert(r == 0);
  fprintf(stderr, "Locking rwlock via pthread_rwlock_wrlock().\n");
  r = pthread_rwlock_wrlock(&rwlock);
  assert(r == 0);
  r = pthread_rwlock_unlock(&rwlock);
  assert(r == 0);
  fprintf(stderr, "Locking rwlock via pthread_rwlock_trywrlock().\n");
  r = pthread_rwlock_trywrlock(&rwlock);
  assert(r == 0);
  r = pthread_rwlock_unlock(&rwlock);
  assert(r == 0);
  fprintf(stderr, "Locking rwlock via pthread_rwlock_timedwrlock().\n");
  r = pthread_rwlock_timedwrlock(&rwlock, &abs_timeout);
  assert(r == 0);
  r = pthread_rwlock_unlock(&rwlock);
  assert(r == 0);
  fprintf(stderr, "Locking rwlock via pthread_rwlock_rdlock().\n");
  r = pthread_rwlock_rdlock(&rwlock);
  assert(r == 0);
  r = pthread_rwlock_rdlock(&rwlock);
  assert(r == 0);
  r = pthread_rwlock_rdlock(&rwlock);
  assert(r == 0);
  r = pthread_rwlock_unlock(&rwlock);
  assert(r == 0);
  r = pthread_rwlock_unlock(&rwlock);
  assert(r == 0);
  r = pthread_rwlock_unlock(&rwlock);
  assert(r == 0);
  fprintf(stderr, "Locking rwlock via pthread_rwlock_tryrdlock().\n");
  r = pthread_rwlock_tryrdlock(&rwlock);
  assert(r == 0);
  r = pthread_rwlock_unlock(&rwlock);
  assert(r == 0);
  fprintf(stderr, "Locking rwlock via pthread_rwlock_timedrdlock().\n");
  r = pthread_rwlock_timedrdlock(&rwlock, &abs_timeout);
  assert(r == 0);
  r = pthread_rwlock_unlock(&rwlock);
  assert(r == 0);
  fprintf(stderr, "Attempt to lock for writing recursively (not allowed).\n");
  r = pthread_rwlock_wrlock(&rwlock);
  assert(r == 0);
  r = pthread_rwlock_wrlock(&rwlock);
  assert(r != 0);
  r = pthread_rwlock_unlock(&rwlock);
  assert(r == 0);
  r = pthread_rwlock_destroy(&rwlock);
  assert(r == 0);
  r = pthread_mutex_init(&mutex, NULL);
  assert(r == 0);
  fprintf(stderr, "Locking mutex via pthread_mutex_trylock().\n");
  r = pthread_mutex_trylock(&mutex);
  assert(r == 0);
  r = pthread_mutex_unlock(&mutex);
  assert(r == 0);
  fprintf(stderr, "Locking mutex via pthread_mutex_lock().\n");
  r = pthread_mutex_lock(&mutex);
  assert(r == 0);
  r = pthread_mutex_unlock(&mutex);
  assert(r == 0);
  fprintf(stderr, "Locking mutex via pthread_mutex_timedlock().\n");
  r = pthread_mutex_timedlock(&mutex, &abs_timeout);
  assert(r == 0);
  r = pthread_mutex_unlock(&mutex);
  assert(r == 0);
  r = pthread_mutex_destroy(&mutex);
  assert(r == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
call   10e0 <time@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x30(%rbp)
lea    -0x1c(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1100 <pthread_rwlock_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
call   10c0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
call   1040 <pthread_rwlock_wrlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1110 <pthread_rwlock_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
call   10c0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
call   10a0 <pthread_rwlock_trywrlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1110 <pthread_rwlock_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
lea    0xd3e(%rip),%rsi
call   10c0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <pthread_rwlock_timedwrlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1110 <pthread_rwlock_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
lea    0xd1d(%rip),%rsi
call   10c0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
call   1080 <pthread_rwlock_rdlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1080 <pthread_rwlock_rdlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1080 <pthread_rwlock_rdlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1110 <pthread_rwlock_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1110 <pthread_rwlock_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1110 <pthread_rwlock_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
lea    0xc87(%rip),%rsi
call   10c0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
call   1070 <pthread_rwlock_tryrdlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1110 <pthread_rwlock_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2b65(%rip),%rax
mov    (%rax),%edi
lea    0xc68(%rip),%rsi
call   10c0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1120 <pthread_rwlock_timedrdlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1110 <pthread_rwlock_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2b12(%rip),%rax
mov    (%rax),%edi
lea    0xc47(%rip),%rsi
call   10c0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
call   1040 <pthread_rwlock_wrlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1040 <pthread_rwlock_wrlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1110 <pthread_rwlock_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1050 <pthread_rwlock_destroy@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1130 <pthread_mutex_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2a68(%rip),%rax
mov    (%rax),%edi
lea    0xbd5(%rip),%rsi
call   10c0 <fprintf@plt>
lea    -0x18(%rbp),%rdi
call   1090 <pthread_mutex_trylock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x18(%rbp),%rdi
call   10f0 <pthread_mutex_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2a19(%rip),%rax
mov    (%rax),%edi
lea    0xbb2(%rip),%rsi
call   10c0 <fprintf@plt>
lea    -0x18(%rbp),%rdi
call   1140 <pthread_mutex_lock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x18(%rbp),%rdi
call   10f0 <pthread_mutex_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x29ca(%rip),%rax
mov    (%rax),%edi
lea    0xb8c(%rip),%rsi
call   10c0 <fprintf@plt>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10d0 <pthread_mutex_timedlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x18(%rbp),%rdi
call   10f0 <pthread_mutex_unlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
lea    -0x18(%rbp),%rdi
call   1060 <pthread_mutex_destroy@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   10e0 <time@plt>
movq   $0x0,0x18(%rsp)
addl   $0xa,0x10(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1100 <pthread_rwlock_init@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    0x2d79(%rip),%r15
mov    (%r15),%edi
lea    0xd8f(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <pthread_rwlock_wrlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    (%r15),%edi
lea    0xd83(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
call   10a0 <pthread_rwlock_trywrlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    (%r15),%edi
lea    0xd7a(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <pthread_rwlock_timedwrlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    (%r15),%edi
lea    0xd70(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <pthread_rwlock_rdlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1080 <pthread_rwlock_rdlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1080 <pthread_rwlock_rdlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    (%r15),%edi
lea    0xd10(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <pthread_rwlock_tryrdlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    (%r15),%edi
lea    0xd07(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1120 <pthread_rwlock_timedrdlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    (%r15),%edi
lea    0xcfd(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <pthread_rwlock_wrlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1040 <pthread_rwlock_wrlock@plt>
xor    %edi,%edi
test   %eax,%eax
setne  %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1050 <pthread_rwlock_destroy@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1130 <pthread_mutex_init@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    (%r15),%edi
lea    0xcb6(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
call   1090 <pthread_mutex_trylock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   10f0 <pthread_mutex_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    (%r15),%edi
lea    0xca9(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
call   1140 <pthread_mutex_lock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   10f0 <pthread_mutex_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    (%r15),%edi
lea    0xc99(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10d0 <pthread_mutex_timedlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   10f0 <pthread_mutex_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
call   1060 <pthread_mutex_destroy@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10b0 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@stderr = global i32 0
@.str = [45 x i8] c"Locking rwlock via pthread_rwlock_wrlock().\0A\00"
@.str.1 = [48 x i8] c"Locking rwlock via pthread_rwlock_trywrlock().\0A\00"
@.str.2 = [50 x i8] c"Locking rwlock via pthread_rwlock_timedwrlock().\0A\00"
@.str.3 = [45 x i8] c"Locking rwlock via pthread_rwlock_rdlock().\0A\00"
@.str.4 = [48 x i8] c"Locking rwlock via pthread_rwlock_tryrdlock().\0A\00"
@.str.5 = [50 x i8] c"Locking rwlock via pthread_rwlock_timedrdlock().\0A\00"
@.str.6 = [56 x i8] c"Attempt to lock for writing recursively (not allowed).\0A\00"
@.str.7 = [44 x i8] c"Locking mutex via pthread_mutex_trylock().\0A\00"
@.str.8 = [41 x i8] c"Locking mutex via pthread_mutex_lock().\0A\00"
@.str.9 = [46 x i8] c"Locking mutex via pthread_mutex_timedlock().\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.timespec
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%11 = call i32 @time(i32* %10)
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 1
store i64 0, i64* %12
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 10
store i32 %15, i32* %13
%16 = call i32 @pthread_rwlock_init(i32* %8, i32* null)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @pthread_rwlock_wrlock(i32* %8)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call i32 @pthread_rwlock_unlock(i32* %8)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @pthread_rwlock_trywrlock(i32* %8)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = call i32 @pthread_rwlock_unlock(i32* %8)
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = icmp eq i32 %41, 0
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @pthread_rwlock_timedwrlock(i32* %8, %struct.timespec* %9)
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 0
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = call i32 @pthread_rwlock_unlock(i32* %8)
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = icmp eq i32 %53, 0
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%59 = call i32 @pthread_rwlock_rdlock(i32* %8)
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = icmp eq i32 %60, 0
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = call i32 @pthread_rwlock_rdlock(i32* %8)
store i32 %64, i32* %6
%65 = load i32, i32* %6
%66 = icmp eq i32 %65, 0
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = call i32 @pthread_rwlock_rdlock(i32* %8)
store i32 %69, i32* %6
%70 = load i32, i32* %6
%71 = icmp eq i32 %70, 0
%72 = zext i1 %71 to i32
%73 = call i32 @assert(i32 %72)
%74 = call i32 @pthread_rwlock_unlock(i32* %8)
store i32 %74, i32* %6
%75 = load i32, i32* %6
%76 = icmp eq i32 %75, 0
%77 = zext i1 %76 to i32
%78 = call i32 @assert(i32 %77)
%79 = call i32 @pthread_rwlock_unlock(i32* %8)
store i32 %79, i32* %6
%80 = load i32, i32* %6
%81 = icmp eq i32 %80, 0
%82 = zext i1 %81 to i32
%83 = call i32 @assert(i32 %82)
%84 = call i32 @pthread_rwlock_unlock(i32* %8)
store i32 %84, i32* %6
%85 = load i32, i32* %6
%86 = icmp eq i32 %85, 0
%87 = zext i1 %86 to i32
%88 = call i32 @assert(i32 %87)
%89 = load i32, i32* @stderr
%90 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%91 = call i32 @pthread_rwlock_tryrdlock(i32* %8)
store i32 %91, i32* %6
%92 = load i32, i32* %6
%93 = icmp eq i32 %92, 0
%94 = zext i1 %93 to i32
%95 = call i32 @assert(i32 %94)
%96 = call i32 @pthread_rwlock_unlock(i32* %8)
store i32 %96, i32* %6
%97 = load i32, i32* %6
%98 = icmp eq i32 %97, 0
%99 = zext i1 %98 to i32
%100 = call i32 @assert(i32 %99)
%101 = load i32, i32* @stderr
%102 = call i32 @fprintf(i32 %101, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
%103 = call i32 @pthread_rwlock_timedrdlock(i32* %8, %struct.timespec* %9)
store i32 %103, i32* %6
%104 = load i32, i32* %6
%105 = icmp eq i32 %104, 0
%106 = zext i1 %105 to i32
%107 = call i32 @assert(i32 %106)
%108 = call i32 @pthread_rwlock_unlock(i32* %8)
store i32 %108, i32* %6
%109 = load i32, i32* %6
%110 = icmp eq i32 %109, 0
%111 = zext i1 %110 to i32
%112 = call i32 @assert(i32 %111)
%113 = load i32, i32* @stderr
%114 = call i32 @fprintf(i32 %113, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0))
%115 = call i32 @pthread_rwlock_wrlock(i32* %8)
store i32 %115, i32* %6
%116 = load i32, i32* %6
%117 = icmp eq i32 %116, 0
%118 = zext i1 %117 to i32
%119 = call i32 @assert(i32 %118)
%120 = call i32 @pthread_rwlock_wrlock(i32* %8)
store i32 %120, i32* %6
%121 = load i32, i32* %6
%122 = icmp ne i32 %121, 0
%123 = zext i1 %122 to i32
%124 = call i32 @assert(i32 %123)
%125 = call i32 @pthread_rwlock_unlock(i32* %8)
store i32 %125, i32* %6
%126 = load i32, i32* %6
%127 = icmp eq i32 %126, 0
%128 = zext i1 %127 to i32
%129 = call i32 @assert(i32 %128)
%130 = call i32 @pthread_rwlock_destroy(i32* %8)
store i32 %130, i32* %6
%131 = load i32, i32* %6
%132 = icmp eq i32 %131, 0
%133 = zext i1 %132 to i32
%134 = call i32 @assert(i32 %133)
%135 = call i32 @pthread_mutex_init(i32* %7, i32* null)
store i32 %135, i32* %6
%136 = load i32, i32* %6
%137 = icmp eq i32 %136, 0
%138 = zext i1 %137 to i32
%139 = call i32 @assert(i32 %138)
%140 = load i32, i32* @stderr
%141 = call i32 @fprintf(i32 %140, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0))
%142 = call i32 @pthread_mutex_trylock(i32* %7)
store i32 %142, i32* %6
%143 = load i32, i32* %6
%144 = icmp eq i32 %143, 0
%145 = zext i1 %144 to i32
%146 = call i32 @assert(i32 %145)
%147 = call i32 @pthread_mutex_unlock(i32* %7)
store i32 %147, i32* %6
%148 = load i32, i32* %6
%149 = icmp eq i32 %148, 0
%150 = zext i1 %149 to i32
%151 = call i32 @assert(i32 %150)
%152 = load i32, i32* @stderr
%153 = call i32 @fprintf(i32 %152, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0))
%154 = call i32 @pthread_mutex_lock(i32* %7)
store i32 %154, i32* %6
%155 = load i32, i32* %6
%156 = icmp eq i32 %155, 0
%157 = zext i1 %156 to i32
%158 = call i32 @assert(i32 %157)
%159 = call i32 @pthread_mutex_unlock(i32* %7)
store i32 %159, i32* %6
%160 = load i32, i32* %6
%161 = icmp eq i32 %160, 0
%162 = zext i1 %161 to i32
%163 = call i32 @assert(i32 %162)
%164 = load i32, i32* @stderr
%165 = call i32 @fprintf(i32 %164, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0))
%166 = call i32 @pthread_mutex_timedlock(i32* %7, %struct.timespec* %9)
store i32 %166, i32* %6
%167 = load i32, i32* %6
%168 = icmp eq i32 %167, 0
%169 = zext i1 %168 to i32
%170 = call i32 @assert(i32 %169)
%171 = call i32 @pthread_mutex_unlock(i32* %7)
store i32 %171, i32* %6
%172 = load i32, i32* %6
%173 = icmp eq i32 %172, 0
%174 = zext i1 %173 to i32
%175 = call i32 @assert(i32 %174)
%176 = call i32 @pthread_mutex_destroy(i32* %7)
store i32 %176, i32* %6
%177 = load i32, i32* %6
%178 = icmp eq i32 %177, 0
%179 = zext i1 %178 to i32
%180 = call i32 @assert(i32 %179)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@stderr = global i32 0
@.str = [45 x i8] c"Locking rwlock via pthread_rwlock_wrlock().\0A\00"
@.str.1 = [48 x i8] c"Locking rwlock via pthread_rwlock_trywrlock().\0A\00"
@.str.2 = [50 x i8] c"Locking rwlock via pthread_rwlock_timedwrlock().\0A\00"
@.str.3 = [45 x i8] c"Locking rwlock via pthread_rwlock_rdlock().\0A\00"
@.str.4 = [48 x i8] c"Locking rwlock via pthread_rwlock_tryrdlock().\0A\00"
@.str.5 = [50 x i8] c"Locking rwlock via pthread_rwlock_timedrdlock().\0A\00"
@.str.6 = [56 x i8] c"Attempt to lock for writing recursively (not allowed).\0A\00"
@.str.7 = [44 x i8] c"Locking mutex via pthread_mutex_trylock().\0A\00"
@.str.8 = [41 x i8] c"Locking mutex via pthread_mutex_lock().\0A\00"
@.str.9 = [46 x i8] c"Locking mutex via pthread_mutex_timedlock().\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timespec
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.timespec* %5 to i8*
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
%10 = call i32 @time(i32* %9)
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 1
store i64 0, i64* %11
%12 = load i32, i32* %9
%13 = add nsw i32 %12, 10
store i32 %13, i32* %9
%14 = call i32 @pthread_rwlock_init(i32* %4, i32* null)
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @pthread_rwlock_wrlock(i32* %4)
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i32 @pthread_rwlock_unlock(i32* %4)
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @pthread_rwlock_trywrlock(i32* %4)
%31 = icmp eq i32 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = call i32 @pthread_rwlock_unlock(i32* %4)
%35 = icmp eq i32 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @pthread_rwlock_timedwrlock(i32* %4, %struct.timespec* %5)
%41 = icmp eq i32 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = call i32 @pthread_rwlock_unlock(i32* %4)
%45 = icmp eq i32 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%50 = call i32 @pthread_rwlock_rdlock(i32* %4)
%51 = icmp eq i32 %50, 0
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = call i32 @pthread_rwlock_rdlock(i32* %4)
%55 = icmp eq i32 %54, 0
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = call i32 @pthread_rwlock_rdlock(i32* %4)
%59 = icmp eq i32 %58, 0
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = call i32 @pthread_rwlock_unlock(i32* %4)
%63 = icmp eq i32 %62, 0
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = call i32 @pthread_rwlock_unlock(i32* %4)
%67 = icmp eq i32 %66, 0
%68 = zext i1 %67 to i32
%69 = call i32 @assert(i32 %68)
%70 = call i32 @pthread_rwlock_unlock(i32* %4)
%71 = icmp eq i32 %70, 0
%72 = zext i1 %71 to i32
%73 = call i32 @assert(i32 %72)
%74 = load i32, i32* @stderr
%75 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%76 = call i32 @pthread_rwlock_tryrdlock(i32* %4)
%77 = icmp eq i32 %76, 0
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = call i32 @pthread_rwlock_unlock(i32* %4)
%81 = icmp eq i32 %80, 0
%82 = zext i1 %81 to i32
%83 = call i32 @assert(i32 %82)
%84 = load i32, i32* @stderr
%85 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
%86 = call i32 @pthread_rwlock_timedrdlock(i32* %4, %struct.timespec* %5)
%87 = icmp eq i32 %86, 0
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
%90 = call i32 @pthread_rwlock_unlock(i32* %4)
%91 = icmp eq i32 %90, 0
%92 = zext i1 %91 to i32
%93 = call i32 @assert(i32 %92)
%94 = load i32, i32* @stderr
%95 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0))
%96 = call i32 @pthread_rwlock_wrlock(i32* %4)
%97 = icmp eq i32 %96, 0
%98 = zext i1 %97 to i32
%99 = call i32 @assert(i32 %98)
%100 = call i32 @pthread_rwlock_wrlock(i32* %4)
%101 = icmp ne i32 %100, 0
%102 = zext i1 %101 to i32
%103 = call i32 @assert(i32 %102)
%104 = call i32 @pthread_rwlock_unlock(i32* %4)
%105 = icmp eq i32 %104, 0
%106 = zext i1 %105 to i32
%107 = call i32 @assert(i32 %106)
%108 = call i32 @pthread_rwlock_destroy(i32* %4)
%109 = icmp eq i32 %108, 0
%110 = zext i1 %109 to i32
%111 = call i32 @assert(i32 %110)
%112 = call i32 @pthread_mutex_init(i32* %3, i32* null)
%113 = icmp eq i32 %112, 0
%114 = zext i1 %113 to i32
%115 = call i32 @assert(i32 %114)
%116 = load i32, i32* @stderr
%117 = call i32 @fprintf(i32 %116, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0))
%118 = call i32 @pthread_mutex_trylock(i32* %3)
%119 = icmp eq i32 %118, 0
%120 = zext i1 %119 to i32
%121 = call i32 @assert(i32 %120)
%122 = call i32 @pthread_mutex_unlock(i32* %3)
%123 = icmp eq i32 %122, 0
%124 = zext i1 %123 to i32
%125 = call i32 @assert(i32 %124)
%126 = load i32, i32* @stderr
%127 = call i32 @fprintf(i32 %126, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0))
%128 = call i32 @pthread_mutex_lock(i32* %3)
%129 = icmp eq i32 %128, 0
%130 = zext i1 %129 to i32
%131 = call i32 @assert(i32 %130)
%132 = call i32 @pthread_mutex_unlock(i32* %3)
%133 = icmp eq i32 %132, 0
%134 = zext i1 %133 to i32
%135 = call i32 @assert(i32 %134)
%136 = load i32, i32* @stderr
%137 = call i32 @fprintf(i32 %136, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0))
%138 = call i32 @pthread_mutex_timedlock(i32* %3, %struct.timespec* %5)
%139 = icmp eq i32 %138, 0
%140 = zext i1 %139 to i32
%141 = call i32 @assert(i32 %140)
%142 = call i32 @pthread_mutex_unlock(i32* %3)
%143 = icmp eq i32 %142, 0
%144 = zext i1 %143 to i32
%145 = call i32 @assert(i32 %144)
%146 = call i32 @pthread_mutex_destroy(i32* %3)
%147 = icmp eq i32 %146, 0
%148 = zext i1 %147 to i32
%149 = call i32 @assert(i32 %148)
ret i32 0
}