#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
scalar_t__ est_triple(int, char *, char);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, char);
void RLEcompress(int in, int out) {
  ssize_t lu;
  signed char bufRead[1024];
  signed char bufWrite[128];
  int poswrite = 0;
  signed char occurence = 0;
  int mode = 1;
  while ((lu = read(in, bufRead, 1024)) != 0) {
    if (poswrite == 0)
      mode = -1;
    int i;
    for (i = 0; i < lu; i++) {
      if (occurence == 128 || occurence == -128) {
        if (mode == 1) {
          signed char c[1];
          c[0] = occurence - 1;
          write(out, c, 1);
          write(out, bufWrite, 1);
        } else {
          if (0) {
          } else {
            signed char c[1];
            c[0] = -(occurence);
            write(out, c, 1);
            write(out, bufWrite, (occurence));
          }
        }
      }
      if (mode == 1) {
        if (est_triple(poswrite, bufWrite, bufRead[i])) {
          occurence++;
        } else {
          mode = -1;
          if (occurence > 2) {
            signed char c[1];
            c[0] = occurence - 1;
            write(out, c, 1);
            write(out, bufWrite, 1);
            bufWrite[0] = bufRead[i];
          } else {
            bufWrite[poswrite] = bufRead[i];
            poswrite++;
            occurence++;
            continue;
          }
          occurence = 1;
          poswrite = 1;
        }
      } else {
        if (est_triple(poswrite, bufWrite, bufRead[i])) {
          mode = 1;
          signed char c[1];
          c[0] = -(occurence - 2);
          write(out, c, 1);
          write(out, bufWrite, (occurence - 2));
          bufWrite[0] = bufRead[i];
          bufWrite[1] = bufRead[i];
          poswrite = 2;
          occurence = 3;
        } else {
          bufWrite[poswrite] = bufRead[i];
          poswrite++;
          occurence++;
        }
      }
    }
  }
  if (mode == 1) {
    signed char c[1];
    c[0] = occurence - 1;
    write(out, c, 1);
    write(out, bufWrite, 1);
  } else {
    signed char c[1];
    c[0] = -(occurence);
    write(out, c, 1);
    write(out, bufWrite, (occurence));
  }
  close(out);
  close(in);
}


x86 assembly (clang, -O0):
<RLEcompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0x494(%rbp)
movb   $0x0,-0x495(%rbp)
movl   $0x1,-0x49c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1485 <RLEcompress+0x345>
cmpl   $0x0,-0x494(%rbp)
jne    11a3 <RLEcompress+0x63>
movl   $0xffffffff,-0x49c(%rbp)
ff ff ff
movl   $0x0,-0x4a0(%rbp)
mov    -0x4a0(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1480 <RLEcompress+0x340>
movsbl -0x495(%rbp),%eax
cmp    $0x80,%eax
je     11de <RLEcompress+0x9e>
movsbl -0x495(%rbp),%eax
cmp    $0xffffff80,%eax
jne    1268 <RLEcompress+0x128>
cmpl   $0x1,-0x49c(%rbp)
jne    1228 <RLEcompress+0xe8>
movsbl -0x495(%rbp),%eax
sub    $0x1,%eax
mov    %al,-0x4a1(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x4a1(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x490(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1263 <RLEcompress+0x123>
movsbl -0x495(%rbp),%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %al,-0x4a2(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x4a2(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x490(%rbp),%rsi
movsbl -0x495(%rbp),%edx
call   1030 <write@plt>
jmp    1268 <RLEcompress+0x128>
cmpl   $0x1,-0x49c(%rbp)
jne    1372 <RLEcompress+0x232>
mov    -0x494(%rbp),%edi
lea    -0x490(%rbp),%rsi
movslq -0x4a0(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%edx
ff
call   1060 <est_triple@plt>
cmp    $0x0,%rax
je     12b3 <RLEcompress+0x173>
mov    -0x495(%rbp),%al
add    $0x1,%al
mov    %al,-0x495(%rbp)
jmp    136d <RLEcompress+0x22d>
movl   $0xffffffff,-0x49c(%rbp)
ff ff ff
movsbl -0x495(%rbp),%eax
cmp    $0x2,%eax
jle    131e <RLEcompress+0x1de>
movsbl -0x495(%rbp),%eax
sub    $0x1,%eax
mov    %al,-0x4a3(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x4a3(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x490(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
movslq -0x4a0(%rbp),%rax
mov    -0x410(%rbp,%rax,1),%al
mov    %al,-0x490(%rbp)
jmp    135c <RLEcompress+0x21c>
movslq -0x4a0(%rbp),%rax
mov    -0x410(%rbp,%rax,1),%cl
movslq -0x494(%rbp),%rax
mov    %cl,-0x490(%rbp,%rax,1)
mov    -0x494(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x494(%rbp)
mov    -0x495(%rbp),%al
add    $0x1,%al
mov    %al,-0x495(%rbp)
jmp    146c <RLEcompress+0x32c>
movb   $0x1,-0x495(%rbp)
movl   $0x1,-0x494(%rbp)
jmp    1467 <RLEcompress+0x327>
mov    -0x494(%rbp),%edi
lea    -0x490(%rbp),%rsi
movslq -0x4a0(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%edx
ff
call   1060 <est_triple@plt>
cmp    $0x0,%rax
je     1429 <RLEcompress+0x2e9>
movl   $0x1,-0x49c(%rbp)
movsbl -0x495(%rbp),%ecx
sub    $0x2,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %al,-0x4a4(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x4a4(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x490(%rbp),%rsi
movsbl -0x495(%rbp),%eax
sub    $0x2,%eax
movsbl %al,%edx
call   1030 <write@plt>
movslq -0x4a0(%rbp),%rax
mov    -0x410(%rbp,%rax,1),%al
mov    %al,-0x490(%rbp)
movslq -0x4a0(%rbp),%rax
mov    -0x410(%rbp,%rax,1),%al
mov    %al,-0x48f(%rbp)
movl   $0x2,-0x494(%rbp)
movb   $0x3,-0x495(%rbp)
jmp    1462 <RLEcompress+0x322>
movslq -0x4a0(%rbp),%rax
mov    -0x410(%rbp,%rax,1),%cl
movslq -0x494(%rbp),%rax
mov    %cl,-0x490(%rbp,%rax,1)
mov    -0x494(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x494(%rbp)
mov    -0x495(%rbp),%al
add    $0x1,%al
mov    %al,-0x495(%rbp)
jmp    1467 <RLEcompress+0x327>
jmp    146c <RLEcompress+0x32c>
mov    -0x4a0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4a0(%rbp)
jmp    11ad <RLEcompress+0x6d>
jmp    116c <RLEcompress+0x2c>
cmpl   $0x1,-0x49c(%rbp)
jne    14cf <RLEcompress+0x38f>
movsbl -0x495(%rbp),%eax
sub    $0x1,%eax
mov    %al,-0x4a5(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x4a5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x490(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    150a <RLEcompress+0x3ca>
movsbl -0x495(%rbp),%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %al,-0x4a6(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x4a6(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x490(%rbp),%rsi
movsbl -0x495(%rbp),%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RLEcompress>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4a8,%rsp
mov    %esi,%ebx
lea    0xa0(%rsp),%rsi
mov    %edi,0x14(%rsp)
mov    $0x400,%edx
call   1050 <read@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     1381 <RLEcompress+0x241>
mov    %ebx,0x10(%rsp)
mov    $0x1,%r13d
xor    %r12d,%r12d
jmp    11ae <RLEcompress+0x6e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x14(%rsp),%edi
lea    0xa0(%rsp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
je     1375 <RLEcompress+0x235>
mov    %r13d,%ecx
cmp    $0x1,%r14d
sbb    %r13d,%r13d
or     %ecx,%r13d
test   %eax,%eax
jle    1190 <RLEcompress+0x50>
mov    %eax,%eax
mov    %rax,0x18(%rsp)
xor    %r15d,%r15d
jmp    11eb <RLEcompress+0xab>
movslq %r14d,%rax
mov    %bl,0x20(%rsp,%rax,1)
add    $0x1,%r14d
add    $0x1,%r12b
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r15,0x18(%rsp)
je     1190 <RLEcompress+0x50>
cmp    $0x80,%r12b
jne    1230 <RLEcompress+0xf0>
cmp    $0x1,%r13d
jne    1270 <RLEcompress+0x130>
movb   $0x7f,0xf(%rsp)
mov    0x10(%rsp),%ebx
mov    %ebx,%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    123b <RLEcompress+0xfb>
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%r13d
lea    0x20(%rsp),%rbp
jne    129e <RLEcompress+0x15e>
movzbl 0xa0(%rsp,%r15,1),%ebx
movsbl %bl,%edx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1060 <est_triple@plt>
test   %rax,%rax
je     130d <RLEcompress+0x1cd>
add    $0x1,%r12b
mov    $0x1,%r13d
jmp    11e0 <RLEcompress+0xa0>
nopw   0x0(%rax,%rax,1)
movb   $0x80,0xf(%rsp)
mov    0x10(%rsp),%ebx
mov    %ebx,%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
mov    $0xffffff80,%edx
call   1030 <write@plt>
movzbl 0xa0(%rsp,%r15,1),%ebx
movsbl %bl,%edx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1060 <est_triple@plt>
test   %rax,%rax
je     11cb <RLEcompress+0x8b>
mov    $0x2,%al
sub    %r12b,%al
add    $0xfe,%r12b
mov    %al,0xf(%rsp)
mov    $0x1,%r13d
mov    0x10(%rsp),%r14d
mov    %r14d,%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
movsbl %r12b,%edx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1030 <write@plt>
mov    %bl,0x20(%rsp)
mov    %bl,0x21(%rsp)
mov    $0x3,%r12b
mov    $0x2,%r14d
jmp    11e0 <RLEcompress+0xa0>
cmp    $0x3,%r12b
jge    132d <RLEcompress+0x1ed>
movslq %r14d,%rax
mov    %bl,0x20(%rsp,%rax,1)
add    $0x1,%r14d
add    $0x1,%r12b
mov    $0xffffffff,%r13d
jmp    11e0 <RLEcompress+0xa0>
add    $0xff,%r12b
mov    %r12b,0xf(%rsp)
mov    $0x1,%r14d
mov    0x10(%rsp),%r12d
mov    %r12d,%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %bl,0x20(%rsp)
mov    $0xffffffff,%r13d
mov    $0x1,%r12b
jmp    11e0 <RLEcompress+0xa0>
cmp    $0x1,%r13d
jne    13ac <RLEcompress+0x26c>
mov    0x10(%rsp),%ebx
jmp    1384 <RLEcompress+0x244>
xor    %r12d,%r12d
add    $0xff,%r12b
mov    %r12b,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
jmp    13d5 <RLEcompress+0x295>
mov    %r12d,%eax
neg    %al
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    0x10(%rsp),%ebx
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
movsbl %r12b,%edx
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x14(%rsp),%edi
call   1040 <close@plt>
add    $0x4a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @RLEcompress(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [128 x i8]
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca [1 x i8]
%13 = alloca [1 x i8]
%14 = alloca [1 x i8]
%15 = alloca [1 x i8]
%16 = alloca [1 x i8]
%17 = alloca [1 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %8
store i8 0, i8* %9
store i32 1, i32* %10
br label %18
18: ; preds = %172, %2
%19 = load i32, i32* %3
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 1024)
store i32 %21, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %173
23: ; preds = %18
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 -1, i32* %10
br label %27
27: ; preds = %26, %23
store i32 0, i32* %11
br label %28
28: ; preds = %169, %27
%29 = load i32, i32* %11
%30 = load i32, i32* %5
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %172
32: ; preds = %28
%33 = load i8, i8* %9
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 128
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = load i8, i8* %9
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, -128
br i1 %39, label %40, label %69
40: ; preds = %36, %32
%41 = load i32, i32* %10
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %55
43: ; preds = %40
%44 = load i8, i8* %9
%45 = sext i8 %44 to i32
%46 = sub nsw i32 %45, 1
%47 = trunc i32 %46 to i8
%48 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
store i8 %47, i8* %48
%49 = load i32, i32* %4
%50 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%51 = call i32 @write(i32 %49, i8* %50, i8 signext 1)
%52 = load i32, i32* %4
%53 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%54 = call i32 @write(i32 %52, i8* %53, i8 signext 1)
br label %68
55: ; preds = %40
%56 = load i8, i8* %9
%57 = sext i8 %56 to i32
%58 = sub nsw i32 0, %57
%59 = trunc i32 %58 to i8
%60 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
store i8 %59, i8* %60
%61 = load i32, i32* %4
%62 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%63 = call i32 @write(i32 %61, i8* %62, i8 signext 1)
%64 = load i32, i32* %4
%65 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%66 = load i8, i8* %9
%67 = call i32 @write(i32 %64, i8* %65, i8 signext %66)
br label %68
68: ; preds = %55, %43
br label %69
69: ; preds = %68, %36
%70 = load i32, i32* %10
%71 = icmp eq i32 %70, 1
br i1 %71, label %72, label %119
72: ; preds = %69
%73 = load i32, i32* %8
%74 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%75 = load i32, i32* %11
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = call i64 @est_triple(i32 %73, i8* %74, i8 signext %78)
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %72
%82 = load i8, i8* %9
%83 = add i8 %82, 1
store i8 %83, i8* %9
br label %118
84: ; preds = %72
store i32 -1, i32* %10
%85 = load i8, i8* %9
%86 = sext i8 %85 to i32
%87 = icmp sgt i32 %86, 2
br i1 %87, label %88, label %105
88: ; preds = %84
%89 = load i8, i8* %9
%90 = sext i8 %89 to i32
%91 = sub nsw i32 %90, 1
%92 = trunc i32 %91 to i8
%93 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
store i8 %92, i8* %93
%94 = load i32, i32* %4
%95 = getelementptr inbounds [1 x i8], [1 x i8]* %14, i64 0, i64 0
%96 = call i32 @write(i32 %94, i8* %95, i8 signext 1)
%97 = load i32, i32* %4
%98 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%99 = call i32 @write(i32 %97, i8* %98, i8 signext 1)
%100 = load i32, i32* %11
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %101
%103 = load i8, i8* %102
%104 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
store i8 %103, i8* %104
br label %117
105: ; preds = %84
%106 = load i32, i32* %11
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %107
%109 = load i8, i8* %108
%110 = load i32, i32* %8
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %111
store i8 %109, i8* %112
%113 = load i32, i32* %8
%114 = add nsw i32 %113, 1
store i32 %114, i32* %8
%115 = load i8, i8* %9
%116 = add i8 %115, 1
store i8 %116, i8* %9
br label %169
117: ; preds = %88
store i8 1, i8* %9
store i32 1, i32* %8
br label %118
118: ; preds = %117, %81
br label %168
119: ; preds = %69
%120 = load i32, i32* %8
%121 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%122 = load i32, i32* %11
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %123
%125 = load i8, i8* %124
%126 = call i64 @est_triple(i32 %120, i8* %121, i8 signext %125)
%127 = icmp ne i64 %126, 0
br i1 %127, label %128, label %155
128: ; preds = %119
store i32 1, i32* %10
%129 = load i8, i8* %9
%130 = sext i8 %129 to i32
%131 = sub nsw i32 %130, 2
%132 = sub nsw i32 0, %131
%133 = trunc i32 %132 to i8
%134 = getelementptr inbounds [1 x i8], [1 x i8]* %15, i64 0, i64 0
store i8 %133, i8* %134
%135 = load i32, i32* %4
%136 = getelementptr inbounds [1 x i8], [1 x i8]* %15, i64 0, i64 0
%137 = call i32 @write(i32 %135, i8* %136, i8 signext 1)
%138 = load i32, i32* %4
%139 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%140 = load i8, i8* %9
%141 = sext i8 %140 to i32
%142 = sub nsw i32 %141, 2
%143 = trunc i32 %142 to i8
%144 = call i32 @write(i32 %138, i8* %139, i8 signext %143)
%145 = load i32, i32* %11
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %146
%148 = load i8, i8* %147
%149 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
store i8 %148, i8* %149
%150 = load i32, i32* %11
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %151
%153 = load i8, i8* %152
%154 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 1
store i8 %153, i8* %154
store i32 2, i32* %8
store i8 3, i8* %9
br label %167
155: ; preds = %119
%156 = load i32, i32* %11
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %157
%159 = load i8, i8* %158
%160 = load i32, i32* %8
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %161
store i8 %159, i8* %162
%163 = load i32, i32* %8
%164 = add nsw i32 %163, 1
store i32 %164, i32* %8
%165 = load i8, i8* %9
%166 = add i8 %165, 1
store i8 %166, i8* %9
br label %167
167: ; preds = %155, %128
br label %168
168: ; preds = %167, %118
br label %169
169: ; preds = %168, %105
%170 = load i32, i32* %11
%171 = add nsw i32 %170, 1
store i32 %171, i32* %11
br label %28
172: ; preds = %28
br label %18
173: ; preds = %18
%174 = load i32, i32* %10
%175 = icmp eq i32 %174, 1
br i1 %175, label %176, label %188
176: ; preds = %173
%177 = load i8, i8* %9
%178 = sext i8 %177 to i32
%179 = sub nsw i32 %178, 1
%180 = trunc i32 %179 to i8
%181 = getelementptr inbounds [1 x i8], [1 x i8]* %16, i64 0, i64 0
store i8 %180, i8* %181
%182 = load i32, i32* %4
%183 = getelementptr inbounds [1 x i8], [1 x i8]* %16, i64 0, i64 0
%184 = call i32 @write(i32 %182, i8* %183, i8 signext 1)
%185 = load i32, i32* %4
%186 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%187 = call i32 @write(i32 %185, i8* %186, i8 signext 1)
br label %201
188: ; preds = %173
%189 = load i8, i8* %9
%190 = sext i8 %189 to i32
%191 = sub nsw i32 0, %190
%192 = trunc i32 %191 to i8
%193 = getelementptr inbounds [1 x i8], [1 x i8]* %17, i64 0, i64 0
store i8 %192, i8* %193
%194 = load i32, i32* %4
%195 = getelementptr inbounds [1 x i8], [1 x i8]* %17, i64 0, i64 0
%196 = call i32 @write(i32 %194, i8* %195, i8 signext 1)
%197 = load i32, i32* %4
%198 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%199 = load i8, i8* %9
%200 = call i32 @write(i32 %197, i8* %198, i8 signext %199)
br label %201
201: ; preds = %188, %176
%202 = load i32, i32* %4
%203 = call i32 @close(i32 %202)
%204 = load i32, i32* %3
%205 = call i32 @close(i32 %204)
ret void
}

LLVM IR (-O2):
define void @RLEcompress(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [128 x i8]
%5 = alloca [1 x i8]
%6 = alloca [1 x i8]
%7 = alloca [1 x i8]
%8 = alloca [1 x i8]
%9 = alloca [1 x i8]
%10 = alloca [1 x i8]
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%13 = call i32 @read(i32 %0, i8* %11, i32 1024)
%14 = icmp eq i32 %13, 0
br i1 %14, label %93, label %15
15: ; preds = %2
%16 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 1
%19 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
br label %27
21: ; preds = %85, %27
%22 = phi i32 [ %31, %27 ], [ %86, %85 ]
%23 = phi i8 [ %30, %27 ], [ %87, %85 ]
%24 = phi i32 [ %33, %27 ], [ %88, %85 ]
%25 = call i32 @read(i32 %0, i8* %11, i32 1024)
%26 = icmp eq i32 %25, 0
br i1 %26, label %91, label %27
27: ; preds = %15, %21
%28 = phi i32 [ %13, %15 ], [ %25, %21 ]
%29 = phi i32 [ 1, %15 ], [ %24, %21 ]
%30 = phi i8 [ 0, %15 ], [ %23, %21 ]
%31 = phi i32 [ 0, %15 ], [ %22, %21 ]
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i32 -1, i32 %29
%34 = icmp sgt i32 %28, 0
br i1 %34, label %35, label %21
35: ; preds = %27
%36 = zext i32 %28 to i64
br label %37
37: ; preds = %35, %85
%38 = phi i64 [ 0, %35 ], [ %89, %85 ]
%39 = phi i32 [ %33, %35 ], [ %88, %85 ]
%40 = phi i8 [ %30, %35 ], [ %87, %85 ]
%41 = phi i32 [ %31, %35 ], [ %86, %85 ]
%42 = icmp eq i8 %40, -128
%43 = icmp eq i32 %39, 1
br i1 %42, label %44, label %51
44: ; preds = %37
br i1 %43, label %45, label %48
45: ; preds = %44
store i8 127, i8* %19
%46 = call i32 @write(i32 %1, i8* %19, i8 signext 1)
%47 = call i32 @write(i32 %1, i8* %12, i8 signext 1)
br label %52
48: ; preds = %44
store i8 -128, i8* %16
%49 = call i32 @write(i32 %1, i8* %16, i8 signext 1)
%50 = call i32 @write(i32 %1, i8* %12, i8 signext -128)
br label %70
51: ; preds = %37
br i1 %43, label %52, label %70
52: ; preds = %45, %51
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %38
%54 = load i8, i8* %53
%55 = call i64 @est_triple(i32 %41, i8* %12, i8 signext %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %52
%58 = add i8 %40, 1
br label %85
59: ; preds = %52
%60 = icmp sgt i8 %40, 2
br i1 %60, label %61, label %65
61: ; preds = %59
%62 = add nsw i8 %40, -1
store i8 %62, i8* %20
%63 = call i32 @write(i32 %1, i8* %20, i8 signext 1)
%64 = call i32 @write(i32 %1, i8* %12, i8 signext 1)
store i8 %54, i8* %12
br label %85
65: ; preds = %59
%66 = sext i32 %41 to i64
%67 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %66
store i8 %54, i8* %67
%68 = add nsw i32 %41, 1
%69 = add nsw i8 %40, 1
br label %85
70: ; preds = %48, %51
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %38
%72 = load i8, i8* %71
%73 = call i64 @est_triple(i32 %41, i8* %12, i8 signext %72)
%74 = icmp eq i64 %73, 0
br i1 %74, label %80, label %75
75: ; preds = %70
%76 = add i8 %40, -2
%77 = sub i8 2, %40
store i8 %77, i8* %17
%78 = call i32 @write(i32 %1, i8* %17, i8 signext 1)
%79 = call i32 @write(i32 %1, i8* %12, i8 signext %76)
store i8 %72, i8* %12
store i8 %72, i8* %18
br label %85
80: ; preds = %70
%81 = sext i32 %41 to i64
%82 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %81
store i8 %72, i8* %82
%83 = add nsw i32 %41, 1
%84 = add i8 %40, 1
br label %85
85: ; preds = %61, %57, %80, %75, %65
%86 = phi i32 [ %41, %57 ], [ 1, %61 ], [ %68, %65 ], [ 2, %75 ], [ %83, %80 ]
%87 = phi i8 [ %58, %57 ], [ 1, %61 ], [ %69, %65 ], [ 3, %75 ], [ %84, %80 ]
%88 = phi i32 [ 1, %57 ], [ -1, %61 ], [ -1, %65 ], [ 1, %75 ], [ %39, %80 ]
%89 = add nuw nsw i64 %38, 1
%90 = icmp eq i64 %89, %36
br i1 %90, label %21, label %37
91: ; preds = %21
%92 = icmp eq i32 %24, 1
br i1 %92, label %93, label %99
93: ; preds = %2, %91
%94 = phi i8 [ %23, %91 ], [ 0, %2 ]
%95 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%96 = add i8 %94, -1
store i8 %96, i8* %95
%97 = call i32 @write(i32 %1, i8* %95, i8 signext 1)
%98 = call i32 @write(i32 %1, i8* %12, i8 signext 1)
br label %104
99: ; preds = %91
%100 = getelementptr inbounds [1 x i8], [1 x i8]* %10, i64 0, i64 0
%101 = sub i8 0, %23
store i8 %101, i8* %100
%102 = call i32 @write(i32 %1, i8* %100, i8 signext 1)
%103 = call i32 @write(i32 %1, i8* %12, i8 signext %23)
br label %104
104: ; preds = %99, %93
%105 = call i32 @close(i32 %1)
%106 = call i32 @close(i32 %0)
ret void
}