#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int pthread_rwlock_destroy(int /*<<< orphan*/ *);
int pthread_rwlock_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char **argv) {
  pthread_rwlock_t locks[2000];
  int n;
  int e;
  for (n = 0; n < 2000; n++) {
    if ((e = pthread_rwlock_init(locks + n, NULL)) != 0) {
      fprintf(stderr, "pthread_rwlock_init[%d]: %s\n", n, strerror(e));
      exit(1);
    }
  }
  for (n = 0; n < 2000; n++) {
    if ((e = pthread_rwlock_destroy(locks + n)) != 0) {
      fprintf(stderr, "pthread_rwlock_destroy[%d]: %s\n", n, strerror(e));
      exit(1);
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1f54(%rbp)
cmpl   $0x7d0,-0x1f54(%rbp)
jge    1214 <main+0xc4>
lea    -0x1f50(%rbp),%rdi
movslq -0x1f54(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <pthread_rwlock_init@plt>
mov    %eax,-0x1f58(%rbp)
cmp    $0x0,%eax
je     11fb <main+0xab>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1f60(%rbp)
mov    -0x1f54(%rbp),%eax
mov    %eax,-0x1f5c(%rbp)
mov    -0x1f58(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x1f60(%rbp),%edi
mov    -0x1f5c(%rbp),%edx
mov    %rax,%rcx
lea    0xe14(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1200 <main+0xb0>
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    1173 <main+0x23>
movl   $0x0,-0x1f54(%rbp)
cmpl   $0x7d0,-0x1f54(%rbp)
jge    12bb <main+0x16b>
lea    -0x1f50(%rbp),%rdi
movslq -0x1f54(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1030 <pthread_rwlock_destroy@plt>
mov    %eax,-0x1f58(%rbp)
cmp    $0x0,%eax
je     12a2 <main+0x152>
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1f68(%rbp)
mov    -0x1f54(%rbp),%eax
mov    %eax,-0x1f64(%rbp)
mov    -0x1f58(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x1f68(%rbp),%edi
mov    -0x1f64(%rbp),%edx
mov    %rax,%rcx
lea    0xd8a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    12a7 <main+0x157>
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    121e <main+0xce>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1f48,%rsp
mov    %rsp,%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <pthread_rwlock_init@plt>
test   %eax,%eax
jne    11b4 <main+0x64>
add    $0x1,%r14
add    $0x4,%rbx
cmp    $0x7d0,%r14
jne    1160 <main+0x10>
mov    %rsp,%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <pthread_rwlock_destroy@plt>
test   %eax,%eax
jne    11cd <main+0x7d>
add    $0x1,%r14
add    $0x4,%rbx
cmp    $0x7d0,%r14
jne    1190 <main+0x40>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2e25(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1070 <strerror@plt>
lea    0xe35(%rip),%rsi
jmp    11e4 <main+0x94>
mov    0x2e0c(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1070 <strerror@plt>
lea    0xe39(%rip),%rsi
mov    %ebx,%edi
mov    %r14d,%edx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"pthread_rwlock_init[%d]: %s\0A\00"
@.str.1 = [32 x i8] c"pthread_rwlock_destroy[%d]: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2000 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %9
9: ; preds = %27, %2
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 2000
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = getelementptr inbounds [2000 x i32], [2000 x i32]* %6, i64 0, i64 0
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = call i32 @pthread_rwlock_init(i32* %16, i32* null)
store i32 %17, i32* %8
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %21, i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %9
30: ; preds = %9
store i32 0, i32* %7
br label %31
31: ; preds = %49, %30
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 2000
br i1 %33, label %34, label %52
34: ; preds = %31
%35 = getelementptr inbounds [2000 x i32], [2000 x i32]* %6, i64 0, i64 0
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = call i32 @pthread_rwlock_destroy(i32* %38)
store i32 %39, i32* %8
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = load i32, i32* %7
%44 = load i32, i32* %8
%45 = call i8* @strerror(i32 %44)
%46 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %43, i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %34
br label %49
49: ; preds = %48
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %31
52: ; preds = %31
%53 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"pthread_rwlock_init[%d]: %s\0A\00"
@.str.1 = [32 x i8] c"pthread_rwlock_destroy[%d]: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2000 x i32]
%4 = bitcast [2000 x i32]* %3 to i8*
br label %5
5: ; preds = %2, %16
%6 = phi i64 [ 0, %2 ], [ %17, %16 ]
%7 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 %6
%8 = call i32 @pthread_rwlock_init(i32* %7, i32* null)
%9 = icmp eq i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %5
%11 = trunc i64 %6 to i32
%12 = load i32, i32* @stderr
%13 = call i8* @strerror(i32 %8)
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %5
%17 = add nuw nsw i64 %6, 1
%18 = icmp eq i64 %17, 2000
br i1 %18, label %19, label %5
19: ; preds = %16, %30
%20 = phi i64 [ %31, %30 ], [ 0, %16 ]
%21 = getelementptr inbounds [2000 x i32], [2000 x i32]* %3, i64 0, i64 %20
%22 = call i32 @pthread_rwlock_destroy(i32* %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %19
%25 = trunc i64 %20 to i32
%26 = load i32, i32* @stderr
%27 = call i8* @strerror(i32 %22)
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %19
%31 = add nuw nsw i64 %20, 1
%32 = icmp eq i64 %31, 2000
br i1 %32, label %33, label %19
33: ; preds = %30
%34 = call i32 @exit(i32 0)
unreachable
}