#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*/ compr_put_byte(int);
int compr_read_byte();
void compr(void) {
  int j, c, lc, lled, rep, num;
  rep = 0;
  c = compr_read_byte();
  lc = 0;
  num = 0;
  while (c >= 0) {
    if (lc == 0xED)
      lled = 1;
    else
      lled = 0;
    lc = c;
    c = compr_read_byte();
    if (c == lc && num != 255 && (!lled || rep)) {
      if (!rep) {
        num = 1;
        rep = 1;
      }
      num++;
    } else {
      if (rep) {
        if (num < 5 && lc != 0xED)
          for (j = 0; j < num; j++)
            compr_put_byte(lc);
        else {
          compr_put_byte(0xED);
          compr_put_byte(0xED);
          compr_put_byte(num);
          compr_put_byte(lc);
          num = 0;
        }
        rep = 0;
      } else
        compr_put_byte(lc);
    }
  }
  compr_put_byte(0x00);
  compr_put_byte(0xED);
  compr_put_byte(0xED);
  compr_put_byte(0x00);
}


x86 assembly (clang, -O0):
<compr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <compr_read_byte@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     126c <compr+0x14c>
cmpl   $0xed,-0xc(%rbp)
jne    116a <compr+0x4a>
movl   $0x1,-0x10(%rbp)
jmp    1171 <compr+0x51>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <compr_read_byte@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11d4 <compr+0xb4>
cmpl   $0xff,-0x18(%rbp)
je     11d4 <compr+0xb4>
cmpl   $0x0,-0x10(%rbp)
je     11ae <compr+0x8e>
cmpl   $0x0,-0x14(%rbp)
je     11d4 <compr+0xb4>
cmpl   $0x0,-0x14(%rbp)
jne    11c6 <compr+0xa6>
movl   $0x1,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1267 <compr+0x147>
cmpl   $0x0,-0x14(%rbp)
je     125a <compr+0x13a>
cmpl   $0x5,-0x18(%rbp)
jge    1223 <compr+0x103>
cmpl   $0xed,-0xc(%rbp)
je     1223 <compr+0x103>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    121e <compr+0xfe>
mov    -0xc(%rbp),%edi
call   1040 <compr_put_byte@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11fc <compr+0xdc>
jmp    124e <compr+0x12e>
mov    $0xed,%edi
call   1040 <compr_put_byte@plt>
mov    $0xed,%edi
call   1040 <compr_put_byte@plt>
mov    -0x18(%rbp),%edi
call   1040 <compr_put_byte@plt>
mov    -0xc(%rbp),%edi
call   1040 <compr_put_byte@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    1262 <compr+0x142>
mov    -0xc(%rbp),%edi
call   1040 <compr_put_byte@plt>
jmp    1267 <compr+0x147>
jmp    1147 <compr+0x27>
xor    %edi,%edi
call   1040 <compr_put_byte@plt>
mov    $0xed,%edi
call   1040 <compr_put_byte@plt>
mov    $0xed,%edi
call   1040 <compr_put_byte@plt>
xor    %edi,%edi
call   1040 <compr_put_byte@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <compr_read_byte@plt>
test   %eax,%eax
js     11fc <compr+0xdc>
mov    %eax,%ebp
mov    $0x2,%r15d
xor    %r14d,%r14d
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    1168 <compr+0x48>
nopl   0x0(%rax)
mov    %ebp,%edi
call   1040 <compr_put_byte@plt>
xor    %r12d,%r12d
mov    %ebp,%ebx
mov    %r13d,%ebp
test   %r13d,%r13d
js     11fc <compr+0xdc>
xor    %eax,%eax
call   1030 <compr_read_byte@plt>
mov    %eax,%r13d
cmp    %ebp,%eax
jne    11a0 <compr+0x80>
cmp    $0xff,%r14d
je     11a0 <compr+0x80>
cmp    $0xed,%ebx
jne    118c <compr+0x6c>
test   %r12d,%r12d
je     1150 <compr+0x30>
add    $0x1,%r14d
test   %r12d,%r12d
cmove  %r15d,%r14d
mov    $0x1,%r12d
jmp    115a <compr+0x3a>
nop
test   %r12d,%r12d
je     1150 <compr+0x30>
cmp    $0x4,%r14d
jg     11ce <compr+0xae>
cmp    $0xed,%ebp
je     11ce <compr+0xae>
xor    %r12d,%r12d
test   %r14d,%r14d
jle    115a <compr+0x3a>
mov    %r14d,%ebx
xchg   %ax,%ax
mov    %ebp,%edi
call   1040 <compr_put_byte@plt>
add    $0xffffffff,%ebx
jne    11c0 <compr+0xa0>
jmp    115a <compr+0x3a>
mov    $0xed,%edi
call   1040 <compr_put_byte@plt>
mov    $0xed,%edi
call   1040 <compr_put_byte@plt>
mov    %r14d,%edi
call   1040 <compr_put_byte@plt>
mov    %ebp,%edi
call   1040 <compr_put_byte@plt>
xor    %r12d,%r12d
xor    %r14d,%r14d
jmp    115a <compr+0x3a>
xor    %edi,%edi
call   1040 <compr_put_byte@plt>
mov    $0xed,%edi
call   1040 <compr_put_byte@plt>
mov    $0xed,%edi
call   1040 <compr_put_byte@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <compr_put_byte@plt>

LLVM IR (-O0):
define void @compr() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %5
%7 = call i32 (...) @compr_read_byte()
store i32 %7, i32* %2
store i32 0, i32* %3
store i32 0, i32* %6
br label %8
8: ; preds = %71, %0
%9 = load i32, i32* %2
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %72
11: ; preds = %8
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 237
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 1, i32* %4
br label %16
15: ; preds = %11
store i32 0, i32* %4
br label %16
16: ; preds = %15, %14
%17 = load i32, i32* %2
store i32 %17, i32* %3
%18 = call i32 (...) @compr_read_byte()
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %38
22: ; preds = %16
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 255
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %28, %25
%32 = load i32, i32* %5
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %31
store i32 1, i32* %6
store i32 1, i32* %5
br label %35
35: ; preds = %34, %31
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %71
38: ; preds = %28, %22, %16
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %67
41: ; preds = %38
%42 = load i32, i32* %6
%43 = icmp slt i32 %42, 5
br i1 %43, label %44, label %59
44: ; preds = %41
%45 = load i32, i32* %3
%46 = icmp ne i32 %45, 237
br i1 %46, label %47, label %59
47: ; preds = %44
store i32 0, i32* %1
br label %48
48: ; preds = %55, %47
%49 = load i32, i32* %1
%50 = load i32, i32* %6
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = load i32, i32* %3
%54 = call i32 @compr_put_byte(i32 %53)
br label %55
55: ; preds = %52
%56 = load i32, i32* %1
%57 = add nsw i32 %56, 1
store i32 %57, i32* %1
br label %48
58: ; preds = %48
br label %66
59: ; preds = %44, %41
%60 = call i32 @compr_put_byte(i32 237)
%61 = call i32 @compr_put_byte(i32 237)
%62 = load i32, i32* %6
%63 = call i32 @compr_put_byte(i32 %62)
%64 = load i32, i32* %3
%65 = call i32 @compr_put_byte(i32 %64)
store i32 0, i32* %6
br label %66
66: ; preds = %59, %58
store i32 0, i32* %5
br label %70
67: ; preds = %38
%68 = load i32, i32* %3
%69 = call i32 @compr_put_byte(i32 %68)
br label %70
70: ; preds = %67, %66
br label %71
71: ; preds = %70, %35
br label %8
72: ; preds = %8
%73 = call i32 @compr_put_byte(i32 0)
%74 = call i32 @compr_put_byte(i32 237)
%75 = call i32 @compr_put_byte(i32 237)
%76 = call i32 @compr_put_byte(i32 0)
ret void
}

LLVM IR (-O2):
define void @compr() {
%1 = tail call i32 (...) @compr_read_byte()
%2 = icmp sgt i32 %1, -1
br i1 %2, label %3, label %43
3: ; preds = %0, %39
%4 = phi i32 [ %41, %39 ], [ 0, %0 ]
%5 = phi i32 [ %40, %39 ], [ 0, %0 ]
%6 = phi i32 [ %7, %39 ], [ 0, %0 ]
%7 = phi i32 [ %8, %39 ], [ %1, %0 ]
%8 = tail call i32 (...) @compr_read_byte()
%9 = icmp eq i32 %8, %7
%10 = icmp ne i32 %4, 255
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %19
12: ; preds = %3
%13 = icmp ne i32 %6, 237
%14 = icmp ne i32 %5, 0
%15 = or i1 %13, %14
br i1 %15, label %16, label %37
16: ; preds = %12
%17 = add nsw i32 %4, 1
%18 = select i1 %14, i32 %17, i32 2
br label %39
19: ; preds = %3
%20 = icmp eq i32 %5, 0
br i1 %20, label %37, label %21
21: ; preds = %19
%22 = icmp slt i32 %4, 5
%23 = icmp ne i32 %7, 237
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = icmp sgt i32 %4, 0
br i1 %26, label %27, label %39
27: ; preds = %25, %27
%28 = phi i32 [ %30, %27 ], [ 0, %25 ]
%29 = tail call i32 @compr_put_byte(i32 %7)
%30 = add nuw nsw i32 %28, 1
%31 = icmp eq i32 %30, %4
br i1 %31, label %39, label %27
32: ; preds = %21
%33 = tail call i32 @compr_put_byte(i32 237)
%34 = tail call i32 @compr_put_byte(i32 237)
%35 = tail call i32 @compr_put_byte(i32 %4)
%36 = tail call i32 @compr_put_byte(i32 %7)
br label %39
37: ; preds = %12, %19
%38 = tail call i32 @compr_put_byte(i32 %7)
br label %39
39: ; preds = %27, %25, %32, %37, %16
%40 = phi i32 [ 1, %16 ], [ 0, %37 ], [ 0, %32 ], [ 0, %25 ], [ 0, %27 ]
%41 = phi i32 [ %18, %16 ], [ %4, %37 ], [ 0, %32 ], [ %4, %25 ], [ %4, %27 ]
%42 = icmp sgt i32 %8, -1
br i1 %42, label %3, label %43
43: ; preds = %39, %0
%44 = tail call i32 @compr_put_byte(i32 0)
%45 = tail call i32 @compr_put_byte(i32 237)
%46 = tail call i32 @compr_put_byte(i32 237)
%47 = tail call i32 @compr_put_byte(i32 0)
ret void
}