#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*/ die(char *, int, int, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *hlr_strcpysFunc(char *to, char *from, int toLengthMax) {
  if (strlen(from) > toLengthMax)
    die("hlr_strcpys: overflow: toLengthMax=%d, strlen(from)=%d, "
        "from='%.50s...'",
        toLengthMax, strlen(from), from);
  strcpy(to, from);
  return to;
}


x86 assembly (clang, -O0):
<hlr_strcpysFunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x14(%rbp),%eax
jle    1179 <hlr_strcpysFunc+0x49>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
lea    0xe8c(%rip),%rdi
call   1050 <die@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hlr_strcpysFunc>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jle    1163 <hlr_strcpysFunc+0x33>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xea9(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   1050 <die@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [72 x i8] c"hlr_strcpys: overflow: toLengthMax=%d, strlen(from)=%d, from='%.50s...'\00"
define i8* @hlr_strcpysFunc(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i8*, i8** %5
%8 = call i32 @strlen(i8* %7)
%9 = load i32, i32* %6
%10 = icmp sgt i32 %8, %9
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* %6
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = load i8*, i8** %5
%16 = call i32 @die(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14, i8* %15)
br label %17
17: ; preds = %11, %3
%18 = load i8*, i8** %4
%19 = load i8*, i8** %5
%20 = call i32 @strcpy(i8* %18, i8* %19)
%21 = load i8*, i8** %4
ret i8* %21
}

LLVM IR (-O2):
@.str = [72 x i8] c"hlr_strcpys: overflow: toLengthMax=%d, strlen(from)=%d, from='%.50s...'\00"
define i8* @hlr_strcpysFunc(i8* returned %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, %2
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %1)
%8 = tail call i32 @die(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %7, i8* %1)
br label %9
9: ; preds = %6, %3
%10 = tail call i32 @strcpy(i8* %0, i8* %1)
ret i8* %0
}