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

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ pthread_rwlock_init(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_rwlock_rdlock(int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_rwlock_timedwrlock(int /*<<< orphan*/ *,
                                              struct timespec *);
int /*<<< orphan*/ pthread_rwlock_unlock(int /*<<< orphan*/ *);
int /*<<< orphan*/ time_show(struct timespec *);
int main(int argc, char *argv[]) {
  pthread_rwlock_t rwlock;
  pthread_rwlock_init(&rwlock, NULL);
  pthread_rwlock_rdlock(&rwlock);
  printf("pthread_rwlock_rdlock has locked!\n");
  pthread_rwlock_rdlock(&rwlock);
  printf("pthread_rwlock_rdlock has locked again!\n");
  struct timespec ts;
  time_show(&ts);
  ts.tv_sec += 5;
  pthread_rwlock_timedwrlock(&rwlock, &ts);
  time_show(&ts);
  pthread_rwlock_unlock(&rwlock);
  pthread_rwlock_unlock(&rwlock);
  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)
lea    -0x14(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <pthread_rwlock_init@plt>
lea    -0x14(%rbp),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
lea    -0x14(%rbp),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
lea    0xe7b(%rip),%rdi
call   1050 <printf@plt>
lea    -0x18(%rbp),%rdi
call   1040 <time_show@plt>
mov    -0x18(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x18(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <pthread_rwlock_timedwrlock@plt>
lea    -0x18(%rbp),%rdi
call   1040 <time_show@plt>
lea    -0x14(%rbp),%rdi
call   1080 <pthread_rwlock_unlock@plt>
lea    -0x14(%rbp),%rdi
call   1080 <pthread_rwlock_unlock@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <pthread_rwlock_init@plt>
mov    %r14,%rdi
call   1060 <pthread_rwlock_rdlock@plt>
lea    0xe7e(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1060 <pthread_rwlock_rdlock@plt>
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <time_show@plt>
addl   $0x5,(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <pthread_rwlock_timedwrlock@plt>
mov    %rbx,%rdi
call   1050 <time_show@plt>
mov    %r14,%rdi
call   1080 <pthread_rwlock_unlock@plt>
mov    %r14,%rdi
call   1080 <pthread_rwlock_unlock@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [35 x i8] c"pthread_rwlock_rdlock has locked!\0A\00"
@.str.1 = [41 x i8] c"pthread_rwlock_rdlock has locked again!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.timespec
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @pthread_rwlock_init(i32* %6, i32* null)
%9 = call i32 @pthread_rwlock_rdlock(i32* %6)
%10 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @pthread_rwlock_rdlock(i32* %6)
%12 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @time_show(%struct.timespec* %7)
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 5
store i32 %16, i32* %14
%17 = call i32 @pthread_rwlock_timedwrlock(i32* %6, %struct.timespec* %7)
%18 = call i32 @time_show(%struct.timespec* %7)
%19 = call i32 @pthread_rwlock_unlock(i32* %6)
%20 = call i32 @pthread_rwlock_unlock(i32* %6)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@str = [34 x i8] c"pthread_rwlock_rdlock has locked!\00"
@str.2 = [40 x i8] c"pthread_rwlock_rdlock has locked again!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = bitcast i32* %3 to i8*
%6 = call i32 @pthread_rwlock_init(i32* %3, i32* null)
%7 = call i32 @pthread_rwlock_rdlock(i32* %3)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%9 = call i32 @pthread_rwlock_rdlock(i32* %3)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.2, i64 0, i64 0))
%11 = bitcast %struct.timespec* %4 to i8*
%12 = call i32 @time_show(%struct.timespec* %4)
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 5
store i32 %15, i32* %13
%16 = call i32 @pthread_rwlock_timedwrlock(i32* %3, %struct.timespec* %4)
%17 = call i32 @time_show(%struct.timespec* %4)
%18 = call i32 @pthread_rwlock_unlock(i32* %3)
%19 = call i32 @pthread_rwlock_unlock(i32* %3)
ret i32 0
}