#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 */
struct option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ *member_2;
  int /*<<< orphan*/ const member_1;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
scalar_t__ geteuid();
char getopt_long(int, char **, char *, struct option *, int /*<<< orphan*/ *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
#define required_argument 128
scalar_t__ setproctitle(unsigned int, char *);
char *strdup(int /*<<< orphan*/);
unsigned int strtoul(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  unsigned int pid = 0;
  char *title = NULL, opt = '\0';
  if (geteuid() != 0) {
    printf("Error: This utility requires root privileges.\n");
    return EXIT_FAILURE;
  }
  static struct option long_options[] = {
      {"pid", required_argument, NULL, 'p'},
      {"title", required_argument, NULL, 't'},
      {0, 0, 0, 0},
  };
  while ((opt = getopt_long(argc, argv, "p:t:", long_options, NULL)) != -1) {
    switch (opt) {
    case 'p':
      errno = 0;
      pid = strtoul(optarg, NULL, 10);
      if (errno != 0) {
        pid = 0;
      }
      break;
    case 't':
      title = strdup(optarg);
      break;
    default:
      printf("Usage: %s --pid PID --title TITLE\n", argv[0]);
      ;
      return EXIT_FAILURE;
    }
  }
  if (pid == 0 || title == NULL) {
    printf("Usage: %s --pid PID --title TITLE\n", argv[0]);
    ;
    return EXIT_FAILURE;
  }
  if (setproctitle(pid, title) == 0) {
    return EXIT_SUCCESS;
  }
  return EXIT_FAILURE;
}


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)
movq   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
cmp    $0x0,%rax
je     11b9 <main+0x59>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1305 <main+0x1a5>
jmp    11be <main+0x5e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdx
lea    0x2e8d(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <getopt_long@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1297 <main+0x137>
movsbl -0x21(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x70,%eax
je     1212 <main+0xb2>
jmp    1201 <main+0xa1>
mov    -0x28(%rbp),%eax
sub    $0x74,%eax
je     1255 <main+0xf5>
jmp    126c <main+0x10c>
mov    0x2dbf(%rip),%rax
movl   $0x0,(%rax)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d98(%rip),%rax
cmpl   $0x0,(%rax)
je     1250 <main+0xf0>
movl   $0x0,-0x14(%rbp)
jmp    1292 <main+0x132>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    1292 <main+0x132>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1305 <main+0x1a5>
jmp    11be <main+0x5e>
cmpl   $0x0,-0x14(%rbp)
je     12ac <main+0x14c>
cmpq   $0x0,-0x20(%rbp)
jne    12d2 <main+0x172>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1305 <main+0x1a5>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <setproctitle@plt>
cmp    $0x0,%rax
jne    12f9 <main+0x199>
mov    0x2cd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1305 <main+0x1a5>
mov    0x2cd0(%rip),%rax
mov    (%rax),%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
push   %rax
mov    %rsi,%r13
mov    %edi,%ebp
xor    %eax,%eax
call   1070 <geteuid@plt>
test   %rax,%rax
je     119d <main+0x2d>
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
jmp    1278 <main+0x108>
lea    0xe66(%rip),%rdx
lea    0x2eb5(%rip),%rcx
mov    %ebp,%edi
mov    %r13,%rsi
xor    %r8d,%r8d
call   1050 <getopt_long@plt>
cmp    $0xff,%al
je     1266 <main+0xf6>
lea    0x2e99(%rip),%r12
mov    0x2e0a(%rip),%r14
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    120c <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1090 <strdup@plt>
mov    %rax,%r15
mov    %ebp,%edi
mov    %r13,%rsi
lea    0xe0d(%rip),%rdx
mov    %r12,%rcx
xor    %r8d,%r8d
call   1050 <getopt_long@plt>
cmp    $0xff,%al
je     1245 <main+0xd5>
movsbl %al,%eax
cmp    $0x74,%eax
je     11e0 <main+0x70>
cmp    $0x70,%eax
jne    1266 <main+0xf6>
movl   $0x0,(%r14)
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %eax,%ebx
cmpl   $0x0,(%r14)
mov    $0x0,%eax
cmovne %eax,%ebx
jmp    11f1 <main+0x81>
test   %ebx,%ebx
je     1266 <main+0xf6>
test   %r15,%r15
je     1266 <main+0xf6>
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <setproctitle@plt>
test   %rax,%rax
jne    1278 <main+0x108>
mov    0x2d64(%rip),%rax
jmp    127f <main+0x10f>
mov    0x0(%r13),%rsi
lea    0xd9e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32*, i32 }
@.str = [47 x i8] c"Error: This utility requires root privileges.\0A\00"
@EXIT_FAILURE = global i32 0
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32* null, i32 112 }, %struct.option { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8 -128, i32* null, i32 116 }, %struct.option zeroinitializer]
@.str.1 = [4 x i8] c"pid\00"
@.str.2 = [6 x i8] c"title\00"
@.str.3 = [5 x i8] c"p:t:\00"
@errno = global i32 0
@optarg = global i32 0
@.str.4 = [35 x i8] c"Usage: %s --pid PID --title TITLE\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %7
store i8 0, i8* %8
%9 = call i64 (...) @geteuid()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %62
14: ; preds = %2
br label %15
15: ; preds = %40, %14
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call signext i8 @getopt_long(i32 %16, i8** %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* null)
store i8 %18, i8* %8
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %41
21: ; preds = %15
%22 = load i8, i8* %8
%23 = sext i8 %22 to i32
switch i32 %23, label %34 [
i32 112, label %24
i32 116, label %31
]
24: ; preds = %21
store i32 0, i32* @errno
%25 = load i32, i32* @optarg
%26 = call i32 @strtoul(i32 %25, i32* null, i32 10)
store i32 %26, i32* %6
%27 = load i32, i32* @errno
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 0, i32* %6
br label %30
30: ; preds = %29, %24
br label %40
31: ; preds = %21
%32 = load i32, i32* @optarg
%33 = call i8* @strdup(i32 %32)
store i8* %33, i8** %7
br label %40
34: ; preds = %21
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
store i32 %39, i32* %3
br label %62
40: ; preds = %31, %30
br label %15
41: ; preds = %15
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = load i8*, i8** %7
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %53
47: ; preds = %44, %41
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
store i32 %52, i32* %3
br label %62
53: ; preds = %44
%54 = load i32, i32* %6
%55 = load i8*, i8** %7
%56 = call i64 @setproctitle(i32 %54, i8* %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = load i32, i32* @EXIT_SUCCESS
store i32 %59, i32* %3
br label %62
60: ; preds = %53
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %3
br label %62
62: ; preds = %60, %58, %47, %34, %11
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32*, i32 }
@EXIT_FAILURE = global i32 0
@main.long_options = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32* null, i32 112 }, %struct.option { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8 -128, i32* null, i32 116 }, %struct.option zeroinitializer]
@.str.1 = [4 x i8] c"pid\00"
@.str.2 = [6 x i8] c"title\00"
@.str.3 = [5 x i8] c"p:t:\00"
@errno = global i32 0
@optarg = global i32 0
@.str.4 = [35 x i8] c"Usage: %s --pid PID --title TITLE\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [46 x i8] c"Error: This utility requires root privileges.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 (...) @geteuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call signext i8 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* null)
%7 = icmp eq i8 %6, -1
br i1 %7, label %36, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %43
10: ; preds = %5, %27
%11 = phi i8 [ %30, %27 ], [ %6, %5 ]
%12 = phi i8* [ %29, %27 ], [ null, %5 ]
%13 = phi i32 [ %28, %27 ], [ 0, %5 ]
%14 = sext i8 %11 to i32
switch i32 %14, label %24 [
i32 112, label %15
i32 116, label %21
]
15: ; preds = %10
store i32 0, i32* @errno
%16 = load i32, i32* @optarg
%17 = tail call i32 @strtoul(i32 %16, i32* null, i32 10)
%18 = load i32, i32* @errno
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i32 %17, i32 0
br label %27
21: ; preds = %10
%22 = load i32, i32* @optarg
%23 = tail call i8* @strdup(i32 %22)
br label %27
24: ; preds = %10
%25 = load i8*, i8** %1
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %43
27: ; preds = %21, %15
%28 = phi i32 [ %13, %21 ], [ %20, %15 ]
%29 = phi i8* [ %23, %21 ], [ %12, %15 ]
%30 = tail call signext i8 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* null)
%31 = icmp eq i8 %30, -1
br i1 %31, label %32, label %10
32: ; preds = %27
%33 = icmp eq i32 %28, 0
%34 = icmp eq i8* %29, null
%35 = select i1 %33, i1 true, i1 %34
br i1 %35, label %36, label %39
36: ; preds = %5, %32
%37 = load i8*, i8** %1
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %37)
br label %43
39: ; preds = %32
%40 = tail call i64 @setproctitle(i32 %28, i8* %29)
%41 = icmp eq i64 %40, 0
%42 = select i1 %41, i32* @EXIT_SUCCESS, i32* @EXIT_FAILURE
br label %43
43: ; preds = %39, %36, %24, %8
%44 = phi i32* [ @EXIT_FAILURE, %8 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_FAILURE, %36 ], [ %42, %39 ]
%45 = load i32, i32* %44
ret i32 %45
}