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

/* Variables and functions */
int /*<<< orphan*/ fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, ...);
int sched_getscheduler(int /*<<< orphan*/);
int /*<<< orphan*/ sched_setlimit(int /*<<< orphan*/, int);
int /*<<< orphan*/ sched_setscheduler(int /*<<< orphan*/, int,
                                      struct sched_param *);
int main(void) {
  struct sched_param param = {0};
  pid_t pid;
  printf("Old Policy: %d\n", sched_getscheduler(0));
  sched_setscheduler(0, 7, &param);
  printf("New Policy: %d\n", sched_getscheduler(0));
  sched_setlimit(0, 50);
  if ((pid = fork()) != 0) {
    printf("pid: %d, policy: %d\n", getpid(), sched_getscheduler(0));
  } else
    printf("pid: %d, policy: %d\n", getpid(), sched_getscheduler(0));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
mov    $0x7,%esi
lea    -0x8(%rbp),%rdx
call   1070 <sched_setscheduler@plt>
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
mov    $0x32,%esi
call   1050 <sched_setlimit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1215 <main+0xa5>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x10(%rbp)
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1239 <main+0xc9>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
lea    0xe85(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%rdx
xor    %edi,%edi
mov    $0x7,%esi
call   1070 <sched_setscheduler@plt>
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
lea    0xe6d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
mov    $0x32,%esi
call   1050 <sched_setlimit@plt>
xor    %eax,%eax
call   1080 <fork@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1030 <sched_getscheduler@plt>
lea    0xe4a(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [16 x i8] c"Old Policy: %d\0A\00"
@.str.1 = [16 x i8] c"New Policy: %d\0A\00"
@.str.2 = [21 x i8] c"pid: %d, policy: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sched_param
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast %struct.sched_param* %2 to i8*
%5 = call i32 @sched_getscheduler(i32 0)
%6 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @sched_setscheduler(i32 0, i32 7, %struct.sched_param* %2)
%8 = call i32 @sched_getscheduler(i32 0)
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i32 @sched_setlimit(i32 0, i32 50)
%11 = call i32 (...) @fork()
store i32 %11, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = call i32 (...) @getpid()
%15 = call i32 @sched_getscheduler(i32 0)
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %15)
br label %21
17: ; preds = %0
%18 = call i32 (...) @getpid()
%19 = call i32 @sched_getscheduler(i32 0)
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %19)
br label %21
21: ; preds = %17, %13
ret i32 0
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [16 x i8] c"Old Policy: %d\0A\00"
@.str.1 = [16 x i8] c"New Policy: %d\0A\00"
@.str.2 = [21 x i8] c"pid: %d, policy: %d\0A\00"
define i32 @main() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 0, i32* %3
%4 = tail call i32 @sched_getscheduler(i32 0)
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @sched_setscheduler(i32 0, i32 7, %struct.sched_param* %1)
%7 = call i32 @sched_getscheduler(i32 0)
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 @sched_setlimit(i32 0, i32 50)
%10 = call i32 (...) @fork()
%11 = call i32 (...) @getpid()
%12 = call i32 @sched_getscheduler(i32 0)
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %12)
ret i32 0
}