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

/* Variables and functions */
int SIGTERM;
void *atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
int kill(void *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  pid_t pid;
  int sig;
  int res;
  int opt;
  extern int optind;
  extern char *optarg;
  sig = SIGTERM;
  while ((opt = getopt(argc, argv, "s:")) != -1) {
    switch (opt) {
    case 's':
      sig = atoi(optarg);
      break;
    default:
      usage(argv[0]);
      return 1;
    }
  }
  if (optind < argc) {
    pid = atoi(argv[optind]);
  } else {
    usage(argv[0]);
    fprintf(stderr, "  missing PID argument\n");
    return 1;
  }
  res = kill(pid, sig);
  if (-1 == res) {
    perror("kill");
    return 1;
  }
  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)
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     11e6 <main+0x86>
mov    -0x24(%rbp),%eax
sub    $0x73,%eax
jne    11c9 <main+0x69>
jmp    11b2 <main+0x52>
mov    0x2e1f(%rip),%rax
mov    (%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    11e1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x121>
jmp    1182 <main+0x22>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1218 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x2dc5(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <atoi@plt>
mov    %rax,-0x18(%rbp)
jmp    1245 <main+0xe5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usage@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x121>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <kill@plt>
mov    %eax,-0x20(%rbp)
mov    $0xffffffff,%eax
cmp    -0x20(%rbp),%eax
jne    127a <main+0x11a>
lea    0xdb2(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x121>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e74(%rip),%rax
mov    (%rax),%r14d
lea    0xe82(%rip),%r15
mov    0x2e53(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
cmp    $0x73,%eax
jne    11b0 <main+0x50>
mov    (%r12),%rdi
call   1080 <atoi@plt>
mov    %rax,%r14
jmp    1190 <main+0x30>
cmp    $0xffffffff,%eax
jne    11ee <main+0x8e>
mov    0x2e0c(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    11f8 <main+0x98>
mov    (%rbx,%rax,8),%rdi
call   1080 <atoi@plt>
mov    %rax,%rdi
mov    %r14d,%esi
call   1040 <kill@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    121a <main+0xba>
lea    0xe34(%rip),%rdi
call   1060 <perror@plt>
jmp    1215 <main+0xb5>
mov    (%rbx),%rdi
call   1050 <usage@plt>
jmp    1215 <main+0xb5>
mov    (%rbx),%rdi
call   1050 <usage@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SIGTERM = global i32 0
@.str = [3 x i8] c"s:\00"
@optarg = external global i8*
@optind = external global i32
@stderr = global i32 0
@.str.1 = [24 x i8] c" missing PID argument\0A\00"
@.str.2 = [5 x i8] c"kill\00"
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 i32, i32* @SIGTERM
store i32 %10, i32* %7
br label %11
11: ; preds = %27, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %9
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load i32, i32* %9
switch i32 %17, label %22 [
i32 115, label %18
]
18: ; preds = %16
%19 = load i8*, i8** @optarg
%20 = call i8* @atoi(i8* %19)
%21 = ptrtoint i8* %20 to i32
store i32 %21, i32* %7
br label %27
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @usage(i8* %25)
store i32 1, i32* %3
br label %55
27: ; preds = %18
br label %11
28: ; preds = %11
%29 = load i32, i32* @optind
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i8**, i8*** %5
%34 = load i32, i32* @optind
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i8* @atoi(i8* %37)
store i8* %38, i8** %6
br label %46
39: ; preds = %28
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @usage(i8* %42)
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %55
46: ; preds = %32
%47 = load i8*, i8** %6
%48 = load i32, i32* %7
%49 = call i32 @kill(i8* %47, i32 %48)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = icmp eq i32 -1, %50
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %55
54: ; preds = %46
store i32 0, i32* %3
br label %55
55: ; preds = %54, %52, %39, %22
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@.str = [3 x i8] c"s:\00"
@optarg = external global i8*
@optind = external global i32
@stderr = global i32 0
@.str.1 = [24 x i8] c" missing PID argument\0A\00"
@.str.2 = [5 x i8] c"kill\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @SIGTERM
br label %4
4: ; preds = %7, %2
%5 = phi i32 [ %3, %2 ], [ %11, %7 ]
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %12 [
i32 -1, label %15
i32 115, label %7
]
7: ; preds = %4
%8 = load i8*, i8** @optarg
%9 = tail call i8* @atoi(i8* %8)
%10 = ptrtoint i8* %9 to i64
%11 = trunc i64 %10 to i32
br label %4
12: ; preds = %4
%13 = load i8*, i8** %1
%14 = tail call i32 @usage(i8* %13)
br label %32
15: ; preds = %4
%16 = load i32, i32* @optind
%17 = icmp slt i32 %16, %0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = tail call i8* @atoi(i8* %21)
%23 = tail call i32 @kill(i8* %22, i32 %5)
%24 = icmp eq i32 %23, -1
br i1 %24, label %30, label %32
25: ; preds = %15
%26 = load i8*, i8** %1
%27 = tail call i32 @usage(i8* %26)
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %32
30: ; preds = %18
%31 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %18, %30, %25, %12
%33 = phi i32 [ 1, %12 ], [ 1, %30 ], [ 1, %25 ], [ 0, %18 ]
ret i32 %33
}