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

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned int);
int rle_expand_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
                     unsigned char *in, unsigned int ilen) {
  int i;
  if (ilen == 0 || olen < (ilen - 1)) {
    return (-1);
  }
  i = *(in++);
  if (i == 0) {
    memcpy(out, in, ilen - 1);
  }
  return (ilen - 1);
}


x86 assembly (clang, -O0):
<rle_expand_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1146 <rle_expand_block+0x36>
mov    -0x1c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    1152 <rle_expand_block+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <rle_expand_block+0x7d>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl (%rax),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    1184 <rle_expand_block+0x74>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
sub    $0x1,%edx
call   1030 <memcpy@plt>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rle_expand_block>:
push   %rbx
mov    $0xffffffff,%eax
test   %r8d,%r8d
je     113d <rle_expand_block+0x2d>
mov    %r8d,%ebx
add    $0xffffffff,%ebx
cmp    %edx,%ebx
ja     113d <rle_expand_block+0x2d>
cmpb   $0x0,(%rcx)
jne    113b <rle_expand_block+0x2b>
add    $0x1,%rcx
mov    %rsi,%rdi
mov    %rcx,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @rle_expand_block(i32* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%13 = load i32, i32* %11
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %5
%16 = load i32, i32* %9
%17 = load i32, i32* %11
%18 = sub i32 %17, 1
%19 = icmp ult i32 %16, %18
br i1 %19, label %20, label %21
20: ; preds = %15, %5
store i32 -1, i32* %6
br label %37
21: ; preds = %15
%22 = load i8*, i8** %10
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %10
%24 = load i8, i8* %22
%25 = zext i8 %24 to i32
store i32 %25, i32* %12
%26 = load i32, i32* %12
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i8*, i8** %8
%30 = load i8*, i8** %10
%31 = load i32, i32* %11
%32 = sub i32 %31, 1
%33 = call i32 @memcpy(i8* %29, i8* %30, i32 %32)
br label %34
34: ; preds = %28, %21
%35 = load i32, i32* %11
%36 = sub i32 %35, 1
store i32 %36, i32* %6
br label %37
37: ; preds = %34, %20
%38 = load i32, i32* %6
ret i32 %38
}

LLVM IR (-O2):
define i32 @rle_expand_block(i32* nocapture readnone %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = icmp eq i32 %4, 0
br i1 %6, label %16, label %7
7: ; preds = %5
%8 = add i32 %4, -1
%9 = icmp ugt i32 %8, %2
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %3, i64 1
%15 = tail call i32 @memcpy(i8* %1, i8* %14, i32 %8)
br label %16
16: ; preds = %10, %13, %5, %7
%17 = phi i32 [ -1, %7 ], [ -1, %5 ], [ %8, %13 ], [ %8, %10 ]
ret i32 %17
}