#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
scalar_t__ kill(int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int killchldrn(int **pidlst, int numchld, int sig) {
  int i, cpid, errflag = 0;
  for (i = 0; i < numchld; i++) {
    cpid = *(*pidlst + i);
    if (cpid > 0) {
      if (kill(cpid, sig) < 0) {
        fprintf(stderr, "killchldrn: kill %d failed, %s\n", cpid,
                strerror(errno));
        errflag--;
      }
    }
  }
  return (errflag);
}


x86 assembly (clang, -O0):
<killchldrn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e2 <killchldrn+0xb2>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11cf <killchldrn+0x9f>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <kill@plt>
cmp    $0x0,%rax
jge    11ca <killchldrn+0x9a>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%edx
mov    %rax,%rcx
lea    0xe44(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cf <killchldrn+0x9f>
jmp    11d4 <killchldrn+0xa4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1150 <killchldrn+0x20>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<killchldrn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11b7 <killchldrn+0x87>
mov    %edx,%r13d
mov    %rdi,%r15
mov    %esi,%ebx
xor    %r14d,%r14d
xor    %r12d,%r12d
mov    %rbx,(%rsp)
jmp    1169 <killchldrn+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14
cmp    %r14,%rbx
je     11ba <killchldrn+0x8a>
mov    (%r15),%rax
mov    (%rax,%r14,4),%ebp
test   %ebp,%ebp
jle    1160 <killchldrn+0x30>
mov    %ebp,%edi
mov    %r13d,%esi
call   1040 <kill@plt>
test   %rax,%rax
jns    1160 <killchldrn+0x30>
mov    0x2e56(%rip),%rax
mov    (%rax),%ebx
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %ebx,%edi
mov    (%rsp),%rbx
lea    0xe59(%rip),%rsi
mov    %ebp,%edx
mov    %rax,%rcx
call   1030 <fprintf@plt>
add    $0xffffffff,%r12d
jmp    1160 <killchldrn+0x30>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"killchldrn: kill %d failed, %s\0A\00"
@errno = global i32 0
define i32 @killchldrn(i32** nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %27
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %23
%8 = phi i64 [ 0, %5 ], [ %25, %23 ]
%9 = phi i32 [ 0, %5 ], [ %24, %23 ]
%10 = load i32*, i32** %0
%11 = getelementptr inbounds i32, i32* %10, i64 %8
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %7
%15 = tail call i64 @kill(i32 %12, i32 %2)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %20)
%22 = add nsw i32 %9, -1
br label %23
23: ; preds = %7, %17, %14
%24 = phi i32 [ %22, %17 ], [ %9, %14 ], [ %9, %7 ]
%25 = add nuw nsw i64 %8, 1
%26 = icmp eq i64 %25, %6
br i1 %26, label %27, label %7
27: ; preds = %23, %3
%28 = phi i32 [ 0, %3 ], [ %24, %23 ]
ret i32 %28
}