#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 const *,
                           char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
void strconcat(char *buffer, const char *a, const char *b, size_t max_len) {
  int la, lb;
  la = strlen(a);
  lb = strlen(b);
  if (la + lb >= max_len)
    fprintf(stderr, "Error: max length overflow at concat: %s%s\n", a, b);
  strcpy(buffer, a);
  strcpy(buffer + la, b);
}


x86 assembly (clang, -O0):
<strconcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
cltq
cmp    -0x20(%rbp),%rax
jb     118f <strconcat+0x5f>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strconcat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %ebp,%eax
cltq
cmp    %r12,%rax
jb     117a <strconcat+0x4a>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
movslq %ebp,%rdi
add    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"Error: max length overflow at concat: %s%s\0A\00"
define void @strconcat(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %9
%13 = load i8*, i8** %7
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %10
%15 = load i32, i32* %9
%16 = load i32, i32* %10
%17 = add nsw i32 %15, %16
%18 = sext i32 %17 to i64
%19 = load i64, i64* %8
%20 = icmp uge i64 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %4
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %24)
br label %26
26: ; preds = %21, %4
%27 = load i8*, i8** %5
%28 = load i8*, i8** %6
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8*, i8** %5
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8*, i8** %7
%35 = call i32 @strcpy(i8* %33, i8* %34)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"Error: max length overflow at concat: %s%s\0A\00"
define void @strconcat(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @strlen(i8* %2)
%7 = add nsw i32 %6, %5
%8 = sext i32 %7 to i64
%9 = icmp ult i64 %8, %3
br i1 %9, label %13, label %10
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
br label %13
13: ; preds = %10, %4
%14 = tail call i32 @strcpy(i8* %0, i8* %1)
%15 = sext i32 %5 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = tail call i32 @strcpy(i8* %16, i8* %2)
ret void
}