#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*/ SCHED_FIFO;
int /*<<< orphan*/ printf(char *, ...);
int pthread_mutexattr_setprioceiling(int /*<<< orphan*/ *, int);
int sched_get_priority_min(int /*<<< orphan*/);
int main(void) {
  pthread_mutexattr_t mta;
  int prioceiling, ret;
  prioceiling = sched_get_priority_min(SCHED_FIFO);
  if ((ret = pthread_mutexattr_setprioceiling(&mta, prioceiling)) == 0) {
    printf("Test PASSED: *Note: Returned 0 instead of EINVAL when passed an "
           "uninitialized mutex attribute object to "
           "pthread_mutexattr_setprioceiling, but standard says 'may' fail.\n");
    return 0;
  }
  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)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
call   1040 <sched_get_priority_min@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    -0x8(%rbp),%rdi
call   1050 <pthread_mutexattr_setprioceiling@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    1182 <main+0x52>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <main+0x96>
mov    -0x10(%rbp),%eax
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%eax
je     11b1 <main+0x81>
mov    -0x10(%rbp),%esi
lea    0xf0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c6 <main+0x96>
lea    0xf2d(%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    0x2ea0(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_min@plt>
lea    0x4(%rsp),%rdi
mov    %eax,%esi
call   1060 <pthread_mutexattr_setprioceiling@plt>
test   %eax,%eax
je     1173 <main+0x33>
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%eax
jne    1183 <main+0x43>
lea    0xecb(%rip),%rdi
jmp    117a <main+0x3a>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe76(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@SCHED_FIFO = global i32 0
@.str = [169 x i8] c"Test PASSED: *Note: Returned 0 instead of EINVAL when passed an uninitialized mutex attribute object to pthread_mutexattr_setprioceiling, 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 = load i32, i32* @SCHED_FIFO
%6 = call i32 @sched_get_priority_min(i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @pthread_mutexattr_setprioceiling(i32* %2, i32 %7)
store i32 %8, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = 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 %21
12: ; preds = %0
%13 = load i32, i32* %4
%14 = load i32, i32* @EINVAL
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %17)
store i32 1, i32* %1
br label %21
19: ; preds = %12
%20 = 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 %21
21: ; preds = %19, %16, %10
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@SCHED_FIFO = global i32 0
@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_setprioceiling, but standard says 'may' fail.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @SCHED_FIFO
%4 = tail call i32 @sched_get_priority_min(i32 %3)
%5 = call i32 @pthread_mutexattr_setprioceiling(i32* %1, i32 %4)
%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
}