#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 argc, char **argv) {
  int fds[2];
  pipe(fds);
  if (!fork()) {
    close(fds[0]);
    close(1);
    dup(fds[1]);
    execlp("pgrep", "pgrep", argv[1], NULL);
  }
  close(fds[1]);
  close(0);
  dup(fds[0]);
  int pid;
  while (scanf("%d", &pid) != EOF)
    kill(pid, SIGTERM);
  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)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%eax
jne    11d4 <main+0x64>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1030 <dup@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe38(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1080 <execlp@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1030 <dup@plt>
lea    0xe14(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <scanf@plt>
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%rax
je     1221 <main+0xb1>
mov    -0x1c(%rbp),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    11eb <main+0x7b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
lea    0x10(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
jne    11c4 <main+0x54>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x14(%rsp),%edi
call   1030 <dup@plt>
mov    0x8(%rbx),%rdx
lea    0xe46(%rip),%rdi
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1080 <execlp@plt>
mov    0x14(%rsp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1040 <close@plt>
mov    0x10(%rsp),%edi
call   1030 <dup@plt>
lea    0xe22(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x2deb(%rip),%r15
cmp    (%r15),%rax
je     122d <main+0xbd>
mov    0x2de7(%rip),%r12
lea    0xdfe(%rip),%r14
lea    0xc(%rsp),%rbx
nopl   (%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    1210 <main+0xa0>
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 = [3 x i8] c"%d\00"
@EOF = global i64 0
@SIGTERM = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = call i32 (...) @fork()
%11 = icmp ne i32 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %2
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%14 = load i32, i32* %13
%15 = call i32 @close(i32 %14)
%16 = call i32 @close(i32 1)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 @dup(i32 %18)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = 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* %22, i32* null)
br label %24
24: ; preds = %12, %2
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = call i32 @close(i32 0)
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%30 = load i32, i32* %29
%31 = call i32 @dup(i32 %30)
br label %32
32: ; preds = %36, %24
%33 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%34 = load i64, i64* @EOF
%35 = icmp ne i64 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i32, i32* %7
%38 = load i32, i32* @SIGTERM
%39 = call i32 @kill(i32 %37, i32 %38)
br label %32
40: ; preds = %32
ret i32 0
}

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