#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*/ PRIO_PROCESS;
int /*<<< orphan*/ __set_errno(int);
int errno;
int getpriority(int /*<<< orphan*/, int /*<<< orphan*/);
int setpriority(int /*<<< orphan*/, int /*<<< orphan*/, int);
int nice(int incr) {
  int save;
  int prio;
  int result;
  save = errno;
  __set_errno(0);
  prio = getpriority(PRIO_PROCESS, 0);
  if (prio == -1) {
    if (errno != 0)
      return -1;
    else
      __set_errno(save);
  }
  result = setpriority(PRIO_PROCESS, 0, prio + incr);
  if (result != -1)
    return getpriority(PRIO_PROCESS, 0);
  else
    return -1;
}


x86 assembly (clang, -O0):
<nice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
xor    %edi,%edi
call   1030 <__set_errno@plt>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <getpriority@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1194 <nice+0x64>
mov    0x2e66(%rip),%rax
cmpl   $0x0,(%rax)
je     1187 <nice+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <nice+0xa6>
mov    -0xc(%rbp),%edi
call   1030 <__set_errno@plt>
jmp    1194 <nice+0x64>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
add    -0x8(%rbp),%edx
xor    %esi,%esi
call   1050 <setpriority@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11cf <nice+0x9f>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <getpriority@plt>
mov    %eax,-0x4(%rbp)
jmp    11d6 <nice+0xa6>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nice>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
mov    0x2e97(%rip),%r12
mov    (%r12),%r14d
xor    %edi,%edi
call   1030 <__set_errno@plt>
mov    0x2e8d(%rip),%r15
mov    (%r15),%edi
xor    %esi,%esi
call   1040 <getpriority@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1189 <nice+0x59>
mov    (%r15),%edi
add    %ebx,%ebp
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <setpriority@plt>
cmp    $0xffffffff,%eax
je     1190 <nice+0x60>
mov    (%r15),%edi
xor    %esi,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <getpriority@plt>
cmpl   $0x0,(%r12)
je     119e <nice+0x6e>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%edi
call   1030 <__set_errno@plt>
jmp    1164 <nice+0x34>

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

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