#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 */
int /*<<< orphan*/ BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
long LONG_MAX;
long LONG_MIN;
int /*<<< orphan*/ PRIO_PROCESS;
int /*<<< orphan*/ execvp(char *, char **);
int getpriority(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ helpAndLeave(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printf(char *, int);
int setpriority(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncmp(char *, char *, int /*<<< orphan*/);
long strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  long adjustment = -10;
  int command_start = 1;
  int niceness = getpriority(PRIO_PROCESS, 0);
  if (niceness == -1)
    pexit("getpriority");
  if (argc == 1) {
    printf("%d\n", getpriority(PRIO_PROCESS, 0));
  } else {
    if (!strncmp(argv[1], "-n", BUFSIZ)) {
      char *endptr;
      adjustment = strtol(argv[2], &endptr, 10);
      if (adjustment == LONG_MIN || adjustment == LONG_MAX || *endptr != '\0')
        helpAndLeave(argv[0], EXIT_FAILURE);
      command_start = 3;
    }
    if (command_start >= argc)
      helpAndLeave(argv[0], EXIT_FAILURE);
    if (setpriority(PRIO_PROCESS, 0, niceness + adjustment) == -1)
      pexit("setpriority");
    execvp(argv[command_start], &argv[command_start]);
    pexit("exec");
  }
  return EXIT_SUCCESS;
}


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)
movq   $0xfffffffffffffff6,-0x18(%rbp)
ff
movl   $0x1,-0x1c(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <getpriority@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11ce <main+0x4e>
lea    0xe37(%rip),%rdi
call   10a0 <pexit@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11fb <main+0x7b>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <getpriority@plt>
mov    %eax,%esi
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
jmp    130b <main+0x18b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
lea    0xdfd(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    128f <main+0x10f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2da2(%rip),%rcx
cmp    (%rcx),%rax
je     1273 <main+0xf3>
mov    -0x18(%rbp),%rax
mov    0x2d76(%rip),%rcx
cmp    (%rcx),%rax
je     1273 <main+0xf3>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1288 <main+0x108>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
call   1080 <helpAndLeave@plt>
movl   $0x3,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     12b0 <main+0x130>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2d17(%rip),%rax
mov    (%rax),%esi
call   1080 <helpAndLeave@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
movslq -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1060 <setpriority@plt>
cmp    $0xffffffff,%eax
jne    12df <main+0x15f>
lea    0xd39(%rip),%rdi
call   10a0 <pexit@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1090 <execvp@plt>
lea    0xd19(%rip),%rdi
call   10a0 <pexit@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e41(%rip),%r12
mov    (%r12),%edi
xor    %esi,%esi
call   1030 <getpriority@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     11cd <main+0x4d>
cmp    $0x1,%ebx
jne    11de <main+0x5e>
mov    (%r12),%edi
xor    %esi,%esi
call   1030 <getpriority@plt>
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
jmp    1259 <main+0xd9>
lea    0xe2c(%rip),%rdi
call   10a0 <pexit@plt>
cmp    $0x1,%ebx
je     11af <main+0x2f>
mov    0x8(%r14),%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
lea    0xe1e(%rip),%rsi
call   1040 <strncmp@plt>
test   %eax,%eax
je     1271 <main+0xf1>
mov    $0xfffffff6,%ebp
mov    $0x1,%r13d
cmp    %ebx,%r13d
jl     121c <main+0x9c>
mov    (%r14),%rdi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
call   1080 <helpAndLeave@plt>
mov    (%r12),%edi
add    %r15d,%ebp
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <setpriority@plt>
cmp    $0xffffffff,%eax
jne    123d <main+0xbd>
lea    0xddb(%rip),%rdi
call   10a0 <pexit@plt>
mov    %r13d,%eax
lea    (%r14,%rax,8),%rsi
mov    (%r14,%rax,8),%rdi
call   1090 <execvp@plt>
lea    0xdcb(%rip),%rdi
call   10a0 <pexit@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%r14),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rbp
mov    0x2d5c(%rip),%rax
cmp    (%rax),%rbp
je     12a6 <main+0x126>
mov    0x2d38(%rip),%rax
cmp    (%rax),%rbp
je     12a6 <main+0x126>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     12b7 <main+0x137>
mov    (%r14),%rdi
mov    0x2d10(%rip),%rax
mov    (%rax),%esi
call   1080 <helpAndLeave@plt>
mov    $0x3,%r13d
cmp    %ebx,%r13d
jge    120b <main+0x8b>
jmp    121c <main+0x9c>

LLVM IR (-O0):
@PRIO_PROCESS = global i32 0
@.str = [12 x i8] c"getpriority\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [3 x i8] c"-n\00"
@BUFSIZ = global i32 0
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@EXIT_FAILURE = global i32 0
@.str.3 = [12 x i8] c"setpriority\00"
@.str.4 = [5 x i8] c"exec\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 -10, i64* %6
store i32 1, i32* %7
%10 = load i32, i32* @PRIO_PROCESS
%11 = call i32 @getpriority(i32 %10, i32 0)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* @PRIO_PROCESS
%21 = call i32 @getpriority(i32 %20, i32 0)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %87
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @BUFSIZ
%28 = call i32 @strncmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %54, label %30
30: ; preds = %23
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i64 @strtol(i8* %33, i8** %9, i32 10)
store i64 %34, i64* %6
%35 = load i64, i64* %6
%36 = load i64, i64* @LONG_MIN
%37 = icmp eq i64 %35, %36
br i1 %37, label %47, label %38
38: ; preds = %30
%39 = load i64, i64* %6
%40 = load i64, i64* @LONG_MAX
%41 = icmp eq i64 %39, %40
br i1 %41, label %47, label %42
42: ; preds = %38
%43 = load i8*, i8** %9
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %42, %38, %30
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @helpAndLeave(i8* %50, i32 %51)
br label %53
53: ; preds = %47, %42
store i32 3, i32* %7
br label %54
54: ; preds = %53, %23
%55 = load i32, i32* %7
%56 = load i32, i32* %4
%57 = icmp sge i32 %55, %56
br i1 %57, label %58, label %64
58: ; preds = %54
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @helpAndLeave(i8* %61, i32 %62)
br label %64
64: ; preds = %58, %54
%65 = load i32, i32* @PRIO_PROCESS
%66 = load i32, i32* %8
%67 = sext i32 %66 to i64
%68 = load i64, i64* %6
%69 = add nsw i64 %67, %68
%70 = trunc i64 %69 to i32
%71 = call i32 @setpriority(i32 %65, i32 0, i32 %70)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %75
73: ; preds = %64
%74 = call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %75
75: ; preds = %73, %64
%76 = load i8**, i8*** %5
%77 = load i32, i32* %7
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %76, i64 %78
%80 = load i8*, i8** %79
%81 = load i8**, i8*** %5
%82 = load i32, i32* %7
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8*, i8** %81, i64 %83
%85 = call i32 @execvp(i8* %80, i8** %84)
%86 = call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %87
87: ; preds = %75, %19
%88 = load i32, i32* @EXIT_SUCCESS
ret i32 %88
}

LLVM IR (-O2):
@PRIO_PROCESS = global i32 0
@.str = [12 x i8] c"getpriority\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [3 x i8] c"-n\00"
@BUFSIZ = global i32 0
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@EXIT_FAILURE = global i32 0
@.str.3 = [12 x i8] c"setpriority\00"
@.str.4 = [5 x i8] c"exec\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = load i32, i32* @PRIO_PROCESS
%5 = tail call i32 @getpriority(i32 %4, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = icmp eq i32 %0, 1
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = load i32, i32* @PRIO_PROCESS
%13 = tail call i32 @getpriority(i32 %12, i32 0)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %62
15: ; preds = %9
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @BUFSIZ
%19 = tail call i32 @strncmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %41
21: ; preds = %15
%22 = bitcast i8** %3 to i8*
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i64 @strtol(i8* %24, i8** %3, i32 10)
%26 = load i64, i64* @LONG_MIN
%27 = icmp eq i64 %25, %26
%28 = load i64, i64* @LONG_MAX
%29 = icmp eq i64 %25, %28
%30 = select i1 %27, i1 true, i1 %29
br i1 %30, label %35, label %31
31: ; preds = %21
%32 = load i8*, i8** %3
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %31, %21
%36 = load i8*, i8** %1
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @helpAndLeave(i8* %36, i32 %37)
br label %39
39: ; preds = %35, %31
%40 = trunc i64 %25 to i32
br label %41
41: ; preds = %39, %15
%42 = phi i32 [ 1, %15 ], [ 3, %39 ]
%43 = phi i32 [ -10, %15 ], [ %40, %39 ]
%44 = icmp slt i32 %42, %0
br i1 %44, label %49, label %45
45: ; preds = %41
%46 = load i8*, i8** %1
%47 = load i32, i32* @EXIT_FAILURE
%48 = tail call i32 @helpAndLeave(i8* %46, i32 %47)
br label %49
49: ; preds = %45, %41
%50 = load i32, i32* @PRIO_PROCESS
%51 = add i32 %43, %5
%52 = tail call i32 @setpriority(i32 %50, i32 0, i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = tail call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %49
%57 = zext i32 %42 to i64
%58 = getelementptr inbounds i8*, i8** %1, i64 %57
%59 = load i8*, i8** %58
%60 = tail call i32 @execvp(i8* %59, i8** %58)
%61 = tail call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %62
62: ; preds = %56, %11
%63 = load i32, i32* @EXIT_SUCCESS
ret i32 %63
}