#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)
    return 0;
  if (olen <= ilen)
    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)
jne    1141 <rle_compress_block+0x31>
movl   $0x0,-0x4(%rbp)
jmp    1184 <rle_compress_block+0x74>
mov    -0x1c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
ja     1159 <rle_compress_block+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <rle_compress_block+0x74>
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>:
push   %rbx
test   %r8d,%r8d
je     113e <rle_compress_block+0x2e>
mov    %r8d,%ebx
mov    $0xffffffff,%eax
cmp    %r8d,%edx
jbe    113c <rle_compress_block+0x2c>
movb   $0x0,(%rsi)
add    $0x1,%rsi
mov    %rsi,%rdi
mov    %rcx,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
add    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret
xor    %eax,%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 %14, label %15
14: ; preds = %5
store i32 0, i32* %6
br label %29
15: ; preds = %5
%16 = load i32, i32* %9
%17 = load i32, i32* %11
%18 = icmp ule i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %6
br label %29
20: ; preds = %15
%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, %14
%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
br i1 %6, label %13, label %7
7: ; preds = %5
%8 = icmp ugt i32 %2, %4
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %1
%11 = tail call i32 @memcpy(i8* %10, i8* %3, i32 %4)
%12 = add nuw i32 %4, 1
br label %13
13: ; preds = %7, %5, %9
%14 = phi i32 [ %12, %9 ], [ 0, %5 ], [ -1, %7 ]
ret i32 %14
}