#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execl(char *, char *, char *, ...);
int fork();
int /*<<< orphan*/ pipe(int *);
int main() {
  int pidFils;
  int fp[2];
  pipe(fp);
  char buffer[1000];
  pidFils = fork();
  if (pidFils != 0) {
    close(fp[0]);
    dup2(fp[1], STDOUT_FILENO);
    execl("/usr/bin/who", "who", NULL);
  } else {
    close(fp[1]);
    dup2(fp[0], STDIN_FILENO);
    execl("/bin/grep", "grep", "dcremill", NULL);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11b6 <main+0x66>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xe61(%rip),%rdi
lea    0xe63(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1060 <execl@plt>
jmp    11ef <main+0x9f>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xe37(%rip),%rdi
lea    0xe35(%rip),%rsi
lea    0xe33(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   1060 <execl@plt>
mov    -0x4(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1197 <main+0x47>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xe7b(%rip),%rdi
lea    0xe7d(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <execl@plt>
jmp    11cf <main+0x7f>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xe55(%rip),%rdi
lea    0xe53(%rip),%rsi
lea    0xe51(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <execl@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [13 x i8] c"/usr/bin/who\00"
@.str.1 = [4 x i8] c"who\00"
@STDIN_FILENO = global i32 0
@.str.2 = [10 x i8] c"/bin/grep\00"
@.str.3 = [5 x i8] c"grep\00"
@.str.4 = [9 x i8] c"dcremill\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca [1000 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%12 = load i32, i32* %11
%13 = call i32 @close(i32 %12)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%15 = load i32, i32* %14
%16 = load i32, i32* @STDOUT_FILENO
%17 = call i32 @dup2(i32 %15, i32 %16)
%18 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* null)
br label %28
19: ; preds = %0
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%24 = load i32, i32* %23
%25 = load i32, i32* @STDIN_FILENO
%26 = call i32 @dup2(i32 %24, i32 %25)
%27 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* null)
br label %28
28: ; preds = %19, %10
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [13 x i8] c"/usr/bin/who\00"
@.str.1 = [4 x i8] c"who\00"
@STDIN_FILENO = global i32 0
@.str.2 = [10 x i8] c"/bin/grep\00"
@.str.3 = [5 x i8] c"grep\00"
@.str.4 = [9 x i8] c"dcremill\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i32 @pipe(i32* %3)
%5 = call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = load i32, i32* %3
%9 = call i32 @close(i32 %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%11 = load i32, i32* %10
%12 = load i32, i32* @STDOUT_FILENO
%13 = call i32 @dup2(i32 %11, i32 %12)
%14 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* null)
br label %23
15: ; preds = %0
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* %3
%20 = load i32, i32* @STDIN_FILENO
%21 = call i32 @dup2(i32 %19, i32 %20)
%22 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* null)
br label %23
23: ; preds = %15, %7
ret i32 0
}