#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*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int strncat_delimit(char *dest, char *src) {
  char tmp[2048];
  assert(2048 >= 3);
  strncpy(tmp, "; ", 2048);
  if (strlen(src) > (2048 - strlen(dest) - strlen(tmp) - 1))
    fprintf(stderr, "Value Truncated: %s, Increase MAX_VAL_LEN\n", src);
  strncat(tmp, src, 2048 - strlen(tmp) - 1);
  strncat(dest, tmp, 2048 - strlen(dest) - 1);
  return 0;
}


x86 assembly (clang, -O0):
<strncat_delimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1060 <assert@plt>
lea    -0x810(%rbp),%rdi
lea    0xe85(%rip),%rsi
mov    $0x800,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x814(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0x800,%eax
sub    %ecx,%eax
mov    %eax,-0x818(%rbp)
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x818(%rbp),%ecx
mov    %eax,%edx
mov    -0x814(%rbp),%eax
sub    %edx,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    11ec <strncat_delimit+0x9c>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe1c(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x810(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x830(%rbp)
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x838(%rbp),%rdi
mov    -0x830(%rbp),%rsi
mov    $0x800,%edx
sub    %eax,%edx
sub    $0x1,%edx
call   1050 <strncat@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x828(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x820(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x828(%rbp),%rdi
mov    -0x820(%rbp),%rsi
mov    $0x800,%edx
sub    %eax,%edx
sub    $0x1,%edx
call   1050 <strncat@plt>
xor    %eax,%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncat_delimit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x1,%edi
call   1060 <assert@plt>
lea    0xe8a(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x800,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1040 <strlen@plt>
add    %ebp,%eax
mov    $0x7ff,%ebp
mov    $0x7ff,%ecx
sub    %eax,%ecx
cmp    %ecx,%ebx
jle    11cc <strncat_delimit+0x7c>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x7ff,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strncat@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <strncat@plt>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"; \00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Value Truncated: %s, Increase MAX_VAL_LEN\0A\00"
define i32 @strncat_delimit(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [2048 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i32 @assert(i32 1)
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%8 = call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2048)
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 2048, %12
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %13, %15
%17 = sub nsw i32 %16, 1
%18 = icmp sgt i32 %10, %17
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %4
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %2
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%25 = load i8*, i8** %4
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 2048, %27
%29 = sub nsw i32 %28, 1
%30 = call i32 @strncat(i8* %24, i8* %25, i32 %29)
%31 = load i8*, i8** %3
%32 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%33 = load i8*, i8** %3
%34 = call i32 @strlen(i8* %33)
%35 = sub nsw i32 2048, %34
%36 = sub nsw i32 %35, 1
%37 = call i32 @strncat(i8* %31, i8* %32, i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"; \00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Value Truncated: %s, Increase MAX_VAL_LEN\0A\00"
define i32 @strncat_delimit(i8* %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @assert(i32 1)
%6 = call i32 @strncpy(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2048)
%7 = call i32 @strlen(i8* %1)
%8 = call i32 @strlen(i8* %0)
%9 = call i32 @strlen(i8* %4)
%10 = add i32 %8, %9
%11 = sub i32 2047, %10
%12 = icmp sgt i32 %7, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %16
16: ; preds = %13, %2
%17 = call i32 @strlen(i8* %4)
%18 = sub i32 2047, %17
%19 = call i32 @strncat(i8* %4, i8* %1, i32 %18)
%20 = call i32 @strlen(i8* %0)
%21 = sub i32 2047, %20
%22 = call i32 @strncat(i8* %0, i8* %4, i32 %21)
ret i32 0
}