#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*/ memcpy(unsigned char *, unsigned char *, char);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, char);
void RLEUncompress(unsigned char *output, unsigned char *input, int length) {
  signed char count;
  while (length > 0) {
    count = (signed char)*input++;
    if (count > 0) {
      memset(output, *input++, count);
    } else if (count < 0) {
      count = (signed char)-count;
      memcpy(output, input, count);
      input += count;
    }
    output += count;
    length -= count;
  }
}


x86 assembly (clang, -O0):
<RLEUncompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11e9 <RLEUncompress+0xc9>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
jle    1184 <RLEUncompress+0x64>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%esi
mov    -0x15(%rbp),%al
movsbl %al,%edx
call   1030 <memset@plt>
jmp    11c6 <RLEUncompress+0xa6>
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
jge    11c1 <RLEUncompress+0xa1>
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x15(%rbp),%al
movsbl %al,%edx
call   1040 <memcpy@plt>
movsbl -0x15(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    11c6 <RLEUncompress+0xa6>
movsbl -0x15(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
movsbl -0x15(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <RLEUncompress+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RLEUncompress>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    1199 <RLEUncompress+0x79>
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rbx
jmp    1165 <RLEUncompress+0x45>
nopw   0x0(%rax,%rax,1)
movzbl 0x1(%r14),%esi
add    $0x2,%r14
movsbl %bpl,%edx
mov    %rbx,%rdi
call   1030 <memset@plt>
movsbl %bpl,%eax
movsbq %al,%rcx
add    %rcx,%rbx
sub    %eax,%r12d
jle    1199 <RLEUncompress+0x79>
movzbl (%r14),%ebp
test   %bpl,%bpl
jg     1140 <RLEUncompress+0x20>
add    $0x1,%r14
test   %bpl,%bpl
js     117b <RLEUncompress+0x5b>
xor    %ebp,%ebp
jmp    1155 <RLEUncompress+0x35>
neg    %bpl
movsbl %bpl,%r15d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
movsbq %r15b,%rax
add    %rax,%r14
jmp    1155 <RLEUncompress+0x35>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @RLEUncompress(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %45, %3
%9 = load i32, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %55
11: ; preds = %8
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
%14 = load i8, i8* %12
store i8 %14, i8* %7
%15 = load i8, i8* %7
%16 = sext i8 %15 to i32
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
%22 = load i8, i8* %20
%23 = zext i8 %22 to i32
%24 = load i8, i8* %7
%25 = call i32 @memset(i8* %19, i32 %23, i8 signext %24)
br label %45
26: ; preds = %11
%27 = load i8, i8* %7
%28 = sext i8 %27 to i32
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %44
30: ; preds = %26
%31 = load i8, i8* %7
%32 = sext i8 %31 to i32
%33 = sub nsw i32 0, %32
%34 = trunc i32 %33 to i8
store i8 %34, i8* %7
%35 = load i8*, i8** %4
%36 = load i8*, i8** %5
%37 = load i8, i8* %7
%38 = call i32 @memcpy(i8* %35, i8* %36, i8 signext %37)
%39 = load i8, i8* %7
%40 = sext i8 %39 to i32
%41 = load i8*, i8** %5
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8* %43, i8** %5
br label %44
44: ; preds = %30, %26
br label %45
45: ; preds = %44, %18
%46 = load i8, i8* %7
%47 = sext i8 %46 to i32
%48 = load i8*, i8** %4
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8* %50, i8** %4
%51 = load i8, i8* %7
%52 = sext i8 %51 to i32
%53 = load i32, i32* %6
%54 = sub nsw i32 %53, %52
store i32 %54, i32* %6
br label %8
55: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @RLEUncompress(i8* %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %32
5: ; preds = %3, %24
%6 = phi i32 [ %30, %24 ], [ %2, %3 ]
%7 = phi i8* [ %25, %24 ], [ %1, %3 ]
%8 = phi i8* [ %29, %24 ], [ %0, %3 ]
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = load i8, i8* %7
%11 = icmp sgt i8 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %5
%13 = getelementptr inbounds i8, i8* %7, i64 2
%14 = load i8, i8* %9
%15 = zext i8 %14 to i32
%16 = tail call i32 @memset(i8* %8, i32 %15, i8 signext %10)
br label %24
17: ; preds = %5
%18 = icmp slt i8 %10, 0
br i1 %18, label %19, label %24
19: ; preds = %17
%20 = sub i8 0, %10
%21 = tail call i32 @memcpy(i8* %8, i8* %9, i8 signext %20)
%22 = sext i8 %20 to i64
%23 = getelementptr inbounds i8, i8* %9, i64 %22
br label %24
24: ; preds = %17, %19, %12
%25 = phi i8* [ %13, %12 ], [ %23, %19 ], [ %9, %17 ]
%26 = phi i8 [ %10, %12 ], [ %20, %19 ], [ 0, %17 ]
%27 = sext i8 %26 to i32
%28 = sext i8 %26 to i64
%29 = getelementptr inbounds i8, i8* %8, i64 %28
%30 = sub nsw i32 %6, %27
%31 = icmp sgt i32 %30, 0
br i1 %31, label %5, label %32
32: ; preds = %24, %3
ret void
}