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


x86 assembly (clang, -O0):
<SafeMemcpy>:
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)
cmpq   $0x0,-0x20(%rbp)
jne    1153 <SafeMemcpy+0x33>
movl   $0x1,-0x4(%rbp)
jmp    11ac <SafeMemcpy+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1030 <SafeMemCheck@plt>
cmp    $0x1,%eax
je     117d <SafeMemcpy+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    11ac <SafeMemcpy+0x8c>
cmpq   $0x0,-0x18(%rbp)
jne    1194 <SafeMemcpy+0x74>
movl   $0x0,-0x4(%rbp)
jmp    11ac <SafeMemcpy+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define i32 @SafeMemcpy(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 i64, i64* %9
%13 = icmp ne i64 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %5
store i32 1, i32* %6
br label %32
15: ; preds = %5
%16 = load i8*, i8** %7
%17 = load i64, i64* %9
%18 = load i8*, i8** %10
%19 = load i8*, i8** %11
%20 = call i32 @SafeMemCheck(i8* %16, i64 %17, i8* %18, i8* %19)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 0, i32* %6
br label %32
23: ; preds = %15
%24 = load i8*, i8** %8
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 0, i32* %6
br label %32
27: ; preds = %23
%28 = load i8*, i8** %7
%29 = load i8*, i8** %8
%30 = load i64, i64* %9
%31 = call i32 @memcpy(i8* %28, i8* %29, i64 %30)
store i32 1, i32* %6
br label %32
32: ; preds = %27, %26, %22, %14
%33 = load i32, i32* %6
ret i32 %33
}

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