#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;
};
typedef int /*<<< orphan*/ sp;

/* Variables and functions */
scalar_t__ EPERM;
scalar_t__ SCHED_FIFO;
scalar_t__ errno;
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
scalar_t__ sched_getscheduler(int /*<<< orphan*/);
int sched_setscheduler(int /*<<< orphan*/, scalar_t__, struct sched_param *);
int /*<<< orphan*/ set_normal();
int /*<<< orphan*/ terminal_error(char *);
int test_fifo(void) {
  struct sched_param sp;
  memset(&sp, 0, sizeof(sp));
  sp.sched_priority = 99;
  if (sched_setscheduler(0, SCHED_FIFO, &sp) == -1) {
    if (errno != EPERM)
      terminal_error("sched_setscheduler");
    goto out_fail;
  }
  if (sched_getscheduler(0) != SCHED_FIFO)
    goto out_fail;
  set_normal();
  return 1;
out_fail:
  set_normal();
  return 0;
}


x86 assembly (clang, -O0):
<test_fifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
movl   $0x63,-0x8(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%rsi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1040 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
jne    11b8 <test_fifo+0x68>
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%rax
je     11b3 <test_fifo+0x63>
lea    0xe52(%rip),%rdi
call   1070 <terminal_error@plt>
jmp    11e7 <test_fifo+0x97>
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%rax
je     11d4 <test_fifo+0x84>
jmp    11e7 <test_fifo+0x97>
mov    $0x0,%al
call   1060 <set_normal@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <test_fifo+0xa5>
mov    $0x0,%al
call   1060 <set_normal@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_fifo>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
movl   $0x63,(%rsp)
mov    0x2e74(%rip),%r14
mov    (%r14),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
call   1040 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
je     1199 <test_fifo+0x49>
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    $0x1,%ebx
cmp    (%r14),%rax
jne    11bb <test_fifo+0x6b>
jmp    11bd <test_fifo+0x6d>
mov    0x2e38(%rip),%rax
mov    (%rax),%rax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%rax
je     11bb <test_fifo+0x6b>
lea    0xe4a(%rip),%rdi
call   1070 <terminal_error@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <set_normal@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i64 0
@errno = global i64 0
@EPERM = global i64 0
@.str = [19 x i8] c"sched_setscheduler\00"
define i32 @test_fifo() {
%1 = alloca i32
%2 = alloca %struct.sched_param
%3 = call i32 @memset(%struct.sched_param* %2, i32 0, i32 4)
%4 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
store i32 99, i32* %4
%5 = load i64, i64* @SCHED_FIFO
%6 = call i32 @sched_setscheduler(i32 0, i64 %5, %struct.sched_param* %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EPERM
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @terminal_error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
br label %22
15: ; preds = %0
%16 = call i64 @sched_getscheduler(i32 0)
%17 = load i64, i64* @SCHED_FIFO
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
br label %22
20: ; preds = %15
%21 = call i32 (...) @set_normal()
store i32 1, i32* %1
br label %24
22: ; preds = %19, %14
%23 = call i32 (...) @set_normal()
store i32 0, i32* %1
br label %24
24: ; preds = %22, %20
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i64 0
@errno = global i64 0
@EPERM = global i64 0
@.str = [19 x i8] c"sched_setscheduler\00"
define i32 @test_fifo() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = call i32 @memset(%struct.sched_param* %1, i32 0, i32 4)
%4 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 99, i32* %4
%5 = load i64, i64* @SCHED_FIFO
%6 = call i32 @sched_setscheduler(i32 0, i64 %5, %struct.sched_param* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EPERM
%11 = icmp eq i64 %9, %10
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = call i32 @terminal_error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %18
14: ; preds = %0
%15 = call i64 @sched_getscheduler(i32 0)
%16 = load i64, i64* @SCHED_FIFO
%17 = icmp eq i64 %15, %16
br i1 %17, label %19, label %18
18: ; preds = %14, %8, %12
br label %19
19: ; preds = %14, %18
%20 = phi i32 [ 0, %18 ], [ 1, %14 ]
%21 = call i32 (...) @set_normal()
ret i32 %20
}