#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_compress_block(COMP_CTX *ctx, unsigned char *out, unsigned int olen,
                       unsigned char *in, unsigned int ilen) {
  if (ilen == 0 || olen < (ilen - 1)) {
    return (-1);
  }
  *(out++) = 0;
  memcpy(out, in, ilen);
  return (ilen + 1);
}


x86 assembly (clang, -O0):
<rle_compress_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_compress_block+0x36>
mov    -0x1c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    1152 <rle_compress_block+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    117d <rle_compress_block+0x6d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rle_compress_block>:
mov    %r8d,%edi
mov    $0xffffffff,%eax
sub    $0x1,%edi
jb     1140 <rle_compress_block+0x30>
cmp    %edx,%edi
ja     1140 <rle_compress_block+0x30>
push   %rbx
mov    %r8d,%ebx
movb   $0x0,(%rsi)
add    $0x1,%rsi
mov    %rsi,%rdi
mov    %rcx,%rsi
mov    %r8d,%edx
call   1030 <memcpy@plt>
add    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @rle_compress_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
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
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %5
%15 = load i32, i32* %9
%16 = load i32, i32* %11
%17 = sub i32 %16, 1
%18 = icmp ult i32 %15, %17
br i1 %18, label %19, label %20
19: ; preds = %14, %5
store i32 -1, i32* %6
br label %29
20: ; preds = %14
%21 = load i8*, i8** %8
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %8
store i8 0, i8* %21
%23 = load i8*, i8** %8
%24 = load i8*, i8** %10
%25 = load i32, i32* %11
%26 = call i32 @memcpy(i8* %23, i8* %24, i32 %25)
%27 = load i32, i32* %11
%28 = add i32 %27, 1
store i32 %28, i32* %6
br label %29
29: ; preds = %20, %19
%30 = load i32, i32* %6
ret i32 %30
}

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