#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 */
int PRIO_PGRP;
int PRIO_PROCESS;
int PRIO_USER;
scalar_t__ _renice(int, int, int, char **);
int _usage();
int getopt(int, char **, char *);
char *optarg;
int optind;
int strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  int nice = 0;
  int type = PRIO_PROCESS;
  int o;
  char *p;
  while ((o = getopt(argc, argv, "n:gpu")) != -1)
    switch (o) {
    case 'n':
      nice = strtol(optarg, &p, 10);
      if (*optarg == '\0' || *p != '\0')
        return _usage();
      break;
    case 'g':
      type = PRIO_PGRP;
      break;
    case 'p':
      type = PRIO_PROCESS;
      break;
    case 'u':
      type = PRIO_USER;
      break;
    default:
      return _usage();
    }
  if (argc - optind < 1)
    return _usage();
  return (_renice(nice, type, argc - optind, &argv[optind]) == 0) ? 0 : 2;
}


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   $0x0,-0x14(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xec5(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     124d <main+0x10d>
mov    -0x1c(%rbp),%eax
add    $0xffffff99,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xe,%eax
ja     1239 <main+0xf9>
mov    -0x30(%rbp),%rax
lea    0xe58(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e40(%rip),%rax
mov    (%rax),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f2 <main+0xb2>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1201 <main+0xc1>
mov    $0x0,%al
call   1030 <_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12b1 <main+0x171>
jmp    1248 <main+0x108>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1248 <main+0x108>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1248 <main+0x108>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1248 <main+0x108>
mov    $0x0,%al
call   1030 <_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12b1 <main+0x171>
jmp    1169 <main+0x29>
mov    -0x8(%rbp),%eax
mov    0x2d81(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jge    1271 <main+0x131>
mov    $0x0,%al
call   1030 <_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12b1 <main+0x171>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    0x2d57(%rip),%rax
sub    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    0x2d4a(%rip),%rax
movslq (%rax),%rax
shl    $0x3,%rax
add    %rax,%rcx
call   1040 <_renice@plt>
mov    %rax,%rdx
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2e6d(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
lea    0xed6(%rip),%r12
mov    0x2e53(%rip),%r15
lea    0xe8c(%rip),%r13
mov    %eax,0xc(%rsp)
jmp    1189 <main+0x49>
nopw   0x0(%rax,%rax,1)
mov    0x2e59(%rip),%rax
mov    (%rax),%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1060 <getopt@plt>
lea    -0x67(%rax),%ecx
cmp    $0xe,%ecx
ja     11f4 <main+0xb4>
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
mov    %r15,%rax
jmp    *%rcx
mov    0x2e15(%rip),%rax
mov    (%rax),%ebp
jmp    1189 <main+0x49>
nopw   0x0(%rax,%rax,1)
mov    0x2e31(%rip),%rax
mov    (%rax),%rdi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    0x2e18(%rip),%rcx
mov    (%rcx),%rcx
cmpb   $0x0,(%rcx)
je     1235 <main+0xf5>
mov    0x10(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     1174 <main+0x34>
jmp    1235 <main+0xf5>
cmp    $0xffffffff,%eax
jne    1235 <main+0xf5>
mov    0x2dd8(%rip),%rax
movslq (%rax),%rax
sub    %eax,%r14d
jle    1235 <main+0xf5>
lea    (%rbx,%rax,8),%rcx
mov    0xc(%rsp),%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <_renice@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
add    %ecx,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_usage@plt>

LLVM IR (-O0):
@PRIO_PROCESS = global i32 0
@.str = [6 x i8] c"n:gpu\00"
@optarg = global i8* null
@PRIO_PGRP = global i32 0
@PRIO_USER = global i32 0
@optind = global i32 0
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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = load i32, i32* @PRIO_PROCESS
store i32 %10, i32* %7
br label %11
11: ; preds = %41, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %8
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %42
16: ; preds = %11
%17 = load i32, i32* %8
switch i32 %17, label %39 [
i32 110, label %18
i32 103, label %33
i32 112, label %35
i32 117, label %37
]
18: ; preds = %16
%19 = load i8*, i8** @optarg
%20 = call i32 @strtol(i8* %19, i8** %9, i32 10)
store i32 %20, i32* %6
%21 = load i8*, i8** @optarg
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %18
%26 = load i8*, i8** %9
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25, %18
%31 = call i32 (...) @_usage()
store i32 %31, i32* %3
br label %63
32: ; preds = %25
br label %41
33: ; preds = %16
%34 = load i32, i32* @PRIO_PGRP
store i32 %34, i32* %7
br label %41
35: ; preds = %16
%36 = load i32, i32* @PRIO_PROCESS
store i32 %36, i32* %7
br label %41
37: ; preds = %16
%38 = load i32, i32* @PRIO_USER
store i32 %38, i32* %7
br label %41
39: ; preds = %16
%40 = call i32 (...) @_usage()
store i32 %40, i32* %3
br label %63
41: ; preds = %37, %35, %33, %32
br label %11
42: ; preds = %11
%43 = load i32, i32* %4
%44 = load i32, i32* @optind
%45 = sub nsw i32 %43, %44
%46 = icmp slt i32 %45, 1
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 (...) @_usage()
store i32 %48, i32* %3
br label %63
49: ; preds = %42
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = load i32, i32* %4
%53 = load i32, i32* @optind
%54 = sub nsw i32 %52, %53
%55 = load i8**, i8*** %5
%56 = load i32, i32* @optind
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = call i64 @_renice(i32 %50, i32 %51, i32 %54, i8** %58)
%60 = icmp eq i64 %59, 0
%61 = zext i1 %60 to i64
%62 = select i1 %60, i32 0, i32 2
store i32 %62, i32* %3
br label %63
63: ; preds = %49, %47, %39, %30
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@PRIO_PROCESS = global i32 0
@.str = [6 x i8] c"n:gpu\00"
@optarg = global i8* null
@PRIO_PGRP = global i32 0
@PRIO_USER = global i32 0
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = load i32, i32* @PRIO_PROCESS
%5 = bitcast i8** %3 to i8*
br label %6
6: ; preds = %18, %2
%7 = phi i32 [ %14, %18 ], [ 0, %2 ]
%8 = phi i32 [ %10, %18 ], [ %4, %2 ]
br label %9
9: ; preds = %26, %6
%10 = phi i32 [ %8, %6 ], [ %28, %26 ]
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %11, label %29 [
i32 -1, label %31
i32 110, label %12
i32 103, label %26
i32 112, label %24
i32 117, label %25
]
12: ; preds = %9
%13 = load i8*, i8** @optarg
%14 = call i32 @strtol(i8* %13, i8** %3, i32 10)
%15 = load i8*, i8** @optarg
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %12
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %6, label %22
22: ; preds = %18, %12
%23 = tail call i32 (...) @_usage()
br label %43
24: ; preds = %9
br label %26
25: ; preds = %9
br label %26
26: ; preds = %9, %25, %24
%27 = phi i32* [ @PRIO_USER, %25 ], [ @PRIO_PROCESS, %24 ], [ @PRIO_PGRP, %9 ]
%28 = load i32, i32* %27
br label %9
29: ; preds = %9
%30 = tail call i32 (...) @_usage()
br label %43
31: ; preds = %9
%32 = load i32, i32* @optind
%33 = sub nsw i32 %0, %32
%34 = icmp slt i32 %33, 1
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = tail call i32 (...) @_usage()
br label %43
37: ; preds = %31
%38 = sext i32 %32 to i64
%39 = getelementptr inbounds i8*, i8** %1, i64 %38
%40 = tail call i64 @_renice(i32 %7, i32 %10, i32 %33, i8** %39)
%41 = icmp eq i64 %40, 0
%42 = select i1 %41, i32 0, i32 2
br label %43
43: ; preds = %37, %35, %29, %22
%44 = phi i32 [ %30, %29 ], [ %23, %22 ], [ %36, %35 ], [ %42, %37 ]
ret i32 %44
}