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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int SIGTERM;
int atoi(char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ kill(int /*<<< orphan*/, int);
int /*<<< orphan*/ read_pid(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc < 2 || argc > 3) {
    fprintf(stderr, "usage: %s <pid_file> [signal_number]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  int signo = SIGTERM;
  if (argc == 3) {
    const char *sig_str = argv[2];
    signo = atoi(sig_str);
    if (0 == signo) {
      fprintf(stderr, "Invalid signal number: %s", sig_str);
      exit(EXIT_FAILURE);
    }
  }
  pid_t pid = read_pid(argv[1]);
  kill(pid, signo);
  exit(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)
cmpl   $0x2,-0x8(%rbp)
jl     117a <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jle    11a4 <main+0x54>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1209 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    1204 <main+0xb4>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe35(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1209 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <read_pid@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <kill@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
lea    -0x4(%rdi),%eax
cmp    $0xfffffffd,%eax
ja     1174 <main+0x24>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe8e(%rip),%rsi
jmp    119e <main+0x4e>
cmp    $0x3,%edi
jne    11b1 <main+0x61>
mov    0x10(%rbx),%r14
mov    %r14,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11ba <main+0x6a>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rdi
call   1030 <read_pid@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1050 <kill@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"usage: %s <pid_file> [signal_number]\0A\00"
@EXIT_FAILURE = global i32 0
@SIGTERM = global i32 0
@.str.1 = [26 x i8] c"Invalid signal number: %s\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 3
br i1 %13, label %14, label %22
14: ; preds = %11, %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %11
%23 = load i32, i32* @SIGTERM
store i32 %23, i32* %6
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %41
26: ; preds = %22
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp eq i32 0, %32
br i1 %33, label %34, label %40
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %7
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %26
br label %41
41: ; preds = %40, %22
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @read_pid(i8* %44)
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = load i32, i32* %6
%48 = call i32 @kill(i32 %46, i32 %47)
%49 = load i32, i32* @EXIT_SUCCESS
%50 = call i32 @exit(i32 %49)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"usage: %s <pid_file> [signal_number]\0A\00"
@EXIT_FAILURE = global i32 0
@SIGTERM = global i32 0
@.str.1 = [26 x i8] c"Invalid signal number: %s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -4
%4 = icmp ult i32 %3, -2
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = load i32, i32* @SIGTERM
%13 = icmp eq i32 %0, 3
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %14, %11
%25 = phi i32 [ %12, %11 ], [ %17, %14 ]
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = tail call i32 @read_pid(i8* %27)
%29 = tail call i32 @kill(i32 %28, i32 %25)
%30 = load i32, i32* @EXIT_SUCCESS
%31 = tail call i32 @exit(i32 %30)
unreachable
}