#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);
char *gettext(char *);
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(gettext("getpriority"));
    return (1);
  }
  if (setpriority(which, who, prio) < 0) {
    fprintf(stderr, "renice: %d: ", who);
    perror(gettext("setpriority"));
    return (1);
  }
  errno = 0;
  newprio = getpriority(which, who);
  if (newprio == -1 && errno) {
    fprintf(stderr, "renice: %d: ", who);
    perror(gettext("getpriority"));
    return (1);
  }
  printf(gettext("%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    0x2e60(%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    11e0 <donice+0x80>
mov    0x2e3a(%rip),%rax
cmpq   $0x0,(%rax)
je     11e0 <donice+0x80>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe45(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xe46(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c3 <donice+0x163>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <setpriority@plt>
cmp    $0x0,%rax
jge    1230 <donice+0xd0>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xdf5(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xe02(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c3 <donice+0x163>
mov    0x2da1(%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    129f <donice+0x13f>
mov    0x2d7b(%rip),%rax
cmpq   $0x0,(%rax)
je     129f <donice+0x13f>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xd86(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xd87(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c3 <donice+0x163>
lea    0xd7f(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1050 <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    0x2e62(%rip),%r12
movq   $0x0,(%r12)
call   1030 <getpriority@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    1192 <donice+0x32>
cmpq   $0x0,(%r12)
jne    11e8 <donice+0x88>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r15d,%edx
call   1060 <setpriority@plt>
test   %rax,%rax
js     1208 <donice+0xa8>
movq   $0x0,(%r12)
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <getpriority@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11c2 <donice+0x62>
cmpq   $0x0,(%r12)
jne    11e8 <donice+0x88>
lea    0xe5c(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    %ebx,%edx
call   1070 <fprintf@plt>
lea    0xe07(%rip),%rdi
jmp    1226 <donice+0xc6>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
mov    %ebx,%edx
call   1070 <fprintf@plt>
lea    0xdf3(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    11df <donice+0x7f>

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 %24
15: ; preds = %3
%16 = load i64, i64* @errno
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %24
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 i8* @gettext(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @perror(i8* %22)
store i32 1, i32* %4
br label %57
24: ; preds = %15, %3
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = call i64 @setpriority(i32 %25, i32 %26, i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = load i32, i32* %6
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = call i8* @gettext(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @perror(i8* %34)
store i32 1, i32* %4
br label %57
36: ; preds = %24
store i64 0, i64* @errno
%37 = load i32, i32* %5
%38 = load i32, i32* %6
%39 = call i32 @getpriority(i32 %37, i32 %38)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %51
42: ; preds = %36
%43 = load i64, i64* @errno
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = load i32, i32* %6
%48 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = call i8* @gettext(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @perror(i8* %49)
store i32 1, i32* %4
br label %57
51: ; preds = %42, %36
%52 = call i8* @gettext(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* %6
%54 = load i32, i32* %8
%55 = load i32, i32* %9
%56 = call i32 @printf(i8* %52, i32 %53, i32 %54, i32 %55)
store i32 0, i32* %4
br label %57
57: ; preds = %51, %45, %30, %18
%58 = load i32, i32* %4
ret i32 %58
}

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 %14
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 i8* @gettext(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @perror(i8* %12)
br label %36
14: ; preds = %3
%15 = tail call i64 @setpriority(i32 %0, i32 %1, i32 %2)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%20 = tail call i8* @gettext(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 @perror(i8* %20)
br label %36
22: ; preds = %14
store i64 0, i64* @errno
%23 = tail call i32 @getpriority(i32 %0, i32 %1)
%24 = icmp eq i32 %23, -1
%25 = load i64, i64* @errno
%26 = icmp ne i64 %25, 0
%27 = select i1 %24, i1 %26, i1 false
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%31 = tail call i8* @gettext(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%32 = tail call i32 @perror(i8* %31)
br label %36
33: ; preds = %22
%34 = tail call i8* @gettext(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%35 = tail call i32 @printf(i8* %34, i32 %1, i32 %4, i32 %23)
br label %36
36: ; preds = %33, %28, %17, %9
%37 = phi i32 [ 1, %9 ], [ 1, %17 ], [ 1, %28 ], [ 0, %33 ]
ret i32 %37
}