#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_RR;
int get_sched_policy();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
int main() {
  int ret;
  struct sched_param sp;
  ret = get_sched_policy();
  printf("Tyring to set a new policy: RR?\n");
  sp.sched_priority = 2;
  ret = sched_setscheduler(0, SCHED_RR, &sp);
  if (ret == -1)
    perror("sched_setpriority");
  printf("The current policy is....\n");
  ret = get_sched_policy();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <get_sched_policy@plt>
mov    %eax,-0x8(%rbp)
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x10(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1050 <sched_setscheduler@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1199 <main+0x59>
lea    0xe8d(%rip),%rdi
call   1060 <perror@plt>
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <get_sched_policy@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1040 <get_sched_policy@plt>
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
movl   $0x2,(%rsp)
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1050 <sched_setscheduler@plt>
cmp    $0xffffffff,%eax
je     118a <main+0x4a>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <get_sched_policy@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe6f(%rip),%rdi
call   1060 <perror@plt>
jmp    1173 <main+0x33>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [33 x i8] c"Tyring to set a new policy: RR?\0A\00"
@SCHED_RR = global i32 0
@.str.1 = [18 x i8] c"sched_setpriority\00"
@.str.2 = [27 x i8] c"The current policy is....\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sched_param
store i32 0, i32* %1
%4 = call i32 (...) @get_sched_policy()
store i32 %4, i32* %2
%5 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
store i32 2, i32* %6
%7 = load i32, i32* @SCHED_RR
%8 = call i32 @sched_setscheduler(i32 0, i32 %7, %struct.sched_param* %3)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (...) @get_sched_policy()
store i32 %15, i32* %2
ret i32 0
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@.str.1 = [18 x i8] c"sched_setpriority\00"
@str = [32 x i8] c"Tyring to set a new policy: RR?\00"
@str.3 = [26 x i8] c"The current policy is....\00"
define i32 @main() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = tail call i32 (...) @get_sched_policy()
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%5 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 2, i32* %5
%6 = load i32, i32* @SCHED_RR
%7 = call i32 @sched_setscheduler(i32 0, i32 %6, %struct.sched_param* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.3, i64 0, i64 0))
%13 = call i32 (...) @get_sched_policy()
ret i32 0
}