#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 */
struct stat {
  int st_ino;
};
struct dirent {
  int /*<<< orphan*/ d_name;
};
typedef int pid_t;
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int BUFSIZ;
scalar_t__ EINVAL;
scalar_t__ chdir(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int getsid(int /*<<< orphan*/);
scalar_t__ kill(int, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int sscanf(char const *, char *, int *, unsigned long *, unsigned long *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strrchr(char *, char);
int strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int killall(int sig) {
  int sid = getsid(0);
  struct stat st;
  if (stat("/proc/stat", &st) < 0) {
    perror("killall5: can't access /proc/stat");
    return 1;
  }
  if (stat("/proc", &st) < 0 || st.st_ino != 1) {
    fprintf(stderr, "killall5: /proc not mounted");
    return 1;
  }
  if (chdir("/proc") < 0) {
    perror("killall5: can't enter /proc");
    return 1;
  }
  DIR *dir = opendir(".");
  if (!dir) {
    perror("killall5: can't open /proc");
    return 1;
  }
  struct dirent *entry;
  while ((entry = readdir(dir))) {
    errno = 0;
    pid_t pid = strtol(entry->d_name, NULL, 10);
    if (errno || pid <= 1)
      continue;
    char path[32], buf[BUFSIZ];
    snprintf(path, sizeof(path), "/proc/%d/stat", pid);
    FILE *f = fopen(path, "rb");
    if (!f)
      goto next;
    if (!fread(buf, 1, BUFSIZ, f))
      goto next;
    const char *p = strrchr(buf, ')');
    if (!p)
      goto next;
    p += 2;
    int procsid;
    unsigned long startcode, endcode;
    if (sscanf(p,
               "%*c %*d %*d %d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %*d "
               "%*d %*d %*d %*u %*u %*d %*u %lu %lu",
               &procsid, &startcode, &endcode) < 3)
      goto next;
    if (!procsid || procsid == sid || (startcode == 0 && endcode == 0))
      goto next;
    if (kill(pid, sig) < 0 && errno == EINVAL) {
      fclose(f);
      closedir(dir);
      fprintf(stderr, "killall5: invalid signal: %d\n", sig);
      return 1;
    }
  next:
    if (f)
      fclose(f);
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<killall>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
xor    %edi,%edi
call   1090 <getsid@plt>
mov    %eax,-0xc(%rbp)
lea    0xdf8(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0x0,%rax
jge    124a <killall+0x4a>
lea    0xdc7(%rip),%rdi
call   1120 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1544 <killall+0x344>
lea    0xe20(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0x0,%rax
jl     126e <killall+0x6e>
cmpl   $0x1,-0x10(%rbp)
je     1291 <killall+0x91>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1544 <killall+0x344>
lea    0xdd9(%rip),%rdi
call   1060 <chdir@plt>
cmp    $0x0,%rax
jge    12bf <killall+0xbf>
lea    0xd90(%rip),%rdi
call   1120 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1544 <killall+0x344>
lea    0xd94(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12f2 <killall+0xf2>
lea    0xd7b(%rip),%rdi
call   1120 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1544 <killall+0x344>
jmp    12f7 <killall+0xf7>
mov    -0x18(%rbp),%rdi
call   10f0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1534 <killall+0x334>
mov    0x2cbb(%rip),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10d0 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    0x2c96(%rip),%rax
cmpq   $0x0,(%rax)
jne    134e <killall+0x14e>
cmpl   $0x1,-0x24(%rbp)
jg     1353 <killall+0x153>
jmp    12f7 <killall+0xf7>
mov    0x2c7e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x24(%rbp),%ecx
mov    $0x20,%esi
lea    0xce2(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x50(%rbp),%rdi
lea    0xce0(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    13be <killall+0x1be>
jmp    14f2 <killall+0x2f2>
mov    -0x98(%rbp),%rdi
mov    0x2c0c(%rip),%rax
mov    (%rax),%edx
mov    -0x68(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    13ea <killall+0x1ea>
jmp    14f2 <killall+0x2f2>
mov    -0x98(%rbp),%rdi
mov    $0x29,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    140f <killall+0x20f>
jmp    14f2 <killall+0x2f2>
mov    -0x70(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
lea    0xc62(%rip),%rsi
lea    -0x74(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    -0x88(%rbp),%r8
call   1100 <sscanf@plt>
cmp    $0x3,%eax
jge    1448 <killall+0x248>
jmp    14f2 <killall+0x2f2>
cmpl   $0x0,-0x74(%rbp)
je     1477 <killall+0x277>
mov    -0x74(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1477 <killall+0x277>
cmpq   $0x0,-0x80(%rbp)
jne    147c <killall+0x27c>
cmpq   $0x0,-0x88(%rbp)
jne    147c <killall+0x27c>
jmp    14f2 <killall+0x2f2>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10e0 <kill@plt>
cmp    $0x0,%rax
jge    14ed <killall+0x2ed>
mov    0x2b38(%rip),%rax
mov    (%rax),%rax
mov    0x2b26(%rip),%rcx
cmp    (%rcx),%rax
jne    14ed <killall+0x2ed>
mov    -0x68(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <closedir@plt>
mov    0x2b1c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xc1b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
jmp    1510 <killall+0x310>
jmp    14f2 <killall+0x2f2>
cmpq   $0x0,-0x68(%rbp)
je     1506 <killall+0x306>
mov    -0x68(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x8c(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
mov    -0x8c(%rbp),%eax
test   %eax,%eax
je     152f <killall+0x32f>
jmp    152a <killall+0x32a>
jmp    1544 <killall+0x344>
jmp    12f7 <killall+0xf7>
mov    -0x18(%rbp),%rdi
call   10a0 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<killall>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edi,%r14d
xor    %edi,%edi
call   1090 <getsid@plt>
mov    %eax,-0x38(%rbp)
lea    0xdf2(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   10c0 <stat@plt>
test   %rax,%rax
js     1453 <killall+0x253>
lea    0xe33(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   10c0 <stat@plt>
test   %rax,%rax
js     141c <killall+0x21c>
cmpl   $0x1,-0x30(%rbp)
jne    141c <killall+0x21c>
lea    0xe10(%rip),%rdi
call   1060 <chdir@plt>
test   %rax,%rax
js     1461 <killall+0x261>
lea    0xde4(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     146f <killall+0x26f>
mov    %rax,%r13
mov    %r14d,-0x34(%rbp)
mov    %rax,%rdi
call   10f0 <readdir@plt>
test   %rax,%rax
je     143a <killall+0x23a>
mov    0x2d2d(%rip),%rbx
jmp    12cd <killall+0xcd>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    -0x48(%rbp),%rsp
mov    %r13,%rdi
call   10f0 <readdir@plt>
test   %rax,%rax
je     143a <killall+0x23a>
movq   $0x0,(%rbx)
mov    (%rax),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   10d0 <strtol@plt>
cmpq   $0x0,(%rbx)
jne    12bc <killall+0xbc>
mov    %eax,%r15d
cmp    $0x2,%eax
jl     12bc <killall+0xbc>
mov    %rsp,-0x48(%rbp)
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    -0x80(%rbp),%r12
mov    %r12,%rdi
mov    $0x20,%esi
lea    0xd56(%rip),%rdx
mov    %r15d,%ecx
call   1070 <snprintf@plt>
mov    %r12,%rdi
lea    0xd52(%rip),%rsi
call   1110 <fopen@plt>
test   %rax,%rax
je     12b8 <killall+0xb8>
mov    %rax,%r12
mov    0x2c8d(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r12,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     12b0 <killall+0xb0>
mov    %r14,%rdi
mov    $0x29,%esi
call   1080 <strrchr@plt>
test   %rax,%rax
je     12b0 <killall+0xb0>
add    $0x2,%rax
mov    %rax,%rdi
lea    0xcff(%rip),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x58(%rbp),%rcx
lea    -0x50(%rbp),%r8
call   1100 <sscanf@plt>
cmp    $0x3,%eax
jl     12b0 <killall+0xb0>
mov    -0x3c(%rbp),%eax
test   %eax,%eax
je     12b0 <killall+0xb0>
cmp    -0x38(%rbp),%eax
je     12b0 <killall+0xb0>
mov    -0x58(%rbp),%rax
or     -0x50(%rbp),%rax
je     12b0 <killall+0xb0>
mov    %r15d,%edi
mov    -0x34(%rbp),%esi
call   10e0 <kill@plt>
test   %rax,%rax
jns    12b0 <killall+0xb0>
mov    (%rbx),%rax
mov    0x2be5(%rip),%rcx
cmp    (%rcx),%rax
jne    12b0 <killall+0xb0>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
call   10a0 <closedir@plt>
mov    0x2bdd(%rip),%rax
mov    (%rax),%edi
lea    0xcdf(%rip),%rsi
mov    -0x34(%rbp),%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    -0x48(%rbp),%rsp
jmp    1433 <killall+0x233>
mov    0x2bbd(%rip),%rax
mov    (%rax),%edi
lea    0xbf6(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%eax
jmp    1444 <killall+0x244>
mov    %r13,%rdi
call   10a0 <closedir@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xba6(%rip),%rdi
call   1120 <perror@plt>
jmp    1433 <killall+0x233>
lea    0xbd6(%rip),%rdi
call   1120 <perror@plt>
jmp    1433 <killall+0x233>
lea    0xbe6(%rip),%rdi
call   1120 <perror@plt>
jmp    1433 <killall+0x233>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i32 }
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [34 x i8] c"killall5: can't access /proc/stat\00"
@.str.2 = [6 x i8] c"/proc\00"
@stderr = global i32 0
@.str.3 = [28 x i8] c"killall5: /proc not mounted\00"
@.str.4 = [28 x i8] c"killall5: can't enter /proc\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [27 x i8] c"killall5: can't open /proc\00"
@errno = global i64 0
@BUFSIZ = global i32 0
@.str.7 = [14 x i8] c"/proc/%d/stat\00"
@.str.8 = [3 x i8] c"rb\00"
@.str.9 = [99 x i8] c"%*c %*d %*d %d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %*d %*d %*d %*d %*u %*u %*d %*u %lu %lu\00"
@EINVAL = global i64 0
@.str.10 = [30 x i8] c"killall5: invalid signal: %d\0A\00"
define i32 @killall(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i32
%9 = alloca [32 x i8]
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
%17 = alloca i32
store i32 %0, i32* %3
%18 = call i32 @getsid(i32 0)
store i32 %18, i32* %4
%19 = call i64 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %struct.stat* %5)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %137
23: ; preds = %1
%24 = call i64 @stat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %5)
%25 = icmp slt i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%28 = load i32, i32* %27
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %33
30: ; preds = %26, %23
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %2
br label %137
33: ; preds = %26
%34 = call i64 @chdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %137
38: ; preds = %33
%39 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %39, i32** %6
%40 = load i32*, i32** %6
%41 = icmp ne i32* %40, null
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %2
br label %137
44: ; preds = %38
br label %45
45: ; preds = %133, %59, %44
%46 = load i32*, i32** %6
%47 = call %struct.dirent* @readdir(i32* %46)
store %struct.dirent* %47, %struct.dirent** %7
%48 = icmp ne %struct.dirent* %47, null
br i1 %48, label %49, label %134
49: ; preds = %45
store i64 0, i64* @errno
%50 = load %struct.dirent*, %struct.dirent** %7
%51 = getelementptr inbounds %struct.dirent, %struct.dirent* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @strtol(i32 %52, i32* null, i32 10)
store i32 %53, i32* %8
%54 = load i64, i64* @errno
%55 = icmp ne i64 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %49
%57 = load i32, i32* %8
%58 = icmp sle i32 %57, 1
br i1 %58, label %59, label %60
59: ; preds = %56, %49
br label %45
60: ; preds = %56
%61 = load i32, i32* @BUFSIZ
%62 = zext i32 %61 to i64
%63 = call i8* @llvm.stacksave()
store i8* %63, i8** %10
%64 = alloca i8, i64 %62
store i64 %62, i64* %11
%65 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%66 = load i32, i32* %8
%67 = call i32 @snprintf(i8* %65, i32 32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %66)
%68 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%69 = call i32* @fopen(i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %69, i32** %12
%70 = load i32*, i32** %12
%71 = icmp ne i32* %70, null
br i1 %71, label %73, label %72
72: ; preds = %60
br label %123
73: ; preds = %60
%74 = load i32, i32* @BUFSIZ
%75 = load i32*, i32** %12
%76 = call i32 @fread(i8* %64, i32 1, i32 %74, i32* %75)
%77 = icmp ne i32 %76, 0
br i1 %77, label %79, label %78
78: ; preds = %73
br label %123
79: ; preds = %73
%80 = call i8* @strrchr(i8* %64, i8 signext 41)
store i8* %80, i8** %13
%81 = load i8*, i8** %13
%82 = icmp ne i8* %81, null
br i1 %82, label %84, label %83
83: ; preds = %79
br label %123
84: ; preds = %79
%85 = load i8*, i8** %13
%86 = getelementptr inbounds i8, i8* %85, i64 2
store i8* %86, i8** %13
%87 = load i8*, i8** %13
%88 = call i32 @sscanf(i8* %87, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.9, i64 0, i64 0), i32* %14, i64* %15, i64* %16)
%89 = icmp slt i32 %88, 3
br i1 %89, label %90, label %91
90: ; preds = %84
br label %123
91: ; preds = %84
%92 = load i32, i32* %14
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %104
94: ; preds = %91
%95 = load i32, i32* %14
%96 = load i32, i32* %4
%97 = icmp eq i32 %95, %96
br i1 %97, label %104, label %98
98: ; preds = %94
%99 = load i64, i64* %15
%100 = icmp eq i64 %99, 0
br i1 %100, label %101, label %105
101: ; preds = %98
%102 = load i64, i64* %16
%103 = icmp eq i64 %102, 0
br i1 %103, label %104, label %105
104: ; preds = %101, %94, %91
br label %123
105: ; preds = %101, %98
%106 = load i32, i32* %8
%107 = load i32, i32* %3
%108 = call i64 @kill(i32 %106, i32 %107)
%109 = icmp slt i64 %108, 0
br i1 %109, label %110, label %122
110: ; preds = %105
%111 = load i64, i64* @errno
%112 = load i64, i64* @EINVAL
%113 = icmp eq i64 %111, %112
br i1 %113, label %114, label %122
114: ; preds = %110
%115 = load i32*, i32** %12
%116 = call i32 @fclose(i32* %115)
%117 = load i32*, i32** %6
%118 = call i32 @closedir(i32* %117)
%119 = load i32, i32* @stderr
%120 = load i32, i32* %3
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i32 %120)
store i32 1, i32* %2
store i32 1, i32* %17
br label %130
122: ; preds = %110, %105
br label %123
123: ; preds = %122, %104, %90, %83, %78, %72
%124 = load i32*, i32** %12
%125 = icmp ne i32* %124, null
br i1 %125, label %126, label %129
126: ; preds = %123
%127 = load i32*, i32** %12
%128 = call i32 @fclose(i32* %127)
br label %129
129: ; preds = %126, %123
store i32 0, i32* %17
br label %130
130: ; preds = %129, %114
%131 = load i8*, i8** %10
%132 = load i32, i32* %17
switch i32 %132, label %139 [
i32 0, label %133
i32 1, label %137
]
133: ; preds = %130
br label %45
134: ; preds = %45
%135 = load i32*, i32** %6
%136 = call i32 @closedir(i32* %135)
store i32 0, i32* %2
br label %137
137: ; preds = %134, %130, %42, %36, %30, %21
%138 = load i32, i32* %2
ret i32 %138
139: ; preds = %130
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i32 }
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [34 x i8] c"killall5: can't access /proc/stat\00"
@.str.2 = [6 x i8] c"/proc\00"
@stderr = global i32 0
@.str.3 = [28 x i8] c"killall5: /proc not mounted\00"
@.str.4 = [28 x i8] c"killall5: can't enter /proc\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [27 x i8] c"killall5: can't open /proc\00"
@errno = global i64 0
@BUFSIZ = global i32 0
@.str.7 = [14 x i8] c"/proc/%d/stat\00"
@.str.8 = [3 x i8] c"rb\00"
@.str.9 = [99 x i8] c"%*c %*d %*d %d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %*d %*d %*d %*d %*u %*u %*d %*u %lu %lu\00"
@EINVAL = global i64 0
@.str.10 = [30 x i8] c"killall5: invalid signal: %d\0A\00"
define i32 @killall(i32 %0) {
%2 = alloca %struct.stat
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = tail call i32 @getsid(i32 0)
%8 = bitcast %struct.stat* %2 to i8*
%9 = call i64 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %97
13: ; preds = %1
%14 = call i64 @stat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %2)
%15 = icmp slt i64 %14, 0
%16 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%17 = load i32, i32* %16
%18 = icmp ne i32 %17, 1
%19 = select i1 %15, i1 true, i1 %18
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %97
23: ; preds = %13
%24 = call i64 @chdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %97
28: ; preds = %23
%29 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = call %struct.dirent* @readdir(i32* %29)
%33 = icmp eq %struct.dirent* %32, null
br i1 %33, label %90, label %34
34: ; preds = %31
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
br label %38
36: ; preds = %28
%37 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %97
38: ; preds = %34, %87
%39 = phi %struct.dirent* [ %32, %34 ], [ %88, %87 ]
store i64 0, i64* @errno
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i64 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 @strtol(i32 %41, i32* null, i32 10)
%43 = load i64, i64* @errno
%44 = icmp ne i64 %43, 0
%45 = icmp slt i32 %42, 2
%46 = select i1 %44, i1 true, i1 %45
br i1 %46, label %87, label %47
47: ; preds = %38
%48 = load i32, i32* @BUFSIZ
%49 = zext i32 %48 to i64
%50 = call i8* @llvm.stacksave()
%51 = alloca i8, i64 %49
%52 = call i32 @snprintf(i8* %35, i32 32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %42)
%53 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%54 = icmp eq i32* %53, null
br i1 %54, label %86, label %55
55: ; preds = %47
%56 = load i32, i32* @BUFSIZ
%57 = call i32 @fread(i8* %51, i32 1, i32 %56, i32* %53)
%58 = icmp eq i32 %57, 0
br i1 %58, label %84, label %59
59: ; preds = %55
%60 = call i8* @strrchr(i8* %51, i8 signext 41)
%61 = icmp eq i8* %60, null
br i1 %61, label %84, label %62
62: ; preds = %59
%63 = getelementptr inbounds i8, i8* %60, i64 2
%64 = call i32 @sscanf(i8* %63, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.9, i64 0, i64 0), i32* %4, i64* %5, i64* %6)
%65 = icmp slt i32 %64, 3
%66 = load i32, i32* %4
%67 = icmp eq i32 %66, 0
%68 = select i1 %65, i1 true, i1 %67
%69 = icmp eq i32 %66, %7
%70 = select i1 %68, i1 true, i1 %69
br i1 %70, label %84, label %71
71: ; preds = %62
%72 = load i64, i64* %5
%73 = icmp eq i64 %72, 0
%74 = load i64, i64* %6
%75 = icmp eq i64 %74, 0
%76 = select i1 %73, i1 %75, i1 false
br i1 %76, label %84, label %77
77: ; preds = %71
%78 = call i64 @kill(i32 %42, i32 %0)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %77
%81 = load i64, i64* @errno
%82 = load i64, i64* @EINVAL
%83 = icmp eq i64 %81, %82
br i1 %83, label %92, label %84
84: ; preds = %55, %59, %62, %71, %80, %77
%85 = call i32 @fclose(i32* %53)
br label %86
86: ; preds = %47, %84
br label %87
87: ; preds = %38, %86
%88 = call %struct.dirent* @readdir(i32* %29)
%89 = icmp eq %struct.dirent* %88, null
br i1 %89, label %90, label %38
90: ; preds = %87, %31
%91 = call i32 @closedir(i32* %29)
br label %97
92: ; preds = %80
%93 = call i32 @fclose(i32* %53)
%94 = call i32 @closedir(i32* %29)
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i32 %0)
br label %97
97: ; preds = %92, %36, %90, %26, %20, %11
%98 = phi i32 [ 1, %11 ], [ 1, %20 ], [ 1, %26 ], [ 1, %36 ], [ 0, %90 ], [ 1, %92 ]
ret i32 %98
}