#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 stat {
  int dummy;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int getopt(int, char **, char *);
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
long syscall(int, int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  struct stat name;
  char *tst;
  if (argc != 4) {
    printf("Usage: ptag <PID> <flag> <tag>\n");
    return 0;
  }
  pid_t PID = atoi(argv[1]);
  if (kill(PID, 0) != 0) {
    printf("Error: PID does not exist or does not belong to you!\n");
    return -1;
  }
  int opt = getopt(argc, argv, "ar");
  if (opt == 63)
    return 0;
  long x = syscall(337, PID, argv[3], opt);
  return 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)
cmpl   $0x4,-0x8(%rbp)
je     1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1213 <main+0xc3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
xor    %esi,%esi
call   1050 <kill@plt>
cmp    $0x0,%rax
je     11c4 <main+0x74>
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <main+0xc3>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe84(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x3f,-0x28(%rbp)
jne    11f0 <main+0xa0>
movl   $0x0,-0x4(%rbp)
jmp    1213 <main+0xc3>
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    -0x28(%rbp),%ecx
mov    $0x151,%edi
call   1040 <syscall@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x4,%edi
jne    118a <main+0x3a>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %eax,%edi
xor    %esi,%esi
call   1050 <kill@plt>
test   %rax,%rax
je     119f <main+0x4f>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1198 <main+0x48>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe5a(%rip),%rdx
mov    $0x4,%edi
mov    %r14,%rsi
call   1060 <getopt@plt>
cmp    $0x3f,%eax
je     1198 <main+0x48>
mov    0x18(%r14),%rdx
mov    $0x151,%edi
mov    %ebp,%esi
mov    %eax,%ecx
call   1040 <syscall@plt>
jmp    1198 <main+0x48>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [32 x i8] c"Usage: ptag <PID> <flag> <tag>\0A\00"
@.str.1 = [54 x i8] c"Error: PID does not exist or does not belong to you!\0A\00"
@.str.2 = [3 x i8] c"ar\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %39
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = call i64 @kill(i32 %20, i32 0)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
25: ; preds = %15
%26 = load i32, i32* %4
%27 = load i8**, i8*** %5
%28 = call i32 @getopt(i32 %26, i8** %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp eq i32 %29, 63
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 0, i32* %3
br label %39
32: ; preds = %25
%33 = load i32, i32* %8
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = load i32, i32* %9
%38 = call i64 @syscall(i32 337, i32 %33, i8* %36, i32 %37)
store i64 %38, i64* %10
store i32 0, i32* %3
br label %39
39: ; preds = %32, %31, %23, %13
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"ar\00"
@str = [53 x i8] c"Error: PID does not exist or does not belong to you!\00"
@str.3 = [31 x i8] c"Usage: ptag <PID> <flag> <tag>\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.3, i64 0, i64 0))
br label %21
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i64 @kill(i32 %9, i32 0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
br label %21
14: ; preds = %6
%15 = tail call i32 @getopt(i32 4, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32 %15, 63
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i64 @syscall(i32 337, i32 %9, i8* %19, i32 %15)
br label %21
21: ; preds = %12, %14, %17, %4
%22 = phi i32 [ 0, %4 ], [ -1, %12 ], [ 0, %14 ], [ 0, %17 ]
ret i32 %22
}