#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(int);
int fprintf(int /*<<< orphan*/ *, char *, char);
int /*<<< orphan*/ printf(char *);
void add_character_counts(FILE *file, int freq[256], int num_bytes) {
  char *ptr = 0;
  int i = 0, ret = 0, j = 0;
  for (i = 0; i < 256; i++) {
    if (freq[i] == 0) {
      continue;
    }
    ptr = (char *)&freq[i];
    for (j = (num_bytes - 1); j >= 0; j--) {
      if ((ret = fprintf(file, "%c", ptr[j])) != 1) {
        printf("Failure to output the freqency byte.\n");
        exit(1);
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<add_character_counts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jge    1215 <add_character_counts+0xe5>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    118b <add_character_counts+0x5b>
jmp    1207 <add_character_counts+0xd7>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     1202 <add_character_counts+0xd2>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
lea    0xe3c(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1040 <fprintf@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x1,%eax
je     11ef <add_character_counts+0xbf>
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11f4 <add_character_counts+0xc4>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a7 <add_character_counts+0x77>
jmp    1207 <add_character_counts+0xd7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1167 <add_character_counts+0x37>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_character_counts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
mov    %edx,%eax
mov    %rax,(%rsp)
lea    -0x1(%rsi),%rbx
xor    %ebp,%ebp
lea    0xeac(%rip),%r15
jmp    1171 <add_character_counts+0x41>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
add    $0x4,%rbx
cmp    $0x100,%rbp
je     11b4 <add_character_counts+0x84>
cmpl   $0x0,(%r14,%rbp,4)
je     1160 <add_character_counts+0x30>
mov    (%rsp),%r12
nopl   0x0(%rax)
test   %r12d,%r12d
jle    1160 <add_character_counts+0x30>
movsbl (%rbx,%r12,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
add    $0xffffffffffffffff,%r12
cmp    $0x1,%eax
je     1180 <add_character_counts+0x50>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [38 x i8] c"Failure to output the freqency byte.\0A\00"
define void @add_character_counts(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i8* null, i8** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %8
br label %11
11: ; preds = %50, %3
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 256
br i1 %13, label %14, label %53
14: ; preds = %11
%15 = load i32*, i32** %5
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
br label %50
22: ; preds = %14
%23 = load i32*, i32** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = bitcast i32* %26 to i8*
store i8* %27, i8** %7
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %10
br label %30
30: ; preds = %46, %22
%31 = load i32, i32* %10
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %49
33: ; preds = %30
%34 = load i32*, i32** %4
%35 = load i8*, i8** %7
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %39)
store i32 %40, i32* %9
%41 = icmp ne i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %33
%43 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %33
br label %46
46: ; preds = %45
%47 = load i32, i32* %10
%48 = add nsw i32 %47, -1
store i32 %48, i32* %10
br label %30
49: ; preds = %30
br label %50
50: ; preds = %49, %21
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %11
53: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@str = [37 x i8] c"Failure to output the freqency byte.\00"
define void @add_character_counts(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = zext i32 %2 to i64
br label %5
5: ; preds = %3, %25
%6 = phi i64 [ 0, %3 ], [ %26, %25 ]
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %5
%11 = bitcast i32* %7 to i8*
br label %12
12: ; preds = %17, %10
%13 = phi i64 [ %14, %17 ], [ %4, %10 ]
%14 = add nsw i64 %13, -1
%15 = trunc i64 %13 to i32
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %11, i64 %14
%19 = load i8, i8* %18
%20 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %19)
%21 = icmp eq i32 %20, 1
br i1 %21, label %12, label %22
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %12, %5
%26 = add nuw nsw i64 %6, 1
%27 = icmp eq i64 %26, 256
br i1 %27, label %28, label %5
28: ; preds = %25
ret void
}