#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 scalar_t__ int64_t;

/* Variables and functions */
scalar_t__ __asan_buffspace(char *);
scalar_t__ __asan_strlen(char const *);
bool check_strcpy(char *dest, const char *src) {
  int64_t length = __asan_strlen(src);
  if (length < 0)
    return false;
  if (length >= __asan_buffspace(dest))
    return false;
  if (dest <= src && dest + length >= src)
    return false;
  return true;
}


x86 assembly (clang, -O0):
<check_strcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <__asan_strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1154 <check_strcpy+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <check_strcpy+0x94>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <__asan_buffspace@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jl     1181 <check_strcpy+0x61>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <check_strcpy+0x94>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
ja     11ad <check_strcpy+0x8d>
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     11ad <check_strcpy+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <check_strcpy+0x94>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_strcpy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <__asan_strlen@plt>
xor    %r15d,%r15d
test   %rax,%rax
js     1162 <check_strcpy+0x42>
mov    %rax,%rbp
mov    %r14,%rdi
call   1030 <__asan_buffspace@plt>
cmp    %rax,%rbp
jge    1162 <check_strcpy+0x42>
cmp    %rbx,%r14
seta   %al
add    %r14,%rbp
cmp    %rbx,%rbp
setb   %cl
or     %al,%cl
movzbl %cl,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_strcpy(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @__asan_strlen(i8* %7)
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %30
12: ; preds = %2
%13 = load i64, i64* %6
%14 = load i8*, i8** %4
%15 = call i64 @__asan_buffspace(i8* %14)
%16 = icmp sge i64 %13, %15
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 0, i32* %3
br label %30
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = icmp ule i8* %19, %20
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = load i64, i64* %6
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8*, i8** %5
%27 = icmp uge i8* %25, %26
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 0, i32* %3
br label %30
29: ; preds = %22, %18
store i32 1, i32* %3
br label %30
30: ; preds = %29, %28, %17, %11
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @check_strcpy(i8* %0, i8* %1) {
%3 = tail call i64 @__asan_strlen(i8* %1)
%4 = icmp slt i64 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i64 @__asan_buffspace(i8* %0)
%7 = icmp slt i64 %3, %6
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = icmp ugt i8* %0, %1
%10 = getelementptr inbounds i8, i8* %0, i64 %3
%11 = icmp ult i8* %10, %1
%12 = select i1 %9, i1 true, i1 %11
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %8, %5, %2
%15 = phi i32 [ 0, %2 ], [ 0, %5 ], [ %13, %8 ]
ret i32 %15
}