1 Function noMoreFreeMemory() Which Returns Nothing Is External;
   2 Function segmentationFault() Which Returns Nothing Is External;
   3 Function
   4 printString(PointerToCharacter string) Which Returns Nothing Is External;
   5 Function clearScreen() Which Returns Nothing Is External;
   6 Function getLengthOfTheInput() Which Returns Integer16 Is External;
   7 Function
   8 getCharacterOfTheInput(Integer16 index) Which Returns Character Is External;
   9 
  10 Integer32 NDEBUG : = 1;
  11 
  12 Structure TreeNode Consists Of {
  13   Character character;
  14   Integer16 frequencyOfCharacter;
  15   PointerToTreeNode leftChild, rightChild;
  16   Character code[16];
  17 }
  18 EndStructure;
  19 
  20 InstantiateStructure TreeNode treeNodes[64];
  21 Integer16 isTreeNodeUsed[64];
  22 
  23 Function isTreeNodeWithinBounds(
  24     PointerToTreeNode treeNode) Which Returns Integer32 Does {
  25   Return AddressOf(treeNodes[0]) <= treeNode <= AddressOf(treeNodes[64 - 1]) and
  26       mod(treeNode - AddressOf(treeNodes[0]), SizeOf(TreeNode)) =
  27       0; // In C, testing whether the mod is equal to 0 would not be necessary,
  28          // but, since AEC supports unaligned access, it is necessary here.
  29 }
  30 EndFunction;
  31 
  32 Function
  33 convertIntegerToString(PointerToCharacter string,
  34                        Integer32 integer) Which Returns Nothing Is Declared;
  35 Function strcat(PointerToCharacter dest,
  36                 PointerToCharacter src) Which Returns Nothing Is Declared;
  37 Function strlen(PointerToCharacter string) Which Returns Integer32 Is Declared;
  38 
  39 Function newTreeNode() Which Returns PointerToTreeNode Does {
  40   Integer16 i : = 0;
  41   While i < 64 Loop {
  42     If not(isTreeNodeUsed[i]) Then {
  43       treeNodes[i].character : = 0;
  44       treeNodes[i].leftChild : = treeNodes[i].rightChild
  45           : = PointerToTreeNode(0);
  46       treeNodes[i].code[0] : = 0;
  47       treeNodes[i].frequencyOfCharacter : = 0;
  48       isTreeNodeUsed[i] : = 1;
  49       If NDEBUG = 0 Then {
  50         Character stringToBePrinted[64] : = {0};
  51         strcat(AddressOf(stringToBePrinted[0]),
  52                "NDEBUG: Allocating the TreeNode #");
  53         convertIntegerToString(AddressOf(stringToBePrinted[0]) +
  54                                    strlen(AddressOf(stringToBePrinted[0])),
  55                                i);
  56         strcat(AddressOf(stringToBePrinted[0]), "\n");
  57         printString(AddressOf(stringToBePrinted[0]));
  58       }
  59       EndIf;
  60       Return AddressOf(treeNodes[i]);
  61     }
  62     EndIf;
  63     i += 1;
  64   }
  65   EndWhile;
  66   noMoreFreeMemory();
  67 }
  68 EndFunction;
  69 
  70 Function freeTreeNode(PointerToTreeNode treeNode) Which Returns Nothing Does {
  71   If not(isTreeNodeWithinBounds(treeNode)) Then { segmentationFault(); }
  72   EndIf;
  73   If NDEBUG = 0 Then {
  74     Character stringToBePrinted[64] : = {0};
  75     strcat(AddressOf(stringToBePrinted[0]), "NDEBUG: Freeing the TreeNode #");
  76     convertIntegerToString(AddressOf(stringToBePrinted[0]) +
  77                                strlen(AddressOf(stringToBePrinted[0])),
  78                            (treeNode - AddressOf(treeNodes[0])) /
  79                                SizeOf(TreeNode));
  80     strcat(AddressOf(stringToBePrinted[0]), "\n");
  81     printString(AddressOf(stringToBePrinted[0]));
  82   }
  83   EndIf;
  84   isTreeNodeUsed[(treeNode - AddressOf(treeNodes[0])) / SizeOf(TreeNode)] : = 0;
  85 }
  86 EndFunction;
  87 
  88 Function strlen(PointerToCharacter str) Which Returns Integer32 Does {
  89   If str = 0 Then { Return 0; }
  90   EndIf;
  91   Integer32 length : = 0;
  92   While ValueAt(str + length) Loop { length += 1; }
  93   EndWhile;
  94   Return length;
  95 }
  96 EndFunction;
  97 
  98 Function strncmp(PointerToCharacter first, PointerToCharacter second,
  99                  Integer32 n) Which Returns Integer32 Does {
 100   If first = 0 or second = 0 Then { Return 1; }
 101   EndIf;
 102   Integer32 iterator : = 0;
 103   While iterator < n Loop {
 104     If ValueAt(first + iterator) = ValueAt(second + iterator) Then {
 105       iterator += 1;
 106     }
 107     Else { Return ValueAt(first + iterator) - ValueAt(second + iterator); }
 108     EndIf;
 109   }
 110   EndWhile;
 111   Return 0;
 112 }
 113 EndFunction;
 114 
 115 Function strcpy(PointerToCharacter dest,
 116                 PointerToCharacter src) Which Returns Nothing Does {
 117   While ValueAt(src) Loop {
 118     ValueAt(dest) : = ValueAt(src);
 119     dest += 1;
 120     src += 1;
 121   }
 122   EndWhile;
 123   ValueAt(dest) : = 0;
 124 }
 125 EndFunction;
 126 
 127 Function strcat(PointerToCharacter dest,
 128                 PointerToCharacter src) Which Returns Nothing Does {
 129   strcpy(dest + strlen(dest), src);
 130 }
 131 EndFunction;
 132 
 133 Function reverseString(PointerToCharacter string) Which Returns Nothing Does {
 134   PointerToCharacter pointerToLastCharacter : = string + strlen(string) - 1;
 135   While pointerToLastCharacter - string > 0 Loop {
 136     Character tmp : = ValueAt(string);
 137     ValueAt(string) : = ValueAt(pointerToLastCharacter);
 138     ValueAt(pointerToLastCharacter) : = tmp;
 139     string += 1;
 140     pointerToLastCharacter -= 1;
 141   }
 142   EndWhile;
 143 }
 144 EndFunction;
 145 
 146 Function convertIntegerToString(PointerToCharacter string,
 147                                 Integer32 number) Which Returns Nothing Does {
 148   Integer32 isNumberNegative : = 0;
 149   If number < 0 Then {
 150   number:
 151     = -number;
 152   isNumberNegative:
 153     = 1;
 154   }
 155   EndIf;
 156   Integer32 i : = 0;
 157   While number >= 10 Loop {
 158     ValueAt(string + i) : = '0' + mod(number, 10);
 159     number /= 10;
 160     i += 1;
 161   }
 162   EndWhile;
 163   ValueAt(string + i) : = '0' + number;
 164   i += 1;
 165   If isNumberNegative Then {
 166     ValueAt(string + i) : = '-';
 167     i += 1;
 168   }
 169   EndIf;
 170   ValueAt(string + i) : = 0;
 171   reverseString(string);
 172 }
 173 EndFunction;
 174 
 175 Function convertDecimalToString(PointerToCharacter string,
 176                                 Decimal32 number) Which Returns Nothing Does {
 177   convertIntegerToString(string, number);
 178   number -= Integer32(number);
 179   If number < 0 Then { number *= -1; }
 180   EndIf;
 181   If number = 0 Then { Return; }
 182   EndIf;
 183   strcat(string, ".");
 184   Integer16 numberOfDecimals : = 0;
 185   While numberOfDecimals<3 and number> 0 Loop {
 186     numberOfDecimals += 1;
 187     number *= 10;
 188     Character stringWithTheNewDigit[2];
 189     stringWithTheNewDigit[0] : = stringWithTheNewDigit[1] : = 0;
 190     stringWithTheNewDigit[0] : = '0' + number;
 191     strcat(string, AddressOf(stringWithTheNewDigit[0]));
 192     number -= Integer32(number);
 193   }
 194   EndWhile;
 195 }
 196 EndFunction;
 197 
 198 PointerToCharacter mapOfCodes[256];
 199 
 200 Function assignCode(PointerToCharacter currentCode,
 201                     PointerToTreeNode treeNode) Which Returns Nothing Does {
 202   If NDEBUG = 0 Then {
 203     Character stringToBePrinted[64] : = {0};
 204     strcat(AddressOf(stringToBePrinted[0]), "NDEBUG: Assigning the code \"");
 205     strcat(AddressOf(stringToBePrinted[0]), currentCode);
 206     strcat(AddressOf(stringToBePrinted[0]), "\" to the TreeNode #");
 207     convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 208                                strlen(AddressOf(stringToBePrinted[0])),
 209                            (treeNode - AddressOf(treeNodes[0])) /
 210                                SizeOf(TreeNode));
 211     strcat(AddressOf(stringToBePrinted[0]), ".\n");
 212     printString(AddressOf(stringToBePrinted[0]));
 213 
 214     stringToBePrinted[0] : = 0;
 215     strcat(AddressOf(stringToBePrinted[0]),
 216            "NDEBUG: Its left child is the TreeNode #");
 217     If treeNode->leftChild Then {
 218       convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 219                                  strlen(AddressOf(stringToBePrinted[0])),
 220                              (treeNode->leftChild - AddressOf(treeNodes[0])) /
 221                                  SizeOf(TreeNode));
 222     }
 223     Else { strcat(AddressOf(stringToBePrinted[0]), "null"); }
 224     EndIf;
 225     strcat(AddressOf(stringToBePrinted[0]), ".\n");
 226     printString(AddressOf(stringToBePrinted[0]));
 227 
 228     stringToBePrinted[0] : = 0;
 229     strcat(AddressOf(stringToBePrinted[0]),
 230            "NDEBUG: Its right child is the TreeNode #");
 231     If treeNode->leftChild Then {
 232       convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 233                                  strlen(AddressOf(stringToBePrinted[0])),
 234                              (treeNode->rightChild - AddressOf(treeNodes[0])) /
 235                                  SizeOf(TreeNode));
 236     }
 237     Else { strcat(AddressOf(stringToBePrinted[0]), "null"); }
 238     EndIf;
 239     strcat(AddressOf(stringToBePrinted[0]), ".\n");
 240     printString(AddressOf(stringToBePrinted[0]));
 241   }
 242   EndIf;
 243 
 244   If not(isTreeNodeWithinBounds(treeNode)) Then { segmentationFault(); }
 245   EndIf;
 246 
 247   strcpy(AddressOf(treeNode->code[0]), currentCode);
 248 
 249   Character leftCode[16] : = {0}, rightCode[16] : = {0};
 250 
 251   strcpy(AddressOf(leftCode[0]), currentCode);
 252   strcat(AddressOf(leftCode[0]), "0");
 253   strcpy(AddressOf(rightCode[0]), currentCode);
 254   strcat(AddressOf(rightCode[0]), "1");
 255 
 256   If treeNode->leftChild Then {
 257     assignCode(AddressOf(leftCode[0]), treeNode->leftChild);
 258   }
 259   EndIf;
 260   If treeNode->rightChild Then {
 261     assignCode(AddressOf(rightCode[0]), treeNode->rightChild);
 262   }
 263   EndIf;
 264 
 265   If treeNode->character Then {
 266     mapOfCodes[treeNode->character] : = AddressOf(treeNode->code[0]);
 267     Character codeToPrint[32] : = {0};
 268     codeToPrint[0] : = '\'';
 269     codeToPrint[1] : = treeNode->character;
 270     codeToPrint[2] : = '\'';
 271     codeToPrint[3] : = '=';
 272     codeToPrint[4] : = '>';
 273     codeToPrint[5] : = 0;
 274     strcat(AddressOf(codeToPrint[0]), AddressOf(treeNode->code[0]));
 275     strcat(AddressOf(codeToPrint[0]), "\n");
 276     printString(AddressOf(codeToPrint[0]));
 277   }
 278   EndIf;
 279 }
 280 EndFunction;
 281 
 282 Function freeUpTheTree(PointerToTreeNode tree) Which Returns Nothing Does {
 283   If tree->leftChild Then {
 284     freeUpTheTree(tree->leftChild); // Calling `freeTreeNode` here instead of
 285                                     // `freeUpTheTree` causes a memory leak.
 286   }
 287   EndIf;
 288   If tree->rightChild Then { freeUpTheTree(tree->rightChild); }
 289   EndIf;
 290   freeTreeNode(tree);
 291 }
 292 EndFunction;
 293 
 294 Decimal32 PRECISION : = 500;
 295 Function ln(Decimal32 x) Which Returns Decimal32 Does {
 296   // Natural logarithm is the integral of 1/x from 1 to x, highschool math.
 297   Decimal32 sum : = 0, epsilon : = (x - 1) / (5 * PRECISION), i : = 1;
 298   While(epsilon > 0 and i < x) or (epsilon < 0 and i > x) Loop {
 299     sum += epsilon / i;
 300     i += epsilon;
 301   }
 302   EndWhile;
 303   Return sum;
 304 }
 305 EndFunction;
 306 
 307 Function log2(Decimal32 x) Which Returns Decimal32 Does {
 308   Return ln(x) / ln(2);
 309 }
 310 EndFunction;
 311 
 312 Character input[32];
 313 Character output[256];
 314 
 315 Function main() Which Returns Nothing Does {
 316   clearScreen();
 317   Integer16 lengthOfInput : = getLengthOfTheInput(), i : = 0;
 318   If NDEBUG = 0 Then {
 319     Character stringToBePrinted[64] : = {0};
 320     strcat(AddressOf(stringToBePrinted[0]),
 321            "NDEBUG: The length of the input is: ");
 322     convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 323                                strlen(AddressOf(stringToBePrinted[0])),
 324                            lengthOfInput);
 325     strcat(AddressOf(stringToBePrinted[0]), "\n");
 326     printString(AddressOf(stringToBePrinted[0]));
 327   }
 328   EndIf;
 329   While i < lengthOfInput Loop {
 330     input[i] : = getCharacterOfTheInput(i);
 331     i += 1;
 332   }
 333   EndWhile;
 334   input[lengthOfInput] : = 0;
 335 
 336   If strlen(AddressOf(input[0])) = 0 Then {
 337     printString("The input is empty!\n");
 338     Return;
 339   }
 340   EndIf;
 341 
 342 i:
 343   = 0;
 344   While i < 256 Loop {
 345     mapOfCodes[i] : = PointerToCharacter(0);
 346     i += 1;
 347   }
 348   EndWhile;
 349 
 350   PointerToTreeNode array[32];
 351   Integer16 lengthOfTheArray : = 0;
 352 i:
 353   = 0;
 354   While i < lengthOfInput Loop {
 355     Integer16 j : = 0, haveWeFoundTheCharacterInTheArray : = 0;
 356     While j < lengthOfTheArray Loop {
 357       If array[j]->character = input[i] Then {
 358       haveWeFoundTheCharacterInTheArray:
 359         = 1;
 360         array[j]->frequencyOfCharacter += 1;
 361       }
 362       EndIf;
 363       j += 1;
 364     }
 365     EndWhile;
 366     If not(haveWeFoundTheCharacterInTheArray) Then {
 367       array[lengthOfTheArray] : = newTreeNode();
 368       array[lengthOfTheArray]->character : = input[i];
 369       array[lengthOfTheArray]->frequencyOfCharacter : = 1;
 370       lengthOfTheArray += 1;
 371     }
 372     EndIf;
 373     i += 1;
 374   }
 375   EndWhile;
 376 
 377 i:
 378   = 0;
 379   While i < lengthOfTheArray Loop {
 380     Character stringToBePrinted[64] : = {0};
 381     strcat(AddressOf(stringToBePrinted[0]), "The character '");
 382     Integer16 indexOfCharacter : = strlen(AddressOf(stringToBePrinted[0]));
 383     stringToBePrinted[indexOfCharacter] : = array[i]->character;
 384     stringToBePrinted[indexOfCharacter + 1] : = 0;
 385     strcat(AddressOf(stringToBePrinted[0]), "' has the frequency of ");
 386     convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 387                                strlen(AddressOf(stringToBePrinted[0])),
 388                            array[i]->frequencyOfCharacter);
 389     strcat(AddressOf(stringToBePrinted[0]), ".\n");
 390     printString(AddressOf(stringToBePrinted[0]));
 391     i += 1;
 392   }
 393   EndWhile;
 394 
 395   Decimal32 ShannonEntropy : = 0;
 396 i:
 397   = 0;
 398   While i < lengthOfTheArray Loop {
 399     ShannonEntropy -=
 400         (array[i]->frequencyOfCharacter / Decimal32(lengthOfInput)) *
 401         log2(array[i]->frequencyOfCharacter / Decimal32(lengthOfInput));
 402     i += 1;
 403   }
 404   EndWhile;
 405   output[0] : = 0;
 406   strcat(AddressOf(output[0]), "The Shannon Entropy of the input string is: ");
 407   convertDecimalToString(AddressOf(output[0]) + strlen(AddressOf(output[0])),
 408                          ShannonEntropy);
 409   strcat(AddressOf(output[0]), " bits/symbol.\n");
 410   printString(AddressOf(output[0]));
 411 
 412   While lengthOfTheArray > 1 Loop {
 413     Integer16 minimum : = 0, secondMinimum : = 0;
 414 
 415     Integer16 i : = 0;
 416     If NDEBUG = 0 Then {
 417       Character stringToBePrinted[64] : = {0};
 418       strcat(AddressOf(stringToBePrinted[0]),
 419              "NDEBUG: The length of the array is ");
 420       convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 421                                  strlen(AddressOf(stringToBePrinted[0])),
 422                              lengthOfTheArray);
 423       strcat(AddressOf(stringToBePrinted[0]), ".\n");
 424       printString(AddressOf(stringToBePrinted[0]));
 425     }
 426     EndIf;
 427     While i < lengthOfTheArray Loop {
 428       If NDEBUG = 0 Then {
 429         Character stringToBePrinted[64] : = {0};
 430         strcat(AddressOf(stringToBePrinted[0]),
 431                "NDEBUG: The tree at the index #");
 432         convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 433                                    strlen(AddressOf(stringToBePrinted[0])),
 434                                i);
 435         strcat(AddressOf(stringToBePrinted[0]), " is the TreeNode #");
 436         convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 437                                    strlen(AddressOf(stringToBePrinted[0])),
 438                                (array[i] - AddressOf(treeNodes[0])) /
 439                                    SizeOf(TreeNode));
 440         strcat(AddressOf(stringToBePrinted[0]), ".\n");
 441         printString(AddressOf(stringToBePrinted[0]));
 442       }
 443       EndIf;
 444       If not(isTreeNodeWithinBounds(array[i])) Then {
 445         segmentationFault();
 446         Return;
 447       }
 448       EndIf;
 449       i += 1;
 450     }
 451     EndWhile;
 452 
 453   i:
 454     = 0;
 455     While i < lengthOfTheArray Loop {
 456       If array[i]->frequencyOfCharacter <
 457           array[minimum]->frequencyOfCharacter Then {
 458       minimum:
 459         = i;
 460       }
 461       EndIf;
 462       i += 1;
 463     }
 464     EndWhile;
 465 
 466   i:
 467     = minimum = 0 ? 1 : 0;
 468   secondMinimum:
 469     = i;
 470     While i < lengthOfTheArray Loop {
 471       If array[i]->frequencyOfCharacter <
 472               array[secondMinimum]->frequencyOfCharacter and
 473           not(i = minimum) Then {
 474       secondMinimum:
 475         = i;
 476       }
 477       EndIf;
 478       i += 1;
 479     }
 480     EndWhile;
 481 
 482     If NDEBUG = 0 Then {
 483       Character stringToBePrinted[64] : = {0};
 484       strcat(AddressOf(stringToBePrinted[0]),
 485              "NDEBUG: The minimum and the second minimum are ");
 486       convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 487                                  strlen(AddressOf(stringToBePrinted[0])),
 488                              minimum);
 489       strcat(AddressOf(stringToBePrinted[0]), " and ");
 490       convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 491                                  strlen(AddressOf(stringToBePrinted[0])),
 492                              secondMinimum);
 493       strcat(AddressOf(stringToBePrinted[0]), ".\n");
 494       printString(AddressOf(stringToBePrinted[0]));
 495     }
 496     EndIf;
 497 
 498     If NDEBUG = 0 Then {
 499       Character stringToBePrinted[64] : = {0};
 500       strcat(AddressOf(stringToBePrinted[0]), "NDEBUG: Joining the TreeNode #");
 501       convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 502                                  strlen(AddressOf(stringToBePrinted[0])),
 503                              (array[minimum] - AddressOf(treeNodes[0])) /
 504                                  SizeOf(TreeNode));
 505       strcat(AddressOf(stringToBePrinted[0]), " with the TreeNode #");
 506       convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 507                                  strlen(AddressOf(stringToBePrinted[0])),
 508                              (array[secondMinimum] - AddressOf(treeNodes[0])) /
 509                                  SizeOf(TreeNode));
 510       strcat(AddressOf(stringToBePrinted[0]), ".\n");
 511       printString(AddressOf(stringToBePrinted[0]));
 512     }
 513     EndIf;
 514 
 515     PointerToTreeNode sumOfTheTwoMostFrequent : = newTreeNode();
 516     sumOfTheTwoMostFrequent->frequencyOfCharacter
 517         : = array[minimum]->frequencyOfCharacter +
 518             array[secondMinimum]->frequencyOfCharacter;
 519     sumOfTheTwoMostFrequent->leftChild : = array[minimum];
 520     sumOfTheTwoMostFrequent->rightChild : = array[secondMinimum];
 521 
 522     If NDEBUG = 0 Then {
 523       Character stringToBePrinted[64] : = {0};
 524       strcat(AddressOf(stringToBePrinted[0]),
 525              "NDEBUG: The new TreeNode has the frequency of: ");
 526       convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 527                                  strlen(AddressOf(stringToBePrinted[0])),
 528                              sumOfTheTwoMostFrequent->frequencyOfCharacter);
 529       strcat(AddressOf(stringToBePrinted[0]), ".\n");
 530       printString(AddressOf(stringToBePrinted[0]));
 531     }
 532     EndIf;
 533 
 534     array[minimum] : = sumOfTheTwoMostFrequent;
 535 
 536   // Delete the second minimum from the array...
 537   i:
 538     = secondMinimum;
 539     While i < lengthOfTheArray - 1 Loop {
 540       array[i] : = array[i + 1];
 541       i += 1;
 542     }
 543     EndWhile;
 544 
 545     lengthOfTheArray -= 1;
 546   }
 547   EndWhile;
 548 
 549   If NDEBUG = 0 Then {
 550     Character stringToBePrinted[128] : = {0};
 551     strcat(AddressOf(stringToBePrinted[0]),
 552            "NDEBUG: The frequency of the root node is ");
 553     convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 554                                strlen(AddressOf(stringToBePrinted[0])),
 555                            array[0]->frequencyOfCharacter);
 556     strcat(AddressOf(stringToBePrinted[0]),
 557            ". If the algorithm is correctly implemented, it should be ");
 558     convertIntegerToString(AddressOf(stringToBePrinted[0]) +
 559                                strlen(AddressOf(stringToBePrinted[0])),
 560                            lengthOfInput);
 561     strcat(AddressOf(stringToBePrinted[0]), ".\n");
 562     printString(AddressOf(stringToBePrinted[0]));
 563   }
 564   EndIf;
 565 
 566   printString("The tree has been constructed, let us assign Huffman codes to "
 567               "characters:\n");
 568   assignCode("", array[0]);
 569 
 570   Integer16 lengthOfTheOutput : = 0;
 571 i:
 572   = 0;
 573   While i < lengthOfInput Loop {
 574     lengthOfTheOutput += strlen(mapOfCodes[input[i]]);
 575     i += 1;
 576   }
 577   EndWhile;
 578   output[0] : = 0;
 579   strcat(AddressOf(output[0]), "The length of the encoded string is: ");
 580   convertIntegerToString(AddressOf(output[0]) + strlen(AddressOf(output[0])),
 581                          lengthOfTheOutput);
 582   strcat(AddressOf(output[0]), " bits.\n");
 583   printString(AddressOf(output[0]));
 584 
 585   output[0] : = 0;
 586   strcat(AddressOf(output[0]),
 587          "The average length of the symbol in the Huffman code is: ");
 588   convertDecimalToString(AddressOf(output[0]) + strlen(AddressOf(output[0])),
 589                          Decimal32(lengthOfTheOutput) / lengthOfInput);
 590   strcat(AddressOf(output[0]), " bits/symbol.\n");
 591   printString(AddressOf(output[0]));
 592 
 593   output[0] : = 0;
 594 i:
 595   = 0;
 596   While i < lengthOfInput Loop {
 597     strcat(AddressOf(output[0]), mapOfCodes[input[i]]);
 598     i += 1;
 599   }
 600   EndWhile;
 601   strcat(AddressOf(output[0]), "\n");
 602   printString("The Huffman code of the input is:\n");
 603   printString(AddressOf(output[0]));
 604 
 605   freeUpTheTree(array[0]);
 606 
 607   Character stringToBePrinted[64] : = {0};
 608   strcat(AddressOf(stringToBePrinted[0]), "Decoding the output...\n");
 609   printString(AddressOf(stringToBePrinted[0]));
 610 
 611   Integer16 j : = 0;
 612   While j < strlen(AddressOf(output[0])) - 1 Loop {
 613   i:
 614     = 0;
 615     If NDEBUG = 0 Then {
 616       printString(
 617           "NDEBUG: We are entering the loop for decoding the output!\n");
 618     }
 619     EndIf;
 620     While(mapOfCodes[i] = 0 or strncmp(AddressOf(output[j]), mapOfCodes[i],
 621                                        strlen(mapOfCodes[i]))) and
 622         i < 256 Loop {
 623       If NDEBUG = 0 Then {
 624         If mapOfCodes[i] = 0 Then {
 625           printString("NDEBUG: Skipping the character because it's NULL.\n");
 626         }
 627         Else {
 628           printString(
 629               "NDEBUG: Skipping the character because it doesn't match!\n");
 630         }
 631         EndIf;
 632       }
 633       EndIf;
 634       i += 1;
 635     }
 636     EndWhile;
 637     If i = 256 Then {
 638       printString("ERROR: Cannot find the beginning of the current string in "
 639                   "the map of codes!\n");
 640       Return;
 641     }
 642     EndIf;
 643     stringToBePrinted[0] : = 0;
 644     strcat(AddressOf(stringToBePrinted[0]), mapOfCodes[i]);
 645     strcat(AddressOf(stringToBePrinted[0]), "=>");
 646     Character stringToBeAdded[5];
 647     stringToBeAdded[0] : = '\'';
 648     stringToBeAdded[1] : = i;
 649     stringToBeAdded[2] : = '\'';
 650     stringToBeAdded[3] : = '\n';
 651     stringToBeAdded[4] : = 0;
 652     strcat(AddressOf(stringToBePrinted[0]), AddressOf(stringToBeAdded[0]));
 653     printString(AddressOf(stringToBePrinted[0]));
 654     j += strlen(mapOfCodes[i]);
 655   }
 656   EndWhile;
 657 }
 658 EndFunction;
 659