#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*/ snoopy_error_handler(char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
void snoopy_string_append(char *destString, char *appendThis,
                          int destStringMaxLength) {
  int destStringSize = -1;
  int destStringSizeRemaining = -1;
  int appendThisSize = -1;
  destStringSize = strlen(destString);
  appendThisSize = strlen(appendThis);
  destStringSizeRemaining = destStringMaxLength - destStringSize;
  if (destStringSizeRemaining < appendThisSize) {
    snoopy_error_handler("Maximum destination string size exceeded");
  }
  strcat(&destString[destStringSize], appendThis);
}


x86 assembly (clang, -O0):
<snoopy_string_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1191 <snoopy_string_append+0x61>
lea    0xe74(%rip),%rdi
call   1030 <snoopy_error_handler@plt>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snoopy_string_append>:
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
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %r15d,%ebp
cmp    %eax,%ebp
jge    1162 <snoopy_string_append+0x32>
lea    0xea3(%rip),%rdi
call   1030 <snoopy_error_handler@plt>
movslq %r15d,%rax
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <strcat@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"Maximum destination string size exceeded\00"
define void @snoopy_string_append(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 -1, i32* %7
store i32 -1, i32* %8
store i32 -1, i32* %9
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %7
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %9
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = sub nsw i32 %14, %15
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @snoopy_error_handler(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %3
%23 = load i8*, i8** %4
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8*, i8** %5
%28 = call i32 @strcat(i8* %26, i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"Maximum destination string size exceeded\00"
define void @snoopy_string_append(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = sub nsw i32 %2, %4
%7 = icmp slt i32 %6, %5
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @snoopy_error_handler(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
%11 = sext i32 %4 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = tail call i32 @strcat(i8* %12, i8* %1)
ret void
}