#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 EINVAL;
int /*<<< orphan*/ printf(char *, ...);
int pthread_rwlock_unlock(int /*<<< orphan*/ *);
int main(void) {
  static pthread_rwlock_t rwlock;
  int rc;
  rc = pthread_rwlock_unlock(&rwlock);
  if (rc != 0) {
    if (rc == EINVAL) {
      printf("Test PASSED\n");
      return 0;
    }
    printf("Test FAILED: Incorrect error code, expected 0 or EINVAL, got %d\n",
           rc);
    return 1;
  }
  printf("Test PASSED: Note*: Returned 0 instead of EINVAL, but standard "
         "specified _may_ fail.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0x2efe(%rip),%rdi
call   1040 <pthread_rwlock_unlock@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1191 <main+0x71>
mov    -0x8(%rbp),%eax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%eax
jne    1174 <main+0x54>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a6 <main+0x86>
mov    -0x8(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a6 <main+0x86>
lea    0xeb6(%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    0x2f04(%rip),%rdi
call   1050 <pthread_rwlock_unlock@plt>
test   %eax,%eax
je     1155 <main+0x25>
mov    0x2e98(%rip),%rcx
cmp    (%rcx),%eax
jne    1165 <main+0x35>
lea    0xf43(%rip),%rdi
jmp    115c <main+0x2c>
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe94(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@main.rwlock = internal global i32 0
@EINVAL = global i32 0
@.str = [13 x i8] c"Test PASSED\0A\00"
@.str.1 = [65 x i8] c"Test FAILED: Incorrect error code, expected 0 or EINVAL, got %d\0A\00"
@.str.2 = [86 x i8] c"Test PASSED: Note*: Returned 0 instead of EINVAL, but standard specified _may_ fail.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @pthread_rwlock_unlock(i32* @main.rwlock)
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %0
%7 = load i32, i32* %2
%8 = load i32, i32* @EINVAL
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %17
12: ; preds = %6
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 1, i32* %1
br label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %17
17: ; preds = %15, %12, %10
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@main.rwlock = internal global i32 0
@EINVAL = global i32 0
@.str.1 = [65 x i8] c"Test FAILED: Incorrect error code, expected 0 or EINVAL, got %d\0A\00"
@str = [85 x i8] c"Test PASSED: Note*: Returned 0 instead of EINVAL, but standard specified _may_ fail.\00"
@str.3 = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = tail call i32 @pthread_rwlock_unlock(i32* @main.rwlock)
%2 = icmp eq i32 %1, 0
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = load i32, i32* @EINVAL
%5 = icmp eq i32 %1, %4
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.3, i64 0, i64 0))
br label %12
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %12
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %10, %8, %6
%13 = phi i32 [ 0, %6 ], [ 1, %8 ], [ 0, %10 ]
ret i32 %13
}