#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*/ RotateBufLeft(char *, char *, unsigned int);
int /*<<< orphan*/ RotateBufRight(char *, char *, unsigned int);
int /*<<< orphan*/ SwapBuffer(char *, char *, unsigned int);
void SlowSwapBufferParts(char *begin1, char *end1, char *begin2, char *end2) {
  unsigned len1, len2, difference;
  len1 = (unsigned)(end1 - begin1);
  len2 = (unsigned)(end2 - begin2);
  if (len1 < len2) {
    difference = len2 - len1;
    RotateBufRight(end1, begin2 + difference, difference);
    SwapBuffer(begin1, begin2 + difference, len1);
    RotateBufRight(begin1, end1 + difference, difference);
  } else if (len1 > len2) {
    difference = len1 - len2;
    RotateBufLeft(end1 - difference, begin2, difference);
    SwapBuffer(begin1, begin2, len2);
    RotateBufLeft(begin2 - difference, end2, difference);
  } else {
    SwapBuffer(begin1, begin2, len1);
  }
}


x86 assembly (clang, -O0):
<SlowSwapBufferParts>:
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    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jae    11c0 <SlowSwapBufferParts+0x90>
mov    -0x28(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%eax
add    %rax,%rsi
mov    -0x2c(%rbp),%edx
call   1040 <RotateBufRight@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%eax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
call   1050 <SwapBuffer@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%eax
add    %rax,%rsi
mov    -0x2c(%rbp),%edx
call   1040 <RotateBufRight@plt>
jmp    1239 <SlowSwapBufferParts+0x109>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jbe    1224 <SlowSwapBufferParts+0xf4>
mov    -0x24(%rbp),%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <RotateBufLeft@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1050 <SwapBuffer@plt>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <RotateBufLeft@plt>
jmp    1234 <SlowSwapBufferParts+0x104>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <SwapBuffer@plt>
jmp    1239 <SlowSwapBufferParts+0x109>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SlowSwapBufferParts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    %r12d,%ebp
sub    %r14d,%ebp
mov    %ecx,%ebx
sub    %r15d,%ebx
mov    %ebp,%r13d
sub    %ebx,%r13d
jae    1194 <SlowSwapBufferParts+0x64>
sub    %ebp,%ebx
add    %rbx,%r15
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <RotateBufRight@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <SwapBuffer@plt>
add    %rbx,%r12
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <RotateBufRight@plt>
jbe    11d6 <SlowSwapBufferParts+0xa6>
sub    %r13,%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
mov    %rcx,%rbp
call   1030 <RotateBufLeft@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <SwapBuffer@plt>
sub    %r13,%r15
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <RotateBufLeft@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <SwapBuffer@plt>

LLVM IR (-O0):
define void @SlowSwapBufferParts(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%12 = load i8*, i8** %6
%13 = load i8*, i8** %5
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
store i32 %17, i32* %9
%18 = load i8*, i8** %8
%19 = load i8*, i8** %7
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = trunc i64 %22 to i32
store i32 %23, i32* %10
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = icmp ult i32 %24, %25
br i1 %26, label %27, label %52
27: ; preds = %4
%28 = load i32, i32* %10
%29 = load i32, i32* %9
%30 = sub i32 %28, %29
store i32 %30, i32* %11
%31 = load i8*, i8** %6
%32 = load i8*, i8** %7
%33 = load i32, i32* %11
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i32, i32* %11
%37 = call i32 @RotateBufRight(i8* %31, i8* %35, i32 %36)
%38 = load i8*, i8** %5
%39 = load i8*, i8** %7
%40 = load i32, i32* %11
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i32, i32* %9
%44 = call i32 @SwapBuffer(i8* %38, i8* %42, i32 %43)
%45 = load i8*, i8** %5
%46 = load i8*, i8** %6
%47 = load i32, i32* %11
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i32, i32* %11
%51 = call i32 @RotateBufRight(i8* %45, i8* %49, i32 %50)
br label %86
52: ; preds = %4
%53 = load i32, i32* %9
%54 = load i32, i32* %10
%55 = icmp ugt i32 %53, %54
br i1 %55, label %56, label %80
56: ; preds = %52
%57 = load i32, i32* %9
%58 = load i32, i32* %10
%59 = sub i32 %57, %58
store i32 %59, i32* %11
%60 = load i8*, i8** %6
%61 = load i32, i32* %11
%62 = zext i32 %61 to i64
%63 = sub i64 0, %62
%64 = getelementptr inbounds i8, i8* %60, i64 %63
%65 = load i8*, i8** %7
%66 = load i32, i32* %11
%67 = call i32 @RotateBufLeft(i8* %64, i8* %65, i32 %66)
%68 = load i8*, i8** %5
%69 = load i8*, i8** %7
%70 = load i32, i32* %10
%71 = call i32 @SwapBuffer(i8* %68, i8* %69, i32 %70)
%72 = load i8*, i8** %7
%73 = load i32, i32* %11
%74 = zext i32 %73 to i64
%75 = sub i64 0, %74
%76 = getelementptr inbounds i8, i8* %72, i64 %75
%77 = load i8*, i8** %8
%78 = load i32, i32* %11
%79 = call i32 @RotateBufLeft(i8* %76, i8* %77, i32 %78)
br label %85
80: ; preds = %52
%81 = load i8*, i8** %5
%82 = load i8*, i8** %7
%83 = load i32, i32* %9
%84 = call i32 @SwapBuffer(i8* %81, i8* %82, i32 %83)
br label %85
85: ; preds = %80, %56
br label %86
86: ; preds = %85, %27
ret void
}

LLVM IR (-O2):
define void @SlowSwapBufferParts(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = ptrtoint i8* %1 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = trunc i64 %7 to i32
%9 = ptrtoint i8* %3 to i64
%10 = ptrtoint i8* %2 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = icmp ult i32 %8, %12
br i1 %13, label %14, label %22
14: ; preds = %4
%15 = sub i32 %12, %8
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = tail call i32 @RotateBufRight(i8* %1, i8* %17, i32 %15)
%19 = tail call i32 @SwapBuffer(i8* %0, i8* %17, i32 %8)
%20 = getelementptr inbounds i8, i8* %1, i64 %16
%21 = tail call i32 @RotateBufRight(i8* %0, i8* %20, i32 %15)
br label %35
22: ; preds = %4
%23 = icmp ugt i32 %8, %12
br i1 %23, label %24, label %33
24: ; preds = %22
%25 = sub i32 %8, %12
%26 = zext i32 %25 to i64
%27 = sub nsw i64 0, %26
%28 = getelementptr inbounds i8, i8* %1, i64 %27
%29 = tail call i32 @RotateBufLeft(i8* %28, i8* %2, i32 %25)
%30 = tail call i32 @SwapBuffer(i8* %0, i8* %2, i32 %12)
%31 = getelementptr inbounds i8, i8* %2, i64 %27
%32 = tail call i32 @RotateBufLeft(i8* %31, i8* %3, i32 %25)
br label %35
33: ; preds = %22
%34 = tail call i32 @SwapBuffer(i8* %0, i8* %2, i32 %8)
br label %35
35: ; preds = %24, %33, %14
ret void
}