#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(void *, unsigned char *, size_t);
scalar_t__ malloc(int);
void *ft_memmove(void *s1, const void *s2, size_t n) {
  unsigned char *buf;
  buf = (unsigned char *)malloc(sizeof(unsigned char) * n);
  if (!buf)
    return (0);
  ft_memcpy(buf, s2, n);
  ft_memcpy(s1, buf, n);
  free(buf);
  return (s1);
}


x86 assembly (clang, -O0):
<ft_memmove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116f <ft_memmove+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <ft_memmove+0x72>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <ft_memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <ft_memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%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    %r15d,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1177 <ft_memmove+0x47>
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>
jmp    117a <ft_memmove+0x4a>
xor    %r14d,%r14d
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*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i64, i64* %7
%10 = mul i64 1, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %3
store i8* null, i8** %4
br label %29
17: ; preds = %3
%18 = load i8*, i8** %8
%19 = load i8*, i8** %6
%20 = load i64, i64* %7
%21 = call i32 @ft_memcpy(i8* %18, i8* %19, i64 %20)
%22 = load i8*, i8** %5
%23 = load i8*, i8** %8
%24 = load i64, i64* %7
%25 = call i32 @ft_memcpy(i8* %22, i8* %23, i64 %24)
%26 = load i8*, i8** %8
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %5
store i8* %28, i8** %4
br label %29
29: ; preds = %17, %16
%30 = load i8*, i8** %4
ret i8* %30
}

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