#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*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char *cmd[4] = {"file", "-b", NULL, NULL};
  int pfd[2], n;
  char ch;
  cmd[2] = argv[1];
  if (pipe(pfd) == -1) {
    perror("pipe");
    exit(1);
  }
  switch (fork()) {
  case 0:
    close(pfd[0]);
    close(1);
    dup(pfd[1]);
    execvp(cmd[0], cmd);
  case -1:
    break;
  default:
    close(pfd[1]);
    while (read(pfd[0], &ch, 1) > 0) {
      write(1, &ch, 1);
    }
    wait(NULL);
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c43(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c40(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c3d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c3a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1216 <main+0x76>
lea    0xe01(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
sub    $0xffffffff,%eax
je     1267 <main+0xc7>
jmp    1230 <main+0x90>
mov    -0x44(%rbp),%eax
test   %eax,%eax
jne    126c <main+0xcc>
jmp    1240 <main+0xa0>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    -0x34(%rbp),%edi
call   1040 <dup@plt>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <execvp@plt>
jmp    12ac <main+0x10c>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
mov    -0x38(%rbp),%edi
lea    -0x3d(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0x0,%eax
jle    12a3 <main+0x103>
mov    $0x1,%edx
lea    -0x3d(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    1274 <main+0xd4>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <wait@plt>
mov    $0x1,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movaps 0x2c64(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c48(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    0x8(%rsi),%rax
mov    %rax,0x20(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     1289 <main+0xe9>
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     127e <main+0xde>
test   %eax,%eax
jne    121c <main+0x7c>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1040 <dup@plt>
lea    0xdf0(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1090 <execvp@plt>
jmp    127e <main+0xde>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1277 <main+0xd7>
lea    0x7(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
test   %eax,%eax
jg     1250 <main+0xb0>
xor    %edi,%edi
call   10b0 <wait@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xd78(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"file\00"
@.str.1 = [3 x i8] c"-b\00"
@__const.main.cmd = [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null, i8* null]
@.str.2 = [5 x i8] c"pipe\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i8*]
%7 = alloca [2 x i32]
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [4 x i8*]* %6 to i8*
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 2
store i8* %13, i8** %14
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%16 = call i32 @pipe(i32* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i32 (...) @fork()
switch i32 %22, label %36 [
i32 0, label %23
i32 -1, label %35
]
23: ; preds = %21
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = call i32 @close(i32 1)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @dup(i32 %29)
%31 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%32 = load i8*, i8** %31
%33 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%34 = call i32 @execvp(i8* %32, i8** %33)
br label %35
35: ; preds = %21, %23
br label %49
36: ; preds = %21
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
br label %40
40: ; preds = %45, %36
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%42 = load i32, i32* %41
%43 = call i32 @read(i32 %42, i8* %9, i32 1)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = call i32 @write(i32 1, i8* %9, i32 1)
br label %40
47: ; preds = %40
%48 = call i32 @wait(i32* null)
br label %49
49: ; preds = %47, %35
ret i32 1
}

LLVM IR (-O2):
@.str = [5 x i8] c"file\00"
@.str.1 = [3 x i8] c"-b\00"
@__const.main.cmd = [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null, i8* null]
@.str.2 = [5 x i8] c"pipe\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8*]
%4 = alloca [2 x i32]
%5 = alloca i8
%6 = bitcast [4 x i8*]* %3 to i8*
%7 = bitcast [2 x i32]* %4 to i8*
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 2
store i8* %9, i8** %10
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = call i32 (...) @fork()
switch i32 %18, label %28 [
i32 0, label %19
i32 -1, label %42
]
19: ; preds = %17
%20 = load i32, i32* %11
%21 = call i32 @close(i32 %20)
%22 = call i32 @close(i32 1)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @dup(i32 %24)
%26 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%27 = call i32 @execvp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %26)
br label %42
28: ; preds = %17
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %11
%33 = call i32 @read(i32 %32, i8* %5, i32 1)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %28, %35
%36 = call i32 @write(i32 1, i8* %5, i32 1)
%37 = load i32, i32* %11
%38 = call i32 @read(i32 %37, i8* %5, i32 1)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %35, label %40
40: ; preds = %35, %28
%41 = call i32 @wait(i32* null)
br label %42
42: ; preds = %40, %19, %17
ret i32 1
}