#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
char *countFrequency(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd[argc - 1][2];
  pid_t child;
  char *buff = (char *)malloc(sizeof(char));
  char *res = (char *)malloc(sizeof(char));
  int i, j, k;
  if (argc < 2) {
    fprintf(stderr, "usage %s filename invalid", argv[1]);
    exit(0);
  } else {
    for (i = 1; i <= argc - 1; i++) {
      pipe(fd[i]);
      child = fork();
      if (child < 0) {
        perror("Error");
      } else if (child == 0) {
        res = countFrequency(argv[i]);
        close(fd[i][0]);
        write(fd[i][1], res, (strlen(res) + 1));
        close(fd[i][1]);
        exit(0);
      }
    }
    for (k = 1; k <= argc - 1; k++) {
      wait(NULL);
    }
    for (j = 1; j <= argc - 1; j++) {
      close(fd[j][1]);
      read(fd[j][0], buff, sizeof(char *) * (strlen(buff) + 100000));
      close(fd[j][0]);
      printf("%s\n", buff);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    125a <main+0x8a>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdb2(%rip),%rsi
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1341 <main+0x171>
mov    -0x50(%rbp),%rdi
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
call   1080 <pipe@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    12ad <main+0xdd>
lea    0xd77(%rip),%rdi
call   10c0 <perror@plt>
jmp    132e <main+0x15e>
cmpq   $0x0,-0x28(%rbp)
jne    1329 <main+0x159>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <countFrequency@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
mov    %rcx,-0x38(%rbp)
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%edi
call   1070 <close@plt>
mov    -0x50(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <write@plt>
mov    -0x50(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    132e <main+0x15e>
jmp    1333 <main+0x163>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1261 <main+0x91>
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1370 <main+0x1a0>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <wait@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1348 <main+0x178>
movl   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     13ff <main+0x22f>
mov    -0x50(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%edi
call   1070 <close@plt>
mov    -0x50(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
add    $0x186a0,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
call   1090 <read@plt>
mov    -0x50(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%edi
call   1070 <close@plt>
mov    -0x30(%rbp),%rsi
lea    0xc34(%rip),%rdi
call   1060 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1377 <main+0x1a7>
jmp    1404 <main+0x234>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

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,-0x30(%rbp)
mov    %edi,%r14d
lea    -0x1(%r14),%ebx
mov    %rsp,%r15
lea    0xf(,%rbx,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,%r13
mov    $0x1,%edi
call   10b0 <malloc@plt>
cmp    $0x2,%r14d
jl     134e <main+0x17e>
mov    %r14,-0x38(%rbp)
mov    %r14d,%eax
mov    %rax,-0x40(%rbp)
lea    0x0(,%rax,8),%r12
mov    $0x8,%r14d
nopl   0x0(%rax,%rax,1)
lea    (%r15,%r14,1),%rdi
call   1080 <pipe@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %rax,%rax
js     1266 <main+0x96>
je     1309 <main+0x139>
add    $0x8,%r14
cmp    %r14,%r12
jne    1240 <main+0x70>
jmp    1274 <main+0xa4>
lea    0xdad(%rip),%rdi
call   10c0 <perror@plt>
jmp    125b <main+0x8b>
mov    -0x38(%rbp),%r14
cmp    $0x2,%r14d
mov    -0x40(%rbp),%r12
jl     12f8 <main+0x128>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
call   10e0 <wait@plt>
add    $0xffffffff,%ebx
jne    1290 <main+0xc0>
cmp    $0x2,%r14d
jl     12f8 <main+0x128>
mov    $0x1,%r14d
nopl   0x0(%rax,%rax,1)
mov    0x4(%r15,%r14,8),%edi
call   1070 <close@plt>
mov    (%r15,%r14,8),%ebx
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0xc3500(,%rax,8),%edx
mov    %ebx,%edi
mov    %r13,%rsi
call   1090 <read@plt>
mov    (%r15,%r14,8),%edi
call   1070 <close@plt>
lea    0xd39(%rip),%rdi
mov    %r13,%rsi
call   1060 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r12
jne    12b0 <main+0xe0>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    -0x30(%rbp),%rax
mov    (%rax,%r14,1),%rdi
call   1040 <countFrequency@plt>
mov    %rax,%rbx
mov    (%r15,%r14,1),%edi
call   1070 <close@plt>
mov    0x4(%r15,%r14,1),%r12d
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r12d,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
mov    0x4(%r15,%r14,1),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc9a(%rip),%rsi
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"usage %s filename invalid\00"
@.str.1 = [6 x i8] c"Error\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = sub nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %6
%18 = alloca [2 x i32], i64 %16
store i64 %16, i64* %7
%19 = call i64 @malloc(i32 1)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %9
%21 = call i64 @malloc(i32 1)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %10
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %32
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %2
store i32 1, i32* %11
br label %33
33: ; preds = %84, %32
%34 = load i32, i32* %11
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 1
%37 = icmp sle i32 %34, %36
br i1 %37, label %38, label %87
38: ; preds = %33
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 %40
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %41, i64 0, i64 0
%43 = call i32 @pipe(i32* %42)
%44 = call i64 (...) @fork()
store i64 %44, i64* %8
%45 = load i64, i64* %8
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %38
%48 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %83
49: ; preds = %38
%50 = load i64, i64* %8
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %82
52: ; preds = %49
%53 = load i8**, i8*** %5
%54 = load i32, i32* %11
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i8* @countFrequency(i8* %57)
store i8* %58, i8** %10
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 %60
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %61, i64 0, i64 0
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* %11
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 %66
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %67, i64 0, i64 1
%69 = load i32, i32* %68
%70 = load i8*, i8** %10
%71 = load i8*, i8** %10
%72 = call i32 @strlen(i8* %71)
%73 = add nsw i32 %72, 1
%74 = call i32 @write(i32 %69, i8* %70, i32 %73)
%75 = load i32, i32* %11
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 %76
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %77, i64 0, i64 1
%79 = load i32, i32* %78
%80 = call i32 @close(i32 %79)
%81 = call i32 @exit(i32 0)
unreachable
82: ; preds = %49
br label %83
83: ; preds = %82, %47
br label %84
84: ; preds = %83
%85 = load i32, i32* %11
%86 = add nsw i32 %85, 1
store i32 %86, i32* %11
br label %33
87: ; preds = %33
store i32 1, i32* %13
br label %88
88: ; preds = %95, %87
%89 = load i32, i32* %13
%90 = load i32, i32* %4
%91 = sub nsw i32 %90, 1
%92 = icmp sle i32 %89, %91
br i1 %92, label %93, label %98
93: ; preds = %88
%94 = call i32 @wait(i32* null)
br label %95
95: ; preds = %93
%96 = load i32, i32* %13
%97 = add nsw i32 %96, 1
store i32 %97, i32* %13
br label %88
98: ; preds = %88
store i32 1, i32* %12
br label %99
99: ; preds = %132, %98
%100 = load i32, i32* %12
%101 = load i32, i32* %4
%102 = sub nsw i32 %101, 1
%103 = icmp sle i32 %100, %102
br i1 %103, label %104, label %135
104: ; preds = %99
%105 = load i32, i32* %12
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 %106
%108 = getelementptr inbounds [2 x i32], [2 x i32]* %107, i64 0, i64 1
%109 = load i32, i32* %108
%110 = call i32 @close(i32 %109)
%111 = load i32, i32* %12
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 %112
%114 = getelementptr inbounds [2 x i32], [2 x i32]* %113, i64 0, i64 0
%115 = load i32, i32* %114
%116 = load i8*, i8** %9
%117 = load i8*, i8** %9
%118 = call i32 @strlen(i8* %117)
%119 = add nsw i32 %118, 100000
%120 = sext i32 %119 to i64
%121 = mul i64 8, %120
%122 = trunc i64 %121 to i32
%123 = call i32 @read(i32 %115, i8* %116, i32 %122)
%124 = load i32, i32* %12
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 %125
%127 = getelementptr inbounds [2 x i32], [2 x i32]* %126, i64 0, i64 0
%128 = load i32, i32* %127
%129 = call i32 @close(i32 %128)
%130 = load i8*, i8** %9
%131 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %130)
br label %132
132: ; preds = %104
%133 = load i32, i32* %12
%134 = add nsw i32 %133, 1
store i32 %134, i32* %12
br label %99
135: ; preds = %99
br label %136
136: ; preds = %135
store i32 0, i32* %3
%137 = load i8*, i8** %6
%138 = load i32, i32* %3
ret i32 %138
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"usage %s filename invalid\00"
@.str.1 = [6 x i8] c"Error\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add nsw i32 %0, -1
%4 = zext i32 %3 to i64
%5 = alloca [2 x i32], i64 %4
%6 = tail call i64 @malloc(i32 1)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i64 @malloc(i32 1)
%9 = icmp slt i32 %0, 2
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = zext i32 %0 to i64
br label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %45
%19 = icmp sgt i32 %0, 1
br i1 %19, label %51, label %72
20: ; preds = %10, %45
%21 = phi i64 [ 1, %10 ], [ %46, %45 ]
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 %21, i64 0
%23 = call i32 @pipe(i32* %22)
%24 = call i64 (...) @fork()
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %45
28: ; preds = %20
%29 = icmp eq i64 %24, 0
br i1 %29, label %30, label %45
30: ; preds = %28
%31 = and i64 %21, 4294967295
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
%34 = call i8* @countFrequency(i8* %33)
%35 = load i32, i32* %22
%36 = call i32 @close(i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 %31, i64 1
%38 = load i32, i32* %37
%39 = call i32 @strlen(i8* %34)
%40 = add nsw i32 %39, 1
%41 = call i32 @write(i32 %38, i8* %34, i32 %40)
%42 = load i32, i32* %37
%43 = call i32 @close(i32 %42)
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %26, %28
%46 = add nuw nsw i64 %21, 1
%47 = icmp eq i64 %46, %11
br i1 %47, label %18, label %20
48: ; preds = %51
br i1 %19, label %49, label %72
49: ; preds = %48
%50 = zext i32 %0 to i64
br label %56
51: ; preds = %18, %51
%52 = phi i32 [ %54, %51 ], [ 1, %18 ]
%53 = call i32 @wait(i32* null)
%54 = add nuw nsw i32 %52, 1
%55 = icmp eq i32 %54, %0
br i1 %55, label %48, label %51
56: ; preds = %49, %56
%57 = phi i64 [ 1, %49 ], [ %70, %56 ]
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 %57, i64 1
%59 = load i32, i32* %58
%60 = call i32 @close(i32 %59)
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 %57, i64 0
%62 = load i32, i32* %61
%63 = call i32 @strlen(i8* %7)
%64 = shl i32 %63, 3
%65 = add i32 %64, 800000
%66 = call i32 @read(i32 %62, i8* %7, i32 %65)
%67 = load i32, i32* %61
%68 = call i32 @close(i32 %67)
%69 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%70 = add nuw nsw i64 %57, 1
%71 = icmp eq i64 %70, %50
br i1 %71, label %72, label %56
72: ; preds = %56, %18, %48
ret i32 0
}