#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int read(int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int b, i, st;
  pid_t pid;
  st = read(0, &b, sizeof(int));
  for (i = 0; i < b; i++) {
    st = read(0, &pid, sizeof(pid_t));
    if (st < 0) {
      fprintf(stderr, "pipe closed before %d pids transmitted\n", b);
      exit(-1);
    }
    kill(pid, SIGKILL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11da <main+0x9a>
xor    %edi,%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11bb <main+0x7b>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe54(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1170 <main+0x30>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rsi
xor    %edi,%edi
mov    $0x4,%edx
call   1030 <read@plt>
mov    0x4(%rsp),%r14d
test   %r14d,%r14d
jle    1193 <main+0x53>
mov    %rsp,%r15
mov    0x2e6c(%rip),%rbp
mov    %r14d,%ebx
nop
xor    %edi,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <read@plt>
test   %eax,%eax
js     11a0 <main+0x60>
mov    (%rsp),%edi
mov    0x0(%rbp),%esi
call   1050 <kill@plt>
add    $0xffffffff,%ebx
jne    1170 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    %r14d,%edx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"pipe closed before %d pids transmitted\0A\00"
@SIGKILL = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @read(i32 0, i32* %6, i32 4)
store i32 %10, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %31
15: ; preds = %11
%16 = call i32 @read(i32 0, i32* %9, i32 4)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i32, i32* %6
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %15
%25 = load i32, i32* %9
%26 = load i32, i32* @SIGKILL
%27 = call i32 @kill(i32 %25, i32 %26)
br label %28
28: ; preds = %24
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %11
31: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"pipe closed before %d pids transmitted\0A\00"
@SIGKILL = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @read(i32 0, i32* %3, i32 4)
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %2, %18
%11 = phi i32 [ %22, %18 ], [ 0, %2 ]
%12 = call i32 @read(i32 0, i32* %4, i32 4)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %8)
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %10
%19 = load i32, i32* %4
%20 = load i32, i32* @SIGKILL
%21 = tail call i32 @kill(i32 %19, i32 %20)
%22 = add nuw nsw i32 %11, 1
%23 = icmp eq i32 %22, %8
br i1 %23, label %24, label %10
24: ; preds = %18, %2
ret i32 0
}