#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 */
struct sched_param {
  int sched_priority;
};

/* Variables and functions */
scalar_t__ EINVAL;
int /*<<< orphan*/ SCHED_OTHER;
int /*<<< orphan*/ abort();
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ printf(char *);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int main(void) {
  struct sched_param sb;
  sb.sched_priority = 0;
  if (sched_setscheduler(getpid(), SCHED_OTHER, &sb) != 0 ||
      sb.sched_priority != 0)
    abort();
  sb.sched_priority = 5;
  if (sched_setscheduler(getpid(), SCHED_OTHER, &sb) != -1 || errno != EINVAL ||
      sb.sched_priority != 5)
    abort();
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
cmp    $0x0,%eax
jne    1194 <main+0x44>
cmpl   $0x0,-0x8(%rbp)
je     119b <main+0x4b>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x5,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1060 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    11ea <main+0x9a>
mov    0x2e0b(%rip),%rax
mov    (%rax),%rax
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
jne    11ea <main+0x9a>
cmpl   $0x5,-0x8(%rbp)
je     11f1 <main+0xa1>
mov    $0x0,%al
call   1030 <abort@plt>
lea    0xe08(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    0x2e75(%rip),%rbx
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1060 <sched_setscheduler@plt>
or     0x8(%rsp),%eax
jne    11d1 <main+0x81>
movl   $0x5,0x8(%rsp)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1060 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    11d1 <main+0x81>
mov    0x2e30(%rip),%rax
mov    (%rax),%rax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%rax
jne    11d1 <main+0x81>
cmpl   $0x5,0x8(%rsp)
jne    11d1 <main+0x81>
lea    0xe3b(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_OTHER = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@.str = [6 x i8] c"pass\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sched_param
store i32 0, i32* %1
%3 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
store i32 0, i32* %3
%4 = call i32 (...) @getpid()
%5 = load i32, i32* @SCHED_OTHER
%6 = call i32 @sched_setscheduler(i32 %4, i32 %5, %struct.sched_param* %2)
%7 = icmp ne i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
%10 = load i32, i32* %9
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8, %0
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %8
%15 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
store i32 5, i32* %15
%16 = call i32 (...) @getpid()
%17 = load i32, i32* @SCHED_OTHER
%18 = call i32 @sched_setscheduler(i32 %16, i32 %17, %struct.sched_param* %2)
%19 = icmp ne i32 %18, -1
br i1 %19, label %28, label %20
20: ; preds = %14
%21 = load i64, i64* @errno
%22 = load i64, i64* @EINVAL
%23 = icmp ne i64 %21, %22
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 5
br i1 %27, label %28, label %30
28: ; preds = %24, %20, %14
%29 = call i32 (...) @abort()
unreachable
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_OTHER = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@str = [5 x i8] c"pass\00"
define i32 @main() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 0, i32* %3
%4 = tail call i32 (...) @getpid()
%5 = load i32, i32* @SCHED_OTHER
%6 = call i32 @sched_setscheduler(i32 %4, i32 %5, %struct.sched_param* %1)
%7 = icmp ne i32 %6, 0
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (...) @abort()
unreachable
13: ; preds = %0
store i32 5, i32* %3
%14 = call i32 (...) @getpid()
%15 = load i32, i32* @SCHED_OTHER
%16 = call i32 @sched_setscheduler(i32 %14, i32 %15, %struct.sched_param* %1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %25
18: ; preds = %13
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINVAL
%21 = icmp ne i64 %19, %20
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, 5
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %25, label %27
25: ; preds = %18, %13
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %18
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
}