#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(char *);
char *ft_malloc(size_t);
int /*<<< orphan*/ ft_memcpy(char *, void const *, size_t);
void *ft_memmove(void *s1, const void *s2, size_t n) {
  char *s3;
  unsigned int i;
  i = 0;
  s3 = ft_malloc(n);
  if (!s3)
    return (NULL);
  ft_memcpy(s3, s2, n);
  while (i < n) {
    ((char *)s1)[i] = s3[i];
    i++;
  }
  free(s3);
  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)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <ft_malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1170 <ft_memmove+0x40>
movq   $0x0,-0x8(%rbp)
jmp    11c1 <ft_memmove+0x91>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <ft_memcpy@plt>
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%rax
jae    11b0 <ft_memmove+0x80>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1181 <ft_memmove+0x51>
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    %rdx,%rdi
call   1050 <ft_malloc@plt>
test   %rax,%rax
je     118a <ft_memmove+0x5a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <ft_memcpy@plt>
test   %r15,%r15
je     1180 <ft_memmove+0x50>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx,%rax,1),%ecx
mov    %cl,(%r14,%rax,1)
add    $0x1,%eax
cmp    %r15,%rax
jb     1170 <ft_memmove+0x40>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    118d <ft_memmove+0x5d>
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*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 0, i32* %9
%10 = load i64, i64* %7
%11 = call i8* @ft_malloc(i64 %10)
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %3
store i8* null, i8** %4
br label %41
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = load i8*, i8** %6
%18 = load i64, i64* %7
%19 = call i32 @ft_memcpy(i8* %16, i8* %17, i64 %18)
br label %20
20: ; preds = %25, %15
%21 = load i32, i32* %9
%22 = zext i32 %21 to i64
%23 = load i64, i64* %7
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %37
25: ; preds = %20
%26 = load i8*, i8** %8
%27 = load i32, i32* %9
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = load i8*, i8** %5
%32 = load i32, i32* %9
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
%35 = load i32, i32* %9
%36 = add i32 %35, 1
store i32 %36, i32* %9
br label %20
37: ; preds = %20
%38 = load i8*, i8** %8
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %5
store i8* %40, i8** %4
br label %41
41: ; preds = %37, %14
%42 = load i8*, i8** %4
ret i8* %42
}

LLVM IR (-O2):
define i8* @ft_memmove(i8* writeonly %0, i8* %1, i64 %2) {
%4 = tail call i8* @ft_malloc(i64 %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = tail call i32 @ft_memcpy(i8* %4, i8* %1, i64 %2)
%8 = icmp eq i64 %2, 0
br i1 %8, label %17, label %9
9: ; preds = %6, %9
%10 = phi i64 [ %15, %9 ], [ 0, %6 ]
%11 = getelementptr inbounds i8, i8* %4, i64 %10
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 %12, i8* %13
%14 = add nuw nsw i64 %10, 1
%15 = and i64 %14, 4294967295
%16 = icmp ult i64 %15, %2
br i1 %16, label %9, label %17
17: ; preds = %9, %6
%18 = tail call i32 @free(i8* %4)
br label %19
19: ; preds = %3, %17
%20 = phi i8* [ %0, %17 ], [ null, %3 ]
ret i8* %20
}