#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;
scalar_t__ errno;
int getpriority(int /*<<< orphan*/, int /*<<< orphan*/);
int setpriority(int /*<<< orphan*/, int /*<<< orphan*/, int);
int nice(int incr) {
  int prio;
  errno = 0;
  prio = getpriority(PRIO_PROCESS, 0);
  if (prio == -1 && errno)
    return -1;
  if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) {
    if (errno == EACCES)
      errno = EPERM;
    return -1;
  }
  return getpriority(PRIO_PROCESS, 0);
}


x86 assembly (clang, -O0):
<nice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e9e(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <getpriority@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1173 <nice+0x53>
mov    0x2e73(%rip),%rax
cmpq   $0x0,(%rax)
je     1173 <nice+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <nice+0xbf>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
add    -0x8(%rbp),%edx
xor    %esi,%esi
call   1040 <setpriority@plt>
cmp    $0xffffffff,%eax
jne    11cc <nice+0xac>
mov    0x2e37(%rip),%rax
mov    (%rax),%rax
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <nice+0xa0>
mov    0x2e0d(%rip),%rax
mov    (%rax),%rcx
mov    0x2e13(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <nice+0xbf>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <getpriority@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nice>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    0x2ea2(%rip),%r14
movq   $0x0,(%r14)
mov    0x2e9c(%rip),%r15
mov    (%r15),%edi
xor    %esi,%esi
call   1030 <getpriority@plt>
cmp    $0xffffffff,%eax
jne    115c <nice+0x3c>
cmpq   $0x0,(%r14)
je     115c <nice+0x3c>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%r15),%edi
add    %ebx,%eax
xor    %esi,%esi
mov    %eax,%edx
call   1040 <setpriority@plt>
cmp    $0xffffffff,%eax
je     117e <nice+0x5e>
mov    (%r15),%edi
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <getpriority@plt>
mov    (%r14),%rax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%rax
jne    1151 <nice+0x31>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r14)
jmp    1151 <nice+0x31>

LLVM IR (-O0):
@errno = global i64 0
@PRIO_PROCESS = global i32 0
@EACCES = global i64 0
@EPERM = global i64 0
define i32 @nice(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i64 0, i64* @errno
%5 = load i32, i32* @PRIO_PROCESS
%6 = call i32 @getpriority(i32 %5, i32 0)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 -1, i32* %2
br label %30
13: ; preds = %9, %1
%14 = load i32, i32* @PRIO_PROCESS
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = add nsw i32 %15, %16
%18 = call i32 @setpriority(i32 %14, i32 0, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %27
20: ; preds = %13
%21 = load i64, i64* @errno
%22 = load i64, i64* @EACCES
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = load i64, i64* @EPERM
store i64 %25, i64* @errno
br label %26
26: ; preds = %24, %20
store i32 -1, i32* %2
br label %30
27: ; preds = %13
%28 = load i32, i32* @PRIO_PROCESS
%29 = call i32 @getpriority(i32 %28, i32 0)
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %26, %12
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@errno = global i64 0
@PRIO_PROCESS = global i32 0
@EACCES = global i64 0
@EPERM = global i64 0
define i32 @nice(i32 %0) {
store i64 0, i64* @errno
%2 = load i32, i32* @PRIO_PROCESS
%3 = tail call i32 @getpriority(i32 %2, i32 0)
%4 = icmp eq i32 %3, -1
%5 = load i64, i64* @errno
%6 = icmp ne i64 %5, 0
%7 = select i1 %4, i1 %6, i1 false
br i1 %7, label %22, label %8
8: ; preds = %1
%9 = load i32, i32* @PRIO_PROCESS
%10 = add nsw i32 %3, %0
%11 = tail call i32 @setpriority(i32 %9, i32 0, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
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 %22
17: ; preds = %13
%18 = load i64, i64* @EPERM
store i64 %18, i64* @errno
br label %22
19: ; preds = %8
%20 = load i32, i32* @PRIO_PROCESS
%21 = tail call i32 @getpriority(i32 %20, i32 0)
br label %22
22: ; preds = %13, %17, %1, %19
%23 = phi i32 [ %21, %19 ], [ -1, %1 ], [ -1, %17 ], [ -1, %13 ]
ret i32 %23
}