#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*/ SCHED_FIFO;
int /*<<< orphan*/ printf(char *);
int sched_get_priority_max(int /*<<< orphan*/);
scalar_t__ sched_getparam(int /*<<< orphan*/, struct sched_param *);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                              struct sched_param *);
int go_realtime(void) {
  int max_pri;
  struct sched_param sp;
  if (sched_getparam(0, &sp))
    goto _go_err;
  max_pri = sched_get_priority_max(SCHED_FIFO);
  sp.sched_priority = max_pri;
  if (sched_setscheduler(0, SCHED_FIFO, &sp))
    goto _go_err;
  return 0;
_go_err:
  printf(">> Warning: We're not realtime! Are you root?\n");
  return -1;
}


x86 assembly (clang, -O0):
<go_realtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
lea    -0x10(%rbp),%rsi
call   1040 <sched_getparam@plt>
cmp    $0x0,%rax
je     1162 <go_realtime+0x22>
jmp    11a8 <go_realtime+0x68>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1060 <sched_get_priority_max@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1050 <sched_setscheduler@plt>
cmp    $0x0,%rax
je     119c <go_realtime+0x5c>
jmp    11a8 <go_realtime+0x68>
movl   $0x0,-0x4(%rbp)
jmp    11bb <go_realtime+0x7b>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<go_realtime>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %edi,%edi
call   1040 <sched_getparam@plt>
test   %rax,%rax
jne    1179 <go_realtime+0x39>
mov    0x2e8c(%rip),%r14
mov    (%r14),%edi
call   1060 <sched_get_priority_max@plt>
mov    %eax,(%rsp)
mov    (%r14),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1050 <sched_setscheduler@plt>
test   %rax,%rax
je     118a <go_realtime+0x4a>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [47 x i8] c">> Warning: We're not realtime! Are you root?\0A\00"
define i32 @go_realtime() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sched_param
%4 = call i64 @sched_getparam(i32 0, %struct.sched_param* %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
br label %17
7: ; preds = %0
%8 = load i32, i32* @SCHED_FIFO
%9 = call i32 @sched_get_priority_max(i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* @SCHED_FIFO
%13 = call i64 @sched_setscheduler(i32 0, i32 %12, %struct.sched_param* %3)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %7
br label %17
16: ; preds = %7
store i32 0, i32* %1
br label %19
17: ; preds = %15, %6
%18 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %19
19: ; preds = %17, %16
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@str = [46 x i8] c">> Warning: We're not realtime! Are you root?\00"
define i32 @go_realtime() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = call i64 @sched_getparam(i32 0, %struct.sched_param* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = load i32, i32* @SCHED_FIFO
%7 = call i32 @sched_get_priority_max(i32 %6)
%8 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 %7, i32* %8
%9 = load i32, i32* @SCHED_FIFO
%10 = call i64 @sched_setscheduler(i32 0, i32 %9, %struct.sched_param* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %5, %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %5, %12
%15 = phi i32 [ -1, %12 ], [ 0, %5 ]
ret i32 %15
}