#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*/ FILE;

/* Variables and functions */
int EOF;
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(unsigned char, int /*<<< orphan*/ *);
void rle_decode(FILE *in, FILE *out) {
  int c, prev, rle_cnt;
  if ((c = getc(in)) != EOF) {
    prev = c;
    putc((unsigned char)c, out);
  } else
    return;
  while ((c = getc(in)) != EOF) {
    if (c == prev) {
      putc((unsigned char)prev, out);
      if ((rle_cnt = getc(in)) != EOF) {
        while (rle_cnt--) {
          putc((unsigned char)prev, out);
        }
      } else
        break;
    } else {
      putc((unsigned char)c, out);
      prev = c;
    }
  }
}


x86 assembly (clang, -O0):
<rle_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2ea5(%rip),%rcx
cmp    (%rcx),%eax
je     1165 <rle_decode+0x45>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
jmp    116a <rle_decode+0x4a>
jmp    1216 <rle_decode+0xf6>
jmp    116f <rle_decode+0x4f>
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%eax
je     1216 <rle_decode+0xf6>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11fc <rle_decode+0xdc>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%eax
je     11f2 <rle_decode+0xd2>
jmp    11c5 <rle_decode+0xa5>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     11ed <rle_decode+0xcd>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
jmp    11c5 <rle_decode+0xa5>
jmp    11f7 <rle_decode+0xd7>
jmp    1216 <rle_decode+0xf6>
jmp    1211 <rle_decode+0xf1>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    116f <rle_decode+0x4f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rle_decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
call   1040 <getc@plt>
mov    0x2eab(%rip),%r13
cmp    0x0(%r13),%eax
jne    1152 <rle_decode+0x32>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
movzbl %r15b,%edi
mov    %r12,%rsi
call   1030 <putc@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <getc@plt>
cmp    0x0(%r13),%eax
je     1143 <rle_decode+0x23>
mov    %r15d,%ebx
mov    %eax,%r15d
movzbl %r15b,%ebp
mov    %ebp,%edi
mov    %r12,%rsi
call   1030 <putc@plt>
cmp    %ebx,%r15d
jne    1170 <rle_decode+0x50>
mov    %r14,%rdi
call   1040 <getc@plt>
cmp    0x0(%r13),%eax
je     1143 <rle_decode+0x23>
mov    %eax,%ebx
test   %eax,%eax
je     1170 <rle_decode+0x50>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r12,%rsi
call   1030 <putc@plt>
add    $0xffffffff,%ebx
jne    11b0 <rle_decode+0x90>
jmp    1170 <rle_decode+0x50>

LLVM IR (-O0):
@EOF = global i32 0
define void @rle_decode(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%8 = load i32*, i32** %3
%9 = call i32 @getc(i32* %8)
store i32 %9, i32* %5
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* %5
store i32 %13, i32* %6
%14 = load i32, i32* %5
%15 = trunc i32 %14 to i8
%16 = load i32*, i32** %4
%17 = call i32 @putc(i8 zeroext %15, i32* %16)
br label %19
18: ; preds = %2
br label %58
19: ; preds = %12
br label %20
20: ; preds = %57, %19
%21 = load i32*, i32** %3
%22 = call i32 @getc(i32* %21)
store i32 %22, i32* %5
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %58
25: ; preds = %20
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %51
29: ; preds = %25
%30 = load i32, i32* %6
%31 = trunc i32 %30 to i8
%32 = load i32*, i32** %4
%33 = call i32 @putc(i8 zeroext %31, i32* %32)
%34 = load i32*, i32** %3
%35 = call i32 @getc(i32* %34)
store i32 %35, i32* %7
%36 = load i32, i32* @EOF
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %49
38: ; preds = %29
br label %39
39: ; preds = %43, %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, -1
store i32 %41, i32* %7
%42 = icmp ne i32 %40, 0
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i32, i32* %6
%45 = trunc i32 %44 to i8
%46 = load i32*, i32** %4
%47 = call i32 @putc(i8 zeroext %45, i32* %46)
br label %39
48: ; preds = %39
br label %50
49: ; preds = %29
br label %58
50: ; preds = %48
br label %57
51: ; preds = %25
%52 = load i32, i32* %5
%53 = trunc i32 %52 to i8
%54 = load i32*, i32** %4
%55 = call i32 @putc(i8 zeroext %53, i32* %54)
%56 = load i32, i32* %5
store i32 %56, i32* %6
br label %57
57: ; preds = %51, %50
br label %20
58: ; preds = %18, %49, %20
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @rle_decode(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call i32 @getc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %33, label %6
6: ; preds = %2
%7 = trunc i32 %3 to i8
%8 = tail call i32 @putc(i8 zeroext %7, i32* %1)
%9 = tail call i32 @getc(i32* %0)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %33, label %12
12: ; preds = %6, %29
%13 = phi i32 [ %30, %29 ], [ %9, %6 ]
%14 = phi i32 [ %13, %29 ], [ %3, %6 ]
%15 = icmp eq i32 %13, %14
%16 = trunc i32 %13 to i8
%17 = tail call i32 @putc(i8 zeroext %16, i32* %1)
br i1 %15, label %18, label %29
18: ; preds = %12
%19 = tail call i32 @getc(i32* %0)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %33, label %22
22: ; preds = %18
%23 = icmp eq i32 %19, 0
br i1 %23, label %29, label %24
24: ; preds = %22, %24
%25 = phi i32 [ %26, %24 ], [ %19, %22 ]
%26 = add nsw i32 %25, -1
%27 = tail call i32 @putc(i8 zeroext %16, i32* %1)
%28 = icmp eq i32 %26, 0
br i1 %28, label %29, label %24
29: ; preds = %24, %12, %22
%30 = tail call i32 @getc(i32* %0)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %12
33: ; preds = %18, %29, %6, %2
ret void
}