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


x86 assembly (clang, -O0):
<test_locking_writer>:
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    11aa <test_locking_writer+0x6a>
mov    -0x8(%rbp),%rdi
call   1030 <pthread_rwlock_wrlock@plt>
cmp    $0x0,%rax
jne    11aa <test_locking_writer+0x6a>
mov    -0x8(%rbp),%rdi
call   1060 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
jne    11aa <test_locking_writer+0x6a>
mov    -0x8(%rbp),%rdi
call   1040 <pthread_rwlock_destroy@plt>
cmp    $0x0,%rax
jne    11aa <test_locking_writer+0x6a>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_locking_writer>:
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    1182 <test_locking_writer+0x42>
mov    %rbx,%rdi
call   1030 <pthread_rwlock_wrlock@plt>
test   %rax,%rax
jne    1182 <test_locking_writer+0x42>
mov    %rbx,%rdi
call   1060 <pthread_rwlock_unlock@plt>
test   %rax,%rax
jne    1182 <test_locking_writer+0x42>
mov    %rbx,%rdi
call   1040 <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_writer(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 %20
7: ; preds = %1
%8 = load i32*, i32** %2
%9 = call i64 @pthread_rwlock_wrlock(i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load i32*, i32** %2
%13 = call i64 @pthread_rwlock_unlock(i32* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i32*, i32** %2
%17 = call i64 @pthread_rwlock_destroy(i32* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 0, i32* %3
br label %20
20: ; preds = %19, %15, %11, %7, %1
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
define i32 @test_locking_writer(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 %14
4: ; preds = %1
%5 = tail call i64 @pthread_rwlock_wrlock(i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = tail call i64 @pthread_rwlock_unlock(i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i64 @pthread_rwlock_destroy(i32* %0)
%12 = icmp ne i64 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %10, %7, %4, %1
%15 = phi i32 [ 1, %7 ], [ 1, %4 ], [ 1, %1 ], [ %13, %10 ]
ret i32 %15
}