#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 /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ PRIO_MAX;
int /*<<< orphan*/ PRIO_PROCESS;
int /*<<< orphan*/ printf(char *);
scalar_t__ sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
scalar_t__ setpriority(int /*<<< orphan*/, int /*<<< orphan*/,
                       int /*<<< orphan*/);
char toupper(char);
int handle_cli_args(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Invalid args: arg1 affinity (Y|N), arg2 Max PRI (Y|N)");
    return -1;
  }
  char affinity = toupper(*argv[1]);
  if (affinity == 'Y') {
    cpu_set_t my_set;
    CPU_ZERO(&my_set);
    CPU_SET(1, &my_set);
    if (sched_setaffinity(0, sizeof(cpu_set_t), &my_set) > 0) {
      printf("affinity error");
      return -1;
    }
  }
  char maxprio = toupper(*argv[2]);
  if (maxprio == 'Y') {
    if (setpriority(PRIO_PROCESS, 0, PRIO_MAX) != 0) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<handle_cli_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1191 <handle_cli_args+0x31>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <handle_cli_args+0xfa>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x59,%eax
jne    11ff <handle_cli_args+0x9f>
lea    -0x18(%rbp),%rdi
call   1070 <CPU_ZERO@plt>
mov    $0x1,%edi
lea    -0x18(%rbp),%rsi
call   1080 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x18(%rbp),%rdx
call   1060 <sched_setaffinity@plt>
cmp    $0x0,%rax
jle    11fa <handle_cli_args+0x9a>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <handle_cli_args+0xfa>
jmp    11ff <handle_cli_args+0x9f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x59,%eax
jne    1253 <handle_cli_args+0xf3>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <setpriority@plt>
cmp    $0x0,%rax
je     124e <handle_cli_args+0xee>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <handle_cli_args+0xfa>
jmp    1253 <handle_cli_args+0xf3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_cli_args>:
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11b3 <handle_cli_args+0x53>
mov    %rsi,%rbx
mov    0x8(%rsi),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
cmp    $0x59,%al
jne    11c6 <handle_cli_args+0x66>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1070 <CPU_ZERO@plt>
mov    $0x1,%edi
mov    %r14,%rsi
call   1080 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %r14,%rdx
call   1060 <sched_setaffinity@plt>
test   %rax,%rax
jle    11c6 <handle_cli_args+0x66>
lea    0xe85(%rip),%rdi
jmp    11ba <handle_cli_args+0x5a>
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    11fe <handle_cli_args+0x9e>
mov    0x10(%rbx),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
cmp    $0x59,%al
jne    11fc <handle_cli_args+0x9c>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <setpriority@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11fe <handle_cli_args+0x9e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [54 x i8] c"Invalid args: arg1 affinity (Y|N), arg2 Max PRI (Y|N)\00"
@.str.1 = [15 x i8] c"affinity error\00"
@PRIO_PROCESS = global i32 0
@PRIO_MAX = global i32 0
define i32 @handle_cli_args(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i8
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %47
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
%18 = call signext i8 @toupper(i8 signext %17)
store i8 %18, i8* %6
%19 = load i8, i8* %6
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 89
br i1 %21, label %22, label %30
22: ; preds = %13
%23 = call i32 @CPU_ZERO(i32* %7)
%24 = call i32 @CPU_SET(i32 1, i32* %7)
%25 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %7)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %47
29: ; preds = %22
br label %30
30: ; preds = %29, %13
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = load i8, i8* %33
%35 = call signext i8 @toupper(i8 signext %34)
store i8 %35, i8* %8
%36 = load i8, i8* %8
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 89
br i1 %38, label %39, label %46
39: ; preds = %30
%40 = load i32, i32* @PRIO_PROCESS
%41 = load i32, i32* @PRIO_MAX
%42 = call i64 @setpriority(i32 %40, i32 0, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
store i32 -1, i32* %3
br label %47
45: ; preds = %39
br label %46
46: ; preds = %45, %30
store i32 0, i32* %3
br label %47
47: ; preds = %46, %44, %27, %11
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [54 x i8] c"Invalid args: arg1 affinity (Y|N), arg2 Max PRI (Y|N)\00"
@.str.1 = [15 x i8] c"affinity error\00"
@PRIO_PROCESS = global i32 0
@PRIO_MAX = global i32 0
define i32 @handle_cli_args(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 3
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
br label %34
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = tail call signext i8 @toupper(i8 signext %10)
%12 = icmp eq i8 %11, 89
br i1 %12, label %13, label %22
13: ; preds = %7
%14 = bitcast i32* %3 to i8*
%15 = call i32 @CPU_ZERO(i32* %3)
%16 = call i32 @CPU_SET(i32 1, i32* %3)
%17 = call i64 @sched_setaffinity(i32 0, i32 4, i32* %3)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %34
21: ; preds = %13
br label %22
22: ; preds = %21, %7
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
%26 = call signext i8 @toupper(i8 signext %25)
%27 = icmp eq i8 %26, 89
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = load i32, i32* @PRIO_PROCESS
%30 = load i32, i32* @PRIO_MAX
%31 = call i64 @setpriority(i32 %29, i32 0, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28, %22
br label %34
34: ; preds = %19, %28, %33, %5
%35 = phi i32 [ -1, %5 ], [ -1, %19 ], [ 0, %33 ], [ -1, %28 ]
ret i32 %35
}