#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*/ fprintf(int /*<<< orphan*/, char *, char, int);
int /*<<< orphan*/ stderr;
void compress(const char *src) {
  int counter = 0;
  char last_char = 0;
  char p = 0;
  while (p = *src++) {
    if (p == last_char) {
      counter++;
    } else {
      if (counter) {
        fprintf(stderr, "%c%d", last_char, counter);
      }
      last_char = p;
      counter = 1;
    }
  }
  if (counter) {
    fprintf(stderr, "%c%d", last_char, counter);
  }
}


x86 assembly (clang, -O0):
<compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
movb   $0x0,-0xe(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0xe(%rbp)
cmp    $0x0,%al
je     119f <compress+0x8f>
movsbl -0xe(%rbp),%eax
movsbl -0xd(%rbp),%ecx
cmp    %ecx,%eax
jne    1165 <compress+0x55>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119a <compress+0x8a>
cmpl   $0x0,-0xc(%rbp)
je     118d <compress+0x7d>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0xd(%rbp),%al
mov    -0xc(%rbp),%ecx
lea    0xe7b(%rip),%rsi
movsbl %al,%edx
call   1030 <fprintf@plt>
mov    -0xe(%rbp),%al
mov    %al,-0xd(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    112b <compress+0x1b>
cmpl   $0x0,-0xc(%rbp)
je     11c7 <compress+0xb7>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    -0xd(%rbp),%al
mov    -0xc(%rbp),%ecx
lea    0xe41(%rip),%rsi
movsbl %al,%edx
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1190 <compress+0x80>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %ebp,%ebp
mov    0x2eb3(%rip),%r15
lea    0xecc(%rip),%r14
xor    %ecx,%ecx
jmp    114e <compress+0x3e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ecx
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     116f <compress+0x5f>
mov    %ebp,%edx
mov    %eax,%ebp
cmp    %dl,%al
je     1140 <compress+0x30>
test   %ecx,%ecx
je     1168 <compress+0x58>
mov    (%r15),%edi
movsbl %dl,%edx
mov    %r14,%rsi
call   1030 <fprintf@plt>
mov    $0x1,%ecx
jmp    1143 <compress+0x33>
test   %ecx,%ecx
je     1190 <compress+0x80>
mov    (%r15),%edi
movsbl %bpl,%edx
lea    0xe7f(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [5 x i8] c"%c%d\00"
define void @compress(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
store i8 0, i8* %4
store i8 0, i8* %5
br label %6
6: ; preds = %30, %1
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i32 1
store i8* %8, i8** %2
%9 = load i8, i8* %7
store i8 %9, i8* %5
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %6
%12 = load i8, i8* %5
%13 = sext i8 %12 to i32
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %13, %15
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %30
20: ; preds = %11
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = load i8, i8* %4
%26 = load i32, i32* %3
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %25, i32 %26)
br label %28
28: ; preds = %23, %20
%29 = load i8, i8* %5
store i8 %29, i8* %4
store i32 1, i32* %3
br label %30
30: ; preds = %28, %17
br label %6
31: ; preds = %6
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = load i8, i8* %4
%37 = load i32, i32* %3
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %36, i32 %37)
br label %39
39: ; preds = %34, %31
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [5 x i8] c"%c%d\00"
define void @compress(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %27, label %4
4: ; preds = %1, %18
%5 = phi i8 [ %20, %18 ], [ %2, %1 ]
%6 = phi i8* [ %9, %18 ], [ %0, %1 ]
%7 = phi i8 [ %5, %18 ], [ 0, %1 ]
%8 = phi i32 [ %19, %18 ], [ 0, %1 ]
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = icmp eq i8 %5, %7
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = add nsw i32 %8, 1
br label %18
13: ; preds = %4
%14 = icmp eq i32 %8, 0
br i1 %14, label %18, label %15
15: ; preds = %13
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %7, i32 %8)
br label %18
18: ; preds = %13, %15, %11
%19 = phi i32 [ %12, %11 ], [ 1, %15 ], [ 1, %13 ]
%20 = load i8, i8* %9
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %4
22: ; preds = %18
%23 = icmp eq i32 %19, 0
br i1 %23, label %27, label %24
24: ; preds = %22
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %5, i32 %19)
br label %27
27: ; preds = %1, %24, %22
ret void
}