#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)
    return 0;
  if (olen < (ilen - 1))
    return -1;
  i = *(in++);
  if (i != 0)
    return -1;
  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)
jne    1141 <rle_expand_block+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <rle_expand_block+0x95>
mov    -0x1c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    115e <rle_expand_block+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <rle_expand_block+0x95>
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)
je     1189 <rle_expand_block+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <rle_expand_block+0x95>
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
test   %r8d,%r8d
je     112c <rle_expand_block+0x1c>
mov    %r8d,%ebx
add    $0xffffffff,%ebx
mov    $0xffffffff,%eax
cmp    %edx,%ebx
ja     112a <rle_expand_block+0x1a>
cmpb   $0x0,(%rcx)
je     1130 <rle_expand_block+0x20>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
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 %15, label %16
15: ; preds = %5
store i32 0, i32* %6
br label %38
16: ; preds = %5
%17 = load i32, i32* %9
%18 = load i32, i32* %11
%19 = sub i32 %18, 1
%20 = icmp ult i32 %17, %19
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %6
br label %38
22: ; preds = %16
%23 = load i8*, i8** %10
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %10
%25 = load i8, i8* %23
%26 = zext i8 %25 to i32
store i32 %26, i32* %12
%27 = load i32, i32* %12
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 -1, i32* %6
br label %38
30: ; preds = %22
%31 = load i8*, i8** %8
%32 = load i8*, i8** %10
%33 = load i32, i32* %11
%34 = sub i32 %33, 1
%35 = call i32 @memcpy(i8* %31, i8* %32, i32 %34)
%36 = load i32, i32* %11
%37 = sub i32 %36, 1
store i32 %37, i32* %6
br label %38
38: ; preds = %30, %29, %21, %15
%39 = load i32, i32* %6
ret i32 %39
}

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, %7, %5, %13
%17 = phi i32 [ %8, %13 ], [ 0, %5 ], [ -1, %7 ], [ -1, %10 ]
ret i32 %17
}