#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 */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ memcpy(char **, char *, size_t);
int /*<<< orphan*/ printf(char *, ...);
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
size_t strlen(char *);
int main() {
  char input[] = "AAAAAAAAAABBBBBBBBBBBBBBBCCC";
  char c = "";
  int c_len = strlen(input);
  int rle_count = 1;
  printf("c_len: %d\n", c_len);
  if (c_len > 1) {
    c = input[0];
    for (int i = 1; i <= c_len; i++) {
      if (c != input[i] || i == c_len) {
        if (rle_count > 2) {
          printf("%d%c", rle_count, c);
        }
        if ((rle_count > 0) && (rle_count <= 2)) {
          for (int j = 0; j < rle_count; j++) {
            printf("%c", c);
          }
        }
        rle_count = 1;
        c = input[i];
      } else {
        rle_count++;
      }
    }
    printf("\n");
  } else {
    printf("input string not long enough.  Exiting without doing anything.\n");
  }
  char decode[] = "10A15B3C";
  sscanf(decode, "%d", &rle_count);
  char *buf;
  buf = calloc(1, sizeof(char));
  for (int b = 0; b < strlen(buf); b++) {
    buf[b] = 0;
  }
  int res = snprintf(buf, 1, "%d", rle_count);
  free(buf);
  buf = calloc(res, sizeof(char));
  res = snprintf(buf, res, "%d", rle_count);
  memcpy(&decode, &decode[strlen(buf)], strlen(decode) - strlen(buf));
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe64(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe61(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe5f(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xe5a(%rip),%al
mov    %al,-0x14(%rbp)
lea    0xea0(%rip),%rax
mov    %al,-0x31(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x38(%rbp),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1,-0x38(%rbp)
jle    12e8 <main+0x168>
mov    -0x30(%rbp),%al
mov    %al,-0x31(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x38(%rbp),%eax
jg     12d5 <main+0x155>
movsbl -0x31(%rbp),%eax
movslq -0x40(%rbp),%rcx
movsbl -0x30(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    1237 <main+0xb7>
mov    -0x40(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    12b9 <main+0x139>
cmpl   $0x2,-0x3c(%rbp)
jle    1256 <main+0xd6>
mov    -0x3c(%rbp),%esi
movsbl -0x31(%rbp),%edx
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x3c(%rbp)
jle    12a2 <main+0x122>
cmpl   $0x2,-0x3c(%rbp)
jg     12a2 <main+0x122>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    129d <main+0x11d>
movsbl -0x31(%rbp),%esi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1271 <main+0xf1>
jmp    12a2 <main+0x122>
movl   $0x1,-0x3c(%rbp)
movslq -0x40(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%al
mov    %al,-0x31(%rbp)
jmp    12c2 <main+0x142>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12c7 <main+0x147>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    120a <main+0x8a>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f6 <main+0x176>
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0xd70(%rip),%rax
mov    %rax,-0x4d(%rbp)
mov    0xd6e(%rip),%al
mov    %al,-0x45(%rbp)
lea    -0x4d(%rbp),%rdi
lea    0xd61(%rip),%rsi
lea    -0x3c(%rbp),%rdx
call   10a0 <sscanf@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1070 <calloc@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movslq -0x5c(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
cmp    %rcx,%rax
jae    1370 <main+0x1f0>
mov    -0x58(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1335 <main+0x1b5>
mov    -0x58(%rbp),%rdi
mov    -0x3c(%rbp),%ecx
mov    $0x1,%esi
lea    0xcf3(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%esi
mov    -0x3c(%rbp),%ecx
lea    0xcc0(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x60(%rbp)
lea    -0x4d(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
lea    -0x4d(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x70(%rbp)
lea    -0x4d(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x80(%rbp),%rdx
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rsi
sub    %rax,%rdx
call   1090 <memcpy@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe78(%rip),%rdi
mov    $0x1c,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebx
mov    $0x41,%al
mov    $0x1,%r15d
lea    0xe3b(%rip),%r12
lea    0xe5c(%rip),%r14
jmp    11ee <main+0x5e>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebx
add    $0x1,%r15
mov    %r13d,%eax
cmp    $0x1d,%r15
je     122e <main+0x9e>
mov    (%r15,%r12,1),%r13b
cmp    %r13b,%al
jne    1210 <main+0x80>
cmp    $0x1c,%r15
je     1210 <main+0x80>
add    $0x1,%ebx
mov    %eax,%r13d
jmp    11e1 <main+0x51>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%ebp
cmp    $0x3,%ebx
jge    11ce <main+0x3e>
lea    -0x1(%rbx),%eax
cmp    $0x1,%eax
ja     11dc <main+0x4c>
mov    %ebp,%edi
call   1040 <putchar@plt>
add    $0xffffffff,%ebx
jne    1220 <main+0x90>
jmp    11dc <main+0x4c>
mov    %ebx,0x4(%rsp)
mov    $0xa,%edi
call   1040 <putchar@plt>
movabs $0x4333423531413031,%rax
42 33 43
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xddf(%rip),%r15
lea    0x8(%rsp),%r14
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   10b0 <sscanf@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbp
mov    0x4(%rsp),%ecx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1070 <snprintf@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbp
mov    0x4(%rsp),%ecx
mov    %rax,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   1070 <snprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
lea    (%rsp,%rax,1),%rbp
add    $0x8,%rbp
mov    %r14,%rdi
call   1050 <strlen@plt>
sub    %rbx,%rax
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   10a0 <memcpy@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.input = [29 x i8] c"AAAAAAAAAABBBBBBBBBBBBBBBCCC\00"
@.str = [1 x i8] zeroinitializer
@.str.1 = [11 x i8] c"c_len: %d\0A\00"
@.str.2 = [5 x i8] c"%d%c\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [64 x i8] c"input string not long enough. Exiting without doing anything.\0A\00"
@__const.main.decode = [9 x i8] c"10A15B3C\00"
@.str.6 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [29 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [9 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = bitcast [29 x i8]* %2 to i8*
store i8 ptrtoint ([1 x i8]* @.str to i8), i8* %3
%13 = getelementptr inbounds [29 x i8], [29 x i8]* %2, i64 0, i64 0
%14 = call i64 @strlen(i8* %13)
%15 = trunc i64 %14 to i32
store i32 %15, i32* %4
store i32 1, i32* %5
%16 = load i32, i32* %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 1
br i1 %19, label %20, label %81
20: ; preds = %0
%21 = getelementptr inbounds [29 x i8], [29 x i8]* %2, i64 0, i64 0
%22 = load i8, i8* %21
store i8 %22, i8* %3
store i32 1, i32* %6
br label %23
23: ; preds = %76, %20
%24 = load i32, i32* %6
%25 = load i32, i32* %4
%26 = icmp sle i32 %24, %25
br i1 %26, label %27, label %79
27: ; preds = %23
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [29 x i8], [29 x i8]* %2, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %29, %34
br i1 %35, label %40, label %36
36: ; preds = %27
%37 = load i32, i32* %6
%38 = load i32, i32* %4
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %72
40: ; preds = %36, %27
%41 = load i32, i32* %5
%42 = icmp sgt i32 %41, 2
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* %5
%45 = load i8, i8* %3
%46 = sext i8 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 %46)
br label %48
48: ; preds = %43, %40
%49 = load i32, i32* %5
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %67
51: ; preds = %48
%52 = load i32, i32* %5
%53 = icmp sle i32 %52, 2
br i1 %53, label %54, label %67
54: ; preds = %51
store i32 0, i32* %7
br label %55
55: ; preds = %63, %54
%56 = load i32, i32* %7
%57 = load i32, i32* %5
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %66
59: ; preds = %55
%60 = load i8, i8* %3
%61 = sext i8 %60 to i32
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %59
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %55
66: ; preds = %55
br label %67
67: ; preds = %66, %51, %48
store i32 1, i32* %5
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [29 x i8], [29 x i8]* %2, i64 0, i64 %69
%71 = load i8, i8* %70
store i8 %71, i8* %3
br label %75
72: ; preds = %36
%73 = load i32, i32* %5
%74 = add nsw i32 %73, 1
store i32 %74, i32* %5
br label %75
75: ; preds = %72, %67
br label %76
76: ; preds = %75
%77 = load i32, i32* %6
%78 = add nsw i32 %77, 1
store i32 %78, i32* %6
br label %23
79: ; preds = %23
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %83
81: ; preds = %0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.5, i64 0, i64 0))
br label %83
83: ; preds = %81, %79
%84 = bitcast [9 x i8]* %8 to i8*
%85 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%86 = call i32 @sscanf(i8* %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %5)
%87 = call i8* @calloc(i32 1, i32 1)
store i8* %87, i8** %9
store i32 0, i32* %10
br label %88
88: ; preds = %99, %83
%89 = load i32, i32* %10
%90 = sext i32 %89 to i64
%91 = load i8*, i8** %9
%92 = call i64 @strlen(i8* %91)
%93 = icmp ult i64 %90, %92
br i1 %93, label %94, label %102
94: ; preds = %88
%95 = load i8*, i8** %9
%96 = load i32, i32* %10
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
store i8 0, i8* %98
br label %99
99: ; preds = %94
%100 = load i32, i32* %10
%101 = add nsw i32 %100, 1
store i32 %101, i32* %10
br label %88
102: ; preds = %88
%103 = load i8*, i8** %9
%104 = load i32, i32* %5
%105 = call i32 @snprintf(i8* %103, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %104)
store i32 %105, i32* %11
%106 = load i8*, i8** %9
%107 = call i32 @free(i8* %106)
%108 = load i32, i32* %11
%109 = call i8* @calloc(i32 %108, i32 1)
store i8* %109, i8** %9
%110 = load i8*, i8** %9
%111 = load i32, i32* %11
%112 = load i32, i32* %5
%113 = call i32 @snprintf(i8* %110, i32 %111, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %112)
store i32 %113, i32* %11
%114 = bitcast [9 x i8]* %8 to i8**
%115 = load i8*, i8** %9
%116 = call i64 @strlen(i8* %115)
%117 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 %116
%118 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%119 = call i64 @strlen(i8* %118)
%120 = load i8*, i8** %9
%121 = call i64 @strlen(i8* %120)
%122 = sub i64 %119, %121
%123 = call i32 @memcpy(i8** %114, i8* %117, i64 %122)
%124 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@__const.main.input = [29 x i8] c"AAAAAAAAAABBBBBBBBBBBBBBBCCC\00"
@.str.1 = [11 x i8] c"c_len: %d\0A\00"
@.str.2 = [5 x i8] c"%d%c\00"
@__const.main.decode = [9 x i8] c"10A15B3C\00"
@.str.6 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i8]
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 28)
br label %5
5: ; preds = %0, %29
%6 = phi i64 [ 1, %0 ], [ %32, %29 ]
%7 = phi i8 [ 65, %0 ], [ %31, %29 ]
%8 = phi i32 [ 1, %0 ], [ %30, %29 ]
%9 = sext i8 %7 to i32
%10 = getelementptr inbounds [29 x i8], [29 x i8]* @__const.main.input, i64 0, i64 %6
%11 = load i8, i8* %10
%12 = icmp ne i8 %7, %11
%13 = icmp eq i64 %6, 28
%14 = select i1 %12, i1 true, i1 %13
br i1 %14, label %15, label %27
15: ; preds = %5
%16 = icmp sgt i32 %8, 2
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %9)
br label %29
19: ; preds = %15
%20 = add nsw i32 %8, -1
%21 = icmp ult i32 %20, 2
br i1 %21, label %22, label %29
22: ; preds = %19, %22
%23 = phi i32 [ %25, %22 ], [ 0, %19 ]
%24 = tail call i32 @putchar(i32 %9)
%25 = add nuw nsw i32 %23, 1
%26 = icmp eq i32 %25, %8
br i1 %26, label %29, label %22
27: ; preds = %5
%28 = add nsw i32 %8, 1
br label %29
29: ; preds = %22, %17, %19, %27
%30 = phi i32 [ %28, %27 ], [ 1, %19 ], [ 1, %17 ], [ 1, %22 ]
%31 = phi i8 [ %7, %27 ], [ %11, %19 ], [ %11, %17 ], [ %11, %22 ]
%32 = add nuw nsw i64 %6, 1
%33 = icmp eq i64 %32, 29
br i1 %33, label %34, label %5
34: ; preds = %29
store i32 %30, i32* %1
%35 = tail call i32 @putchar(i32 10)
%36 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%37 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %1)
%38 = call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
%39 = load i32, i32* %1
%40 = call i32 @snprintf(i8* %38, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %39)
%41 = call i32 @free(i8* %38)
%42 = call i8* @calloc(i32 %40, i32 1)
%43 = load i32, i32* %1
%44 = call i32 @snprintf(i8* %42, i32 %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %43)
%45 = bitcast [9 x i8]* %2 to i8**
%46 = call i64 @strlen(i8* dereferenceable(1) %42)
%47 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %46
%48 = call i64 @strlen(i8* %36)
%49 = sub i64 %48, %46
%50 = call i32 @memcpy(i8** %45, i8* %47, i64 %49)
%51 = call i32 (...) @getchar()
ret i32 0
}