#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 SafeMemCheck(void *, size_t, void const *, void const *);
int /*<<< orphan*/ memmove(void *, void const *, size_t);
int SafeMemmove(void *dst, const void *src, size_t n, const void *start,
                const void *end) {
  if (SafeMemCheck(dst, n, start, end) != 1)
    return 0;
  ;
  if (src == NULL)
    return 0;
  ;
  memmove(dst, src, n);
  return 1;
}


x86 assembly (clang, -O0):
<SafeMemmove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1030 <SafeMemCheck@plt>
cmp    $0x1,%eax
je     1166 <SafeMemmove+0x46>
movl   $0x0,-0x4(%rbp)
jmp    1195 <SafeMemmove+0x75>
cmpq   $0x0,-0x18(%rbp)
jne    117d <SafeMemmove+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    1195 <SafeMemmove+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memmove@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SafeMemmove>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
call   1030 <SafeMemCheck@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %r15,%r15
je     115d <SafeMemmove+0x3d>
cmp    $0x1,%ecx
jne    115d <SafeMemmove+0x3d>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <memmove@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @SafeMemmove(i8* %0, i8* %1, i64 %2, i8* %3, i8* %4) {
%6 = tail call i32 @SafeMemCheck(i8* %0, i64 %2, i8* %3, i8* %4)
%7 = icmp ne i32 %6, 1
%8 = icmp eq i8* %1, null
%9 = or i1 %8, %7
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = tail call i32 @memmove(i8* %0, i8* %1, i64 %2)
br label %12
12: ; preds = %5, %10
%13 = phi i32 [ 1, %10 ], [ 0, %5 ]
ret i32 %13
}