#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 */
int /*<<< orphan*/ printf(char *, ...);
int pthread_rwlock_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlock_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int main(void) {
  pthread_rwlock_t rwlock;
  int cnt = 0;
  int rc = 0;
  while (cnt++ < 1000) {
    if (pthread_rwlock_init(&rwlock, NULL) != 0) {
      printf("Error at pthread_rwlock_init()\n");
      return 2;
    }
    rc = pthread_rwlock_destroy(&rwlock);
    if (rc != 0) {
      printf("Test FAILED: at %d-th pthread_rwlock_destroy(), with Error "
             "code=%d\n",
             cnt, rc);
      return 1;
    }
  }
  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)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x3e8,%eax
jge    11cf <main+0x9f>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <pthread_rwlock_init@plt>
cmp    $0x0,%rax
je     1194 <main+0x64>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11e4 <main+0xb4>
lea    -0x8(%rbp),%rdi
call   1030 <pthread_rwlock_destroy@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11ca <main+0x9a>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <main+0xb4>
jmp    114d <main+0x1d>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
lea    0x4(%rsp),%r14
nopl   0x0(%rax,%rax,1)
cmp    $0xfffffc18,%ebx
je     1191 <main+0x51>
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <pthread_rwlock_init@plt>
test   %rax,%rax
jne    11a1 <main+0x61>
mov    %r14,%rdi
call   1040 <pthread_rwlock_destroy@plt>
add    $0xffffffff,%ebx
test   %eax,%eax
je     1150 <main+0x10>
neg    %ebx
lea    0xe81(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    11b2 <main+0x72>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11b2 <main+0x72>
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Error at pthread_rwlock_init()\0A\00"
@.str.1 = [68 x i8] c"Test FAILED: at %d-th pthread_rwlock_destroy(), with Error code=%d\0A\00"
@.str.2 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %22, %0
%6 = load i32, i32* %3
%7 = add nsw i32 %6, 1
store i32 %7, i32* %3
%8 = icmp slt i32 %6, 1000
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = call i64 @pthread_rwlock_init(i32* %2, i32* null)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %25
14: ; preds = %9
%15 = call i32 @pthread_rwlock_destroy(i32* %2)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20)
store i32 1, i32* %1
br label %25
22: ; preds = %14
br label %5
23: ; preds = %5
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %25
25: ; preds = %23, %18, %12
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str.1 = [68 x i8] c"Test FAILED: at %d-th pthread_rwlock_destroy(), with Error code=%d\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.3 = [31 x i8] c"Error at pthread_rwlock_init()\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %12, %0
%4 = phi i32 [ 0, %0 ], [ %5, %12 ]
%5 = add nuw nsw i32 %4, 1
%6 = icmp eq i32 %4, 1000
br i1 %6, label %17, label %7
7: ; preds = %3
%8 = call i64 @pthread_rwlock_init(i32* %1, i32* null)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.3, i64 0, i64 0))
br label %19
12: ; preds = %7
%13 = call i32 @pthread_rwlock_destroy(i32* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %3, label %15
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %13)
br label %19
17: ; preds = %3
%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
%20 = phi i32 [ 2, %10 ], [ 1, %15 ], [ 0, %17 ]
ret i32 %20
}