#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*/ Sys_Error(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void Q_strncpyz2(char *dst, const char *src, int dstSize) {
  if (!dst)
    Sys_Error(0, "Q_strncpyz: NULL dst");
  if (!src)
    Sys_Error(0, "Q_strncpyz: NULL src");
  if (dstSize < 1)
    Sys_Error(0, "Q_strncpyz: dstSize < 1");
  strncpy(dst, src, dstSize - 1);
  dst[dstSize - 1] = 0;
}


x86 assembly (clang, -O0):
<Q_strncpyz2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114c <Q_strncpyz2+0x2c>
xor    %edi,%edi
lea    0xeb9(%rip),%rsi
call   1030 <Sys_Error@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1165 <Q_strncpyz2+0x45>
xor    %edi,%edi
lea    0xeb5(%rip),%rsi
call   1030 <Sys_Error@plt>
cmpl   $0x1,-0x14(%rbp)
jge    117d <Q_strncpyz2+0x5d>
xor    %edi,%edi
lea    0xeb2(%rip),%rsi
call   1030 <Sys_Error@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Q_strncpyz2>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     1156 <Q_strncpyz2+0x36>
test   %r14,%r14
je     1169 <Q_strncpyz2+0x49>
test   %ebp,%ebp
jle    117b <Q_strncpyz2+0x5b>
movslq %ebp,%rbp
lea    -0x1(%rbp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strncpy@plt>
movb   $0x0,-0x1(%rbx,%rbp,1)
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xea3(%rip),%rsi
xor    %edi,%edi
call   1030 <Sys_Error@plt>
test   %r14,%r14
jne    1136 <Q_strncpyz2+0x16>
lea    0xea5(%rip),%rsi
xor    %edi,%edi
call   1030 <Sys_Error@plt>
test   %ebp,%ebp
jg     113a <Q_strncpyz2+0x1a>
lea    0xea8(%rip),%rsi
xor    %edi,%edi
call   1030 <Sys_Error@plt>
jmp    113a <Q_strncpyz2+0x1a>

LLVM IR (-O0):
@.str = [21 x i8] c"Q_strncpyz: NULL dst\00"
@.str.1 = [21 x i8] c"Q_strncpyz: NULL src\00"
@.str.2 = [24 x i8] c"Q_strncpyz: dstSize < 1\00"
define void @Q_strncpyz2(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** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = call i32 @Sys_Error(i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %3
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @Sys_Error(i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @Sys_Error(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%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* %6
%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
ret void
}

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