#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 (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)
mov    -0x1c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    1148 <rle_expand_block+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <rle_expand_block+0x73>
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    117a <rle_expand_block+0x6a>
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    %r8d,%ebx
add    $0xffffffff,%ebx
mov    $0xffffffff,%eax
cmp    %edx,%ebx
ja     1138 <rle_expand_block+0x28>
cmpb   $0x0,(%rcx)
jne    1136 <rle_expand_block+0x26>
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* %9
%14 = load i32, i32* %11
%15 = sub i32 %14, 1
%16 = icmp ult i32 %13, %15
br i1 %16, label %17, label %18
17: ; preds = %5
store i32 -1, i32* %6
br label %34
18: ; preds = %5
%19 = load i8*, i8** %10
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %10
%21 = load i8, i8* %19
%22 = zext i8 %21 to i32
store i32 %22, i32* %12
%23 = load i32, i32* %12
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = load i8*, i8** %8
%27 = load i8*, i8** %10
%28 = load i32, i32* %11
%29 = sub i32 %28, 1
%30 = call i32 @memcpy(i8* %26, i8* %27, i32 %29)
br label %31
31: ; preds = %25, %18
%32 = load i32, i32* %11
%33 = sub i32 %32, 1
store i32 %33, i32* %6
br label %34
34: ; preds = %31, %17
%35 = load i32, i32* %6
ret i32 %35
}

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