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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int pthread_rwlockattr_destroy(int /*<<< orphan*/ *);
int pthread_rwlockattr_init(int /*<<< orphan*/ *);
int main(void) {
  pthread_rwlockattr_t rwla;
  int rc = 0;
  rc = pthread_rwlockattr_init(&rwla);
  if (rc != 0) {
    printf("Cannot initialize rwlock attributes object\n");
    return 2;
  }
  rc = pthread_rwlockattr_destroy(&rwla);
  if (rc != 0) {
    printf("Cannot destroy the rwlock attributes object, error code: %d\n", rc);
    return 2;
  }
  rc = pthread_rwlockattr_init(&rwla);
  if (rc != 0) {
    printf("Test FAILED, with error: %d\n", rc);
    return 1;
  } else {
    printf("Test PASSED\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <pthread_rwlockattr_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1176 <main+0x46>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11f1 <main+0xc1>
lea    -0x8(%rbp),%rdi
call   1050 <pthread_rwlockattr_destroy@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a9 <main+0x79>
mov    -0xc(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11f1 <main+0xc1>
lea    -0x8(%rbp),%rdi
call   1040 <pthread_rwlockattr_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11dc <main+0xac>
mov    -0xc(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f1 <main+0xc1>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0x4(%rsp),%rdi
call   1050 <pthread_rwlockattr_init@plt>
test   %eax,%eax
je     115d <main+0x1d>
lea    0xf10(%rip),%rdi
call   1030 <puts@plt>
jmp    117b <main+0x3b>
lea    0x4(%rsp),%rdi
call   1060 <pthread_rwlockattr_destroy@plt>
test   %eax,%eax
je     1182 <main+0x42>
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%eax
pop    %rcx
ret
lea    0x4(%rsp),%rdi
call   1050 <pthread_rwlockattr_init@plt>
test   %eax,%eax
je     11a7 <main+0x67>
lea    0xea6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Cannot initialize rwlock attributes object\0A\00"
@.str.1 = [61 x i8] c"Cannot destroy the rwlock attributes object, error code: %d\0A\00"
@.str.2 = [29 x i8] c"Test FAILED, with error: %d\0A\00"
@.str.3 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = call i32 @pthread_rwlockattr_init(i32* %2)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %25
9: ; preds = %0
%10 = call i32 @pthread_rwlockattr_destroy(i32* %2)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 2, i32* %1
br label %25
16: ; preds = %9
%17 = call i32 @pthread_rwlockattr_init(i32* %2)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %21)
store i32 1, i32* %1
br label %25
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %25
25: ; preds = %23, %20, %13, %7
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str.1 = [61 x i8] c"Cannot destroy the rwlock attributes object, error code: %d\0A\00"
@.str.2 = [29 x i8] c"Test FAILED, with error: %d\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.4 = [43 x i8] c"Cannot initialize rwlock attributes object\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @pthread_rwlockattr_init(i32* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.4, i64 0, i64 0))
br label %19
7: ; preds = %0
%8 = call i32 @pthread_rwlockattr_destroy(i32* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %19
12: ; preds = %7
%13 = call i32 @pthread_rwlockattr_init(i32* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %19
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %17, %15, %10, %5
%20 = phi i32 [ 2, %5 ], [ 2, %10 ], [ 1, %15 ], [ 0, %17 ]
ret i32 %20
}