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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ assert(int);
int clock_gettime(int /*<<< orphan*/, struct timespec *);
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 main(int argc, char **argv) {
  int r;
  pthread_mutex_t mutex;
  pthread_rwlock_t rwlock;
  struct timespec abs_timeout;
  r = clock_gettime(CLOCK_REALTIME, &abs_timeout);
  assert(r == 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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1060 <clock_gettime@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <assert@plt>
mov    -0x20(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x20(%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   10c0 <assert@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
call   10d0 <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   10c0 <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   10c0 <assert@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
lea    0xd48(%rip),%rsi
call   10d0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
call   10b0 <pthread_rwlock_trywrlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <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   10c0 <assert@plt>
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
lea    0xd29(%rip),%rsi
call   10d0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
lea    -0x20(%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   10c0 <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   10c0 <assert@plt>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xd08(%rip),%rsi
call   10d0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <pthread_rwlock_rdlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <pthread_rwlock_rdlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <pthread_rwlock_rdlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <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   10c0 <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   10c0 <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   10c0 <assert@plt>
mov    0x2b9f(%rip),%rax
mov    (%rax),%edi
lea    0xc72(%rip),%rsi
call   10d0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
call   1080 <pthread_rwlock_tryrdlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <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   10c0 <assert@plt>
mov    0x2b50(%rip),%rax
mov    (%rax),%edi
lea    0xc53(%rip),%rsi
call   10d0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
lea    -0x20(%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   10c0 <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   10c0 <assert@plt>
mov    0x2afd(%rip),%rax
mov    (%rax),%edi
lea    0xc32(%rip),%rsi
call   10d0 <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   10c0 <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   10c0 <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   10c0 <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   10c0 <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   10c0 <assert@plt>
mov    0x2a53(%rip),%rax
mov    (%rax),%edi
lea    0xbc0(%rip),%rsi
call   10d0 <fprintf@plt>
lea    -0x18(%rbp),%rdi
call   10a0 <pthread_mutex_trylock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <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   10c0 <assert@plt>
mov    0x2a04(%rip),%rax
mov    (%rax),%edi
lea    0xb9d(%rip),%rsi
call   10d0 <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   10c0 <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   10c0 <assert@plt>
mov    0x29b5(%rip),%rax
mov    (%rax),%edi
lea    0xb77(%rip),%rsi
call   10d0 <fprintf@plt>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10e0 <pthread_mutex_timedlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <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   10c0 <assert@plt>
lea    -0x18(%rbp),%rdi
call   1070 <pthread_mutex_destroy@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%r14
mov    %r14,%rsi
call   1060 <clock_gettime@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
addl   $0xa,(%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   10c0 <assert@plt>
mov    0x2d6f(%rip),%r15
mov    (%r15),%edi
lea    0xd85(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <pthread_rwlock_wrlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    (%r15),%edi
lea    0xd79(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
call   10b0 <pthread_rwlock_trywrlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    (%r15),%edi
lea    0xd70(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <pthread_rwlock_timedwrlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    (%r15),%edi
lea    0xd66(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
call   1090 <pthread_rwlock_rdlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1090 <pthread_rwlock_rdlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1090 <pthread_rwlock_rdlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    (%r15),%edi
lea    0xd06(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <pthread_rwlock_tryrdlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    (%r15),%edi
lea    0xcfd(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1120 <pthread_rwlock_timedrdlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    (%r15),%edi
lea    0xcf3(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <pthread_rwlock_wrlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1040 <pthread_rwlock_wrlock@plt>
xor    %edi,%edi
test   %eax,%eax
setne  %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1110 <pthread_rwlock_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1050 <pthread_rwlock_destroy@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <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   10c0 <assert@plt>
mov    (%r15),%edi
lea    0xcac(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
call   10a0 <pthread_mutex_trylock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   10f0 <pthread_mutex_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    (%r15),%edi
lea    0xc9f(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
call   1140 <pthread_mutex_lock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   10f0 <pthread_mutex_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    (%r15),%edi
lea    0xc8f(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10e0 <pthread_mutex_timedlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   10f0 <pthread_mutex_unlock@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
mov    %rbx,%rdi
call   1070 <pthread_mutex_destroy@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10c0 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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