#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 _pidof(char const *, int /*<<< orphan*/ **);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int kill(int /*<<< orphan*/, int);
int killall(const char *name, int sig) {
  pid_t *pids;
  int i;
  int r;
  if ((i = _pidof(name, &pids)) > 0) {
    r = 0;
    do {
      r |= kill(pids[--i], sig);
    } while (i > 0);
    free(pids);
    return r;
  }
  return -2;
}


x86 assembly (clang, -O0):
<killall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <_pidof@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    119e <killall+0x6e>
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x14(%rbp),%esi
call   1040 <kill@plt>
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     115f <killall+0x2f>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a5 <killall+0x75>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<killall>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
lea    0x8(%rsp),%rsi
call   1050 <_pidof@plt>
test   %eax,%eax
jle    118b <killall+0x5b>
mov    %eax,%ebx
add    $0x1,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
lea    -0x2(%rbx),%ecx
mov    (%rax,%rcx,4),%edi
mov    %r14d,%esi
call   1040 <kill@plt>
or     %eax,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1160 <killall+0x30>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    1190 <killall+0x60>
mov    $0xfffffffe,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @killall(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32 @_pidof(i8* %9, i32** %6)
store i32 %10, i32* %7
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %2
store i32 0, i32* %8
br label %13
13: ; preds = %24, %12
%14 = load i32*, i32** %6
%15 = load i32, i32* %7
%16 = add nsw i32 %15, -1
store i32 %16, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %14, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %5
%21 = call i32 @kill(i32 %19, i32 %20)
%22 = load i32, i32* %8
%23 = or i32 %22, %21
store i32 %23, i32* %8
br label %24
24: ; preds = %13
%25 = load i32, i32* %7
%26 = icmp sgt i32 %25, 0
br i1 %26, label %13, label %27
27: ; preds = %24
%28 = load i32*, i32** %6
%29 = call i32 @free(i32* %28)
%30 = load i32, i32* %8
store i32 %30, i32* %3
br label %32
31: ; preds = %2
store i32 -2, i32* %3
br label %32
32: ; preds = %31, %27
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @killall(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = call i32 @_pidof(i8* %0, i32** %3)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %2
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ %8, %7 ], [ %13, %9 ]
%11 = phi i32 [ 0, %7 ], [ %18, %9 ]
%12 = load i32*, i32** %3
%13 = add nsw i64 %10, -1
%14 = and i64 %13, 4294967295
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = call i32 @kill(i32 %16, i32 %1)
%18 = or i32 %17, %11
%19 = icmp ugt i64 %10, 1
br i1 %19, label %9, label %20
20: ; preds = %9
%21 = load i32*, i32** %3
%22 = call i32 @free(i32* %21)
br label %23
23: ; preds = %2, %20
%24 = phi i32 [ %18, %20 ], [ -2, %2 ]
ret i32 %24
}