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

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ printf(char *, ...);
int pthread_mutexattr_getprioceiling(int /*<<< orphan*/ *, int *);
int main(void) {
  int prioceiling, ret;
  pthread_mutexattr_t mta;
  if ((ret = pthread_mutexattr_getprioceiling(&mta, &prioceiling)) == 0) {
    printf("Test PASSED: *Note: Returned 0 instead of EINVAL when passed an "
           "uninitialized mutex attribute object to "
           "pthread_mutexattr_getprioceiling, but standard says 'may' fail.\n");
    return 0;
  } else if (ret != EINVAL) {
    printf("Test FAILED: Invalid return code %d. Expected EINVAL or 0.\n", ret);
    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)
lea    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <pthread_mutexattr_getprioceiling@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    1162 <main+0x42>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ab <main+0x8b>
mov    -0xc(%rbp),%eax
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%eax
je     1191 <main+0x71>
mov    -0xc(%rbp),%esi
lea    0xf2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ab <main+0x8b>
jmp    1196 <main+0x76>
lea    0xf48(%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
mov    %rsp,%rdi
lea    0x4(%rsp),%rsi
call   1050 <pthread_mutexattr_getprioceiling@plt>
test   %eax,%eax
je     1156 <main+0x26>
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%eax
jne    1166 <main+0x36>
lea    0xee8(%rip),%rdi
jmp    115d <main+0x2d>
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe93(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [169 x i8] c"Test PASSED: *Note: Returned 0 instead of EINVAL when passed an uninitialized mutex attribute object to pthread_mutexattr_getprioceiling, but standard says 'may' fail.\0A\00"
@EINVAL = global i32 0
@.str.1 = [60 x i8] c"Test FAILED: Invalid return code %d. Expected EINVAL or 0.\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
%5 = call i32 @pthread_mutexattr_getprioceiling(i32* %4, i32* %2)
store i32 %5, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %19
9: ; preds = %0
%10 = load i32, i32* %3
%11 = load i32, i32* @EINVAL
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 1, i32* %1
br label %19
16: ; preds = %9
br label %17
17: ; preds = %16
%18 = 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 %19
19: ; preds = %17, %13, %7
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@EINVAL = global i32 0
@.str.1 = [60 x i8] c"Test FAILED: Invalid return code %d. Expected EINVAL or 0.\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.3 = [168 x i8] c"Test PASSED: *Note: Returned 0 instead of EINVAL when passed an uninitialized mutex attribute object to pthread_mutexattr_getprioceiling, but standard says 'may' fail.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @pthread_mutexattr_getprioceiling(i32* %2, i32* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([168 x i8], [168 x i8]* @str.3, i64 0, i64 0))
br label %16
9: ; preds = %0
%10 = load i32, i32* @EINVAL
%11 = icmp eq i32 %5, %10
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %16
14: ; preds = %9
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %12, %7
%17 = phi i32 [ 0, %7 ], [ 1, %12 ], [ 0, %14 ]
ret i32 %17
}