#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 dirent {
  char *d_name;
};
typedef int pid_t;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int SIGCONT;
int SIGSTOP;
int atoi(char *);
int getpid();
int getsid(int);
int /*<<< orphan*/ kill(int, int);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  struct dirent *dir;
  DIR *dirstream;
  register pid_t pid, sid, mypid, mysid;
  int signal = -1;
  unsigned int sig_sent = 0;
  if (argc == 2) {
    if (argv[1][0] == '-')
      argv[1]++;
    signal = atoi(argv[1]);
  }
  if ((signal < 1) || (signal > 31)) {
    write(2, "Usage: killall5 SIGNAL\n", sizeof "Usage: killall5 SIGNAL\n" - 1);
    return 1;
  }
  kill(-1, SIGSTOP);
  if ((dirstream = opendir("/proc"))) {
    mypid = getpid();
    mysid = getsid(0);
    while ((dir = readdir(dirstream))) {
      pid = atoi(dir->d_name);
      if (pid > 1) {
        sig_sent = 1;
        sid = getsid(pid);
        if ((pid != mypid) && (sid != mysid))
          kill(pid, signal);
      }
    }
  }
  kill(-1, SIGCONT);
  if (!sig_sent) {
    write(2, "No processes found - /proc not mounted?\n",
          sizeof "No processes found - /proc not mounted?\n" - 1);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11d2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11c2 <main+0x52>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
jl     11e6 <main+0x76>
cmpl   $0x1f,-0x34(%rbp)
jle    1208 <main+0x98>
mov    $0x2,%edi
lea    0xe0e(%rip),%rsi
mov    $0x17,%edx
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    1303 <main+0x193>
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
call   1070 <kill@plt>
lea    0xdf6(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12bd <main+0x14d>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x2c(%rbp)
xor    %edi,%edi
call   1060 <getsid@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12b8 <main+0x148>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jle    12b3 <main+0x143>
movl   $0x1,-0x38(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <getsid@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     12ae <main+0x13e>
mov    -0x28(%rbp),%eax
cmp    -0x30(%rbp),%eax
je     12ae <main+0x13e>
mov    -0x24(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1070 <kill@plt>
jmp    12b3 <main+0x143>
jmp    1249 <main+0xd9>
jmp    12bd <main+0x14d>
mov    0x2d24(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
call   1070 <kill@plt>
cmpl   $0x0,-0x38(%rbp)
jne    12fc <main+0x18c>
mov    $0x2,%edi
lea    0xd38(%rip),%rsi
mov    $0x28,%edx
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    1303 <main+0x193>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11a2 <main+0x32>
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    1191 <main+0x21>
add    $0x1,%rdi
mov    %rdi,0x8(%rsi)
call   1090 <atoi@plt>
mov    %eax,%r14d
lea    -0x20(%r14),%eax
cmp    $0xffffffe0,%eax
ja     11cc <main+0x5c>
lea    0xe57(%rip),%rsi
mov    $0x2,%edi
mov    $0x17,%edx
call   1030 <write@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
call   1070 <kill@plt>
lea    0xe32(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1217 <main+0xa7>
mov    %rax,%rbx
xor    %r13d,%r13d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%r12d
xor    %edi,%edi
call   1060 <getsid@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
jne    123d <main+0xcd>
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
call   1070 <kill@plt>
jmp    128d <main+0x11d>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     126f <main+0xff>
mov    (%rax),%rdi
call   1090 <atoi@plt>
cmp    $0x2,%eax
jl     1230 <main+0xc0>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <getsid@plt>
mov    $0x1,%r13d
cmp    %r12d,%ebp
je     1230 <main+0xc0>
cmp    %r15d,%eax
je     1230 <main+0xc0>
mov    %ebp,%edi
mov    %r14d,%esi
call   1070 <kill@plt>
jmp    1230 <main+0xc0>
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
call   1070 <kill@plt>
xor    %eax,%eax
test   %r13d,%r13d
jne    11bd <main+0x4d>
lea    0xd8a(%rip),%rsi
mov    $0x2,%edi
mov    $0x28,%edx
jmp    11b3 <main+0x43>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [24 x i8] c"Usage: killall5 SIGNAL\0A\00"
@SIGSTOP = global i32 0
@.str.1 = [6 x i8] c"/proc\00"
@SIGCONT = global i32 0
@.str.2 = [41 x i8] c"No processes found - /proc not mounted?\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.dirent*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %12
store i32 0, i32* %13
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %34
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 %29
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, i32 1
store i8* %28, i8** %26
br label %29
29: ; preds = %24, %16
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %12
br label %34
34: ; preds = %29, %2
%35 = load i32, i32* %12
%36 = icmp slt i32 %35, 1
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load i32, i32* %12
%39 = icmp sgt i32 %38, 31
br i1 %39, label %40, label %42
40: ; preds = %37, %34
%41 = call i32 @write(i32 2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 23)
store i32 1, i32* %3
br label %86
42: ; preds = %37
%43 = load i32, i32* @SIGSTOP
%44 = call i32 @kill(i32 -1, i32 %43)
%45 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32* %45, i32** %7
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %78
47: ; preds = %42
%48 = call i32 (...) @getpid()
store i32 %48, i32* %10
%49 = call i32 @getsid(i32 0)
store i32 %49, i32* %11
br label %50
50: ; preds = %76, %47
%51 = load i32*, i32** %7
%52 = call %struct.dirent* @readdir(i32* %51)
store %struct.dirent* %52, %struct.dirent** %6
%53 = icmp ne %struct.dirent* %52, null
br i1 %53, label %54, label %77
54: ; preds = %50
%55 = load %struct.dirent*, %struct.dirent** %6
%56 = getelementptr inbounds %struct.dirent, %struct.dirent* %55, i32 0, i32 0
%57 = load i8*, i8** %56
%58 = call i32 @atoi(i8* %57)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp sgt i32 %59, 1
br i1 %60, label %61, label %76
61: ; preds = %54
store i32 1, i32* %13
%62 = load i32, i32* %8
%63 = call i32 @getsid(i32 %62)
store i32 %63, i32* %9
%64 = load i32, i32* %8
%65 = load i32, i32* %10
%66 = icmp ne i32 %64, %65
br i1 %66, label %67, label %75
67: ; preds = %61
%68 = load i32, i32* %9
%69 = load i32, i32* %11
%70 = icmp ne i32 %68, %69
br i1 %70, label %71, label %75
71: ; preds = %67
%72 = load i32, i32* %8
%73 = load i32, i32* %12
%74 = call i32 @kill(i32 %72, i32 %73)
br label %75
75: ; preds = %71, %67, %61
br label %76
76: ; preds = %75, %54
br label %50
77: ; preds = %50
br label %78
78: ; preds = %77, %42
%79 = load i32, i32* @SIGCONT
%80 = call i32 @kill(i32 -1, i32 %79)
%81 = load i32, i32* %13
%82 = icmp ne i32 %81, 0
br i1 %82, label %85, label %83
83: ; preds = %78
%84 = call i32 @write(i32 2, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 40)
store i32 1, i32* %3
br label %86
85: ; preds = %78
store i32 0, i32* %3
br label %86
86: ; preds = %85, %83, %40
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [24 x i8] c"Usage: killall5 SIGNAL\0A\00"
@SIGSTOP = global i32 0
@.str.1 = [6 x i8] c"/proc\00"
@SIGCONT = global i32 0
@.str.2 = [41 x i8] c"No processes found - /proc not mounted?\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 45
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %6, i64 1
store i8* %10, i8** %5
br label %11
11: ; preds = %4, %9
%12 = phi i8* [ %6, %4 ], [ %10, %9 ]
%13 = tail call i32 @atoi(i8* %12)
%14 = add i32 %13, -32
%15 = icmp ult i32 %14, -31
br i1 %15, label %16, label %18
16: ; preds = %2, %11
%17 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 23)
br label %55
18: ; preds = %11
%19 = load i32, i32* @SIGSTOP
%20 = tail call i32 @kill(i32 -1, i32 %19)
%21 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %50, label %23
23: ; preds = %18
%24 = tail call i32 (...) @getpid()
%25 = tail call i32 @getsid(i32 0)
%26 = tail call %struct.dirent* @readdir(i32* %21)
%27 = icmp eq %struct.dirent* %26, null
br i1 %27, label %50, label %28
28: ; preds = %23, %42
%29 = phi %struct.dirent* [ %44, %42 ], [ %26, %23 ]
%30 = phi i32 [ %43, %42 ], [ 0, %23 ]
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 0
%32 = load i8*, i8** %31
%33 = tail call i32 @atoi(i8* %32)
%34 = icmp sgt i32 %33, 1
br i1 %34, label %35, label %42
35: ; preds = %28
%36 = tail call i32 @getsid(i32 %33)
%37 = icmp eq i32 %33, %24
%38 = icmp eq i32 %36, %25
%39 = select i1 %37, i1 true, i1 %38
br i1 %39, label %42, label %40
40: ; preds = %35
%41 = tail call i32 @kill(i32 %33, i32 %13)
br label %42
42: ; preds = %35, %40, %28
%43 = phi i32 [ 1, %40 ], [ 1, %35 ], [ %30, %28 ]
%44 = tail call %struct.dirent* @readdir(i32* %21)
%45 = icmp eq %struct.dirent* %44, null
br i1 %45, label %46, label %28
46: ; preds = %42
%47 = load i32, i32* @SIGCONT
%48 = tail call i32 @kill(i32 -1, i32 %47)
%49 = icmp eq i32 %43, 0
br i1 %49, label %53, label %55
50: ; preds = %23, %18
%51 = load i32, i32* @SIGCONT
%52 = tail call i32 @kill(i32 -1, i32 %51)
br label %53
53: ; preds = %50, %46
%54 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 40)
br label %55
55: ; preds = %46, %53, %16
%56 = phi i32 [ 1, %16 ], [ 1, %53 ], [ 0, %46 ]
ret i32 %56
}