#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 */

/* Variables and functions */
int /*<<< orphan*/ SCHED_OTHER;
scalar_t__ errno;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sched_get_priority_max(int /*<<< orphan*/);
int main(void) {
  int result = -1;
  result = sched_get_priority_max(SCHED_OTHER);
  if (result != -1 && errno == 0) {
    printf("The maximum priority for policy SCHED_OTHER is %i.\n", result);
    printf("Test PASSED\n");
    return 0;
  } else {
    perror("An error occurs");
    return 1;
  }
  printf("This code should not be executed.\n");
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_max@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     119d <main+0x6d>
mov    0x2e70(%rip),%rax
cmpq   $0x0,(%rax)
jne    119d <main+0x6d>
mov    -0x8(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <main+0x80>
lea    0xe9d(%rip),%rdi
call   1040 <perror@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
call   1060 <sched_get_priority_max@plt>
cmp    $0xffffffff,%eax
je     1183 <main+0x43>
mov    0x2e7d(%rip),%rcx
cmpq   $0x0,(%rcx)
jne    1183 <main+0x43>
lea    0xe98(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xeaa(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%ebx
jmp    117f <main+0x3f>

LLVM IR (-O0):
@SCHED_OTHER = global i32 0
@errno = global i64 0
@.str = [52 x i8] c"The maximum priority for policy SCHED_OTHER is %i.\0A\00"
@.str.1 = [13 x i8] c"Test PASSED\0A\00"
@.str.2 = [16 x i8] c"An error occurs\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
%3 = load i32, i32* @SCHED_OTHER
%4 = call i32 @sched_get_priority_max(i32 %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %16
14: ; preds = %7, %0
%15 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %16
16: ; preds = %14, %10
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@SCHED_OTHER = global i32 0
@errno = global i64 0
@.str = [52 x i8] c"The maximum priority for policy SCHED_OTHER is %i.\0A\00"
@.str.2 = [16 x i8] c"An error occurs\00"
@str = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = load i32, i32* @SCHED_OTHER
%2 = tail call i32 @sched_get_priority_max(i32 %1)
%3 = icmp ne i32 %2, -1
%4 = load i64, i64* @errno
%5 = icmp eq i64 %4, 0
%6 = select i1 %3, i1 %5, i1 false
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %2)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %12
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ 0, %7 ], [ 1, %10 ]
ret i32 %13
}