#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*/ free(void *);
void *malloc(unsigned short);
void *memmove(void *destination, const void *source, unsigned short num) {
  unsigned short i;
  void *temp = malloc(num);
  for (i = 0; i < num; i++)
    ((char *)temp)[i] = ((char *)source)[i];
  for (i = 0; i < num; i++)
    ((char *)destination)[i] = ((char *)temp)[i];
  free(temp);
  return destination;
}


x86 assembly (clang, -O0):
<memmove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movw   $0x0,-0x14(%rbp)
movzwl -0x14(%rbp),%eax
movzwl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jge    1181 <memmove+0x61>
mov    -0x10(%rbp),%rax
movzwl -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movzwl -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x14(%rbp)
jmp    114a <memmove+0x2a>
movw   $0x0,-0x14(%rbp)
movzwl -0x14(%rbp),%eax
movzwl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jge    11be <memmove+0x9e>
mov    -0x20(%rbp),%rax
movzwl -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movzwl -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x14(%rbp)
jmp    1187 <memmove+0x67>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memmove>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %edx,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %ebp,%ebp
je     116c <memmove+0x3c>
movzwl %bp,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1040 <memcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @memmove(i8* %0, i8* %1, i16 zeroext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i16
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i16 %2, i16* %6
%9 = load i16, i16* %6
%10 = call i8* @malloc(i16 zeroext %9)
store i8* %10, i8** %8
store i16 0, i16* %7
br label %11
11: ; preds = %27, %3
%12 = load i16, i16* %7
%13 = zext i16 %12 to i32
%14 = load i16, i16* %6
%15 = zext i16 %14 to i32
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %30
17: ; preds = %11
%18 = load i8*, i8** %5
%19 = load i16, i16* %7
%20 = zext i16 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = load i8*, i8** %8
%24 = load i16, i16* %7
%25 = zext i16 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
br label %27
27: ; preds = %17
%28 = load i16, i16* %7
%29 = add i16 %28, 1
store i16 %29, i16* %7
br label %11
30: ; preds = %11
store i16 0, i16* %7
br label %31
31: ; preds = %47, %30
%32 = load i16, i16* %7
%33 = zext i16 %32 to i32
%34 = load i16, i16* %6
%35 = zext i16 %34 to i32
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %50
37: ; preds = %31
%38 = load i8*, i8** %8
%39 = load i16, i16* %7
%40 = zext i16 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = load i8*, i8** %4
%44 = load i16, i16* %7
%45 = zext i16 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %42, i8* %46
br label %47
47: ; preds = %37
%48 = load i16, i16* %7
%49 = add i16 %48, 1
store i16 %49, i16* %7
br label %31
50: ; preds = %31
%51 = load i8*, i8** %8
%52 = call i32 @free(i8* %51)
%53 = load i8*, i8** %4
ret i8* %53
}

LLVM IR (-O2):
define i8* @memmove(i8* returned writeonly %0, i8* nocapture %1, i16 zeroext %2) {
%4 = tail call i8* @malloc(i16 zeroext %2)
%5 = icmp eq i16 %2, 0
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = zext i16 %2 to i64
%8 = zext i16 %2 to i64
br label %9
9: ; preds = %3, %6
%10 = tail call i32 @free(i8* %4)
ret i8* %0
}