#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*/ printf(char *, ...);
void string_compress_multi(const char *str) {
  while (*str) {
    const char *last_str = str;
    char c = *str;
    while (*str == c)
      str++;
    if (str - last_str == 1)
      printf("%c", c);
    else
      printf("%c%c", "0123456789"[str - last_str], c);
    if (*str == '\0')
      break;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<string_compress_multi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11cc <string_compress_multi+0xbc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    115e <string_compress_multi+0x4e>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113a <string_compress_multi+0x2a>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x1,%rax
jne    118a <string_compress_multi+0x7a>
movsbl -0x11(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <string_compress_multi+0xa2>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rax,%rcx
lea    0xe69(%rip),%rax
movsbl (%rax,%rcx,1),%esi
movsbl -0x11(%rbp),%edx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c7 <string_compress_multi+0xb7>
jmp    11cc <string_compress_multi+0xbc>
jmp    111c <string_compress_multi+0xc>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_compress_multi>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%al
lea    0xed4(%rip),%r15
lea    0xec8(%rip),%r14
jmp    1155 <string_compress_multi+0x35>
nopw   0x0(%rax,%rax,1)
movsbl (%rcx,%r15,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%al
test   %al,%al
je     1182 <string_compress_multi+0x62>
test   %al,%al
je     1182 <string_compress_multi+0x62>
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rdx
add    $0x1,%rcx
cmp    %al,0x1(%rbx,%rdx,1)
je     1160 <string_compress_multi+0x40>
movsbl %al,%edx
add    %rcx,%rbx
cmp    $0x1,%rcx
jne    1140 <string_compress_multi+0x20>
mov    %edx,%edi
call   1030 <putchar@plt>
jmp    114f <string_compress_multi+0x2f>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [5 x i8] c"%c%c\00"
@.str.2 = [11 x i8] c"0123456789\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @string_compress_multi(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %2
br label %5
5: ; preds = %52, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %53
9: ; preds = %5
%10 = load i8*, i8** %2
store i8* %10, i8** %3
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
store i8 %12, i8* %4
br label %13
13: ; preds = %20, %9
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %16, %18
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %2
br label %13
23: ; preds = %13
%24 = load i8*, i8** %2
%25 = load i8*, i8** %3
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = icmp eq i64 %28, 1
br i1 %29, label %30, label %34
30: ; preds = %23
%31 = load i8, i8* %4
%32 = sext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %46
34: ; preds = %23
%35 = load i8*, i8** %2
%36 = load i8*, i8** %3
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = getelementptr inbounds [11 x i8], [11 x i8]* @.str.2, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = load i8, i8* %4
%44 = sext i8 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %44)
br label %46
46: ; preds = %34, %30
%47 = load i8*, i8** %2
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %46
br label %53
52: ; preds = %46
br label %5
53: ; preds = %51, %5
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%c%c\00"
@.str.2 = [11 x i8] c"0123456789\00"
define void @string_compress_multi(i8* %0) {
%2 = load i8, i8* %0
br label %3
3: ; preds = %25, %1
%4 = phi i8 [ %26, %25 ], [ %2, %1 ]
%5 = phi i8* [ %9, %25 ], [ %0, %1 ]
%6 = icmp eq i8 %4, 0
br i1 %6, label %28, label %7
7: ; preds = %3, %7
%8 = phi i8* [ %9, %7 ], [ %5, %3 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, %4
br i1 %11, label %7, label %12
12: ; preds = %7
%13 = sext i8 %4 to i32
%14 = ptrtoint i8* %9 to i64
%15 = ptrtoint i8* %5 to i64
%16 = sub i64 %14, %15
%17 = icmp eq i64 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @putchar(i32 %13)
br label %25
20: ; preds = %12
%21 = getelementptr inbounds [11 x i8], [11 x i8]* @.str.2, i64 0, i64 %16
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %13)
br label %25
25: ; preds = %20, %18
%26 = load i8, i8* %9
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %3
28: ; preds = %25, %3
%29 = tail call i32 @putchar(i32 10)
ret void
}