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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int kill(int, int);
int /*<<< orphan*/ printf(char *, ...);
int syscall1(int);
int main(int argc, char *argv[]) {
  int sig, pid, res, err;
  switch (argc) {
  case 2:
    sig = 15;
    pid = atoi(argv[1]);
    break;
  case 3:
    if (argv[1][0] == '-')
      sig = atoi(argv[1] + 1);
    else
      sig = atoi(argv[1]);
    pid = atoi(argv[2]);
    break;
  default:
    printf("kill: requires one or two arguments ([signal] pid)\n");
    exit(0);
  }
  printf("kill: sending signal %d to process %d\n", sig, pid);
  res = kill(pid, sig);
  if (res == -1) {
    err = (syscall1(501));
    printf("kill: could not send signal. ");
    switch (err) {
    case 1:
      printf("permission denied\n");
      break;
    case 3:
      printf("no such process\n");
      break;
    case 22:
      printf("invalid signal number\n");
      break;
    default:
      printf("reason unknown; errno = %d\n", err);
    };
  }
  exit(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    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x2,%eax
je     118b <main+0x3b>
jmp    117a <main+0x2a>
mov    -0x24(%rbp),%eax
sub    $0x3,%eax
je     11a7 <main+0x57>
jmp    11f9 <main+0xa9>
movl   $0xf,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    120e <main+0xbe>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11d4 <main+0x84>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    11e4 <main+0x94>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    120e <main+0xbe>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <kill@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12da <main+0x18a>
mov    $0x1f5,%edi
call   1050 <syscall1@plt>
mov    %eax,-0x20(%rbp)
lea    0xe0d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     128b <main+0x13b>
jmp    1269 <main+0x119>
mov    -0x28(%rbp),%eax
sub    $0x3,%eax
je     129e <main+0x14e>
jmp    127a <main+0x12a>
mov    -0x28(%rbp),%eax
sub    $0x16,%eax
je     12b1 <main+0x161>
jmp    12c4 <main+0x174>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d5 <main+0x185>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d5 <main+0x185>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d5 <main+0x185>
mov    -0x20(%rbp),%esi
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12da <main+0x18a>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1192 <main+0x32>
cmp    $0x3,%edi
jne    11f9 <main+0x99>
mov    0x8(%rbx),%rax
xor    %edi,%edi
cmpb   $0x2d,(%rax)
sete   %dil
add    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    $0x2,%eax
jmp    119c <main+0x3c>
mov    $0xf,%ebp
mov    $0x1,%eax
mov    (%rbx,%rax,8),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
lea    0xe52(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <kill@plt>
cmp    $0xffffffff,%eax
jne    122e <main+0xce>
mov    $0x1f5,%edi
call   1060 <syscall1@plt>
mov    %eax,%ebx
lea    0xe4d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x16,%ebx
je     1202 <main+0xa2>
cmp    $0x3,%ebx
je     120b <main+0xab>
cmp    $0x1,%ebx
jne    121e <main+0xbe>
lea    0xe90(%rip),%rdi
jmp    1212 <main+0xb2>
lea    0xe99(%rip),%rdi
jmp    1212 <main+0xb2>
lea    0xe58(%rip),%rdi
jmp    1212 <main+0xb2>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe20(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [52 x i8] c"kill: requires one or two arguments ([signal] pid)\0A\00"
@.str.1 = [39 x i8] c"kill: sending signal %d to process %d\0A\00"
@.str.2 = [30 x i8] c"kill: could not send signal. \00"
@.str.3 = [19 x i8] c"permission denied\0A\00"
@.str.4 = [17 x i8] c"no such process\0A\00"
@.str.5 = [23 x i8] c"invalid signal number\0A\00"
@.str.6 = [28 x i8] c"reason unknown; errno = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%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* %4
switch i32 %10, label %40 [
i32 2, label %11
i32 3, label %16
]
11: ; preds = %2
store i32 15, i32* %6
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %7
br label %43
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 45
br i1 %23, label %24, label %30
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %6
br label %35
30: ; preds = %16
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %6
br label %35
35: ; preds = %30, %24
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %7
br label %43
40: ; preds = %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %35, %11
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %45)
%47 = load i32, i32* %7
%48 = load i32, i32* %6
%49 = call i32 @kill(i32 %47, i32 %48)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %66
52: ; preds = %43
%53 = call i32 @syscall1(i32 501)
store i32 %53, i32* %9
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32, i32* %9
switch i32 %55, label %62 [
i32 1, label %56
i32 3, label %58
i32 22, label %60
]
56: ; preds = %52
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %65
58: ; preds = %52
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %65
60: ; preds = %52
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %65
62: ; preds = %52
%63 = load i32, i32* %9
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62, %60, %58, %56
br label %66
66: ; preds = %65, %43
%67 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [39 x i8] c"kill: sending signal %d to process %d\0A\00"
@.str.2 = [30 x i8] c"kill: could not send signal. \00"
@.str.6 = [28 x i8] c"reason unknown; errno = %d\0A\00"
@str = [22 x i8] c"invalid signal number\00"
@str.7 = [16 x i8] c"no such process\00"
@str.8 = [18 x i8] c"permission denied\00"
@str.9 = [51 x i8] c"kill: requires one or two arguments ([signal] pid)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %11 [
i32 2, label %14
i32 3, label %3
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 45
%8 = zext i1 %7 to i64
%9 = getelementptr i8, i8* %5, i64 %8
%10 = tail call i32 @atoi(i8* %9)
br label %14
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.9, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2, %3
%15 = phi i64 [ 2, %3 ], [ 1, %2 ]
%16 = phi i32 [ %10, %3 ], [ 15, %2 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %15
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %19)
%21 = tail call i32 @kill(i32 %19, i32 %16)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %34
23: ; preds = %14
%24 = tail call i32 @syscall1(i32 501)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
switch i32 %24, label %32 [
i32 1, label %26
i32 3, label %28
i32 22, label %30
]
26: ; preds = %23
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
br label %34
28: ; preds = %23
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
br label %34
30: ; preds = %23
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %34
32: ; preds = %23
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %24)
br label %34
34: ; preds = %26, %28, %30, %32, %14
%35 = tail call i32 @exit(i32 0)
unreachable
}