#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 */

/* Variables and functions */
#define SCHED_FIFO 130
#define SCHED_OTHER 129
#define SCHED_RR 128
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sched_getscheduler(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int get_sched_policy() {
  int policy;
  policy = sched_getscheduler(0);
  switch (policy) {
  case SCHED_OTHER:
    printf("Policy is normal\n");
    break;
  case SCHED_RR:
    printf("Policy is round-robin\n");
    break;
  case SCHED_FIFO:
    printf("Policy is first-in, first-out\n");
    break;
  case -1:
    perror("sched_getscheduler");
    break;
  default:
    fprintf(stderr, "Unknown policy!\n");
    return -1;
  }
  return policy;
}


x86 assembly (clang, -O0):
<get_sched_policy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0xffffffff,%eax
je     11d2 <get_sched_policy+0x92>
jmp    1166 <get_sched_policy+0x26>
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
je     11b0 <get_sched_policy+0x70>
jmp    1179 <get_sched_policy+0x39>
mov    -0xc(%rbp),%eax
sub    $0x81,%eax
je     119f <get_sched_policy+0x5f>
jmp    118c <get_sched_policy+0x4c>
mov    -0xc(%rbp),%eax
sub    $0x82,%eax
je     11c1 <get_sched_policy+0x81>
jmp    11e3 <get_sched_policy+0xa3>
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
jmp    1204 <get_sched_policy+0xc4>
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
jmp    1204 <get_sched_policy+0xc4>
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
jmp    1204 <get_sched_policy+0xc4>
lea    0xe6f(%rip),%rdi
call   1060 <perror@plt>
jmp    1204 <get_sched_policy+0xc4>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <get_sched_policy+0xca>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sched_policy>:
push   %rax
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
cmp    $0x80,%eax
jle    1170 <get_sched_policy+0x30>
cmp    $0x82,%eax
je     1185 <get_sched_policy+0x45>
cmp    $0x81,%eax
jne    119d <get_sched_policy+0x5d>
lea    0xef4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x81,%eax
pop    %rcx
ret
jne    1198 <get_sched_policy+0x58>
lea    0xec9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x80,%eax
pop    %rcx
ret
lea    0xe98(%rip),%rdi
call   1040 <puts@plt>
mov    $0x82,%eax
pop    %rcx
ret
cmp    $0xffffffff,%eax
je     11b9 <get_sched_policy+0x79>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
lea    0xe40(%rip),%rdi
call   1060 <perror@plt>
jmp    11b2 <get_sched_policy+0x72>

LLVM IR (-O0):
@.str = [18 x i8] c"Policy is normal\0A\00"
@.str.1 = [23 x i8] c"Policy is round-robin\0A\00"
@.str.2 = [31 x i8] c"Policy is first-in, first-out\0A\00"
@.str.3 = [19 x i8] c"sched_getscheduler\00"
@stderr = global i32 0
@.str.4 = [17 x i8] c"Unknown policy!\0A\00"
define i32 @get_sched_policy() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @sched_getscheduler(i32 0)
store i32 %3, i32* %2
%4 = load i32, i32* %2
switch i32 %4, label %13 [
i32 129, label %5
i32 128, label %7
i32 130, label %9
i32 -1, label %11
]
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %16
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %16
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %16
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %16
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %18
16: ; preds = %11, %9, %7, %5
%17 = load i32, i32* %2
store i32 %17, i32* %1
br label %18
18: ; preds = %16, %13
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str.3 = [19 x i8] c"sched_getscheduler\00"
@stderr = global i32 0
@.str.4 = [17 x i8] c"Unknown policy!\0A\00"
@str = [30 x i8] c"Policy is first-in, first-out\00"
@str.5 = [22 x i8] c"Policy is round-robin\00"
@str.6 = [17 x i8] c"Policy is normal\00"
define i32 @get_sched_policy() {
%1 = tail call i32 @sched_getscheduler(i32 0)
switch i32 %1, label %10 [
i32 129, label %2
i32 128, label %4
i32 130, label %6
i32 -1, label %8
]
2: ; preds = %0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
br label %13
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0))
br label %13
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %13
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %13
13: ; preds = %2, %4, %6, %8, %10
%14 = phi i32 [ -1, %10 ], [ -1, %8 ], [ 130, %6 ], [ 128, %4 ], [ 129, %2 ]
ret i32 %14
}