#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ SCHED_OTHER;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sched_param *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int sched_get_priority_min(int /*<<< orphan*/);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                              struct sched_param *);
int system_user_can_rtprio() {
  int min_prio;
  struct sched_param schparam;
  memset(&schparam, 0, sizeof(struct sched_param));
  if (-1 == (min_prio = sched_get_priority_min(SCHED_FIFO))) {
    perror("sched_get_priority");
    exit(EXIT_FAILURE);
  }
  schparam.sched_priority = min_prio;
  if (0 == sched_setscheduler(0, SCHED_FIFO, &schparam)) {
    schparam.sched_priority = 0;
    if (0 != sched_setscheduler(0, SCHED_OTHER, &schparam)) {
      perror("sched_setscheduler");
      exit(EXIT_FAILURE);
    }
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<system_user_can_rtprio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1050 <sched_get_priority_min@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11a2 <system_user_can_rtprio+0x52>
lea    0xe71(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1219 <system_user_can_rtprio+0xc9>
movl   $0x0,-0x10(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     120d <system_user_can_rtprio+0xbd>
lea    0xe19(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x1,-0x4(%rbp)
jmp    1220 <system_user_can_rtprio+0xd0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_user_can_rtprio>:
push   %rbp
push   %rbx
push   %rax
mov    %rsp,%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e7d(%rip),%rbx
mov    (%rbx),%edi
call   1050 <sched_get_priority_min@plt>
cmp    $0xffffffff,%eax
je     11b8 <system_user_can_rtprio+0x68>
mov    %eax,(%rsp)
mov    (%rbx),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
test   %rax,%rax
jne    11af <system_user_can_rtprio+0x5f>
movl   $0x0,(%rsp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1030 <sched_setscheduler@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11c1 <system_user_can_rtprio+0x71>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe41(%rip),%rdi
jmp    11c8 <system_user_can_rtprio+0x78>
lea    0xe4b(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [19 x i8] c"sched_get_priority\00"
@EXIT_FAILURE = global i32 0
@SCHED_OTHER = global i32 0
@.str.1 = [19 x i8] c"sched_setscheduler\00"
define i32 @system_user_can_rtprio() {
%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 = load i32, i32* @SCHED_FIFO
%5 = call i32 @sched_get_priority_min(i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 %5, i32* %12
%13 = load i32, i32* @SCHED_FIFO
%14 = call i64 @sched_setscheduler(i32 0, i32 %13, %struct.sched_param* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %11
store i32 0, i32* %12
%17 = load i32, i32* @SCHED_OTHER
%18 = call i64 @sched_setscheduler(i32 0, i32 %17, %struct.sched_param* %1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %11, %16
%25 = phi i32 [ 1, %16 ], [ 0, %11 ]
ret i32 %25
}