#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*/ assert(int);
int /*<<< orphan*/ memmove(int *, int *, size_t);
int /*<<< orphan*/ printf(char *, size_t, size_t, size_t);
void move_part(int *A, size_t N, size_t target, size_t source, size_t size,
               int show_steps) {
  assert(source + size <= N);
  assert(target + size <= N);
  if (show_steps) {
    printf("Moving size %d from %d to %d.\n", size, source, target);
  }
  memmove(A + target, A + source, size * sizeof(int));
}


x86 assembly (clang, -O0):
<move_part>:
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    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x2c(%rbp)
je     11a4 <move_part+0x74>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x28(%rbp),%rdx
shl    $0x2,%rdx
call   1050 <memmove@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<move_part>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r13d
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r12
lea    (%r8,%rcx,1),%rax
xor    %edi,%edi
cmp    %rsi,%rax
setbe  %dil
call   1040 <assert@plt>
lea    (%rbx,%r15,1),%rax
xor    %edi,%edi
cmp    %rbp,%rax
setbe  %dil
call   1040 <assert@plt>
test   %r13d,%r13d
je     118b <move_part+0x5b>
lea    0xe83(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1030 <printf@plt>
lea    (%r12,%r15,4),%rdi
lea    (%r12,%r14,4),%rsi
shl    $0x2,%rbx
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <memmove@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Moving size %d from %d to %d.\0A\00"
define void @move_part(i32* %0, i64 %1, i64 %2, i64 %3, i64 %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i32* %0, i32** %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i64 %4, i64* %11
store i32 %5, i32* %12
%13 = load i64, i64* %10
%14 = load i64, i64* %11
%15 = add i64 %13, %14
%16 = load i64, i64* %8
%17 = icmp ule i64 %15, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i64, i64* %9
%21 = load i64, i64* %11
%22 = add i64 %20, %21
%23 = load i64, i64* %8
%24 = icmp ule i64 %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32, i32* %12
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %6
%30 = load i64, i64* %11
%31 = load i64, i64* %10
%32 = load i64, i64* %9
%33 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %30, i64 %31, i64 %32)
br label %34
34: ; preds = %29, %6
%35 = load i32*, i32** %7
%36 = load i64, i64* %9
%37 = getelementptr inbounds i32, i32* %35, i64 %36
%38 = load i32*, i32** %7
%39 = load i64, i64* %10
%40 = getelementptr inbounds i32, i32* %38, i64 %39
%41 = load i64, i64* %11
%42 = mul i64 %41, 4
%43 = call i32 @memmove(i32* %37, i32* %40, i64 %42)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"Moving size %d from %d to %d.\0A\00"
define void @move_part(i32* %0, i64 %1, i64 %2, i64 %3, i64 %4, i32 %5) {
%7 = add i64 %4, %3
%8 = icmp ule i64 %7, %1
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = add i64 %4, %2
%12 = icmp ule i64 %11, %1
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = icmp eq i32 %5, 0
br i1 %15, label %18, label %16
16: ; preds = %6
%17 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %4, i64 %3, i64 %2)
br label %18
18: ; preds = %16, %6
%19 = getelementptr inbounds i32, i32* %0, i64 %2
%20 = getelementptr inbounds i32, i32* %0, i64 %3
%21 = shl i64 %4, 2
%22 = tail call i32 @memmove(i32* %19, i32* %20, i64 %21)
ret void
}