#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*/ memcpy1(unsigned char *, void const *, size_t);
void *memmove1(void *s1, const void *s2, size_t n) {
  unsigned char temp[n];
  memcpy1(temp, s2, n);
  unsigned char *result = (unsigned char *)s1;
  size_t i;
  for (i = 0; n > 0; n--, i++)
    *result++ = temp[i];
  return s1;
}


x86 assembly (clang, -O0):
<memmove1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy1@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11ac <memmove1+0x9c>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1168 <memmove1+0x58>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memmove1>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rdi,%r14
mov    %rsp,%rbx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1040 <memcpy1@plt>
test   %r15,%r15
je     115c <memmove1+0x3c>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <memcpy@plt>
mov    %r14,%rax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @memmove1(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%11 = load i64, i64* %6
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = call i32 @memcpy1(i8* %13, i8* %14, i64 %15)
%17 = load i8*, i8** %4
store i8* %17, i8** %9
store i64 0, i64* %10
br label %18
18: ; preds = %27, %3
%19 = load i64, i64* %6
%20 = icmp ugt i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i64, i64* %10
%23 = getelementptr inbounds i8, i8* %13, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %9
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %9
store i8 %24, i8* %25
br label %27
27: ; preds = %21
%28 = load i64, i64* %6
%29 = add i64 %28, -1
store i64 %29, i64* %6
%30 = load i64, i64* %10
%31 = add i64 %30, 1
store i64 %31, i64* %10
br label %18
32: ; preds = %18
%33 = load i8*, i8** %4
%34 = load i8*, i8** %7
ret i8* %33
}

LLVM IR (-O2):
define i8* @memmove1(i8* returned writeonly %0, i8* %1, i64 %2) {
%4 = alloca i8, i64 %2
%5 = call i32 @memcpy1(i8* %4, i8* %1, i64 %2)
%6 = icmp eq i64 %2, 0
br i1 %6, label %8, label %7
7: ; preds = %3
br label %8
8: ; preds = %7, %3
ret i8* %0
}