#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*/ SIGKILL;
int /*<<< orphan*/ delete_temp_file(char const *, char const *, int);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void destroy_all_readers(int cpus, int *pid_array, const char *node,
                         const char *port) {
  int cpu;
  for (cpu = 0; cpu < cpus; cpu++) {
    if (pid_array[cpu] > 0) {
      kill(pid_array[cpu], SIGKILL);
      waitpid(pid_array[cpu], NULL, 0);
      delete_temp_file(node, port, cpu);
      pid_array[cpu] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<destroy_all_readers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11cd <destroy_all_readers+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    11ba <destroy_all_readers+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <delete_temp_file@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    11bf <destroy_all_readers+0x8f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114e <destroy_all_readers+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<destroy_all_readers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    119d <destroy_all_readers+0x6d>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%r13d
xor    %ebx,%ebx
mov    0x2e8c(%rip),%rbp
jmp    1169 <destroy_all_readers+0x39>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r13
je     119d <destroy_all_readers+0x6d>
mov    (%r12,%rbx,4),%edi
test   %edi,%edi
jle    1160 <destroy_all_readers+0x30>
mov    0x0(%rbp),%esi
call   1040 <kill@plt>
mov    (%r12,%rbx,4),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <delete_temp_file@plt>
movl   $0x0,(%r12,%rbx,4)
jmp    1160 <destroy_all_readers+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SIGKILL = global i32 0
define void @destroy_all_readers(i32 %0, i32* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %9
br label %10
10: ; preds = %44, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %47
14: ; preds = %10
%15 = load i32*, i32** %6
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %43
21: ; preds = %14
%22 = load i32*, i32** %6
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* @SIGKILL
%28 = call i32 @kill(i32 %26, i32 %27)
%29 = load i32*, i32** %6
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = call i32 @waitpid(i32 %33, i32* null, i32 0)
%35 = load i8*, i8** %7
%36 = load i8*, i8** %8
%37 = load i32, i32* %9
%38 = call i32 @delete_temp_file(i8* %35, i8* %36, i32 %37)
%39 = load i32*, i32** %6
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 0, i32* %42
br label %43
43: ; preds = %21, %14
br label %44
44: ; preds = %43
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %10
47: ; preds = %10
ret void
}

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