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

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exegesis_copyblock(char *, char const *, size_t);
void exegesis_overlap(char *dst, const char *src, size_t count,
                      size_t block_size) {
  if (count < block_size || count > block_size * 2) {
    abort();
  }
  exegesis_copyblock(dst, src, block_size);
  const size_t offset = count - block_size;
  exegesis_copyblock(dst + offset, src + offset, block_size);
}


x86 assembly (clang, -O0):
<exegesis_overlap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     115b <exegesis_overlap+0x3b>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x1,%rcx
cmp    %rcx,%rax
jbe    1162 <exegesis_overlap+0x42>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <exegesis_copyblock@plt>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <exegesis_copyblock@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exegesis_overlap>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
sub    %rcx,%rbx
jb     1169 <exegesis_overlap+0x49>
mov    %rcx,%r14
lea    (%rcx,%rcx,1),%rax
cmp    %rdx,%rax
jb     1169 <exegesis_overlap+0x49>
mov    %rsi,%r15
mov    %rdi,%r12
mov    %r14,%rdx
call   1040 <exegesis_copyblock@plt>
add    %rbx,%r12
add    %rbx,%r15
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <exegesis_copyblock@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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

LLVM IR (-O2):
define void @exegesis_overlap(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = icmp ult i64 %2, %3
%6 = shl i64 %3, 1
%7 = icmp ult i64 %6, %2
%8 = or i1 %5, %7
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 (...) @abort()
unreachable
11: ; preds = %4
%12 = tail call i32 @exegesis_copyblock(i8* %0, i8* %1, i64 %3)
%13 = sub i64 %2, %3
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = getelementptr inbounds i8, i8* %1, i64 %13
%16 = tail call i32 @exegesis_copyblock(i8* %14, i8* %15, i64 %3)
ret void
}