#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_PGRP;
int /*<<< orphan*/ PRIO_PROCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ getchar();
int getpid();
int getpriority(int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int setpriority(int /*<<< orphan*/, int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  pid_t mypid;
  int old_prio, new_prio, i = 1, rc;
  while (i < 3) {
    mypid = fork();
    if (mypid == 0) {
      mypid = getpid();
      old_prio = getpriority(PRIO_PROCESS, (int)mypid);
      getchar();
      printf("\nExamining priorities for PID = %d \n", mypid);
      printf("%10s%10s\n", "Previous", "Assigned");
      new_prio = getpriority(PRIO_PROCESS, (int)mypid);
      printf("%10d%10d\n", old_prio, new_prio);
      exit(0);
    } else
      i++;
  }
  mypid = getpid();
  printf("\nExamining priorities for PID = %d \n", mypid);
  printf("%10s%10s\n", "Previous", "Assigned");
  old_prio = getpriority(PRIO_PROCESS, (int)mypid);
  rc = setpriority(PRIO_PGRP, 0, 20);
  if (rc)
    perror("setpriority.......\n ");
  new_prio = getpriority(PRIO_PROCESS, (int)mypid);
  printf("%10d%10d\n", old_prio, new_prio);
  getchar();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jge    124a <main+0xca>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    123c <main+0xbc>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1030 <getpriority@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x14(%rbp),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe2d(%rip),%rdi
lea    0xe30(%rip),%rsi
lea    0xe32(%rip),%rdx
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1030 <getpriority@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119d <main+0x1d>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdb9(%rip),%rdi
lea    0xdbc(%rip),%rsi
lea    0xdbe(%rip),%rdx
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1030 <getpriority@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <setpriority@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     12c3 <main+0x143>
lea    0xd8d(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1030 <getpriority@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     119a <main+0x1a>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
jne    120c <main+0x8c>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
mov    0x2e36(%rip),%r14
mov    (%r14),%edi
mov    %eax,%esi
call   1030 <getpriority@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0xe3c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe51(%rip),%rdi
lea    0xe54(%rip),%rsi
lea    0xe56(%rip),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%edi
mov    %ebx,%esi
call   1030 <getpriority@plt>
lea    0xe47(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
lea    0xde4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdf9(%rip),%rdi
lea    0xdfc(%rip),%rsi
lea    0xdfe(%rip),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d98(%rip),%r14
mov    (%r14),%edi
mov    %ebx,%esi
call   1030 <getpriority@plt>
mov    %eax,%ebp
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <setpriority@plt>
test   %eax,%eax
je     1279 <main+0xf9>
lea    0xdd7(%rip),%rdi
call   1080 <perror@plt>
mov    (%r14),%edi
mov    %ebx,%esi
call   1030 <getpriority@plt>
lea    0xdb7(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@PRIO_PROCESS = global i32 0
@.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"
@.str.4 = [10 x i8] c"%10d%10d\0A\00"
@PRIO_PGRP = global i32 0
@.str.5 = [21 x i8] c"setpriority.......\0A \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
br label %11
11: ; preds = %37, %2
%12 = load i32, i32* %9
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %38
14: ; preds = %11
%15 = call i32 (...) @fork()
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %14
%19 = call i32 (...) @getpid()
store i32 %19, i32* %6
%20 = load i32, i32* @PRIO_PROCESS
%21 = load i32, i32* %6
%22 = call i32 @getpriority(i32 %20, i32 %21)
store i32 %22, i32* %7
%23 = call i32 (...) @getchar()
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = 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))
%27 = load i32, i32* @PRIO_PROCESS
%28 = load i32, i32* %6
%29 = call i32 @getpriority(i32 %27, i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %31)
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %14
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %37
37: ; preds = %34
br label %11
38: ; preds = %11
%39 = call i32 (...) @getpid()
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = 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))
%43 = load i32, i32* @PRIO_PROCESS
%44 = load i32, i32* %6
%45 = call i32 @getpriority(i32 %43, i32 %44)
store i32 %45, i32* %7
%46 = load i32, i32* @PRIO_PGRP
%47 = call i32 @setpriority(i32 %46, i32 0, i32 20)
store i32 %47, i32* %10
%48 = load i32, i32* %10
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %38
%51 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %52
52: ; preds = %50, %38
%53 = load i32, i32* @PRIO_PROCESS
%54 = load i32, i32* %6
%55 = call i32 @getpriority(i32 %53, i32 %54)
store i32 %55, i32* %8
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %56, i32 %57)
%59 = call i32 (...) @getchar()
%60 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@PRIO_PROCESS = global i32 0
@.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"
@.str.4 = [10 x i8] c"%10d%10d\0A\00"
@PRIO_PGRP = global i32 0
@.str.5 = [21 x i8] c"setpriority.......\0A \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = tail call i32 (...) @fork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = 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))
%12 = load i32, i32* @PRIO_PROCESS
%13 = tail call i32 @getpriority(i32 %12, i32 %9)
%14 = load i32, i32* @PRIO_PGRP
%15 = tail call i32 @setpriority(i32 %14, i32 0, i32 20)
%16 = icmp eq i32 %15, 0
br i1 %16, label %30, label %28
17: ; preds = %5, %2
%18 = tail call i32 (...) @getpid()
%19 = load i32, i32* @PRIO_PROCESS
%20 = tail call i32 @getpriority(i32 %19, i32 %18)
%21 = tail call i32 (...) @getchar()
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %18)
%23 = 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))
%24 = load i32, i32* @PRIO_PROCESS
%25 = tail call i32 @getpriority(i32 %24, i32 %18)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %20, i32 %25)
%27 = tail call i32 @exit(i32 0)
unreachable
28: ; preds = %8
%29 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %28, %8
%31 = load i32, i32* @PRIO_PROCESS
%32 = tail call i32 @getpriority(i32 %31, i32 %9)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %13, i32 %32)
%34 = tail call i32 (...) @getchar()
%35 = tail call i32 @exit(i32 0)
unreachable
}