#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 */
typedef int /*<<< orphan*/ ptr2;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(int);
void *ft_memmove(void *s1, const void *s2, size_t n) {
  size_t i;
  char *tmp;
  char *ptr1;
  char *ptr2;
  i = 0;
  ptr1 = ((char *)s1);
  ptr2 = ((char *)s2);
  tmp = malloc(sizeof(ptr2) * n);
  while (i < n) {
    tmp[i] = ptr2[i];
    i++;
  }
  i = 0;
  while (i < n) {
    ptr1[i] = tmp[i];
    i++;
  }
  free(tmp);
  return (s1);
}


x86 assembly (clang, -O0):
<ft_memmove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1194 <ft_memmove+0x74>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115f <ft_memmove+0x3f>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11d1 <ft_memmove+0xb1>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    119c <ft_memmove+0x7c>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
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,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x0(,%rdx,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
test   %rbx,%rbx
je     1181 <ft_memmove+0x41>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <memmove@plt>
mov    %r12,%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 i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i64 0, i64* %7
%11 = load i8*, i8** %4
store i8* %11, i8** %9
%12 = load i8*, i8** %5
store i8* %12, i8** %10
%13 = load i64, i64* %6
%14 = mul i64 8, %13
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %8
br label %17
17: ; preds = %21, %3
%18 = load i64, i64* %7
%19 = load i64, i64* %6
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i8*, i8** %10
%23 = load i64, i64* %7
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8, i8* %24
%26 = load i8*, i8** %8
%27 = load i64, i64* %7
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8 %25, i8* %28
%29 = load i64, i64* %7
%30 = add i64 %29, 1
store i64 %30, i64* %7
br label %17
31: ; preds = %17
store i64 0, i64* %7
br label %32
32: ; preds = %36, %31
%33 = load i64, i64* %7
%34 = load i64, i64* %6
%35 = icmp ult i64 %33, %34
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load i8*, i8** %8
%38 = load i64, i64* %7
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8, i8* %39
%41 = load i8*, i8** %9
%42 = load i64, i64* %7
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8 %40, i8* %43
%44 = load i64, i64* %7
%45 = add i64 %44, 1
store i64 %45, i64* %7
br label %32
46: ; preds = %32
%47 = load i8*, i8** %8
%48 = call i32 @free(i8* %47)
%49 = load i8*, i8** %4
ret i8* %49
}

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