#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 PRIO_MAX;
int PRIO_MIN;
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;
  int res;
  errno = 0;
  prio = getpriority(PRIO_PROCESS, 0) + incr;
  if (prio < PRIO_MIN)
    prio = PRIO_MIN;
  if (prio >= PRIO_MAX)
    prio = PRIO_MAX - 1;
  if (setpriority(PRIO_PROCESS, 0, prio) == -1)
    return -1;
  else
    return getpriority(PRIO_PROCESS, 0);
}


x86 assembly (clang, -O0):
<nice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e96(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <getpriority@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%eax
jge    116d <nice+0x4d>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%eax
jl     118e <nice+0x6e>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1040 <setpriority@plt>
cmp    $0xffffffff,%eax
jne    11b6 <nice+0x96>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <nice+0xa9>
mov    0x2e13(%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   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e9b(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e95(%rip),%r14
mov    (%r14),%edi
xor    %esi,%esi
call   1030 <getpriority@plt>
add    %eax,%ebx
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%ebx
cmovl  %eax,%ebx
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
lea    -0x1(%rax),%edx
cmp    %eax,%ebx
cmovl  %ebx,%edx
mov    (%r14),%edi
xor    %esi,%esi
call   1040 <setpriority@plt>
cmp    $0xffffffff,%eax
je     1186 <nice+0x66>
mov    (%r14),%edi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <getpriority@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@errno = global i64 0
@PRIO_PROCESS = global i32 0
@PRIO_MIN = global i32 0
@PRIO_MAX = global i32 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 = add nsw i32 %3, %0
%5 = load i32, i32* @PRIO_MIN
%6 = icmp slt i32 %4, %5
%7 = select i1 %6, i32 %5, i32 %4
%8 = load i32, i32* @PRIO_MAX
%9 = icmp slt i32 %7, %8
%10 = add nsw i32 %8, -1
%11 = select i1 %9, i32 %7, i32 %10
%12 = load i32, i32* @PRIO_PROCESS
%13 = tail call i32 @setpriority(i32 %12, i32 0, i32 %11)
%14 = icmp eq i32 %13, -1
br i1 %14, label %18, label %15
15: ; preds = %1
%16 = load i32, i32* @PRIO_PROCESS
%17 = tail call i32 @getpriority(i32 %16, i32 0)
br label %18
18: ; preds = %1, %15
%19 = phi i32 [ %17, %15 ], [ -1, %1 ]
ret i32 %19
}