#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 */
typedef int /*<<< orphan*/ s;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, char);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ strlen(char *);
int main() {
  FILE *f1, *f2;
  f1 = fopen("input.txt", "r");
  f2 = fopen("output.txt", "w");
  char s[10000];
  fgets(s, sizeof(s), f1);
  fscanf(f1, "%s", s);
  int i, k, l, n, m;
  k = 0;
  i = 0;
  while (strlen(s)) {
    l = 1;
    while (s[i + 1] == s[i]) {
      i++;
      l++;
    }
    if (l > 1)
      fprintf(f2, "%d%c", l, s[i - 1]);
    else {
      fprintf(f2, "%d%c", l, s[i]);
      i++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2750,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe8c(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x2730(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2710,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
lea    -0x2730(%rbp),%rdx
lea    0xe62(%rip),%rsi
call   1040 <fscanf@plt>
movl   $0x0,-0x2738(%rbp)
movl   $0x0,-0x2734(%rbp)
lea    -0x2730(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     12b1 <main+0x161>
movl   $0x1,-0x273c(%rbp)
mov    -0x2734(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x2730(%rbp,%rax,1),%eax
ff
movslq -0x2734(%rbp),%rcx
movsbl -0x2730(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
jne    123d <main+0xed>
mov    -0x2734(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2734(%rbp)
mov    -0x273c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x273c(%rbp)
jmp    11f0 <main+0xa0>
cmpl   $0x1,-0x273c(%rbp)
jle    1278 <main+0x128>
mov    -0x18(%rbp),%rdi
mov    -0x273c(%rbp),%edx
mov    -0x2734(%rbp),%eax
sub    $0x1,%eax
cltq
lea    0xdb6(%rip),%rsi
movsbl -0x2730(%rbp,%rax,1),%ecx
ff
call   1060 <fprintf@plt>
jmp    12ac <main+0x15c>
mov    -0x18(%rbp),%rdi
mov    -0x273c(%rbp),%edx
movslq -0x2734(%rbp),%rax
lea    0xd8c(%rip),%rsi
movsbl -0x2730(%rbp,%rax,1),%ecx
ff
call   1060 <fprintf@plt>
mov    -0x2734(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2734(%rbp)
jmp    11d0 <main+0x80>
xor    %eax,%eax
add    $0x2750,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2710,%rsp
lea    0xea9(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe9f(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x2710,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
lea    0xe83(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   1030 <fscanf@plt>
mov    (%rsp),%al
test   %al,%al
je     121f <main+0xdf>
xor    %ebx,%ebx
movabs $0xfffffffe00000000,%r15
ff ff ff
movabs $0x100000000,%r13
lea    0xe57(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rcx
shl    $0x20,%rcx
add    %r15,%rcx
movslq %ebx,%rbx
xor    %edx,%edx
nop
mov    %rbx,%rsi
add    %r13,%rcx
add    $0x1,%rbx
add    $0x1,%edx
cmp    %al,0x1(%rsp,%rsi,1)
je     11e0 <main+0xa0>
cmp    $0x2,%edx
jb     1203 <main+0xc3>
add    $0xffffffffffffffff,%rbx
sar    $0x20,%rcx
mov    (%rsp,%rcx,1),%al
movsbl %al,%ecx
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <fprintf@plt>
cmpb   $0x0,(%rsp)
je     121f <main+0xdf>
movslq %ebx,%rax
mov    (%rsp,%rax,1),%al
jmp    11d0 <main+0x90>
xor    %eax,%eax
add    $0x2710,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [5 x i8] c"%d%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [10000 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %11, i32** %3
%12 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%13 = load i32*, i32** %2
%14 = call i32 @fgets(i8* %12, i32 10000, i32* %13)
%15 = load i32*, i32** %2
%16 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%17 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %16)
store i32 0, i32* %6
store i32 0, i32* %5
br label %18
18: ; preds = %63, %0
%19 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%20 = call i64 @strlen(i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %64
22: ; preds = %18
store i32 1, i32* %7
br label %23
23: ; preds = %36, %22
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %29, %34
br i1 %35, label %36, label %41
36: ; preds = %23
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %23
41: ; preds = %23
%42 = load i32, i32* %7
%43 = icmp sgt i32 %42, 1
br i1 %43, label %44, label %53
44: ; preds = %41
%45 = load i32*, i32** %3
%46 = load i32, i32* %7
%47 = load i32, i32* %5
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %46, i8 signext %51)
br label %63
53: ; preds = %41
%54 = load i32*, i32** %3
%55 = load i32, i32* %7
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = call i32 @fprintf(i32* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %55, i8 signext %59)
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %63
63: ; preds = %53, %44
br label %18
64: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [5 x i8] c"%d%c\00"
define i32 @main() {
%1 = alloca [10000 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%4 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 0
%5 = call i32 @fgets(i8* %4, i32 10000, i32* %2)
%6 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %41, label %9
9: ; preds = %0, %36
%10 = phi i8 [ %40, %36 ], [ %7, %0 ]
%11 = phi i64 [ %32, %36 ], [ 0, %0 ]
%12 = shl i64 %11, 32
%13 = ashr exact i64 %12, 32
br label %14
14: ; preds = %14, %9
%15 = phi i64 [ %17, %14 ], [ %13, %9 ]
%16 = phi i32 [ %21, %14 ], [ 1, %9 ]
%17 = add nsw i64 %15, 1
%18 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, %10
%21 = add nuw nsw i32 %16, 1
br i1 %20, label %14, label %22
22: ; preds = %14
%23 = icmp ugt i32 %16, 1
br i1 %23, label %24, label %30
24: ; preds = %22
%25 = shl i64 %15, 32
%26 = add i64 %25, -4294967296
%27 = ashr exact i64 %26, 32
%28 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %27
%29 = load i8, i8* %28
br label %30
30: ; preds = %22, %24
%31 = phi i8 [ %29, %24 ], [ %10, %22 ]
%32 = phi i64 [ %15, %24 ], [ %17, %22 ]
%33 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %16, i8 signext %31)
%34 = load i8, i8* %4
%35 = icmp eq i8 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %30
%37 = shl i64 %32, 32
%38 = ashr exact i64 %37, 32
%39 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %38
%40 = load i8, i8* %39
br label %9
41: ; preds = %30, %0
ret i32 0
}