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

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_PROCESS_SHARED;
scalar_t__ pthread_rwlock_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ pthread_rwlockattr_init(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlockattr_setpshared(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/);
int ccache_init_thread_rwlock(pthread_rwlock_t *lock) {
  pthread_rwlockattr_t attr;
  if (0 != pthread_rwlockattr_init(&attr)) {
    return -1;
  }
  if (0 != pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)) {
    return -1;
  }
  if (0 != pthread_rwlock_init(lock, &attr)) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ccache_init_thread_rwlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <pthread_rwlockattr_init@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     115f <ccache_init_thread_rwlock+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <ccache_init_thread_rwlock+0x89>
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1030 <pthread_rwlockattr_setpshared@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     118b <ccache_init_thread_rwlock+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <ccache_init_thread_rwlock+0x89>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <pthread_rwlock_init@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11b2 <ccache_init_thread_rwlock+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <ccache_init_thread_rwlock+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccache_init_thread_rwlock>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x4(%rsp),%rdi
call   1040 <pthread_rwlockattr_init@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1174 <ccache_init_thread_rwlock+0x44>
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1030 <pthread_rwlockattr_setpshared@plt>
test   %rax,%rax
jne    1174 <ccache_init_thread_rwlock+0x44>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <pthread_rwlock_init@plt>
neg    %rax
sbb    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PTHREAD_PROCESS_SHARED = global i32 0
define i32 @ccache_init_thread_rwlock(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = call i64 @pthread_rwlockattr_init(i32* %4)
%6 = icmp ne i64 0, %5
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %2
br label %19
8: ; preds = %1
%9 = load i32, i32* @PTHREAD_PROCESS_SHARED
%10 = call i64 @pthread_rwlockattr_setpshared(i32* %4, i32 %9)
%11 = icmp ne i64 0, %10
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 -1, i32* %2
br label %19
13: ; preds = %8
%14 = load i32*, i32** %3
%15 = call i64 @pthread_rwlock_init(i32* %14, i32* %4)
%16 = icmp ne i64 0, %15
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %2
br label %19
18: ; preds = %13
store i32 0, i32* %2
br label %19
19: ; preds = %18, %17, %12, %7
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@PTHREAD_PROCESS_SHARED = global i32 0
define i32 @ccache_init_thread_rwlock(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i64 @pthread_rwlockattr_init(i32* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = load i32, i32* @PTHREAD_PROCESS_SHARED
%8 = call i64 @pthread_rwlockattr_setpshared(i32* %2, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = call i64 @pthread_rwlock_init(i32* %0, i32* %2)
%12 = icmp ne i64 %11, 0
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %10, %6, %1
%15 = phi i32 [ -1, %1 ], [ -1, %6 ], [ %13, %10 ]
ret i32 %15
}