#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 */
scalar_t__ EOF;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ pipe(int *);
scalar_t__ scanf(char *, int *);
int main() {
  int fd[2];
  pipe(fd);
  if (!fork()) {
    close(fd[0]);
    close(1);
    dup(fd[1]);
    execlp("pgrep", "pgrep", "cat", NULL);
  } else {
    close(fd[1]);
    close(0);
    dup(fd[0]);
    int pid;
    while (scanf("%d", &pid) != EOF)
      kill(pid, SIGTERM);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%eax
jne    11d1 <main+0x61>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1030 <dup@plt>
lea    0xe47(%rip),%rsi
lea    0xe46(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1080 <execlp@plt>
jmp    1223 <main+0xb3>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1030 <dup@plt>
lea    0xe1b(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
mov    0x2de1(%rip),%rcx
cmp    (%rcx),%rax
je     121e <main+0xae>
mov    -0x10(%rbp),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    11e8 <main+0x78>
jmp    1223 <main+0xb3>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11ff <main+0x8f>
mov    0x14(%rsp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1040 <close@plt>
mov    0x10(%rsp),%edi
call   1030 <dup@plt>
lea    0xe5a(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x2e1f(%rip),%r15
cmp    (%r15),%rax
je     1233 <main+0xc3>
mov    0x2e1b(%rip),%r12
lea    0xe36(%rip),%r14
lea    0xc(%rsp),%rbx
nopl   0x0(%rax)
mov    0xc(%rsp),%edi
mov    (%r12),%esi
call   1060 <kill@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
cmp    (%r15),%rax
jne    11e0 <main+0x70>
jmp    1233 <main+0xc3>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x14(%rsp),%edi
call   1030 <dup@plt>
lea    0xdde(%rip),%rdi
lea    0xddd(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1080 <execlp@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"pgrep\00"
@.str.1 = [4 x i8] c"cat\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i64 0
@SIGTERM = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = call i32 (...) @fork()
%7 = icmp ne i32 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %0
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%10 = load i32, i32* %9
%11 = call i32 @close(i32 %10)
%12 = call i32 @close(i32 1)
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 @dup(i32 %14)
%16 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %34
17: ; preds = %0
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = call i32 @close(i32 0)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%23 = load i32, i32* %22
%24 = call i32 @dup(i32 %23)
br label %25
25: ; preds = %29, %17
%26 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%27 = load i64, i64* @EOF
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* %3
%31 = load i32, i32* @SIGTERM
%32 = call i32 @kill(i32 %30, i32 %31)
br label %25
33: ; preds = %25
br label %34
34: ; preds = %33, %8
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"pgrep\00"
@.str.1 = [4 x i8] c"cat\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i64 0
@SIGTERM = global i32 0
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = call i32 (...) @fork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %0
%9 = load i32, i32* %4
%10 = call i32 @close(i32 %9)
%11 = call i32 @close(i32 1)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @dup(i32 %13)
%15 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %35
16: ; preds = %0
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 @close(i32 %18)
%20 = call i32 @close(i32 0)
%21 = load i32, i32* %4
%22 = call i32 @dup(i32 %21)
%23 = bitcast i32* %2 to i8*
%24 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %34, label %27
27: ; preds = %16, %27
%28 = load i32, i32* %2
%29 = load i32, i32* @SIGTERM
%30 = call i32 @kill(i32 %28, i32 %29)
%31 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%32 = load i64, i64* @EOF
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %27
34: ; preds = %27, %16
br label %35
35: ; preds = %34, %8
ret i32 0
}