#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*/ error_message(int, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
unsigned int strlen(char *);
char *safe_strcat(char *dest, char *orig, unsigned int max_size,
                  char *fname_src, int lines) {
  if ((strlen(dest) + strlen(orig)) > max_size) {
    error_message(47, fname_src, lines);
  }
  strcat(dest, orig);
  return (dest);
}


x86 assembly (clang, -O0):
<safe_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
cmp    -0x14(%rbp),%eax
jbe    1181 <safe_strcat+0x51>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x2f,%edi
call   1040 <error_message@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_strcat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %edx,%r13d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
cmp    %r13d,%eax
jbe    1170 <safe_strcat+0x40>
mov    $0x2f,%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1040 <error_message@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @safe_strcat(i8* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = load i8*, i8** %7
%14 = call i32 @strlen(i8* %13)
%15 = add i32 %12, %14
%16 = load i32, i32* %8
%17 = icmp ugt i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %5
%19 = load i8*, i8** %9
%20 = load i32, i32* %10
%21 = call i32 @error_message(i32 47, i8* %19, i32 %20)
br label %22
22: ; preds = %18, %5
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %6
ret i8* %26
}

LLVM IR (-O2):
define i8* @safe_strcat(i8* returned %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i32 @strlen(i8* %1)
%8 = add i32 %7, %6
%9 = icmp ugt i32 %8, %2
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @error_message(i32 47, i8* %3, i32 %4)
br label %12
12: ; preds = %10, %5
%13 = tail call i32 @strcat(i8* %0, i8* %1)
ret i8* %0
}