#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fgetcount(int, char const);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int *);
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "error: not enough arguments\n");
    return 1;
  }
  const char ch = *argv[1];
  if (argc < 3) {
    printf("%u\n", fgetcount(0, ch));
    return 0;
  }
  for (size_t i = 1; i < argc; i++)
    if (!fork()) {
      int fd = open(argv[i], O_RDONLY);
      printf("%u %s\n", fgetcount(fd, ch), argv[i]);
      close(fd);
      exit(0);
    }
  int status;
  for (size_t i = 1; i < argc; i++)
    wait(&status);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c1 <main+0x41>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cc <main+0x14c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ff <main+0x7f>
xor    %edi,%edi
movsbl -0x11(%rbp),%esi
call   1040 <fgetcount@plt>
mov    %eax,%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cc <main+0x14c>
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
jae    1292 <main+0x112>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%eax
jne    127c <main+0xfc>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
movsbl -0x11(%rbp),%esi
call   1040 <fgetcount@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    1281 <main+0x101>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1207 <main+0x87>
movq   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
jae    12c5 <main+0x145>
lea    -0x28(%rbp),%rdi
call   1090 <wait@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    129a <main+0x11a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11a8 <main+0x28>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%ebx
jmp    1210 <main+0x90>
mov    %rsi,%r15
mov    0x8(%rsi),%rax
mov    (%rax),%r14b
cmp    $0x2,%edi
jne    11d6 <main+0x56>
movsbl %r14b,%esi
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <fgetcount@plt>
lea    0xe52(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1210 <main+0x90>
mov    %edi,%ebp
mov    $0x1,%ebx
nopl   (%rax)
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     121d <main+0x9d>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11e0 <main+0x60>
add    $0xffffffffffffffff,%rbp
lea    0x4(%rsp),%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1090 <wait@plt>
add    $0xffffffffffffffff,%rbp
jne    1200 <main+0x80>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15,%rbx,8),%rdi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebp
movsbl %r14b,%esi
mov    %eax,%edi
call   1040 <fgetcount@plt>
mov    (%r15,%rbx,8),%rdx
lea    0xdda(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"error: not enough arguments\0A\00"
@.str.1 = [4 x i8] c"%u\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [7 x i8] c"%u %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 i32
%9 = alloca i32
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %70
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
store i8 %20, i8* %6
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i8, i8* %6
%25 = call i32 @fgetcount(i32 0, i8 signext %24)
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 0, i32* %3
br label %70
27: ; preds = %16
store i64 1, i64* %7
br label %28
28: ; preds = %55, %27
%29 = load i64, i64* %7
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = icmp ult i64 %29, %31
br i1 %32, label %33, label %58
33: ; preds = %28
%34 = call i32 (...) @fork()
%35 = icmp ne i32 %34, 0
br i1 %35, label %54, label %36
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = load i64, i64* %7
%39 = getelementptr inbounds i8*, i8** %37, i64 %38
%40 = load i8*, i8** %39
%41 = load i32, i32* @O_RDONLY
%42 = call i32 @open(i8* %40, i32 %41)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = load i8, i8* %6
%45 = call i32 @fgetcount(i32 %43, i8 signext %44)
%46 = load i8**, i8*** %5
%47 = load i64, i64* %7
%48 = getelementptr inbounds i8*, i8** %46, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %45, i8* %49)
%51 = load i32, i32* %8
%52 = call i32 @close(i32 %51)
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %33
br label %55
55: ; preds = %54
%56 = load i64, i64* %7
%57 = add i64 %56, 1
store i64 %57, i64* %7
br label %28
58: ; preds = %28
store i64 1, i64* %10
br label %59
59: ; preds = %66, %58
%60 = load i64, i64* %10
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = icmp ult i64 %60, %62
br i1 %63, label %64, label %69
64: ; preds = %59
%65 = call i32 @wait(i32* %9)
br label %66
66: ; preds = %64
%67 = load i64, i64* %10
%68 = add i64 %67, 1
store i64 %68, i64* %10
br label %59
69: ; preds = %59
store i32 0, i32* %3
br label %70
70: ; preds = %69, %23, %13
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"error: not enough arguments\0A\00"
@.str.1 = [4 x i8] c"%u\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [7 x i8] c"%u %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %43
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = icmp eq i32 %0, 2
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = zext i32 %0 to i64
br label %20
15: ; preds = %8
%16 = tail call i32 @fgetcount(i32 0, i8 signext %11)
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %43
18: ; preds = %34
%19 = bitcast i32* %3 to i8*
br label %38
20: ; preds = %13, %34
%21 = phi i64 [ %35, %34 ], [ 1, %13 ]
%22 = tail call i32 (...) @fork()
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = getelementptr inbounds i8*, i8** %1, i64 %21
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = tail call i32 @open(i8* %26, i32 %27)
%29 = tail call i32 @fgetcount(i32 %28, i8 signext %11)
%30 = load i8*, i8** %25
%31 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %29, i8* %30)
%32 = tail call i32 @close(i32 %28)
%33 = tail call i32 @exit(i32 0)
unreachable
34: ; preds = %20
%35 = add nuw i64 %21, 1
%36 = icmp eq i64 %35, %14
br i1 %36, label %18, label %20
37: ; preds = %38
br label %43
38: ; preds = %18, %38
%39 = phi i64 [ %41, %38 ], [ 1, %18 ]
%40 = call i32 @wait(i32* %3)
%41 = add nuw i64 %39, 1
%42 = icmp eq i64 %41, %14
br i1 %42, label %37, label %38
43: ; preds = %15, %37, %5
%44 = phi i32 [ 1, %5 ], [ 0, %37 ], [ 0, %15 ]
ret i32 %44
}