#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 {
  scalar_t__ sched_priority;
};
typedef int /*<<< orphan*/ msg;

/* Variables and functions */
int /*<<< orphan*/ PRIO_PROCESS;
int atoi(char const *);
scalar_t__ errno;
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ perror(char *);
scalar_t__ sched_setscheduler(int /*<<< orphan*/, int, struct sched_param *);
scalar_t__ setpriority(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int main(int argc, const char *argv[]) {
  int nice = 19;
  struct sched_param sp;
  char msg[50];
  if (argc >= 2) {
    nice = atoi(argv[1]);
  }
  sp.sched_priority = 0;
  if (sched_setscheduler(0, 3, &sp)) {
    perror("sched_setscheduler(0,SCHED_BATCH,{.sched_priority=0}");
  }
  if (setpriority(PRIO_PROCESS, 0, nice) || errno) {
    (void)snprintf(msg, sizeof(msg), "setpriority(PRIO_PROCESS, 0, %d)", nice);
    perror(msg);
  }
  while (1) {
    getchar();
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x13,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1197 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %edi,%edi
mov    $0x3,%esi
lea    -0x20(%rbp),%rdx
call   1050 <sched_setscheduler@plt>
cmp    $0x0,%rax
je     11c5 <main+0x65>
lea    0xe40(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <setpriority@plt>
cmp    $0x0,%rax
jne    11f3 <main+0x93>
mov    0x2def(%rip),%rax
cmpq   $0x0,(%rax)
je     1214 <main+0xb4>
lea    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x32,%esi
lea    0xe2f(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x60(%rbp),%rdi
call   1070 <perror@plt>
jmp    1219 <main+0xb9>
mov    $0x0,%al
call   1060 <getchar@plt>
jmp    1219 <main+0xb9>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    $0x13,%ebx
cmp    $0x2,%edi
jl     117c <main+0x1c>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdx
xor    %edi,%edi
mov    $0x3,%esi
call   1050 <sched_setscheduler@plt>
test   %rax,%rax
jne    11c9 <main+0x69>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <setpriority@plt>
mov    0x2e24(%rip),%rcx
or     (%rcx),%rax
jne    11d7 <main+0x77>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <getchar@plt>
jmp    11c0 <main+0x60>
lea    0xe30(%rip),%rdi
call   1070 <perror@plt>
jmp    119b <main+0x3b>
lea    0xe57(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x32,%esi
mov    %ebx,%ecx
call   1030 <snprintf@plt>
mov    %r14,%rdi
call   1070 <perror@plt>
jmp    11c0 <main+0x60>

LLVM IR (-O0):
%struct.sched_param = type { i64 }
@.str = [53 x i8] c"sched_setscheduler(0,SCHED_BATCH,{.sched_priority=0}\00"
@PRIO_PROCESS = global i32 0
@errno = global i64 0
@.str.1 = [33 x i8] c"setpriority(PRIO_PROCESS, 0, %d)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sched_param
%8 = alloca [50 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 19, i32* %6
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
br label %16
16: ; preds = %11, %2
%17 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %7, i32 0, i32 0
store i64 0, i64* %17
%18 = call i64 @sched_setscheduler(i32 0, i32 3, %struct.sched_param* %7)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = load i32, i32* @PRIO_PROCESS
%24 = load i32, i32* %6
%25 = call i64 @setpriority(i32 %23, i32 0, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = load i64, i64* @errno
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27, %22
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%32 = load i32, i32* %6
%33 = call i32 @snprintf(i8* %31, i32 50, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%35 = call i32 @perror(i8* %34)
br label %36
36: ; preds = %30, %27
br label %37
37: ; preds = %36, %37
%38 = call i32 (...) @getchar()
br label %37
}

LLVM IR (-O2):
%struct.sched_param = type { i64 }
@.str = [53 x i8] c"sched_setscheduler(0,SCHED_BATCH,{.sched_priority=0}\00"
@PRIO_PROCESS = global i32 0
@errno = global i64 0
@.str.1 = [33 x i8] c"setpriority(PRIO_PROCESS, 0, %d)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sched_param
%4 = alloca [50 x i8]
%5 = bitcast %struct.sched_param* %3 to i8*
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
br label %12
12: ; preds = %8, %2
%13 = phi i32 [ %11, %8 ], [ 19, %2 ]
%14 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
store i64 0, i64* %14
%15 = call i64 @sched_setscheduler(i32 0, i32 3, %struct.sched_param* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = load i32, i32* @PRIO_PROCESS
%21 = call i64 @setpriority(i32 %20, i32 0, i32 %13)
%22 = icmp ne i64 %21, 0
%23 = load i64, i64* @errno
%24 = icmp ne i64 %23, 0
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = call i32 @snprintf(i8* %6, i32 50, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%28 = call i32 @perror(i8* %6)
br label %29
29: ; preds = %19, %26
br label %30
30: ; preds = %29, %30
%31 = call i32 (...) @getchar()
br label %30
}