#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 */
int /*<<< orphan*/ decode(char *, char *, char *);
int /*<<< orphan*/ encode(char *, char *, char *);
char *malloc(int);
int /*<<< orphan*/ print_binary_rep(char *);
int /*<<< orphan*/ print_encoded_string(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(int argc, char *argv[]) {
  char def_str[20] = "AAAAABBBCCCCDD0";
  char table[5];
  table[4] = 0;
  int str_elems = 20;
  char *str;
  char *encoded_str;
  char *decoded_str;
  if (argc == 1) {
    str = def_str;
  }
  if (argc == 2) {
    str = argv[1];
    str_elems = strlen(str) + 1;
  }
  printf("Elems: \n%d\n", str_elems);
  encoded_str = malloc(str_elems);
  decoded_str = malloc(str_elems);
  encode(str, table, encoded_str);
  printf("-----------Cadena de entrada--------\n");
  printf("Cadena: \n%s\n", str);
  printf("-----------Resultado de la codificacion--------\n");
  printf("Tabla: \n");
  print_binary_rep(table);
  printf("Cadena codificada: \n");
  print_encoded_string(encoded_str);
  decode(encoded_str, table, decoded_str);
  printf("-----------Resultado de la decodificacion--------\n");
  printf("Cadena decodificada: \n%s\n", decoded_str);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe6e(%rip),%eax
mov    %eax,-0x20(%rbp)
movb   $0x0,-0x31(%rbp)
movl   $0x14,-0x3c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11c2 <main+0x52>
lea    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11e7 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3c(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x3c(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
lea    -0x35(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1030 <encode@plt>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rsi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x35(%rbp),%rdi
call   1070 <print_binary_rep@plt>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x50(%rbp),%rdi
call   1060 <print_encoded_string@plt>
mov    -0x50(%rbp),%rdi
lea    -0x35(%rbp),%rsi
mov    -0x58(%rbp),%rdx
call   1090 <decode@plt>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
movaps 0xe6d(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
movb   $0x0,0xf(%rsp)
cmp    $0x2,%edi
jne    11bd <main+0x3d>
mov    0x8(%rsi),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
jmp    11c7 <main+0x47>
lea    0x10(%rsp),%r15
mov    $0x14,%ebp
lea    0xe46(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
lea    0xb(%rsp),%r12
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <encode@plt>
lea    0xe42(%rip),%rdi
call   1040 <puts@plt>
lea    0xe0f(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe4a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6e(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1080 <print_binary_rep@plt>
lea    0xe62(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1070 <print_encoded_string@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   10a0 <decode@plt>
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
lea    0xdbd(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.def_str = [20 x i8] c"AAAAABBBCCCCDD0\00\00\00\00\00"
@.str = [12 x i8] c"Elems: \0A%d\0A\00"
@.str.1 = [38 x i8] c"-----------Cadena de entrada--------\0A\00"
@.str.2 = [13 x i8] c"Cadena: \0A%s\0A\00"
@.str.3 = [49 x i8] c"-----------Resultado de la codificacion--------\0A\00"
@.str.4 = [9 x i8] c"Tabla: \0A\00"
@.str.5 = [21 x i8] c"Cadena codificada: \0A\00"
@.str.6 = [51 x i8] c"-----------Resultado de la decodificacion--------\0A\00"
@.str.7 = [26 x i8] c"Cadena decodificada: \0A%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i8]
%7 = alloca [5 x i8]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [20 x i8]* %6 to i8*
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 4
store i8 0, i8* %13
store i32 20, i32* %8
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
store i8* %17, i8** %9
br label %18
18: ; preds = %16, %2
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %28
28: ; preds = %21, %18
%29 = load i32, i32* %8
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %8
%32 = call i8* @malloc(i32 %31)
store i8* %32, i8** %10
%33 = load i32, i32* %8
%34 = call i8* @malloc(i32 %33)
store i8* %34, i8** %11
%35 = load i8*, i8** %9
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%37 = load i8*, i8** %10
%38 = call i32 @encode(i8* %35, i8* %36, i8* %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%40 = load i8*, i8** %9
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%44 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%45 = call i32 @print_binary_rep(i8* %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%47 = load i8*, i8** %10
%48 = call i32 @print_encoded_string(i8* %47)
%49 = load i8*, i8** %10
%50 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%51 = load i8*, i8** %11
%52 = call i32 @decode(i8* %49, i8* %50, i8* %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0))
%54 = load i8*, i8** %11
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %54)
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@__const.main.def_str = [20 x i8] c"AAAAABBBCCCCDD0\00\00\00\00\00"
@.str = [12 x i8] c"Elems: \0A%d\0A\00"
@.str.2 = [13 x i8] c"Cadena: \0A%s\0A\00"
@.str.7 = [26 x i8] c"Cadena decodificada: \0A%s\0A\00"
@str = [37 x i8] c"-----------Cadena de entrada--------\00"
@str.8 = [48 x i8] c"-----------Resultado de la codificacion--------\00"
@str.9 = [8 x i8] c"Tabla: \00"
@str.10 = [20 x i8] c"Cadena codificada: \00"
@str.11 = [50 x i8] c"-----------Resultado de la decodificacion--------\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
store i8 0, i8* %7
%8 = icmp eq i32 %0, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
br label %14
14: ; preds = %9, %2
%15 = phi i8* [ %11, %9 ], [ %5, %2 ]
%16 = phi i32 [ %13, %9 ], [ 20, %2 ]
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = tail call i8* @malloc(i32 %16)
%19 = tail call i8* @malloc(i32 %16)
%20 = call i32 @encode(i8* %15, i8* %6, i8* %18)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.8, i64 0, i64 0))
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.9, i64 0, i64 0))
%25 = call i32 @print_binary_rep(i8* %6)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0))
%27 = call i32 @print_encoded_string(i8* %18)
%28 = call i32 @decode(i8* %18, i8* %6, i8* %19)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.11, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %19)
ret i32 0
}