#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 */
scalar_t__ EACCES;
scalar_t__ EPERM;
int /*<<< orphan*/ PRIO_PROCESS;
int atoi(char *);
scalar_t__ errno;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int setpriority(int /*<<< orphan*/, int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  int niceness = 10;
  if (argc >= 2) {
    niceness = atoi(argv[1]);
  }
  errno = 0;
  int rc = setpriority(PRIO_PROCESS, 0, niceness);
  if (rc != 0) {
    if (errno == EACCES) {
      printf("Insufficient privileges (EACCES)\n");
    } else if (errno == EPERM) {
      printf("Operation not permitted (EPERM)\n");
    } else {
      perror("Other setpriority error");
    }
    return 1;
  }
  printf("Successfully used setpriority(PRIO_PROCESS, 0, %d)\n", niceness);
  return 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)
movl   $0xa,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1177 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e52(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <setpriority@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     121c <main+0xdc>
mov    0x2e24(%rip),%rax
mov    (%rax),%rax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
jne    11d2 <main+0x92>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1210 <main+0xd0>
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    0x2ddd(%rip),%rcx
cmp    (%rcx),%rax
jne    11ff <main+0xbf>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120b <main+0xcb>
lea    0xe3d(%rip),%rdi
call   1050 <perror@plt>
jmp    1210 <main+0xd0>
movl   $0x1,-0x4(%rbp)
jmp    1234 <main+0xf4>
mov    -0x14(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0xa,%ebp
cmp    $0x2,%edi
jl     1169 <main+0x19>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    0x2e60(%rip),%r14
movq   $0x0,(%r14)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <setpriority@plt>
test   %eax,%eax
je     11a7 <main+0x57>
mov    (%r14),%rax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%rax
jne    11b9 <main+0x69>
lea    0xec7(%rip),%rdi
jmp    11cc <main+0x7c>
lea    0xe6a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d6 <main+0x86>
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%rax
jne    11dd <main+0x8d>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe1c(%rip),%rdi
call   1060 <perror@plt>
jmp    11d1 <main+0x81>

LLVM IR (-O0):
@errno = global i64 0
@PRIO_PROCESS = global i32 0
@EACCES = global i64 0
@.str = [34 x i8] c"Insufficient privileges (EACCES)\0A\00"
@EPERM = global i64 0
@.str.1 = [33 x i8] c"Operation not permitted (EPERM)\0A\00"
@.str.2 = [24 x i8] c"Other setpriority error\00"
@.str.3 = [52 x i8] c"Successfully used setpriority(PRIO_PROCESS, 0, %d)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %6
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
br label %15
15: ; preds = %10, %2
store i64 0, i64* @errno
%16 = load i32, i32* @PRIO_PROCESS
%17 = load i32, i32* %6
%18 = call i32 @setpriority(i32 %16, i32 0, i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %15
%22 = load i64, i64* @errno
%23 = load i64, i64* @EACCES
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %36
27: ; preds = %21
%28 = load i64, i64* @errno
%29 = load i64, i64* @EPERM
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %35
33: ; preds = %27
%34 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %31
br label %36
36: ; preds = %35, %25
store i32 1, i32* %3
br label %40
37: ; preds = %15
%38 = load i32, i32* %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %38)
store i32 0, i32* %3
br label %40
40: ; preds = %37, %36
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@errno = global i64 0
@PRIO_PROCESS = global i32 0
@EACCES = global i64 0
@EPERM = global i64 0
@.str.2 = [24 x i8] c"Other setpriority error\00"
@.str.3 = [52 x i8] c"Successfully used setpriority(PRIO_PROCESS, 0, %d)\0A\00"
@str = [32 x i8] c"Operation not permitted (EPERM)\00"
@str.4 = [33 x i8] c"Insufficient privileges (EACCES)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %4, %2
%9 = phi i32 [ %7, %4 ], [ 10, %2 ]
store i64 0, i64* @errno
%10 = load i32, i32* @PRIO_PROCESS
%11 = tail call i32 @setpriority(i32 %10, i32 0, i32 %9)
%12 = icmp eq i32 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %8
%14 = load i64, i64* @errno
%15 = load i64, i64* @EACCES
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.4, i64 0, i64 0))
br label %28
19: ; preds = %13
%20 = load i64, i64* @EPERM
%21 = icmp eq i64 %14, %20
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %28
24: ; preds = %19
%25 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %28
26: ; preds = %8
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %9)
br label %28
28: ; preds = %17, %24, %22, %26
%29 = phi i32 [ 0, %26 ], [ 1, %22 ], [ 1, %24 ], [ 1, %17 ]
ret i32 %29
}