#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*/ Q_strncpyz2(char *, char const *, int);
int /*<<< orphan*/ Sys_Error(int /*<<< orphan*/, char *);
int strlen(char *);
void Q_strcat(char *dst, const char *src, int dstSize) {
  int len;
  len = strlen(dst);
  if (len >= dstSize)
    Sys_Error(0, "Q_strcat: already overflowed");
  Q_strncpyz2(dst + len, src, dstSize - len);
}


x86 assembly (clang, -O0):
<Q_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1169 <Q_strcat+0x39>
xor    %edi,%edi
lea    0xe9c(%rip),%rsi
call   1030 <Sys_Error@plt>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
call   1050 <Q_strncpyz2@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Q_strcat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r15d
cmp    %ebp,%eax
jl     1159 <Q_strcat+0x29>
lea    0xeae(%rip),%rsi
xor    %edi,%edi
call   1030 <Sys_Error@plt>
movslq %r15d,%rax
add    %rax,%rbx
sub    %r15d,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <Q_strncpyz2@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Q_strcat: already overflowed\00"
define void @Q_strcat(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @Sys_Error(i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = load i8*, i8** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = sub nsw i32 %21, %22
%24 = call i32 @Q_strncpyz2(i8* %19, i8* %20, i32 %23)
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Q_strcat: already overflowed\00"
define void @Q_strcat(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %4, %2
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @Sys_Error(i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = sext i32 %4 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = sub nsw i32 %2, %4
%12 = tail call i32 @Q_strncpyz2(i8* %10, i8* %1, i32 %11)
ret void
}