#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ PRIO_PROCESS;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int getpriority(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int setpriority(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ stderr;
int main() {
  pid_t mypid;
  int old_prio, new_prio, i, rc;
  mypid = getpid();
  printf("\nExamining priorities for PID = %d \n", mypid);
  printf("%10s%10s\n", "Previous", "Assigned");
  for (i = -20; i < 20; i += 2) {
    old_prio = getpriority(PRIO_PROCESS, (int)mypid);
    rc = setpriority(PRIO_PROCESS, (int)mypid, i);
    if (rc)
      fprintf(stderr, "setpriority() failed ");
    errno = 0;
    new_prio = getpriority(PRIO_PROCESS, (int)mypid);
    printf("%10d%10d\n", old_prio, new_prio);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea4(%rip),%rdi
lea    0xea7(%rip),%rsi
lea    0xea9(%rip),%rdx
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffec,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    1235 <main+0xe5>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
call   1030 <getpriority@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1060 <setpriority@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11f1 <main+0xa1>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dd8(%rip),%rax
movq   $0x0,(%rax)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
call   1030 <getpriority@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    119d <main+0x4d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%r12d
lea    0xe94(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea9(%rip),%rdi
lea    0xeac(%rip),%rsi
lea    0xeae(%rip),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffea,%ebp
mov    0x2e43(%rip),%r13
mov    0x2e2c(%rip),%r15
lea    0xeac(%rip),%r14
jmp    11d6 <main+0x86>
nopl   (%rax)
movq   $0x0,(%r15)
mov    0x0(%r13),%edi
mov    %r12d,%esi
call   1030 <getpriority@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x12,%ebp
jge    1210 <main+0xc0>
add    $0x2,%ebp
mov    0x0(%r13),%edi
mov    %r12d,%esi
call   1030 <getpriority@plt>
mov    %eax,%ebx
mov    0x0(%r13),%edi
mov    %r12d,%esi
mov    %ebp,%edx
call   1060 <setpriority@plt>
test   %eax,%eax
je     11b0 <main+0x60>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11b0 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"\0AExamining priorities for PID = %d \0A\00"
@.str.1 = [10 x i8] c"%10s%10s\0A\00"
@.str.2 = [9 x i8] c"Previous\00"
@.str.3 = [9 x i8] c"Assigned\00"
@PRIO_PROCESS = global i32 0
@stderr = global i32 0
@.str.4 = [22 x i8] c"setpriority() failed \00"
@errno = global i64 0
@.str.5 = [10 x i8] c"%10d%10d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (...) @getpid()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 -20, i32* %5
br label %11
11: ; preds = %34, %0
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 20
br i1 %13, label %14, label %37
14: ; preds = %11
%15 = load i32, i32* @PRIO_PROCESS
%16 = load i32, i32* %2
%17 = call i32 @getpriority(i32 %15, i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* @PRIO_PROCESS
%19 = load i32, i32* %2
%20 = load i32, i32* %5
%21 = call i32 @setpriority(i32 %18, i32 %19, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %24, %14
store i64 0, i64* @errno
%28 = load i32, i32* @PRIO_PROCESS
%29 = load i32, i32* %2
%30 = call i32 @getpriority(i32 %28, i32 %29)
store i32 %30, i32* %4
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %31, i32 %32)
br label %34
34: ; preds = %27
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 2
store i32 %36, i32* %5
br label %11
37: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"\0AExamining priorities for PID = %d \0A\00"
@.str.1 = [10 x i8] c"%10s%10s\0A\00"
@.str.2 = [9 x i8] c"Previous\00"
@.str.3 = [9 x i8] c"Assigned\00"
@PRIO_PROCESS = global i32 0
@stderr = global i32 0
@.str.4 = [22 x i8] c"setpriority() failed \00"
@errno = global i64 0
@.str.5 = [10 x i8] c"%10d%10d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %4
4: ; preds = %0, %14
%5 = phi i32 [ -20, %0 ], [ %18, %14 ]
%6 = load i32, i32* @PRIO_PROCESS
%7 = tail call i32 @getpriority(i32 %6, i32 %1)
%8 = load i32, i32* @PRIO_PROCESS
%9 = tail call i32 @setpriority(i32 %8, i32 %1, i32 %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %14
14: ; preds = %11, %4
store i64 0, i64* @errno
%15 = load i32, i32* @PRIO_PROCESS
%16 = tail call i32 @getpriority(i32 %15, i32 %1)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 %16)
%18 = add nsw i32 %5, 2
%19 = icmp slt i32 %5, 18
br i1 %19, label %4, label %20
20: ; preds = %14
ret i32 0
}