#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
size_t atoi(char *);
char *basename(char *);
size_t *calloc(size_t, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, char *);
size_t load_table(size_t *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ print_table(size_t *, size_t, size_t);
int /*<<< orphan*/ printf(char *, char *, size_t, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  assert(argc == 3);
  char *execname = basename(argv[0]);
  size_t slots = atoi(argv[1]);
  char *filename = argv[2];
  char buffer[strlen(filename) + 5];
  snprintf(buffer, sizeof buffer, "wc %s\n", filename);
  system(buffer);
  printf("%s: slots = %lu, filename = %s\n", execname, slots, filename);
  FILE *wordfile = fopen(filename, "r");
  if (wordfile == NULL) {
    fprintf(stderr, "%s: %s: %s\n", execname, filename, strerror(errno));
    exit(EXIT_FAILURE);
  }
  size_t *table = calloc(slots, sizeof(size_t));
  assert(table != NULL);
  size_t count = load_table(table, slots, wordfile);
  fclose(wordfile);
  print_table(table, slots, count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x3,%eax
sete   %al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10d0 <basename@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x5,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
lea    0xd87(%rip),%rdx
call   1090 <snprintf@plt>
mov    -0x58(%rbp),%rdi
call   1070 <system@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xd6d(%rip),%rdi
call   1080 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xd7d(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1310 <main+0x120>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    -0x60(%rbp),%rcx
mov    %rax,%r8
lea    0xd2c(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1040 <load_table@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1030 <print_table@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%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
push   %rax
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x3,%edi
sete   %al
mov    %eax,%edi
call   10b0 <assert@plt>
mov    (%rbx),%rdi
call   10d0 <basename@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %rax,%r15
mov    0x10(%rbx),%r12
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    0x5(%rax),%esi
mov    %rsp,%rbx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xdb2(%rip),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
call   1090 <snprintf@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
lea    0xd9f(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1080 <printf@plt>
lea    0xdaa(%rip),%rsi
mov    %r12,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     12e3 <main+0xf3>
mov    %rax,%r13
mov    %r15,%rdi
mov    $0x8,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   10b0 <assert@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <load_table@plt>
mov    %rax,%r14
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <print_table@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cf6(%rip),%rax
mov    (%rax),%ebx
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xd28(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %rax,%r8
call   10c0 <fprintf@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"wc %s\0A\00"
@.str.1 = [32 x i8] c"%s: slots = %lu, filename = %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [12 x i8] c"%s: %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i64*
%12 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 3
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i8* @basename(i8* %19)
store i8* %20, i8** %5
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @atoi(i8* %23)
store i64 %24, i64* %6
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = call i32 @strlen(i8* %28)
%30 = add nsw i32 %29, 5
%31 = zext i32 %30 to i64
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %8
%33 = alloca i8, i64 %31
store i64 %31, i64* %9
%34 = trunc i64 %31 to i32
%35 = load i8*, i8** %7
%36 = call i32 @snprintf(i8* %33, i32 %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = call i32 @system(i8* %33)
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = load i8*, i8** %7
%41 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %38, i64 %39, i8* %40)
%42 = load i8*, i8** %7
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %43, i32** %10
%44 = load i32*, i32** %10
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %55
46: ; preds = %2
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %5
%49 = load i8*, i8** %7
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %48, i8* %49, i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %2
%56 = load i64, i64* %6
%57 = call i64* @calloc(i64 %56, i32 8)
store i64* %57, i64** %11
%58 = load i64*, i64** %11
%59 = icmp ne i64* %58, null
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = load i64*, i64** %11
%63 = load i64, i64* %6
%64 = load i32*, i32** %10
%65 = call i64 @load_table(i64* %62, i64 %63, i32* %64)
store i64 %65, i64* %12
%66 = load i32*, i32** %10
%67 = call i32 @fclose(i32* %66)
%68 = load i64*, i64** %11
%69 = load i64, i64* %6
%70 = load i64, i64* %12
%71 = call i32 @print_table(i64* %68, i64 %69, i64 %70)
%72 = load i8*, i8** %8
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"wc %s\0A\00"
@.str.1 = [32 x i8] c"%s: slots = %lu, filename = %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [12 x i8] c"%s: %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = load i8*, i8** %1
%7 = tail call i8* @basename(i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 5
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
%17 = call i32 @snprintf(i8* %16, i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12)
%18 = call i32 @system(i8* %16)
%19 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %7, i64 %10, i8* %12)
%20 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %29
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %7, i8* %12, i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %2
%30 = call i64* @calloc(i64 %10, i32 8)
%31 = icmp ne i64* %30, null
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = call i64 @load_table(i64* %30, i64 %10, i32* %20)
%35 = call i32 @fclose(i32* %20)
%36 = call i32 @print_table(i64* %30, i64 %10, i64 %34)
ret i32 0
}