#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*/ sched_priority;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ PRIO_PROCESS;
int /*<<< orphan*/ SCHED_RR;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char *, char **);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sched_get_priority_max(int /*<<< orphan*/);
int /*<<< orphan*/ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                                      struct sched_param *);
int /*<<< orphan*/ setpriority(int /*<<< orphan*/, int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  int fdOut, fdErr, fdIn;
  char **onlyArgs = argv + 1;
  struct sched_param schParam;
  schParam.sched_priority = sched_get_priority_max(SCHED_RR);
  sched_setscheduler(0, SCHED_RR, &schParam);
  setpriority(PRIO_PROCESS, 0, 12);
  fdOut = open("/tmp/daemon.out", O_RDWR);
  fdErr = open("/tmp/daemon.err", O_RDWR);
  fdIn = open("/tmp/null", O_RDWR);
  dup2(fdIn, STDIN_FILENO);
  dup2(fdOut, STDOUT_FILENO);
  dup2(fdErr, STDERR_FILENO);
  execvp(argv[1], onlyArgs);
  close(fdErr);
  close(fdOut);
  close(fdIn);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1090 <sched_get_priority_max@plt>
mov    %eax,-0x30(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x30(%rbp),%rdx
call   1050 <sched_setscheduler@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <setpriority@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    0xe24(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
lea    0xe1c(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
lea    0xe14(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x14(%rbp),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x18(%rbp),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <execvp@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
lea    0x8(%rsi),%r14
mov    0x2e26(%rip),%rbx
mov    (%rbx),%edi
call   1090 <sched_get_priority_max@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1050 <sched_setscheduler@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <setpriority@plt>
mov    0x2e21(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xe37(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r12d
mov    0x0(%rbp),%esi
lea    0xe35(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%esi
lea    0xe34(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <dup2@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
call   1030 <dup2@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <dup2@plt>
mov    0x8(%r15),%rdi
mov    %r14,%rsi
call   1080 <execvp@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@PRIO_PROCESS = global i32 0
@.str = [16 x i8] c"/tmp/daemon.out\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"/tmp/daemon.err\00"
@.str.2 = [10 x i8] c"/tmp/null\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8**
%10 = alloca %struct.sched_param
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
store i8** %12, i8*** %9
%13 = load i32, i32* @SCHED_RR
%14 = call i32 @sched_get_priority_max(i32 %13)
%15 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %10, i32 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @SCHED_RR
%17 = call i32 @sched_setscheduler(i32 0, i32 %16, %struct.sched_param* %10)
%18 = load i32, i32* @PRIO_PROCESS
%19 = call i32 @setpriority(i32 %18, i32 0, i32 12)
%20 = load i32, i32* @O_RDWR
%21 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* @O_RDWR
%23 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %22)
store i32 %23, i32* %7
%24 = load i32, i32* @O_RDWR
%25 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = load i32, i32* @STDIN_FILENO
%28 = call i32 @dup2(i32 %26, i32 %27)
%29 = load i32, i32* %6
%30 = load i32, i32* @STDOUT_FILENO
%31 = call i32 @dup2(i32 %29, i32 %30)
%32 = load i32, i32* %7
%33 = load i32, i32* @STDERR_FILENO
%34 = call i32 @dup2(i32 %32, i32 %33)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %9
%39 = call i32 @execvp(i8* %37, i8** %38)
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %8
%45 = call i32 @close(i32 %44)
ret i32 0
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_RR = global i32 0
@PRIO_PROCESS = global i32 0
@.str = [16 x i8] c"/tmp/daemon.out\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"/tmp/daemon.err\00"
@.str.2 = [10 x i8] c"/tmp/null\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sched_param
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = bitcast %struct.sched_param* %3 to i8*
%6 = load i32, i32* @SCHED_RR
%7 = tail call i32 @sched_get_priority_max(i32 %6)
%8 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
store i32 %7, i32* %8
%9 = load i32, i32* @SCHED_RR
%10 = call i32 @sched_setscheduler(i32 0, i32 %9, %struct.sched_param* %3)
%11 = load i32, i32* @PRIO_PROCESS
%12 = call i32 @setpriority(i32 %11, i32 0, i32 12)
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @STDIN_FILENO
%20 = call i32 @dup2(i32 %18, i32 %19)
%21 = load i32, i32* @STDOUT_FILENO
%22 = call i32 @dup2(i32 %14, i32 %21)
%23 = load i32, i32* @STDERR_FILENO
%24 = call i32 @dup2(i32 %16, i32 %23)
%25 = load i8*, i8** %4
%26 = call i32 @execvp(i8* %25, i8** %4)
%27 = call i32 @close(i32 %16)
%28 = call i32 @close(i32 %14)
%29 = call i32 @close(i32 %18)
ret i32 0
}