#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 *, char *);
int string_compression(char *input1) {
  char *copy = input1;
  char *copy_temp = input1;
  int count = 0;
  char element;
  while (*copy != '\0') {
    element = *copy;
    while (*copy == element) {
      count++;
      copy++;
    }
    *copy_temp = element;
    copy_temp++;
    *copy_temp = count + 48;
    copy_temp++;
    count = 0;
    if (*copy == '\0') {
      *copy_temp = '\0';
    }
  }
  printf("[%s]\n", input1);
  return 1;
}


x86 assembly (clang, -O0):
<string_compression>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cb <string_compression+0xbb>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x1d(%rbp),%ecx
cmp    %ecx,%eax
jne    1179 <string_compression+0x69>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    114c <string_compression+0x3c>
mov    -0x1d(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c6 <string_compression+0xb6>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1133 <string_compression+0x23>
mov    -0x8(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_compression>:
push   %rax
mov    %rdi,%r8
mov    (%rdi),%al
test   %al,%al
je     1165 <string_compression+0x55>
mov    %r8,%rsi
mov    %r8,%rdi
jmp    1134 <string_compression+0x24>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %al,%al
je     1165 <string_compression+0x55>
mov    $0x30,%cl
cs nopw 0x0(%rax,%rax,1)
mov    %rsi,%rdx
add    $0x1,%rsi
add    $0x1,%cl
cmp    %al,0x1(%rdx)
je     1140 <string_compression+0x30>
mov    %al,(%rdi)
mov    %cl,0x1(%rdi)
add    $0x2,%rdi
mov    (%rsi),%al
test   %al,%al
jne    1130 <string_compression+0x20>
movb   $0x0,(%rdi)
mov    (%rsi),%al
jmp    1130 <string_compression+0x20>
lea    0xe94(%rip),%rdi
mov    %r8,%rsi
call   1030 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret

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

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