#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*/ fprintf(int /*<<< orphan*/, char *, char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
void strcat_s(char *str, int length, char *cat) {
  if (strlen(str) + strlen(cat) + 1 < length) {
    strcat(str, cat);
  } else {
    fprintf(stderr, "error concat oveflow: %s %s > %d", str, cat, length);
  }
}


x86 assembly (clang, -O0):
<strcat_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cmp    -0xc(%rbp),%eax
jge    117d <strcat_s+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
jmp    119e <strcat_s+0x6e>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0xc(%rbp),%r8d
lea    0xe67(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcat_s>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
add    $0x1,%eax
cmp    %r14d,%eax
jge    116e <strcat_s+0x3e>
mov    %rbp,%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <strcat@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
mov    %r14d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"error concat oveflow: %s %s > %d\00"
define void @strcat_s(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 = call i32 @strlen(i8* %7)
%9 = load i8*, i8** %6
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %8, %10
%12 = add nsw i32 %11, 1
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = load i8*, i8** %6
%18 = call i32 @strcat(i8* %16, i8* %17)
br label %25
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %4
%22 = load i8*, i8** %6
%23 = load i32, i32* %5
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22, i32 %23)
br label %25
25: ; preds = %19, %15
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"error concat oveflow: %s %s > %d\00"
define void @strcat_s(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %2)
%6 = add i32 %4, 1
%7 = add i32 %6, %5
%8 = icmp slt i32 %7, %1
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @strcat(i8* %0, i8* %2)
br label %14
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %2, i32 %1)
br label %14
14: ; preds = %11, %9
ret void
}