#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 *, int);
int /*<<< orphan*/ printf(char *);
int add_size(FILE *file, int freq[256]) {
  int i = 0, num_bytes = 0, ret = 0;
  for (i = 0; i < 256; i++) {
    if (freq[i] & 0xFF000000) {
      num_bytes = 4;
    } else if ((freq[i] & 0x00FF0000) && num_bytes < 4) {
      num_bytes = 3;
    } else if ((freq[i] & 0x0000FF00) && num_bytes < 3) {
      num_bytes = 2;
    } else if ((freq[i] & 0x000000FF) && num_bytes < 2) {
      num_bytes = 1;
    }
  }
  if ((ret = fprintf(file, "%c", num_bytes)) != 1) {
    printf("Failure to output size of the frequency byte number.\n");
    exit(1);
  }
  return num_bytes;
}


x86 assembly (clang, -O0):
<add_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jge    1238 <add_size+0x108>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    $0xff000000,%eax
cmp    $0x0,%eax
je     118e <add_size+0x5e>
movl   $0x4,-0x18(%rbp)
jmp    1225 <add_size+0xf5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    $0xff0000,%eax
cmp    $0x0,%eax
je     11bd <add_size+0x8d>
cmpl   $0x4,-0x18(%rbp)
jge    11bd <add_size+0x8d>
movl   $0x3,-0x18(%rbp)
jmp    1220 <add_size+0xf0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    $0xff00,%eax
cmp    $0x0,%eax
je     11ec <add_size+0xbc>
cmpl   $0x3,-0x18(%rbp)
jge    11ec <add_size+0xbc>
movl   $0x2,-0x18(%rbp)
jmp    121b <add_size+0xeb>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
and    $0xff,%eax
cmp    $0x0,%eax
je     1216 <add_size+0xe6>
cmpl   $0x2,-0x18(%rbp)
jge    1216 <add_size+0xe6>
movl   $0x1,-0x18(%rbp)
jmp    121b <add_size+0xeb>
jmp    1220 <add_size+0xf0>
jmp    1225 <add_size+0xf5>
jmp    122a <add_size+0xfa>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115c <add_size+0x2c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xdba(%rip),%rsi
call   1040 <fprintf@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x1,%eax
je     126d <add_size+0x13d>
lea    0xda5(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_size>:
push   %rbx
xor    %eax,%eax
mov    $0x1,%r8d
xor    %ebx,%ebx
jmp    115c <add_size+0x2c>
cmp    $0x2,%edx
mov    %edx,%ebx
cmovl  %r8d,%ebx
test   %cl,%cl
cmove  %edx,%ebx
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    $0x100,%rax
je     1194 <add_size+0x64>
mov    %ebx,%edx
mov    (%rsi,%rax,4),%ecx
mov    $0x4,%ebx
cmp    $0xffffff,%ecx
ja     1150 <add_size+0x20>
test   $0xff0000,%ecx
je     1180 <add_size+0x50>
mov    $0x3,%ebx
cmp    $0x4,%edx
jl     1150 <add_size+0x20>
test   $0xff00,%ecx
je     113d <add_size+0xd>
mov    $0x2,%ebx
cmp    $0x3,%edx
jl     1150 <add_size+0x20>
jmp    113d <add_size+0xd>
lea    0xe65(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
cmp    $0x1,%eax
jne    11ab <add_size+0x7b>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [54 x i8] c"Failure to output size of the frequency byte number.\0A\00"
define i32 @add_size(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %5
br label %8
8: ; preds = %60, %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 256
br i1 %10, label %11, label %63
11: ; preds = %8
%12 = load i32*, i32** %4
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = and i32 %16, -16777216
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 4, i32* %6
br label %59
20: ; preds = %11
%21 = load i32*, i32** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = and i32 %25, 16711680
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %20
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 4
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 3, i32* %6
br label %58
32: ; preds = %28, %20
%33 = load i32*, i32** %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = and i32 %37, 65280
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %32
%41 = load i32, i32* %6
%42 = icmp slt i32 %41, 3
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 2, i32* %6
br label %57
44: ; preds = %40, %32
%45 = load i32*, i32** %4
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = load i32, i32* %48
%50 = and i32 %49, 255
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %44
%53 = load i32, i32* %6
%54 = icmp slt i32 %53, 2
br i1 %54, label %55, label %56
55: ; preds = %52
store i32 1, i32* %6
br label %56
56: ; preds = %55, %52, %44
br label %57
57: ; preds = %56, %43
br label %58
58: ; preds = %57, %31
br label %59
59: ; preds = %58, %19
br label %60
60: ; preds = %59
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %8
63: ; preds = %8
%64 = load i32*, i32** %3
%65 = load i32, i32* %6
%66 = call i32 @fprintf(i32* %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %65)
store i32 %66, i32* %7
%67 = icmp ne i32 %66, 1
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %63
%72 = load i32, i32* %6
ret i32 %72
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@str = [53 x i8] c"Failure to output size of the frequency byte number.\00"
define i32 @add_size(i32* nocapture %0, i32* nocapture %1) {
br label %3
3: ; preds = %2, %25
%4 = phi i64 [ 0, %2 ], [ %27, %25 ]
%5 = phi i32 [ 0, %2 ], [ %26, %25 ]
%6 = getelementptr inbounds i32, i32* %1, i64 %4
%7 = load i32, i32* %6
%8 = icmp ult i32 %7, 16777216
br i1 %8, label %9, label %25
9: ; preds = %3
%10 = and i32 %7, 16711680
%11 = icmp ne i32 %10, 0
%12 = icmp slt i32 %5, 4
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %25, label %14
14: ; preds = %9
%15 = and i32 %7, 65280
%16 = icmp ne i32 %15, 0
%17 = icmp slt i32 %5, 3
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %25, label %19
19: ; preds = %14
%20 = and i32 %7, 255
%21 = icmp ne i32 %20, 0
%22 = icmp slt i32 %5, 2
%23 = select i1 %21, i1 %22, i1 false
%24 = select i1 %23, i32 1, i32 %5
br label %25
25: ; preds = %14, %9, %3, %19
%26 = phi i32 [ %24, %19 ], [ 4, %3 ], [ 3, %9 ], [ 2, %14 ]
%27 = add nuw nsw i64 %4, 1
%28 = icmp eq i64 %27, 256
br i1 %28, label %29, label %3
29: ; preds = %25
%30 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %26)
%31 = icmp eq i32 %30, 1
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %29
ret i32 %26
}