#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(unsigned char *);
int /*<<< orphan*/ ft_memcpy(unsigned char *, unsigned char *, size_t);
scalar_t__ malloc(size_t);
void *ft_memmove(void *dst, const void *src, size_t len) {
  unsigned char *d;
  unsigned char *s;
  unsigned char *tmp;
  d = (unsigned char *)dst;
  s = (unsigned char *)src;
  tmp = (unsigned char *)(malloc(len));
  if (tmp == NULL)
    return (dst);
  ft_memcpy(tmp, s, len);
  ft_memcpy(d, tmp, len);
  free(tmp);
  return (dst);
}


x86 assembly (clang, -O0):
<ft_memmove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1179 <ft_memmove+0x49>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ac <ft_memmove+0x7c>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <ft_memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <ft_memcpy@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_memmove>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rdx,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1175 <ft_memmove+0x45>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1050 <ft_memcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <ft_memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ft_memmove(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%11 = load i8*, i8** %5
store i8* %11, i8** %8
%12 = load i8*, i8** %6
store i8* %12, i8** %9
%13 = load i64, i64* %7
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %10
%16 = load i8*, i8** %10
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = load i8*, i8** %5
store i8* %19, i8** %4
br label %32
20: ; preds = %3
%21 = load i8*, i8** %10
%22 = load i8*, i8** %9
%23 = load i64, i64* %7
%24 = call i32 @ft_memcpy(i8* %21, i8* %22, i64 %23)
%25 = load i8*, i8** %8
%26 = load i8*, i8** %10
%27 = load i64, i64* %7
%28 = call i32 @ft_memcpy(i8* %25, i8* %26, i64 %27)
%29 = load i8*, i8** %10
%30 = call i32 @free(i8* %29)
%31 = load i8*, i8** %5
store i8* %31, i8** %4
br label %32
32: ; preds = %20, %18
%33 = load i8*, i8** %4
ret i8* %33
}

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