#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
scalar_t__ cg_read(char const *, char *, char *, int);
scalar_t__ kill(int, int /*<<< orphan*/);
int strtol(char *, char **, int);
int cg_killall(const char *cgroup) {
  char buf[4096];
  char *ptr = buf;
  if (cg_read(cgroup, "cgroup.procs", buf, sizeof(buf)))
    return -1;
  while (ptr < buf + sizeof(buf)) {
    int pid = strtol(ptr, &ptr, 10);
    if (pid == 0)
      break;
    if (*ptr)
      ptr++;
    else
      break;
    if (kill(pid, SIGKILL))
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cg_killall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1018(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1010(%rbp),%rdx
lea    0xea1(%rip),%rsi
mov    $0x1000,%ecx
call   1030 <cg_read@plt>
cmp    $0x0,%rax
je     117f <cg_killall+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1234 <cg_killall+0x104>
jmp    1184 <cg_killall+0x54>
mov    -0x1018(%rbp),%rax
lea    -0x1010(%rbp),%rcx
add    $0x1000,%rcx
cmp    %rcx,%rax
jae    122d <cg_killall+0xfd>
mov    -0x1018(%rbp),%rdi
lea    -0x1018(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x101c(%rbp)
cmpl   $0x0,-0x101c(%rbp)
jne    11d2 <cg_killall+0xa2>
jmp    122d <cg_killall+0xfd>
mov    -0x1018(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f9 <cg_killall+0xc9>
mov    -0x1018(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1018(%rbp)
jmp    11fe <cg_killall+0xce>
jmp    122d <cg_killall+0xfd>
mov    -0x101c(%rbp),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
cmp    $0x0,%rax
je     1228 <cg_killall+0xf8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1234 <cg_killall+0x104>
jmp    1184 <cg_killall+0x54>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_killall>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1010,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,0x8(%rsp)
lea    0xeb0(%rip),%rsi
mov    %rbx,%rdx
mov    $0x1000,%ecx
call   1030 <cg_read@plt>
test   %rax,%rax
je     1179 <cg_killall+0x49>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x1010(%rsp),%r15
lea    0x8(%rsp),%r14
mov    0x2e53(%rip),%r12
xor    %ebp,%ebp
nop
cmp    %r15,%rbx
jae    1167 <cg_killall+0x37>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
test   %eax,%eax
je     1167 <cg_killall+0x37>
mov    0x8(%rsp),%rbx
cmpb   $0x0,(%rbx)
je     1167 <cg_killall+0x37>
add    $0x1,%rbx
mov    %rbx,0x8(%rsp)
mov    (%r12),%esi
mov    %eax,%edi
call   1050 <kill@plt>
test   %rax,%rax
je     1190 <cg_killall+0x60>
jmp    1162 <cg_killall+0x32>

LLVM IR (-O0):
@.str = [13 x i8] c"cgroup.procs\00"
@SIGKILL = global i32 0
define i32 @cg_killall(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4096 x i8]
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
store i8* %7, i8** %5
%8 = load i8*, i8** %3
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%10 = call i64 @cg_read(i8* %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %9, i32 4096)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %41
13: ; preds = %1
br label %14
14: ; preds = %39, %13
%15 = load i8*, i8** %5
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%17 = getelementptr inbounds i8, i8* %16, i64 4096
%18 = icmp ult i8* %15, %17
br i1 %18, label %19, label %40
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = call i32 @strtol(i8* %20, i8** %5, i32 10)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %40
25: ; preds = %19
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %5
br label %33
32: ; preds = %25
br label %40
33: ; preds = %29
%34 = load i32, i32* %6
%35 = load i32, i32* @SIGKILL
%36 = call i64 @kill(i32 %34, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 -1, i32* %2
br label %41
39: ; preds = %33
br label %14
40: ; preds = %32, %24, %14
store i32 0, i32* %2
br label %41
41: ; preds = %40, %38, %12
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [13 x i8] c"cgroup.procs\00"
@SIGKILL = global i32 0
define i32 @cg_killall(i8* %0) {
%2 = alloca [4096 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%5 = bitcast i8** %3 to i8*
store i8* %4, i8** %3
%6 = call i64 @cg_read(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %4, i32 4096)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %1
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 4096
br label %10
10: ; preds = %8, %20
%11 = phi i8* [ %4, %8 ], [ %21, %20 ]
%12 = icmp ult i8* %11, %9
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = call i32 @strtol(i8* %11, i8** %3, i32 10)
%15 = icmp eq i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %21, i8** %3
%22 = load i32, i32* @SIGKILL
%23 = call i64 @kill(i32 %14, i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %10, label %25
25: ; preds = %16, %13, %20, %10, %1
%26 = phi i32 [ -1, %1 ], [ 0, %16 ], [ 0, %13 ], [ -1, %20 ], [ 0, %10 ]
ret i32 %26
}