#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *, unsigned long, int);
int main(int argc, char *argv[]) {
  int ch, prev = getchar();
  unsigned long count = 1;
  while ((ch = getchar()) != EOF) {
    if (ch != prev) {
      printf("%lu %c\n", count, prev);
      count = 0;
      prev = ch;
    }
    count++;
  }
  printf("%lu %c\n", count, prev);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%eax
je     119f <main+0x7f>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     118e <main+0x6e>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1148 <main+0x28>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2ea9(%rip),%r12
mov    $0x1,%ebx
cmp    (%r12),%eax
jne    116a <main+0x4a>
mov    %ebp,%r15d
lea    0xeac(%rip),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebx
lea    0xe8a(%rip),%r14
jmp    1194 <main+0x74>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %r15d,%ebp
cmp    (%r12),%eax
je     114d <main+0x2d>
mov    %eax,%r15d
cmp    %ebp,%eax
je     1180 <main+0x60>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <printf@plt>
xor    %ebx,%ebx
jmp    1180 <main+0x60>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [8 x i8] c"%lu %c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @getchar()
store i32 %9, i32* %7
store i64 1, i64* %8
br label %10
10: ; preds = %23, %2
%11 = call i32 (...) @getchar()
store i32 %11, i32* %6
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i64, i64* %8
%20 = load i32, i32* %7
%21 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %19, i32 %20)
store i64 0, i64* %8
%22 = load i32, i32* %6
store i32 %22, i32* %7
br label %23
23: ; preds = %18, %14
%24 = load i64, i64* %8
%25 = add i64 %24, 1
store i64 %25, i64* %8
br label %10
26: ; preds = %10
%27 = load i64, i64* %8
%28 = load i32, i32* %7
%29 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %27, i32 %28)
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [8 x i8] c"%lu %c\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getchar()
%4 = tail call i32 (...) @getchar()
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %20, label %7
7: ; preds = %2, %14
%8 = phi i32 [ %17, %14 ], [ %4, %2 ]
%9 = phi i64 [ %16, %14 ], [ 1, %2 ]
%10 = phi i32 [ %8, %14 ], [ %3, %2 ]
%11 = icmp eq i32 %8, %10
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %9, i32 %10)
br label %14
14: ; preds = %12, %7
%15 = phi i64 [ 0, %12 ], [ %9, %7 ]
%16 = add i64 %15, 1
%17 = tail call i32 (...) @getchar()
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %7
20: ; preds = %14, %2
%21 = phi i32 [ %3, %2 ], [ %8, %14 ]
%22 = phi i64 [ 1, %2 ], [ %16, %14 ]
%23 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %22, i32 %21)
ret i32 0
}