#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 /*<<< orphan*/ SIGTERM;
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ waitpid(int /*<<< orphan*/, int /*<<< orphan*/ *,
                   int /*<<< orphan*/);
void killForkedProcesses(pid_t *pids, int len) {
  int i;
  for (i = 0; i < len; ++i) {
    if (kill(pids[i], SIGTERM) < 0) {
      ;
    };
    if (waitpid(pids[i], NULL, 0) < 0) {
      ;
    }
  }
}


x86 assembly (clang, -O0):
<killForkedProcesses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a2 <killForkedProcesses+0x82>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
call   1030 <kill@plt>
cmp    $0x0,%rax
jge    116a <killForkedProcesses+0x4a>
jmp    116a <killForkedProcesses+0x4a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0x0,%rax
jge    118f <killForkedProcesses+0x6f>
jmp    118f <killForkedProcesses+0x6f>
jmp    1194 <killForkedProcesses+0x74>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <killForkedProcesses+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<killForkedProcesses>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1163 <killForkedProcesses+0x43>
mov    %rdi,%r15
mov    %esi,%r14d
xor    %ebx,%ebx
mov    0x2ead(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%edi
mov    (%r12),%esi
call   1030 <kill@plt>
mov    (%r15,%rbx,4),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <killForkedProcesses+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@SIGTERM = global i32 0
define void @killForkedProcesses(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %14, %6 ]
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = load i32, i32* @SIGTERM
%11 = tail call i64 @kill(i32 %9, i32 %10)
%12 = load i32, i32* %8
%13 = tail call i64 @waitpid(i32 %12, i32* null, i32 0)
%14 = add nuw nsw i64 %7, 1
%15 = icmp eq i64 %14, %5
br i1 %15, label %16, label %6
16: ; preds = %6, %2
ret void
}