#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 SIGTERM;
int atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int kill(int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int kill_main(int argc, char **argv) {
  int sig = SIGTERM;
  int result = 0;
  argc--;
  argv++;
  if (argc >= 2 && argv[0][0] == '-') {
    sig = atoi(argv[0] + 1);
    argc--;
    argv++;
  }
  while (argc > 0) {
    int pid = atoi(argv[0]);
    int err = kill(pid, sig);
    if (err < 0) {
      result = err;
      fprintf(stderr, "could not kill pid %d: %s\n", pid, strerror(errno));
    }
    argc--;
    argv++;
  }
  return result;
}


x86 assembly (clang, -O0):
<kill_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jl     11bc <kill_main+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11bc <kill_main+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11c1 <kill_main+0x81>
cmpl   $0x0,-0x4(%rbp)
jle    1247 <kill_main+0x107>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <kill@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    122d <kill_main+0xed>
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    %rax,%rcx
lea    0xdd8(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11c1 <kill_main+0x81>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e94(%rip),%rax
mov    (%rax),%r12d
lea    0x8(%rsi),%rbp
cmp    $0x3,%edi
jl     1187 <kill_main+0x47>
mov    0x0(%rbp),%rdi
cmpb   $0x2d,(%rdi)
jne    11a7 <kill_main+0x67>
mov    %rsi,%r15
add    $0x1,%rdi
call   1050 <atoi@plt>
mov    %eax,%r12d
add    $0xfffffffe,%ebx
add    $0x10,%r15
mov    %ebx,%r14d
mov    %r15,%rbp
jmp    11ad <kill_main+0x6d>
xor    %r15d,%r15d
mov    $0x1,%r14d
cmp    $0x2,%ebx
je     11ad <kill_main+0x6d>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xffffffff,%ebx
mov    %ebx,%r14d
add    $0x1,%r14d
xor    %r15d,%r15d
jmp    11ce <kill_main+0x8e>
cs nopw 0x0(%rax,%rax,1)
add    $0x8,%rbp
add    $0xffffffff,%r14d
cmp    $0x1,%r14d
jle    1195 <kill_main+0x55>
mov    0x0(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%r13d
mov    %eax,%edi
mov    %r12d,%esi
call   1040 <kill@plt>
test   %eax,%eax
jns    11c0 <kill_main+0x80>
mov    %eax,%ebx
mov    0x2de7(%rip),%rax
mov    (%rax),%r15d
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %r15d,%edi
lea    0xdf4(%rip),%rsi
mov    %r13d,%edx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    %ebx,%r15d
jmp    11c0 <kill_main+0x80>

LLVM IR (-O0):
@SIGTERM = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"could not kill pid %d: %s\0A\00"
@errno = global i32 0
define i32 @kill_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* @SIGTERM
store i32 %9, i32* %5
store i32 0, i32* %6
%10 = load i32, i32* %3
%11 = add nsw i32 %10, -1
store i32 %11, i32* %3
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i32 1
store i8** %13, i8*** %4
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 2
br i1 %15, label %16, label %34
16: ; preds = %2
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%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 %34
24: ; preds = %16
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %5
%30 = load i32, i32* %3
%31 = add nsw i32 %30, -1
store i32 %31, i32* %3
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i32 1
store i8** %33, i8*** %4
br label %34
34: ; preds = %24, %16, %2
br label %35
35: ; preds = %55, %34
%36 = load i32, i32* %3
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %60
38: ; preds = %35
%39 = load i8**, i8*** %4
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = load i32, i32* %5
%45 = call i32 @kill(i32 %43, i32 %44)
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %38
%49 = load i32, i32* %8
store i32 %49, i32* %6
%50 = load i32, i32* @stderr
%51 = load i32, i32* %7
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %51, i8* %53)
br label %55
55: ; preds = %48, %38
%56 = load i32, i32* %3
%57 = add nsw i32 %56, -1
store i32 %57, i32* %3
%58 = load i8**, i8*** %4
%59 = getelementptr inbounds i8*, i8** %58, i32 1
store i8** %59, i8*** %4
br label %35
60: ; preds = %35
%61 = load i32, i32* %6
ret i32 %61
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"could not kill pid %d: %s\0A\00"
@errno = global i32 0
define i32 @kill_main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @SIGTERM
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = add nsw i32 %0, -1
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 45
br i1 %10, label %11, label %18
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %8, i64 1
%13 = tail call i32 @atoi(i8* %12)
%14 = add nsw i32 %0, -2
%15 = getelementptr inbounds i8*, i8** %1, i64 2
br label %18
16: ; preds = %2
%17 = icmp eq i32 %0, 2
br i1 %17, label %18, label %40
18: ; preds = %6, %11, %16
%19 = phi i32 [ 1, %16 ], [ %7, %6 ], [ %14, %11 ]
%20 = phi i8** [ %4, %16 ], [ %4, %6 ], [ %15, %11 ]
%21 = phi i32 [ %3, %16 ], [ %3, %6 ], [ %13, %11 ]
br label %22
22: ; preds = %18, %35
%23 = phi i32 [ %37, %35 ], [ %19, %18 ]
%24 = phi i8** [ %38, %35 ], [ %20, %18 ]
%25 = phi i32 [ %36, %35 ], [ 0, %18 ]
%26 = load i8*, i8** %24
%27 = tail call i32 @atoi(i8* %26)
%28 = tail call i32 @kill(i32 %27, i32 %21)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %27, i8* %33)
br label %35
35: ; preds = %30, %22
%36 = phi i32 [ %28, %30 ], [ %25, %22 ]
%37 = add nsw i32 %23, -1
%38 = getelementptr inbounds i8*, i8** %24, i64 1
%39 = icmp sgt i32 %23, 1
br i1 %39, label %22, label %40
40: ; preds = %35, %16
%41 = phi i32 [ 0, %16 ], [ %36, %35 ]
ret i32 %41
}