#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 EXIT_SUCCESS;
char *basename(char *);
int char2int(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int kill(int, int);
int /*<<< orphan*/ printf(char *, int, int);
int signum(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  char *progname = basename(argv[0]);
  if (argc != 3) {
    fprintf(stderr, "Missing parameters, aborting.\n");
    usage(progname);
    exit(5);
  }
  int sign = signum(argv[1]);
  pid_t pid = char2int(argv[2]);
  if (sign < 1) {
    fprintf(stderr, "Invalid signal name %s, %d, aborting.\n", argv[1], sign);
    usage(progname);
    exit(1);
  }
  if (pid < 2) {
    fprintf(stderr, "Invalid pid %d, aborting.\n", pid);
    usage(progname);
    exit(2);
  }
  if ((kill((pid_t)pid, 0)) == -1) {
    fprintf(stderr, "Process with pid %d not running, aborting.\n", pid);
    usage(progname);
    exit(3);
  }
  printf("Sending SIGNAL %d to PID %d\n", sign, pid);
  int is_active = kill((pid_t)pid, sign);
  if (is_active != 0) {
    fprintf(stderr, "Failed to send signal %d to pid %d, aborting.\n", sign,
            pid);
    usage(progname);
    exit(4);
  }
  return EXIT_SUCCESS;
}


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)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <basename@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11da <main+0x5a>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <usage@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <signum@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <char2int@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    1239 <main+0xb9>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <usage@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x2,-0x20(%rbp)
jge    1270 <main+0xf0>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <usage@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%edi
xor    %esi,%esi
call   1060 <kill@plt>
cmp    $0xffffffff,%eax
jne    12b0 <main+0x130>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <usage@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdd0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <kill@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     130a <main+0x18a>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <usage@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rdi
call   1050 <basename@plt>
mov    %rax,%r14
cmp    $0x3,%ebp
jne    120a <main+0x8a>
mov    0x8(%rbx),%rdi
call   1080 <signum@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1070 <char2int@plt>
test   %r15d,%r15d
jle    1233 <main+0xb3>
mov    %eax,%ebp
cmp    $0x1,%eax
jle    1263 <main+0xe3>
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <kill@plt>
cmp    $0xffffffff,%eax
je     128e <main+0x10e>
lea    0xeb3(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %r15d,%esi
call   1060 <kill@plt>
test   %eax,%eax
jne    12b9 <main+0x139>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1090 <usage@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdd8(%rip),%rsi
mov    %r15d,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1090 <usage@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1090 <usage@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1090 <usage@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1090 <usage@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Missing parameters, aborting.\0A\00"
@.str.1 = [39 x i8] c"Invalid signal name %s, %d, aborting.\0A\00"
@.str.2 = [27 x i8] c"Invalid pid %d, aborting.\0A\00"
@.str.3 = [44 x i8] c"Process with pid %d not running, aborting.\0A\00"
@.str.4 = [29 x i8] c"Sending SIGNAL %d to PID %d\0A\00"
@.str.5 = [47 x i8] c"Failed to send signal %d to pid %d, aborting.\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 i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i8* @basename(i8* %12)
store i8* %13, i8** %6
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %6
%20 = call i32 @usage(i8* %19)
%21 = call i32 @exit(i32 5)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @signum(i8* %25)
store i32 %26, i32* %7
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @char2int(i8* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %43
33: ; preds = %22
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i32, i32* %7
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %37, i32 %38)
%40 = load i8*, i8** %6
%41 = call i32 @usage(i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %22
%44 = load i32, i32* %8
%45 = icmp slt i32 %44, 2
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = load i32, i32* %8
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = load i8*, i8** %6
%51 = call i32 @usage(i8* %50)
%52 = call i32 @exit(i32 2)
unreachable
53: ; preds = %43
%54 = load i32, i32* %8
%55 = call i32 @kill(i32 %54, i32 0)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %64
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = load i32, i32* %8
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %59)
%61 = load i8*, i8** %6
%62 = call i32 @usage(i8* %61)
%63 = call i32 @exit(i32 3)
unreachable
64: ; preds = %53
%65 = load i32, i32* %7
%66 = load i32, i32* %8
%67 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %65, i32 %66)
%68 = load i32, i32* %8
%69 = load i32, i32* %7
%70 = call i32 @kill(i32 %68, i32 %69)
store i32 %70, i32* %9
%71 = load i32, i32* %9
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %81
73: ; preds = %64
%74 = load i32, i32* @stderr
%75 = load i32, i32* %7
%76 = load i32, i32* %8
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %75, i32 %76)
%78 = load i8*, i8** %6
%79 = call i32 @usage(i8* %78)
%80 = call i32 @exit(i32 4)
unreachable
81: ; preds = %64
%82 = load i32, i32* @EXIT_SUCCESS
ret i32 %82
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Missing parameters, aborting.\0A\00"
@.str.1 = [39 x i8] c"Invalid signal name %s, %d, aborting.\0A\00"
@.str.2 = [27 x i8] c"Invalid pid %d, aborting.\0A\00"
@.str.3 = [44 x i8] c"Process with pid %d not running, aborting.\0A\00"
@.str.4 = [29 x i8] c"Sending SIGNAL %d to PID %d\0A\00"
@.str.5 = [47 x i8] c"Failed to send signal %d to pid %d, aborting.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i8* @basename(i8* %3)
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @usage(i8* %4)
%10 = tail call i32 @exit(i32 5)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @signum(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @char2int(i8* %16)
%18 = icmp slt i32 %14, 1
br i1 %18, label %19, label %25
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %12
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %14)
%23 = tail call i32 @usage(i8* %4)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %11
%26 = icmp slt i32 %17, 2
br i1 %26, label %27, label %32
27: ; preds = %25
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%30 = tail call i32 @usage(i8* %4)
%31 = tail call i32 @exit(i32 2)
unreachable
32: ; preds = %25
%33 = tail call i32 @kill(i32 %17, i32 0)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%38 = tail call i32 @usage(i8* %4)
%39 = tail call i32 @exit(i32 3)
unreachable
40: ; preds = %32
%41 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %14, i32 %17)
%42 = tail call i32 @kill(i32 %17, i32 %14)
%43 = icmp eq i32 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %14, i32 %17)
%47 = tail call i32 @usage(i8* %4)
%48 = tail call i32 @exit(i32 4)
unreachable
49: ; preds = %40
%50 = load i32, i32* @EXIT_SUCCESS
ret i32 %50
}