#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;
};
typedef int pid_t;

/* Variables and functions */
int SCHED_OTHER;
void *atol(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
scalar_t__ sched_setscheduler(int, int, struct sched_param *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  pid_t pid;
  int policy;
  struct sched_param p;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s pid policy priority\n", argv[0]);
    exit(-1);
  }
  pid = atol(argv[1]);
  policy = atol(argv[2]);
  if (policy > 2) {
    policy = SCHED_OTHER;
  }
  p.sched_priority = atol(argv[3]);
  printf("pid = %d \t policy = %d \t priority = %d\n", pid, policy,
         p.sched_priority);
  if (sched_setscheduler(pid, policy, &p) < 0) {
    perror("sched_setscheduler");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11a6 <main+0x46>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atol@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
jle    11dc <main+0x7c>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atol@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1040 <sched_setscheduler@plt>
cmp    $0x0,%rax
jge    1230 <main+0xd0>
lea    0xe26(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    11e5 <main+0x85>
mov    0x8(%rbx),%rdi
call   1060 <atol@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
call   1060 <atol@plt>
mov    %rax,%r15
cmp    $0x3,%r15d
jl     1199 <main+0x39>
mov    0x2e42(%rip),%rax
mov    (%rax),%r15d
mov    0x18(%rbx),%rdi
call   1060 <atol@plt>
mov    %eax,0x8(%rsp)
lea    0xe72(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
mov    %r15d,%esi
call   1040 <sched_setscheduler@plt>
test   %rax,%rax
jns    1207 <main+0xa7>
lea    0xe71(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe08(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"Usage: %s pid policy priority\0A\00"
@SCHED_OTHER = global i32 0
@.str.1 = [40 x i8] c"pid = %d \09 policy = %d \09 priority = %d\0A\00"
@.str.2 = [19 x i8] c"sched_setscheduler\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sched_param
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i8* @atol(i8* %21)
%23 = ptrtoint i8* %22 to i32
store i32 %23, i32* %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i8* @atol(i8* %26)
%28 = ptrtoint i8* %27 to i32
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp sgt i32 %29, 2
br i1 %30, label %31, label %33
31: ; preds = %18
%32 = load i32, i32* @SCHED_OTHER
store i32 %32, i32* %7
br label %33
33: ; preds = %31, %18
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i8* @atol(i8* %36)
%38 = ptrtoint i8* %37 to i32
%39 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %8, i32 0, i32 0
store i32 %38, i32* %39
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %8, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %41, i32 %43)
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = call i64 @sched_setscheduler(i32 %45, i32 %46, %struct.sched_param* %8)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %33
%50 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %33
%53 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"Usage: %s pid policy priority\0A\00"
@SCHED_OTHER = global i32 0
@.str.1 = [40 x i8] c"pid = %d \09 policy = %d \09 priority = %d\0A\00"
@.str.2 = [19 x i8] c"sched_setscheduler\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sched_param
%4 = bitcast %struct.sched_param* %3 to i8*
%5 = icmp eq i32 %0, 4
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i8* @atol(i8* %13)
%15 = ptrtoint i8* %14 to i64
%16 = trunc i64 %15 to i32
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i8* @atol(i8* %18)
%20 = ptrtoint i8* %19 to i64
%21 = trunc i64 %20 to i32
%22 = icmp sgt i32 %21, 2
%23 = load i32, i32* @SCHED_OTHER
%24 = select i1 %22, i32 %23, i32 %21
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = tail call i8* @atol(i8* %26)
%28 = ptrtoint i8* %27 to i64
%29 = trunc i64 %28 to i32
%30 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
store i32 %29, i32* %30
%31 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %24, i32 %29)
%32 = call i64 @sched_setscheduler(i32 %16, i32 %24, %struct.sched_param* %3)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %11
%35 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %11
%38 = call i32 @exit(i32 0)
unreachable
}