#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*/ Com_Printf(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void Com_strcpy(char *dest, int destSize, const char *src) {
  if (!dest) {
    Com_Printf("Com_strcpy: NULL dst\n");
    return;
  }
  if (!src) {
    Com_Printf("Com_strcpy: NULL src\n");
    return;
  }
  if (destSize < 1) {
    Com_Printf("Com_strcpy: dstSize < 1\n");
    return;
  }
  strncpy(dest, src, destSize - 1);
  dest[destSize - 1] = 0;
}


x86 assembly (clang, -O0):
<Com_strcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114f <Com_strcpy+0x2f>
lea    0xebb(%rip),%rdi
call   1040 <Com_Printf@plt>
jmp    11aa <Com_strcpy+0x8a>
cmpq   $0x0,-0x18(%rbp)
jne    116b <Com_strcpy+0x4b>
lea    0xeb5(%rip),%rdi
call   1040 <Com_Printf@plt>
jmp    11aa <Com_strcpy+0x8a>
cmpl   $0x1,-0xc(%rbp)
jge    1186 <Com_strcpy+0x66>
lea    0xeb0(%rip),%rdi
call   1040 <Com_Printf@plt>
jmp    11aa <Com_strcpy+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Com_strcpy>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1154 <Com_strcpy+0x34>
test   %rdx,%rdx
je     115d <Com_strcpy+0x3d>
mov    %esi,%r14d
test   %esi,%esi
jle    1166 <Com_strcpy+0x46>
mov    %rdi,%rbx
add    $0xffffffff,%r14d
mov    %rdx,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xea5(%rip),%rdi
jmp    116d <Com_strcpy+0x4d>
lea    0xeb2(%rip),%rdi
jmp    116d <Com_strcpy+0x4d>
lea    0xebf(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <Com_Printf@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Com_strcpy: NULL dst\0A\00"
@.str.1 = [22 x i8] c"Com_strcpy: NULL src\0A\00"
@.str.2 = [25 x i8] c"Com_strcpy: dstSize < 1\0A\00"
define void @Com_strcpy(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = call i32 @Com_Printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %32
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @Com_Printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %32
16: ; preds = %11
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @Com_Printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %32
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i8*, i8** %6
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = call i32 @strncpy(i8* %22, i8* %23, i32 %25)
%27 = load i8*, i8** %4
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %21, %19, %14, %9
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Com_strcpy: NULL dst\0A\00"
@.str.1 = [22 x i8] c"Com_strcpy: NULL src\0A\00"
@.str.2 = [25 x i8] c"Com_strcpy: dstSize < 1\0A\00"
define void @Com_strcpy(i8* %0, i32 %1, i8* %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @Com_Printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %20
7: ; preds = %3
%8 = icmp eq i8* %2, null
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @Com_Printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %20
11: ; preds = %7
%12 = icmp slt i32 %1, 1
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 @Com_Printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %20
15: ; preds = %11
%16 = add nsw i32 %1, -1
%17 = tail call i32 @strncpy(i8* %0, i8* %2, i32 %16)
%18 = zext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %15, %13, %9, %5
ret void
}