#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, i);
      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, i);
        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    12b1 <main+0x121>
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    129b <main+0x10b>
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    -0x18(%rbp),%rax
mov    %eax,%esi
call   10b0 <close_pipes@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12a0 <main+0x110>
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    0x2d27(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x41(%rbp)
jne    12f1 <main+0x161>
mov    0x2d09(%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    1301 <main+0x171>
jmp    13c0 <main+0x230>
mov    -0x40(%rbp),%rdi
mov    0x2cc4(%rip),%rax
mov    (%rax),%edx
mov    0x2cd3(%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    13bb <main+0x22b>
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     13a5 <main+0x215>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    0x8(%rax,%rcx,8),%rdx
lea    0xc9a(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
call   10b0 <close_pipes@plt>
mov    0x2c2a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    13aa <main+0x21a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    132d <main+0x19d>
jmp    12ba <main+0x12a>
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     131a <main+0x18a>
mov    %rax,%r13
mov    %r14,-0x38(%rbp)
mov    %rbx,-0x30(%rbp)
cmp    $0x2,%ebx
jb     1227 <main+0x97>
movslq -0x30(%rbp),%r14
mov    $0x1,%ebx
lea    0xe0b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    -0x38(%rbp),%rax
mov    (%rax,%rbx,8),%rdi
mov    %r15,%rsi
call   1080 <popen@plt>
mov    %rax,-0x8(%r13,%rbx,8)
test   %rax,%rax
je     12f3 <main+0x163>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1200 <main+0x70>
mov    -0x30(%rbp),%rax
add    $0xffffffff,%eax
mov    %rax,-0x30(%rbp)
mov    0x2daf(%rip),%rbx
mov    (%rbx),%edi
call   1060 <feof@plt>
test   %eax,%eax
jne    12c5 <main+0x135>
mov    -0x30(%rbp),%rcx
cmp    $0x2,%ecx
mov    $0x1,%eax
cmovae %ecx,%eax
movslq %eax,%r14
jmp    1272 <main+0xe2>
nopl   0x0(%rax)
mov    0x2d81(%rip),%rbx
mov    (%rbx),%edi
call   1060 <feof@plt>
test   %eax,%eax
jne    12c5 <main+0x135>
mov    (%rbx),%edi
call   1030 <ferror@plt>
test   %eax,%eax
jne    12c5 <main+0x135>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edx
mov    (%rbx),%ecx
mov    %r12,%rdi
mov    $0x1,%esi
call   1040 <fread@plt>
cmpl   $0x0,-0x30(%rbp)
je     1260 <main+0xd0>
mov    %rax,%r15
xor    %ebx,%ebx
mov    0x0(%r13,%rbx,8),%rcx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   10a0 <fwrite@plt>
cmp    %r15,%rax
jne    12d8 <main+0x148>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    12a0 <main+0x110>
jmp    1260 <main+0xd0>
mov    %r13,%rdi
mov    -0x30(%rbp),%rsi
call   10b0 <close_pipes@plt>
mov    %eax,%edi
call   1090 <exit@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rax
mov    0x8(%rax,%rbx,8),%rdx
lea    0xd2c(%rip),%rsi
jmp    130b <main+0x17b>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rax
mov    (%rax,%rbx,8),%rdx
lea    0xcf7(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   10b0 <close_pipes@plt>
mov    0x2ca7(%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 = %62, %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 %65
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 %61, 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 i64, i64* %6
%57 = trunc i64 %56 to i32
%58 = call i32 @close_pipes(i32** %55, i32 %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %32
br label %62
62: ; preds = %61
%63 = load i64, i64* %6
%64 = add i64 %63, 1
store i64 %64, i64* %6
br label %27
65: ; preds = %27
%66 = load i32, i32* %4
%67 = add nsw i32 %66, -1
store i32 %67, i32* %4
br label %68
68: ; preds = %115, %65
%69 = load i32, i32* @stdin
%70 = call i32 @feof(i32 %69)
%71 = icmp ne i32 %70, 0
br i1 %71, label %77, label %72
72: ; preds = %68
%73 = load i32, i32* @stdin
%74 = call i32 @ferror(i32 %73)
%75 = icmp ne i32 %74, 0
%76 = xor i1 %75, true
br label %77
77: ; preds = %72, %68
%78 = phi i1 [ false, %68 ], [ %76, %72 ]
br i1 %78, label %79, label %116
79: ; preds = %77
%80 = load i32, i32* @BUFSIZ
%81 = load i32, i32* @stdin
%82 = call i64 @fread(i8* %14, i32 1, i32 %80, i32 %81)
store i64 %82, i64* %7
store i64 0, i64* %6
br label %83
83: ; preds = %112, %79
%84 = load i64, i64* %6
%85 = load i32, i32* %4
%86 = sext i32 %85 to i64
%87 = icmp ult i64 %84, %86
br i1 %87, label %88, label %115
88: ; preds = %83
%89 = load i64, i64* %7
%90 = load i32**, i32*** %8
%91 = load i64, i64* %6
%92 = getelementptr inbounds i32*, i32** %90, i64 %91
%93 = load i32*, i32** %92
%94 = call i64 @fwrite(i8* %14, i32 1, i64 %89, i32* %93)
%95 = load i64, i64* %7
%96 = icmp ne i64 %94, %95
br i1 %96, label %97, label %111
97: ; preds = %88
%98 = load i32, i32* @stderr
%99 = load i8**, i8*** %5
%100 = load i64, i64* %6
%101 = add i64 %100, 1
%102 = getelementptr inbounds i8*, i8** %99, i64 %101
%103 = load i8*, i8** %102
%104 = call i32 @fprintf(i32 %98, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %103)
%105 = load i32**, i32*** %8
%106 = load i64, i64* %6
%107 = trunc i64 %106 to i32
%108 = call i32 @close_pipes(i32** %105, i32 %107)
%109 = load i32, i32* @EXIT_FAILURE
%110 = call i32 @exit(i32 %109)
unreachable
111: ; preds = %88
br label %112
112: ; preds = %111
%113 = load i64, i64* %6
%114 = add i64 %113, 1
store i64 %114, i64* %6
br label %83
115: ; preds = %83
br label %68
116: ; preds = %77
%117 = load i32**, i32*** %8
%118 = load i32, i32* %4
%119 = call i32 @close_pipes(i32** %117, i32 %118)
%120 = call i32 @exit(i32 %119)
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 %36
13: ; preds = %2
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %10, %33
%17 = phi i64 [ %34, %33 ], [ 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 %33
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 = trunc i64 %17 to i32
%30 = tail call i32 @close_pipes(i32** %8, i32 %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %16
%34 = add nuw i64 %17, 1
%35 = icmp eq i64 %34, %11
br i1 %35, label %36, label %16
36: ; preds = %33, %10
%37 = add nsw i32 %0, -1
%38 = load i32, i32* @stdin
%39 = call i32 @feof(i32 %38)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %76
41: ; preds = %36
%42 = icmp eq i32 %37, 0
%43 = call i32 @llvm.umax.i32(i32 %37, i32 1)
%44 = sext i32 %43 to i64
br label %49
45: ; preds = %73, %53
%46 = load i32, i32* @stdin
%47 = call i32 @feof(i32 %46)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %76
49: ; preds = %41, %45
%50 = load i32, i32* @stdin
%51 = call i32 @ferror(i32 %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %76
53: ; preds = %49
%54 = load i32, i32* @BUFSIZ
%55 = load i32, i32* @stdin
%56 = call i64 @fread(i8* %5, i32 1, i32 %54, i32 %55)
br i1 %42, label %45, label %57
57: ; preds = %53, %73
%58 = phi i64 [ %74, %73 ], [ 0, %53 ]
%59 = getelementptr inbounds i32*, i32** %8, i64 %58
%60 = load i32*, i32** %59
%61 = call i64 @fwrite(i8* %5, i32 1, i64 %56, i32* %60)
%62 = icmp eq i64 %61, %56
br i1 %62, label %73, label %63
63: ; preds = %57
%64 = load i32, i32* @stderr
%65 = add nuw i64 %58, 1
%66 = getelementptr inbounds i8*, i8** %1, i64 %65
%67 = load i8*, i8** %66
%68 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %67)
%69 = trunc i64 %58 to i32
%70 = call i32 @close_pipes(i32** %8, i32 %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %57
%74 = add nuw i64 %58, 1
%75 = icmp eq i64 %74, %44
br i1 %75, label %45, label %57
76: ; preds = %49, %45, %36
%77 = call i32 @close_pipes(i32** %8, i32 %37)
%78 = call i32 @exit(i32 %77)
unreachable
}