#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 */
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
unsigned int count_bytes(unsigned int *byte_cnts) {
  unsigned char c;
  while (fread(&c, 1, 1, stdin)) {
    ++byte_cnts[c];
  }
  unsigned int size = 0;
  for (int i = 0; i < 256; ++i) {
    size += byte_cnts[i];
  }
  return size;
}


x86 assembly (clang, -O0):
<count_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ec5(%rip),%rax
mov    (%rax),%ecx
lea    -0x9(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
je     1155 <count_bytes+0x45>
mov    -0x8(%rbp),%rax
movzbl -0x9(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    111c <count_bytes+0xc>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jge    118f <count_bytes+0x7f>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1163 <count_bytes+0x53>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_bytes>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2ec5(%rip),%r15
mov    (%r15),%ecx
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
test   %rax,%rax
je     1173 <count_bytes+0x63>
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0xf(%rsp),%eax
addl   $0x1,(%rbx,%rax,4)
mov    (%r15),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
test   %rax,%rax
jne    1150 <count_bytes+0x40>
pxor   %xmm0,%xmm0
xor    %eax,%eax
pxor   %xmm1,%xmm1
nopl   (%rax)
movdqu (%rbx,%rax,4),%xmm2
paddd  %xmm0,%xmm2
movdqu 0x10(%rbx,%rax,4),%xmm0
paddd  %xmm1,%xmm0
movdqu 0x20(%rbx,%rax,4),%xmm1
movdqu 0x30(%rbx,%rax,4),%xmm3
movdqu 0x40(%rbx,%rax,4),%xmm4
paddd  %xmm1,%xmm4
paddd  %xmm2,%xmm4
movdqu 0x50(%rbx,%rax,4),%xmm2
paddd  %xmm3,%xmm2
paddd  %xmm0,%xmm2
movdqu 0x60(%rbx,%rax,4),%xmm0
paddd  %xmm4,%xmm0
movdqu 0x70(%rbx,%rax,4),%xmm1
paddd  %xmm2,%xmm1
add    $0x20,%rax
cmp    $0x100,%rax
jne    1180 <count_bytes+0x70>
paddd  %xmm0,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @count_bytes(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
br label %6
6: ; preds = %10, %1
%7 = load i32, i32* @stdin
%8 = call i64 @fread(i8* %3, i32 1, i32 1, i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = load i32*, i32** %2
%12 = load i8, i8* %3
%13 = zext i8 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = load i32, i32* %14
%16 = add i32 %15, 1
store i32 %16, i32* %14
br label %6
17: ; preds = %6
store i32 0, i32* %4
store i32 0, i32* %5
br label %18
18: ; preds = %29, %17
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 256
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i32*, i32** %2
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %4
%28 = add i32 %27, %26
store i32 %28, i32* %4
br label %29
29: ; preds = %21
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %18
32: ; preds = %18
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @count_bytes(i32* nocapture %0) {
%2 = alloca i8
%3 = load i32, i32* @stdin
%4 = call i64 @fread(i8* %2, i32 1, i32 1, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %51
6: ; preds = %51, %1
br label %7
7: ; preds = %7, %6
%8 = phi i64 [ 0, %6 ], [ %46, %7 ]
%9 = phi <4 x i32> [ zeroinitializer, %6 ], [ %44, %7 ]
%10 = phi <4 x i32> [ zeroinitializer, %6 ], [ %45, %7 ]
%11 = getelementptr inbounds i32, i32* %0, i64 %8
%12 = bitcast i32* %11 to <4 x i32>*
%13 = load <4 x i32>, <4 x i32>* %12
%14 = getelementptr inbounds i32, i32* %11, i64 4
%15 = bitcast i32* %14 to <4 x i32>*
%16 = load <4 x i32>, <4 x i32>* %15
%17 = add <4 x i32> %13, %9
%18 = add <4 x i32> %16, %10
%19 = or i64 %8, 8
%20 = getelementptr inbounds i32, i32* %0, i64 %19
%21 = bitcast i32* %20 to <4 x i32>*
%22 = load <4 x i32>, <4 x i32>* %21
%23 = getelementptr inbounds i32, i32* %20, i64 4
%24 = bitcast i32* %23 to <4 x i32>*
%25 = load <4 x i32>, <4 x i32>* %24
%26 = add <4 x i32> %22, %17
%27 = add <4 x i32> %25, %18
%28 = or i64 %8, 16
%29 = getelementptr inbounds i32, i32* %0, i64 %28
%30 = bitcast i32* %29 to <4 x i32>*
%31 = load <4 x i32>, <4 x i32>* %30
%32 = getelementptr inbounds i32, i32* %29, i64 4
%33 = bitcast i32* %32 to <4 x i32>*
%34 = load <4 x i32>, <4 x i32>* %33
%35 = add <4 x i32> %31, %26
%36 = add <4 x i32> %34, %27
%37 = or i64 %8, 24
%38 = getelementptr inbounds i32, i32* %0, i64 %37
%39 = bitcast i32* %38 to <4 x i32>*
%40 = load <4 x i32>, <4 x i32>* %39
%41 = getelementptr inbounds i32, i32* %38, i64 4
%42 = bitcast i32* %41 to <4 x i32>*
%43 = load <4 x i32>, <4 x i32>* %42
%44 = add <4 x i32> %40, %35
%45 = add <4 x i32> %43, %36
%46 = add nuw nsw i64 %8, 32
%47 = icmp eq i64 %46, 256
br i1 %47, label %48, label %7
48: ; preds = %7
%49 = add <4 x i32> %45, %44
%50 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %49)
ret i32 %50
51: ; preds = %1, %51
%52 = load i8, i8* %2
%53 = zext i8 %52 to i64
%54 = getelementptr inbounds i32, i32* %0, i64 %53
%55 = load i32, i32* %54
%56 = add i32 %55, 1
store i32 %56, i32* %54
%57 = load i32, i32* @stdin
%58 = call i64 @fread(i8* %2, i32 1, i32 1, i32 %57)
%59 = icmp eq i64 %58, 0
br i1 %59, label %6, label %51
}