#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__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getpriority(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
scalar_t__ setpriority(int, int, int);
int /*<<< orphan*/ stderr;
int donice(int which, int who, int prio) {
  int oldprio, newprio;
  errno = 0;
  oldprio = getpriority(which, who);
  if (oldprio == -1 && errno) {
    fprintf(stderr, "renice: %d: ", who);
    perror(("getpriority"));
    return 1;
  }
  if (setpriority(which, who, prio) < 0) {
    fprintf(stderr, "renice: %d: ", who);
    perror(("setpriority"));
    return 1;
  }
  errno = 0;
  newprio = getpriority(which, who);
  if (newprio == -1 && errno) {
    fprintf(stderr, "renice: %d: ", who);
    perror(("getpriority"));
    return 1;
  }
  printf(("%d: old priority %d, new priority %d\n"), who, oldprio, newprio);
  return 0;
}


x86 assembly (clang, -O0):
<donice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0x2e70(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <getpriority@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c8 <donice+0x78>
mov    0x2e4a(%rip),%rax
cmpq   $0x0,(%rax)
je     11c8 <donice+0x78>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe55(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe56(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1293 <donice+0x143>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <setpriority@plt>
cmp    $0x0,%rax
jge    1210 <donice+0xc0>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe0d(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe1a(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1293 <donice+0x143>
mov    0x2dc1(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <getpriority@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1277 <donice+0x127>
mov    0x2d9b(%rip),%rax
cmpq   $0x0,(%rax)
je     1277 <donice+0x127>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xda6(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xda7(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1293 <donice+0x143>
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xd9e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<donice>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2e72(%rip),%r12
movq   $0x0,(%r12)
call   1030 <getpriority@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    1182 <donice+0x32>
cmpq   $0x0,(%r12)
jne    11ce <donice+0x7e>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r15d,%edx
call   1050 <setpriority@plt>
test   %rax,%rax
js     11ee <donice+0x9e>
movq   $0x0,(%r12)
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <getpriority@plt>
cmp    $0xffffffff,%eax
jne    11b0 <donice+0x60>
cmpq   $0x0,(%r12)
jne    11ce <donice+0x7e>
lea    0xe6e(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
lea    0xe21(%rip),%rdi
jmp    120c <donice+0xbc>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
lea    0xe0d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11c5 <donice+0x75>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [13 x i8] c"renice: %d: \00"
@.str.1 = [12 x i8] c"getpriority\00"
@.str.2 = [12 x i8] c"setpriority\00"
@.str.3 = [38 x i8] c"%d: old priority %d, new priority %d\0A\00"
define i32 @donice(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i64 0, i64* @errno
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 @getpriority(i32 %10, i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %23
15: ; preds = %3
%16 = load i64, i64* @errno
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = load i32, i32* %6
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %53
23: ; preds = %15, %3
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = call i64 @setpriority(i32 %24, i32 %25, i32 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = load i32, i32* %6
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %53
34: ; preds = %23
store i64 0, i64* @errno
%35 = load i32, i32* %5
%36 = load i32, i32* %6
%37 = call i32 @getpriority(i32 %35, i32 %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %48
40: ; preds = %34
%41 = load i64, i64* @errno
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i32, i32* %6
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %45)
%47 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %53
48: ; preds = %40, %34
%49 = load i32, i32* %6
%50 = load i32, i32* %8
%51 = load i32, i32* %9
%52 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %50, i32 %51)
store i32 0, i32* %4
br label %53
53: ; preds = %48, %43, %29, %18
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [13 x i8] c"renice: %d: \00"
@.str.1 = [12 x i8] c"getpriority\00"
@.str.2 = [12 x i8] c"setpriority\00"
@.str.3 = [38 x i8] c"%d: old priority %d, new priority %d\0A\00"
define i32 @donice(i32 %0, i32 %1, i32 %2) {
store i64 0, i64* @errno
%4 = tail call i32 @getpriority(i32 %0, i32 %1)
%5 = icmp eq i32 %4, -1
%6 = load i64, i64* @errno
%7 = icmp ne i64 %6, 0
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%12 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %32
13: ; preds = %3
%14 = tail call i64 @setpriority(i32 %0, i32 %1, i32 %2)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%19 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %32
20: ; preds = %13
store i64 0, i64* @errno
%21 = tail call i32 @getpriority(i32 %0, i32 %1)
%22 = icmp eq i32 %21, -1
%23 = load i64, i64* @errno
%24 = icmp ne i64 %23, 0
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%29 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %32
30: ; preds = %20
%31 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %1, i32 %4, i32 %21)
br label %32
32: ; preds = %30, %26, %16, %9
%33 = phi i32 [ 1, %9 ], [ 1, %16 ], [ 1, %26 ], [ 0, %30 ]
ret i32 %33
}