#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 *, ...);
scalar_t__ pthread_rwlock_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlock_init(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ pthread_rwlock_rdlock(int /*<<< orphan*/ *);
scalar_t__ pthread_rwlock_unlock(int /*<<< orphan*/ *);
int main(void) {
  static pthread_rwlock_t rwlock;
  int i;
  if (pthread_rwlock_init(&rwlock, NULL) != 0) {
    printf("main: Error at pthread_rwlock_init()\n");
    return 2;
  }
  for (i = 0; i < 10; i++) {
    if (pthread_rwlock_rdlock(&rwlock) != 0) {
      printf("Test FAILED: main cannot get read-lock rwlock number: %d\n", i);
      return 1;
    }
  }
  for (i = 0; i < 10; i++) {
    if (pthread_rwlock_unlock(&rwlock) != 0) {
      printf("Test FAILED: main cannot unlock rwlock number %d\n", i);
      return 1;
    }
  }
  if (pthread_rwlock_destroy(&rwlock) != 0) {
    printf("Error at pthread_rwlockattr_destroy()\n");
    return 2;
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0x2ee6(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <pthread_rwlock_init@plt>
cmp    $0x0,%rax
je     1193 <main+0x43>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1286 <main+0x136>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    11ea <main+0x9a>
lea    0x2ea1(%rip),%rdi
call   1050 <pthread_rwlock_rdlock@plt>
cmp    $0x0,%rax
je     11d7 <main+0x87>
mov    -0x8(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1286 <main+0x136>
jmp    11dc <main+0x8c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119a <main+0x4a>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    1241 <main+0xf1>
lea    0x2e4a(%rip),%rdi
call   1070 <pthread_rwlock_unlock@plt>
cmp    $0x0,%rax
je     122e <main+0xde>
mov    -0x8(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1286 <main+0x136>
jmp    1233 <main+0xe3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f1 <main+0xa1>
lea    0x2e04(%rip),%rdi
call   1030 <pthread_rwlock_destroy@plt>
cmp    $0x0,%rax
je     1271 <main+0x121>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1286 <main+0x136>
lea    0xe41(%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   %rbx
lea    0x2eec(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1070 <pthread_rwlock_init@plt>
test   %rax,%rax
je     1189 <main+0x29>
lea    0xf21(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
pop    %rbx
ret
lea    0x2ec4(%rip),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
test   %rax,%rax
jne    1270 <main+0x110>
lea    0x2eaf(%rip),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1270 <main+0x110>
lea    0x2e95(%rip),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
mov    $0x2,%ebx
test   %rax,%rax
jne    1270 <main+0x110>
lea    0x2e7b(%rip),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
mov    $0x3,%ebx
test   %rax,%rax
jne    1270 <main+0x110>
lea    0x2e61(%rip),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
mov    $0x4,%ebx
test   %rax,%rax
jne    1270 <main+0x110>
lea    0x2e4b(%rip),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
mov    $0x5,%ebx
test   %rax,%rax
jne    1270 <main+0x110>
lea    0x2e35(%rip),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
mov    $0x6,%ebx
test   %rax,%rax
jne    1270 <main+0x110>
lea    0x2e1f(%rip),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
mov    $0x7,%ebx
test   %rax,%rax
jne    1270 <main+0x110>
lea    0x2e09(%rip),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
mov    $0x8,%ebx
test   %rax,%rax
jne    1270 <main+0x110>
lea    0x2df3(%rip),%rdi
call   1060 <pthread_rwlock_rdlock@plt>
mov    $0x9,%ebx
test   %rax,%rax
je     1287 <main+0x127>
lea    0xd89(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0x2dc6(%rip),%rdi
call   1080 <pthread_rwlock_unlock@plt>
xor    %esi,%esi
test   %rax,%rax
jne    1370 <main+0x210>
lea    0x2daf(%rip),%rdi
call   1080 <pthread_rwlock_unlock@plt>
mov    $0x1,%esi
test   %rax,%rax
jne    1370 <main+0x210>
lea    0x2d95(%rip),%rdi
call   1080 <pthread_rwlock_unlock@plt>
mov    $0x2,%esi
test   %rax,%rax
jne    1370 <main+0x210>
lea    0x2d7b(%rip),%rdi
call   1080 <pthread_rwlock_unlock@plt>
mov    $0x3,%esi
test   %rax,%rax
jne    1370 <main+0x210>
lea    0x2d61(%rip),%rdi
call   1080 <pthread_rwlock_unlock@plt>
mov    $0x4,%esi
test   %rax,%rax
jne    1370 <main+0x210>
lea    0x2d4b(%rip),%rdi
call   1080 <pthread_rwlock_unlock@plt>
mov    $0x5,%esi
test   %rax,%rax
jne    1370 <main+0x210>
lea    0x2d35(%rip),%rdi
call   1080 <pthread_rwlock_unlock@plt>
mov    $0x6,%esi
test   %rax,%rax
jne    1370 <main+0x210>
lea    0x2d1f(%rip),%rdi
call   1080 <pthread_rwlock_unlock@plt>
mov    $0x7,%esi
test   %rax,%rax
jne    1370 <main+0x210>
lea    0x2d09(%rip),%rdi
call   1080 <pthread_rwlock_unlock@plt>
mov    $0x8,%esi
test   %rax,%rax
jne    1370 <main+0x210>
lea    0x2cf3(%rip),%rdi
call   1080 <pthread_rwlock_unlock@plt>
mov    $0x9,%esi
test   %rax,%rax
je     137c <main+0x21c>
lea    0xcc3(%rip),%rdi
jmp    1279 <main+0x119>
lea    0x2cd1(%rip),%rdi
call   1040 <pthread_rwlock_destroy@plt>
test   %rax,%rax
je     1399 <main+0x239>
lea    0xce4(%rip),%rdi
jmp    117d <main+0x1d>
lea    0xccc(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@main.rwlock = internal global i32 0
@.str = [38 x i8] c"main: Error at pthread_rwlock_init()\0A\00"
@.str.1 = [58 x i8] c"Test FAILED: main cannot get read-lock rwlock number: %d\0A\00"
@.str.2 = [50 x i8] c"Test FAILED: main cannot unlock rwlock number %d\0A\00"
@.str.3 = [39 x i8] c"Error at pthread_rwlockattr_destroy()\0A\00"
@.str.4 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i64 @pthread_rwlock_init(i32* @main.rwlock, i32* null)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %1
br label %42
7: ; preds = %0
store i32 0, i32* %2
br label %8
8: ; preds = %18, %7
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 1, i32* %1
br label %42
17: ; preds = %11
br label %18
18: ; preds = %17
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %8
21: ; preds = %8
store i32 0, i32* %2
br label %22
22: ; preds = %32, %21
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 10
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 %29)
store i32 1, i32* %1
br label %42
31: ; preds = %25
br label %32
32: ; preds = %31
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
br label %22
35: ; preds = %22
%36 = call i64 @pthread_rwlock_destroy(i32* @main.rwlock)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %1
br label %42
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %42
42: ; preds = %40, %38, %28, %14, %5
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@main.rwlock = internal global i32 0
@.str.1 = [58 x i8] c"Test FAILED: main cannot get read-lock rwlock number: %d\0A\00"
@.str.2 = [50 x i8] c"Test FAILED: main cannot unlock rwlock number %d\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.5 = [38 x i8] c"Error at pthread_rwlockattr_destroy()\00"
@str.6 = [37 x i8] c"main: Error at pthread_rwlock_init()\00"
define i32 @main() {
%1 = tail call i64 @pthread_rwlock_init(i32* @main.rwlock, i32* null)
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.6, i64 0, i64 0))
br label %78
8: ; preds = %35, %32, %29, %26, %23, %20, %17, %14, %11, %3
%9 = phi i32 [ 0, %3 ], [ 1, %11 ], [ 2, %14 ], [ 3, %17 ], [ 4, %20 ], [ 5, %23 ], [ 6, %26 ], [ 7, %29 ], [ 8, %32 ], [ 9, %35 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %78
11: ; preds = %3
%12 = tail call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %8
14: ; preds = %11
%15 = tail call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %8
17: ; preds = %14
%18 = tail call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %8
20: ; preds = %17
%21 = tail call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %8
23: ; preds = %20
%24 = tail call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %8
26: ; preds = %23
%27 = tail call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %8
29: ; preds = %26
%30 = tail call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %8
32: ; preds = %29
%33 = tail call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %8
35: ; preds = %32
%36 = tail call i64 @pthread_rwlock_rdlock(i32* @main.rwlock)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %8
38: ; preds = %35
%39 = tail call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %68, %65, %62, %59, %56, %53, %50, %47, %44, %38
%42 = phi i32 [ 0, %38 ], [ 1, %44 ], [ 2, %47 ], [ 3, %50 ], [ 4, %53 ], [ 5, %56 ], [ 6, %59 ], [ 7, %62 ], [ 8, %65 ], [ 9, %68 ]
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %78
44: ; preds = %38
%45 = tail call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %41
47: ; preds = %44
%48 = tail call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %41
50: ; preds = %47
%51 = tail call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %41
53: ; preds = %50
%54 = tail call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %41
56: ; preds = %53
%57 = tail call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %41
59: ; preds = %56
%60 = tail call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %41
62: ; preds = %59
%63 = tail call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %41
65: ; preds = %62
%66 = tail call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %41
68: ; preds = %65
%69 = tail call i64 @pthread_rwlock_unlock(i32* @main.rwlock)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %41
71: ; preds = %68
%72 = tail call i64 @pthread_rwlock_destroy(i32* @main.rwlock)
%73 = icmp eq i64 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %71
%75 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
br label %78
76: ; preds = %71
%77 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %78
78: ; preds = %76, %74, %41, %8, %6
%79 = phi i32 [ 2, %6 ], [ 1, %8 ], [ 1, %41 ], [ 2, %74 ], [ 0, %76 ]
ret i32 %79
}