#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ print_bit(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main() {
  char MESSAGE[101];
  fgets(MESSAGE, 101, stdin);
  char *bits = (char *)malloc(9);
  int current_bit = 0;
  int current_count = 0;
  int i = 0;
  while (MESSAGE[i] != '\n') {
    fprintf(stderr, "MESSAGE[%d] = %c\n", i, MESSAGE[i]);
    for (int j = 6; j >= 0; j--) {
      int bit = MESSAGE[i] >> j & 1;
      fprintf(stderr, "%d = %d\n", i, bit);
      if (current_bit == bit) {
        current_count++;
      } else if (current_count != 0) {
        print_bit(current_bit, current_count);
        printf(" ");
        current_bit = bit;
        current_count = 1;
      } else {
        current_bit = bit;
        current_count = 1;
      }
    }
    i++;
  }
  print_bit(current_bit, current_count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
mov    $0x65,%esi
call   1040 <fgets@plt>
mov    $0x9,%edi
call   1060 <malloc@plt>
mov    %rax,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
movl   $0x0,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
movslq -0x84(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     12c5 <main+0x175>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x84(%rbp),%edx
movslq -0x84(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%ecx
lea    0xe2a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x6,-0x88(%rbp)
cmpl   $0x0,-0x88(%rbp)
jl     12b1 <main+0x161>
movslq -0x84(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
mov    -0x88(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %eax,-0x8c(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    -0x84(%rbp),%edx
mov    -0x8c(%rbp),%ecx
lea    0xde7(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x7c(%rbp),%eax
cmp    -0x8c(%rbp),%eax
jne    124d <main+0xfd>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    1298 <main+0x148>
cmpl   $0x0,-0x80(%rbp)
je     1283 <main+0x133>
mov    -0x7c(%rbp),%edi
mov    -0x80(%rbp),%esi
call   1070 <print_bit@plt>
lea    0xdb2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
movl   $0x1,-0x80(%rbp)
jmp    1293 <main+0x143>
mov    -0x8c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
movl   $0x1,-0x80(%rbp)
jmp    1298 <main+0x148>
jmp    129d <main+0x14d>
mov    -0x88(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x88(%rbp)
jmp    11e5 <main+0x95>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    119f <main+0x4f>
mov    -0x7c(%rbp),%edi
mov    -0x80(%rbp),%esi
call   1070 <print_bit@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x65,%esi
call   1040 <fgets@plt>
mov    $0x9,%edi
call   1060 <malloc@plt>
mov    (%rsp),%al
xor    %ebp,%ebp
mov    $0x0,%r12d
cmp    $0xa,%al
jne    11ab <main+0x5b>
mov    %r12d,%edi
mov    %ebp,%esi
call   1070 <print_bit@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r13d,%r13d
xor    %r12d,%r12d
xor    %ebp,%ebp
jmp    11d5 <main+0x85>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rsp,%r13,1),%r14
add    $0x1,%r14
mov    0x1(%rsp,%r13,1),%al
add    $0x1,%r13
cmp    $0xa,%al
je     1190 <main+0x40>
movsbl %al,%ecx
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    %r13d,%edx
call   1050 <fprintf@plt>
mov    $0x6,%r15d
jmp    1209 <main+0xb9>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
add    $0xffffffff,%r15d
jae    11c0 <main+0x70>
movsbl (%r14),%ebx
mov    %r15d,%ecx
shr    %cl,%ebx
and    $0x1,%ebx
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    %r13d,%edx
mov    %ebx,%ecx
call   1050 <fprintf@plt>
cmp    %ebx,%r12d
je     1200 <main+0xb0>
test   %ebp,%ebp
je     124c <main+0xfc>
mov    %r12d,%edi
mov    %ebp,%esi
call   1070 <print_bit@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x1,%ebp
mov    %ebx,%r12d
add    $0xffffffff,%r15d
jb     1209 <main+0xb9>
jmp    11c0 <main+0x70>

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"MESSAGE[%d] = %c\0A\00"
@.str.1 = [9 x i8] c"%d = %d\0A\00"
@.str.2 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [101 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 101, i32 %10)
%12 = call i64 @malloc(i32 9)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %14
14: ; preds = %68, %0
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br i1 %20, label %21, label %71
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i32, i32* %6
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %28)
store i32 6, i32* %7
br label %30
30: ; preds = %65, %21
%31 = load i32, i32* %7
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %68
33: ; preds = %30
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = load i32, i32* %7
%40 = ashr i32 %38, %39
%41 = and i32 %40, 1
store i32 %41, i32* %8
%42 = load i32, i32* @stderr
%43 = load i32, i32* %6
%44 = load i32, i32* %8
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 %44)
%46 = load i32, i32* %4
%47 = load i32, i32* %8
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %52
49: ; preds = %33
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %64
52: ; preds = %33
%53 = load i32, i32* %5
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %52
%56 = load i32, i32* %4
%57 = load i32, i32* %5
%58 = call i32 @print_bit(i32 %56, i32 %57)
%59 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%60 = load i32, i32* %8
store i32 %60, i32* %4
store i32 1, i32* %5
br label %63
61: ; preds = %52
%62 = load i32, i32* %8
store i32 %62, i32* %4
store i32 1, i32* %5
br label %63
63: ; preds = %61, %55
br label %64
64: ; preds = %63, %49
br label %65
65: ; preds = %64
%66 = load i32, i32* %7
%67 = add nsw i32 %66, -1
store i32 %67, i32* %7
br label %30
68: ; preds = %30
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %6
br label %14
71: ; preds = %14
%72 = load i32, i32* %4
%73 = load i32, i32* %5
%74 = call i32 @print_bit(i32 %72, i32 %73)
ret i32 0
}

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