#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__ calloc(int, int);
int *CharCountArray(char *str) {
  int i;
  int *count;
  count = (int *)calloc(sizeof(int), 256);
  for (i = 0; *(str + i); i++) {
    count[*(str + i)]++;
  }
  return count;
}


x86 assembly (clang, -O0):
<CharCountArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x4,%edi
mov    $0x100,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1170 <CharCountArray+0x60>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
movsbq (%rcx,%rdx,1),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1136 <CharCountArray+0x26>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CharCountArray>:
push   %rbx
mov    %rdi,%rbx
mov    $0x4,%edi
mov    $0x100,%esi
call   1030 <calloc@plt>
mov    (%rbx),%cl
test   %cl,%cl
je     1143 <CharCountArray+0x33>
add    $0x1,%rbx
nopl   (%rax)
movsbq %cl,%rcx
addl   $0x1,(%rax,%rcx,4)
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1130 <CharCountArray+0x20>
pop    %rbx
ret

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

LLVM IR (-O2):
define i32* @CharCountArray(i8* nocapture %0) {
%2 = tail call i64 @calloc(i32 4, i32 256)
%3 = inttoptr i64 %2 to i32*
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %13, %6 ], [ 0, %1 ]
%8 = phi i8 [ %15, %6 ], [ %4, %1 ]
%9 = sext i8 %8 to i64
%10 = getelementptr inbounds i32, i32* %3, i64 %9
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
store i32 %12, i32* %10
%13 = add nuw nsw i64 %7, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %6
17: ; preds = %6, %1
ret i32* %3
}