#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*/ LC_ALL;
scalar_t__ feof(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int *freq_w(FILE *f) {
  setlocale(LC_ALL, "");
  unsigned char x;
  int i;
  int *countsort;
  countsort = (int *)malloc(256 * sizeof(int));
  for (i = 0; i < 256; i++) {
    countsort[i] = 0;
  }
  while (1) {
    x = fgetc(f);
    if (feof(f)) {
      break;
    }
    countsort[x]++;
  }
  return countsort;
}


x86 assembly (clang, -O0):
<freq_w>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
call   1060 <setlocale@plt>
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x100,-0x10(%rbp)
jge    11a0 <freq_w+0x60>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1176 <freq_w+0x36>
jmp    11a5 <freq_w+0x65>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     11c9 <freq_w+0x89>
jmp    11df <freq_w+0x9f>
mov    -0x18(%rbp),%rax
movzbl -0x9(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    11a5 <freq_w+0x65>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<freq_w>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
call   1070 <setlocale@plt>
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x400,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11b1 <freq_w+0x61>
movzbl %bl,%eax
addl   $0x1,(%r14,%rax,4)
jmp    1190 <freq_w+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
define i32* @freq_w(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32*
store i32* %0, i32** %2
%6 = load i32, i32* @LC_ALL
%7 = call i32 @setlocale(i32 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @malloc(i32 1024)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %5
store i32 0, i32* %4
br label %10
10: ; preds = %18, %1
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 256
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i32*, i32** %5
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
store i32 0, i32* %17
br label %18
18: ; preds = %13
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %10
21: ; preds = %10
br label %22
22: ; preds = %21, %29
%23 = load i32*, i32** %2
%24 = call zeroext i8 @fgetc(i32* %23)
store i8 %24, i8* %3
%25 = load i32*, i32** %2
%26 = call i64 @feof(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
br label %36
29: ; preds = %22
%30 = load i32*, i32** %5
%31 = load i8, i8* %3
%32 = zext i8 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %33
br label %22
36: ; preds = %28
%37 = load i32*, i32** %5
ret i32* %37
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
define i32* @freq_w(i32* nocapture %0) {
%2 = load i32, i32* @LC_ALL
%3 = tail call i32 @setlocale(i32 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @malloc(i32 1024)
%5 = inttoptr i64 %4 to i32*
%6 = inttoptr i64 %4 to i8*
%7 = tail call zeroext i8 @fgetc(i32* %0)
%8 = tail call i64 @feof(i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %1, %10
%11 = phi i8 [ %16, %10 ], [ %7, %1 ]
%12 = zext i8 %11 to i64
%13 = getelementptr inbounds i32, i32* %5, i64 %12
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
store i32 %15, i32* %13
%16 = tail call zeroext i8 @fgetc(i32* %0)
%17 = tail call i64 @feof(i32* %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %10, label %19
19: ; preds = %10, %1
ret i32* %5
}