#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 */
scalar_t__ EPERM;
scalar_t__ ESRCH;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ atol(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int kill(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
char *strerror(scalar_t__);
int main(int argc, char *argv[]) {
  int s, sig;
  if (argc != 3 || strcmp(argv[1], "--help") == 0) {
    printf("Usage %s sig-num pid\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  sig = atoi(argv[1]);
  s = kill(atol(argv[2]), sig);
  if (sig != 0) {
    if (sig == -1) {
      printf("Error on kill, %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
  } else {
    if (s == 0) {
      printf("Process exists and we can send it a signal\n");
    } else {
      if (errno == EPERM) {
        printf(
            "process exists but we don't have permission to send a signal\n");
      } else if (errno == ESRCH) {
        printf("Process does not exist\n");
      } else {
        printf("Error on kill %s\n", strerror(errno));
        exit(EXIT_FAILURE);
      }
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11ae <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe61(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <main+0x61>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atol@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%esi
call   1050 <kill@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1242 <main+0xd2>
cmpl   $0xffffffff,-0x18(%rbp)
jne    123d <main+0xcd>
mov    0x2dca(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12f6 <main+0x186>
cmpl   $0x0,-0x14(%rbp)
jne    125f <main+0xef>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f1 <main+0x181>
mov    0x2d7a(%rip),%rax
mov    (%rax),%rax
mov    0x2d50(%rip),%rcx
cmp    (%rcx),%rax
jne    128c <main+0x11c>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ec <main+0x17c>
mov    0x2d4d(%rip),%rax
mov    (%rax),%rax
mov    0x2d1b(%rip),%rcx
cmp    (%rcx),%rax
jne    12b9 <main+0x149>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12e7 <main+0x177>
mov    0x2d20(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12ec <main+0x17c>
jmp    12f1 <main+0x181>
jmp    12f6 <main+0x186>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11a0 <main+0x20>
mov    0x8(%rbx),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11bf <main+0x3f>
mov    (%rbx),%rsi
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   1070 <atol@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1060 <kill@plt>
test   %ebp,%ebp
je     1200 <main+0x80>
cmp    $0xffffffff,%ebp
jne    1244 <main+0xc4>
mov    0x2df4(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xe22(%rip),%rdi
mov    %rax,%rsi
jmp    11aa <main+0x2a>
test   %eax,%eax
jne    120d <main+0x8d>
lea    0xe8b(%rip),%rdi
jmp    123f <main+0xbf>
mov    0x2dcc(%rip),%rax
mov    (%rax),%rdi
mov    0x2da2(%rip),%rax
cmp    (%rax),%rdi
jne    122c <main+0xac>
lea    0xe2f(%rip),%rdi
jmp    123f <main+0xbf>
mov    0x2d85(%rip),%rax
cmp    (%rax),%rdi
jne    1252 <main+0xd2>
lea    0xe03(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
call   10a0 <strerror@plt>
lea    0xdd2(%rip),%rdi
jmp    11fb <main+0x7b>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [22 x i8] c"Usage %s sig-num pid\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [19 x i8] c"Error on kill, %s\0A\00"
@errno = global i64 0
@.str.3 = [44 x i8] c"Process exists and we can send it a signal\0A\00"
@EPERM = global i64 0
@.str.4 = [62 x i8] c"process exists but we don't have permission to send a signal\0A\00"
@ESRCH = global i64 0
@.str.5 = [24 x i8] c"Process does not exist\0A\00"
@.str.6 = [18 x i8] c"Error on kill %s\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 i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %10, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %10
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atol(i8* %30)
%32 = load i32, i32* %7
%33 = call i32 @kill(i32 %31, i32 %32)
store i32 %33, i32* %6
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %23
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i64, i64* @errno
%41 = call i8* @strerror(i64 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %36
br label %72
46: ; preds = %23
%47 = load i32, i32* %6
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %71
51: ; preds = %46
%52 = load i64, i64* @errno
%53 = load i64, i64* @EPERM
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.4, i64 0, i64 0))
br label %70
57: ; preds = %51
%58 = load i64, i64* @errno
%59 = load i64, i64* @ESRCH
%60 = icmp eq i64 %58, %59
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %69
63: ; preds = %57
%64 = load i64, i64* @errno
%65 = call i8* @strerror(i64 %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %65)
%67 = load i32, i32* @EXIT_FAILURE
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %61
br label %70
70: ; preds = %69, %55
br label %71
71: ; preds = %70, %49
br label %72
72: ; preds = %71, %45
%73 = load i32, i32* @EXIT_SUCCESS
%74 = call i32 @exit(i32 %73)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.1 = [22 x i8] c"Usage %s sig-num pid\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [19 x i8] c"Error on kill, %s\0A\00"
@errno = global i64 0
@EPERM = global i64 0
@ESRCH = global i64 0
@.str.6 = [18 x i8] c"Error on kill %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [23 x i8] c"Process does not exist\00"
@str.7 = [61 x i8] c"process exists but we don't have permission to send a signal\00"
@str.8 = [43 x i8] c"Process exists and we can send it a signal\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %4, %2
%10 = load i8*, i8** %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @atol(i8* %18)
%20 = tail call i32 @kill(i32 %19, i32 %16)
switch i32 %16, label %44 [
i32 0, label %27
i32 -1, label %21
]
21: ; preds = %14
%22 = load i64, i64* @errno
%23 = tail call i8* @strerror(i64 %22)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %14
%28 = icmp eq i32 %20, 0
br i1 %28, label %41, label %29
29: ; preds = %27
%30 = load i64, i64* @errno
%31 = load i64, i64* @EPERM
%32 = icmp eq i64 %30, %31
br i1 %32, label %41, label %33
33: ; preds = %29
%34 = load i64, i64* @ESRCH
%35 = icmp eq i64 %30, %34
br i1 %35, label %41, label %36
36: ; preds = %33
%37 = tail call i8* @strerror(i64 %30)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %33, %29, %27
%42 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @str.8, i64 0, i64 0), %27 ], [ getelementptr inbounds ([61 x i8], [61 x i8]* @str.7, i64 0, i64 0), %29 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0), %33 ]
%43 = tail call i32 @puts(i8* dereferenceable(1) %42)
br label %44
44: ; preds = %41, %14
%45 = load i32, i32* @EXIT_SUCCESS
%46 = tail call i32 @exit(i32 %45)
unreachable
}