#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 */
scalar_t__ pthread_rwlock_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlock_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ pthread_rwlock_rdlock(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlock_unlock(int /*<<< orphan*/ *);
int test_locking_reader(pthread_rwlock_t *rwlock) {
  int result = 1;
  if (pthread_rwlock_init(rwlock, NULL) == 0 &&
      pthread_rwlock_rdlock(rwlock) == 0 &&
      pthread_rwlock_rdlock(rwlock) == 0 &&
      pthread_rwlock_rdlock(rwlock) == 0 &&
      pthread_rwlock_unlock(rwlock) == 0 &&
      pthread_rwlock_unlock(rwlock) == 0 &&
      pthread_rwlock_unlock(rwlock) == 0 && pthread_rwlock_destroy(rwlock) == 0)
    result = 0;
  return result;
}


x86 assembly (clang, -O0):
<test_locking_reader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <pthread_rwlock_init@plt>
cmp    $0x0,%rax
jne    11f6 <test_locking_reader+0xb6>
mov    -0x8(%rbp),%rdi
call   1040 <pthread_rwlock_rdlock@plt>
cmp    $0x0,%rax
jne    11f6 <test_locking_reader+0xb6>
mov    -0x8(%rbp),%rdi
call   1040 <pthread_rwlock_rdlock@plt>
cmp    $0x0,%rax
jne    11f6 <test_locking_reader+0xb6>
mov    -0x8(%rbp),%rdi
call   1040 <pthread_rwlock_rdlock@plt>
cmp    $0x0,%rax
jne    11f6 <test_locking_reader+0xb6>
mov    -0x8(%rbp),%rdi
call   1060 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
jne    11f6 <test_locking_reader+0xb6>
mov    -0x8(%rbp),%rdi
call   1060 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
jne    11f6 <test_locking_reader+0xb6>
mov    -0x8(%rbp),%rdi
call   1060 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
jne    11f6 <test_locking_reader+0xb6>
mov    -0x8(%rbp),%rdi
call   1030 <pthread_rwlock_destroy@plt>
cmp    $0x0,%rax
jne    11f6 <test_locking_reader+0xb6>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_locking_reader>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %esi,%esi
call   1050 <pthread_rwlock_init@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11b6 <test_locking_reader+0x76>
mov    %rbx,%rdi
call   1040 <pthread_rwlock_rdlock@plt>
test   %rax,%rax
jne    11b6 <test_locking_reader+0x76>
mov    %rbx,%rdi
call   1040 <pthread_rwlock_rdlock@plt>
test   %rax,%rax
jne    11b6 <test_locking_reader+0x76>
mov    %rbx,%rdi
call   1040 <pthread_rwlock_rdlock@plt>
test   %rax,%rax
jne    11b6 <test_locking_reader+0x76>
mov    %rbx,%rdi
call   1060 <pthread_rwlock_unlock@plt>
test   %rax,%rax
jne    11b6 <test_locking_reader+0x76>
mov    %rbx,%rdi
call   1060 <pthread_rwlock_unlock@plt>
test   %rax,%rax
jne    11b6 <test_locking_reader+0x76>
mov    %rbx,%rdi
call   1060 <pthread_rwlock_unlock@plt>
test   %rax,%rax
jne    11b6 <test_locking_reader+0x76>
mov    %rbx,%rdi
call   1030 <pthread_rwlock_destroy@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @test_locking_reader(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
store i32 1, i32* %3
%4 = load i32*, i32** %2
%5 = call i64 @pthread_rwlock_init(i32* %4, i32* null)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %36
7: ; preds = %1
%8 = load i32*, i32** %2
%9 = call i64 @pthread_rwlock_rdlock(i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %36
11: ; preds = %7
%12 = load i32*, i32** %2
%13 = call i64 @pthread_rwlock_rdlock(i32* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %11
%16 = load i32*, i32** %2
%17 = call i64 @pthread_rwlock_rdlock(i32* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = load i32*, i32** %2
%21 = call i64 @pthread_rwlock_unlock(i32* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = load i32*, i32** %2
%25 = call i64 @pthread_rwlock_unlock(i32* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load i32*, i32** %2
%29 = call i64 @pthread_rwlock_unlock(i32* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i32*, i32** %2
%33 = call i64 @pthread_rwlock_destroy(i32* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 0, i32* %3
br label %36
36: ; preds = %35, %31, %27, %23, %19, %15, %11, %7, %1
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @test_locking_reader(i32* %0) {
%2 = tail call i64 @pthread_rwlock_init(i32* %0, i32* null)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %26
4: ; preds = %1
%5 = tail call i64 @pthread_rwlock_rdlock(i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %26
7: ; preds = %4
%8 = tail call i64 @pthread_rwlock_rdlock(i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = tail call i64 @pthread_rwlock_rdlock(i32* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = tail call i64 @pthread_rwlock_unlock(i32* %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = tail call i64 @pthread_rwlock_unlock(i32* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = tail call i64 @pthread_rwlock_unlock(i32* %0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = tail call i64 @pthread_rwlock_destroy(i32* %0)
%24 = icmp ne i64 %23, 0
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %22, %19, %16, %13, %10, %7, %4, %1
%27 = phi i32 [ 1, %19 ], [ 1, %16 ], [ 1, %13 ], [ 1, %10 ], [ 1, %7 ], [ 1, %4 ], [ 1, %1 ], [ %25, %22 ]
ret i32 %27
}