#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close_pipes(int /*<<< orphan*/ **, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ **malloc(int);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  size_t i, r;
  FILE **pipes;
  char buf[BUFSIZ];
  pipes = malloc(((argc - 1) * sizeof *pipes));
  if (!pipes)
    exit(EXIT_FAILURE);
  for (i = 1; i < argc; i++) {
    pipes[i - 1] = popen(argv[i], "w");
    if (!pipes[i - 1]) {
      fprintf(stderr, "Can not open pipe to '%s\'\n", argv[i]);
      close_pipes(pipes, argc);
      exit(EXIT_FAILURE);
    }
  }
  argc--;
  while (!feof(stdin) && (!ferror(stdin))) {
    r = fread(buf, sizeof(char), BUFSIZ, stdin);
    for (i = 0; i < argc; i++) {
      if (fwrite(buf, sizeof(char), r, pipes[i]) != r) {
        fprintf(stderr, "Write error to `%s\'\n", argv[i + 1]);
        close_pipes(pipes, argc);
        exit(EXIT_FAILURE);
      }
    }
  }
  exit(close_pipes(pipes, argc));
}


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    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1202 <main+0x72>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
jae    12ae <main+0x11e>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdd2(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1298 <main+0x108>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd89(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10b0 <close_pipes@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    129d <main+0x10d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    120a <main+0x7a>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x41(%rbp)
jne    12ee <main+0x15e>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    12fe <main+0x16e>
jmp    13ba <main+0x22a>
mov    -0x40(%rbp),%rdi
mov    0x2cc7(%rip),%rax
mov    (%rax),%edx
mov    0x2cd6(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
jae    13b5 <main+0x225>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
cmp    -0x20(%rbp),%rax
je     139f <main+0x20f>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    0x8(%rax,%rcx,8),%rdx
lea    0xc9d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10b0 <close_pipes@plt>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    13a4 <main+0x214>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    132a <main+0x19a>
jmp    12b7 <main+0x127>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10b0 <close_pipes@plt>
mov    %eax,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x8(,%rbx,8),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     132c <main+0x19c>
mov    %rax,%r13
mov    %r14,-0x38(%rbp)
mov    %rbx,-0x30(%rbp)
cmp    $0x2,%ebx
jb     1228 <main+0x98>
movslq -0x30(%rbp),%r15
add    $0xffffffffffffffff,%r15
xor    %ebx,%ebx
lea    0xe0a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    -0x38(%rbp),%rax
mov    0x8(%rax,%rbx,8),%rdi
mov    %r14,%rsi
call   1080 <popen@plt>
mov    %rax,0x0(%r13,%rbx,8)
test   %rax,%rax
je     1302 <main+0x172>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1200 <main+0x70>
mov    -0x30(%rbp),%r15
add    $0xffffffff,%r15d
mov    0x2db1(%rip),%rbx
mov    (%rbx),%edi
call   1060 <feof@plt>
test   %eax,%eax
jne    12d5 <main+0x145>
cmp    $0x2,%r15d
mov    $0x1,%eax
cmovae %r15d,%eax
movslq %eax,%r14
mov    %r15,-0x30(%rbp)
jmp    1276 <main+0xe6>
nopl   0x0(%rax)
mov    0x2d81(%rip),%rbx
mov    (%rbx),%edi
call   1060 <feof@plt>
test   %eax,%eax
mov    -0x30(%rbp),%r15
jne    12d5 <main+0x145>
mov    (%rbx),%edi
call   1030 <ferror@plt>
test   %eax,%eax
jne    12d5 <main+0x145>
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
mov    (%rbx),%ecx
mov    %r12,%rdi
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %r15,%rcx
test   %ecx,%ecx
je     1260 <main+0xd0>
mov    %rax,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbx,8),%rcx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   10a0 <fwrite@plt>
cmp    %r15,%rax
jne    12e7 <main+0x157>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    12b0 <main+0x120>
jmp    1260 <main+0xd0>
mov    %r13,%rdi
mov    %r15d,%esi
call   10b0 <close_pipes@plt>
mov    %eax,%edi
call   1090 <exit@plt>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rax
mov    0x8(%rax,%rbx,8),%rdx
lea    0xd1d(%rip),%rsi
jmp    131b <main+0x18b>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rax
mov    0x8(%rax,%rbx,8),%rdx
lea    0xce7(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r13,%rdi
mov    -0x30(%rbp),%rsi
call   10b0 <close_pipes@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Can not open pipe to '%s'\0A\00"
@stdin = global i32 0
@.str.2 = [21 x i8] c"Write error to `%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32**
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 8
%19 = trunc i64 %18 to i32
%20 = call i32** @malloc(i32 %19)
store i32** %20, i32*** %8
%21 = load i32**, i32*** %8
%22 = icmp ne i32** %21, null
br i1 %22, label %26, label %23
23: ; preds = %2
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %2
store i64 1, i64* %6
br label %27
27: ; preds = %61, %26
%28 = load i64, i64* %6
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = icmp ult i64 %28, %30
br i1 %31, label %32, label %64
32: ; preds = %27
%33 = load i8**, i8*** %5
%34 = load i64, i64* %6
%35 = getelementptr inbounds i8*, i8** %33, i64 %34
%36 = load i8*, i8** %35
%37 = call i32* @popen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%38 = load i32**, i32*** %8
%39 = load i64, i64* %6
%40 = sub i64 %39, 1
%41 = getelementptr inbounds i32*, i32** %38, i64 %40
store i32* %37, i32** %41
%42 = load i32**, i32*** %8
%43 = load i64, i64* %6
%44 = sub i64 %43, 1
%45 = getelementptr inbounds i32*, i32** %42, i64 %44
%46 = load i32*, i32** %45
%47 = icmp ne i32* %46, null
br i1 %47, label %60, label %48
48: ; preds = %32
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = load i64, i64* %6
%52 = getelementptr inbounds i8*, i8** %50, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = load i32**, i32*** %8
%56 = load i32, i32* %4
%57 = call i32 @close_pipes(i32** %55, i32 %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %32
br label %61
61: ; preds = %60
%62 = load i64, i64* %6
%63 = add i64 %62, 1
store i64 %63, i64* %6
br label %27
64: ; preds = %27
%65 = load i32, i32* %4
%66 = add nsw i32 %65, -1
store i32 %66, i32* %4
br label %67
67: ; preds = %113, %64
%68 = load i32, i32* @stdin
%69 = call i32 @feof(i32 %68)
%70 = icmp ne i32 %69, 0
br i1 %70, label %76, label %71
71: ; preds = %67
%72 = load i32, i32* @stdin
%73 = call i32 @ferror(i32 %72)
%74 = icmp ne i32 %73, 0
%75 = xor i1 %74, true
br label %76
76: ; preds = %71, %67
%77 = phi i1 [ false, %67 ], [ %75, %71 ]
br i1 %77, label %78, label %114
78: ; preds = %76
%79 = load i32, i32* @BUFSIZ
%80 = load i32, i32* @stdin
%81 = call i64 @fread(i8* %14, i32 1, i32 %79, i32 %80)
store i64 %81, i64* %7
store i64 0, i64* %6
br label %82
82: ; preds = %110, %78
%83 = load i64, i64* %6
%84 = load i32, i32* %4
%85 = sext i32 %84 to i64
%86 = icmp ult i64 %83, %85
br i1 %86, label %87, label %113
87: ; preds = %82
%88 = load i64, i64* %7
%89 = load i32**, i32*** %8
%90 = load i64, i64* %6
%91 = getelementptr inbounds i32*, i32** %89, i64 %90
%92 = load i32*, i32** %91
%93 = call i64 @fwrite(i8* %14, i32 1, i64 %88, i32* %92)
%94 = load i64, i64* %7
%95 = icmp ne i64 %93, %94
br i1 %95, label %96, label %109
96: ; preds = %87
%97 = load i32, i32* @stderr
%98 = load i8**, i8*** %5
%99 = load i64, i64* %6
%100 = add i64 %99, 1
%101 = getelementptr inbounds i8*, i8** %98, i64 %100
%102 = load i8*, i8** %101
%103 = call i32 @fprintf(i32 %97, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %102)
%104 = load i32**, i32*** %8
%105 = load i32, i32* %4
%106 = call i32 @close_pipes(i32** %104, i32 %105)
%107 = load i32, i32* @EXIT_FAILURE
%108 = call i32 @exit(i32 %107)
unreachable
109: ; preds = %87
br label %110
110: ; preds = %109
%111 = load i64, i64* %6
%112 = add i64 %111, 1
store i64 %112, i64* %6
br label %82
113: ; preds = %82
br label %67
114: ; preds = %76
%115 = load i32**, i32*** %8
%116 = load i32, i32* %4
%117 = call i32 @close_pipes(i32** %115, i32 %116)
%118 = call i32 @exit(i32 %117)
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Can not open pipe to '%s'\0A\00"
@stdin = global i32 0
@.str.2 = [21 x i8] c"Write error to `%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = shl i32 %0, 3
%7 = add i32 %6, -8
%8 = tail call i32** @malloc(i32 %7)
%9 = icmp eq i32** %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = sext i32 %0 to i64
%12 = icmp ugt i32 %0, 1
br i1 %12, label %16, label %35
13: ; preds = %2
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %10, %32
%17 = phi i64 [ %33, %32 ], [ 1, %10 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32* @popen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = add i64 %17, -1
%22 = getelementptr inbounds i32*, i32** %8, i64 %21
store i32* %20, i32** %22
%23 = icmp eq i32* %20, null
br i1 %23, label %24, label %32
24: ; preds = %16
%25 = getelementptr inbounds i8*, i8** %1, i64 %17
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %25
%28 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = tail call i32 @close_pipes(i32** %8, i32 %0)
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %16
%33 = add nuw i64 %17, 1
%34 = icmp eq i64 %33, %11
br i1 %34, label %35, label %16
35: ; preds = %32, %10
%36 = add nsw i32 %0, -1
%37 = load i32, i32* @stdin
%38 = call i32 @feof(i32 %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %74
40: ; preds = %35
%41 = icmp eq i32 %36, 0
%42 = call i32 @llvm.umax.i32(i32 %36, i32 1)
%43 = sext i32 %42 to i64
br label %48
44: ; preds = %71, %52
%45 = load i32, i32* @stdin
%46 = call i32 @feof(i32 %45)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %74
48: ; preds = %40, %44
%49 = load i32, i32* @stdin
%50 = call i32 @ferror(i32 %49)
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %74
52: ; preds = %48
%53 = load i32, i32* @BUFSIZ
%54 = load i32, i32* @stdin
%55 = call i64 @fread(i8* %5, i32 1, i32 %53, i32 %54)
br i1 %41, label %44, label %56
56: ; preds = %52, %71
%57 = phi i64 [ %72, %71 ], [ 0, %52 ]
%58 = getelementptr inbounds i32*, i32** %8, i64 %57
%59 = load i32*, i32** %58
%60 = call i64 @fwrite(i8* %5, i32 1, i64 %55, i32* %59)
%61 = icmp eq i64 %60, %55
br i1 %61, label %71, label %62
62: ; preds = %56
%63 = load i32, i32* @stderr
%64 = add nuw i64 %57, 1
%65 = getelementptr inbounds i8*, i8** %1, i64 %64
%66 = load i8*, i8** %65
%67 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %66)
%68 = call i32 @close_pipes(i32** %8, i32 %36)
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %56
%72 = add nuw i64 %57, 1
%73 = icmp eq i64 %72, %43
br i1 %73, label %44, label %56
74: ; preds = %48, %44, %35
%75 = call i32 @close_pipes(i32** %8, i32 %36)
%76 = call i32 @exit(i32 %75)
unreachable
}