#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*/ Q_strcat(char *, int, char const *);
int /*<<< orphan*/ Q_strncpyz(char *, char const *, int);
int strlen(char const *);
void Com_TruncateLongString(char *buffer, const char *s) {
  int length = strlen(s);
  if (length <= 64) {
    Q_strncpyz(buffer, s, 64);
  } else {
    Q_strncpyz(buffer, s, (64 / 2) - 3);
    Q_strcat(buffer, 64, " ... ");
    Q_strcat(buffer, 64, s + length - (64 / 2) + 3);
  }
}


x86 assembly (clang, -O0):
<Com_TruncateLongString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x40,-0x14(%rbp)
jg     116d <Com_TruncateLongString+0x3d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1050 <Q_strncpyz@plt>
jmp    11b5 <Com_TruncateLongString+0x85>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1d,%edx
call   1050 <Q_strncpyz@plt>
mov    -0x8(%rbp),%rdi
mov    $0x40,%esi
lea    0xe71(%rip),%rdx
call   1040 <Q_strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x14(%rbp),%rax
add    %rax,%rdx
add    $0xffffffffffffffe0,%rdx
add    $0x3,%rdx
mov    $0x40,%esi
call   1040 <Q_strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Com_TruncateLongString>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    $0x40,%eax
jg     115b <Com_TruncateLongString+0x2b>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x40,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <Q_strncpyz@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1d,%edx
call   1050 <Q_strncpyz@plt>
lea    0xe8c(%rip),%rdx
mov    %r14,%rdi
mov    $0x40,%esi
call   1040 <Q_strcat@plt>
mov    %ebp,%eax
lea    (%rbx,%rax,1),%rdx
add    $0xffffffffffffffe3,%rdx
mov    %r14,%rdi
mov    $0x40,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <Q_strcat@plt>

LLVM IR (-O0):
@.str = [6 x i8] c" ... \00"
define void @Com_TruncateLongString(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sle i32 %8, 64
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load i8*, i8** %4
%13 = call i32 @Q_strncpyz(i8* %11, i8* %12, i32 64)
br label %28
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = call i32 @Q_strncpyz(i8* %15, i8* %16, i32 29)
%18 = load i8*, i8** %3
%19 = call i32 @Q_strcat(i8* %18, i32 64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 -32
%26 = getelementptr inbounds i8, i8* %25, i64 3
%27 = call i32 @Q_strcat(i8* %20, i32 64, i8* %26)
br label %28
28: ; preds = %14, %10
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c" ... \00"
define void @Com_TruncateLongString(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp slt i32 %3, 65
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @Q_strncpyz(i8* %0, i8* %1, i32 64)
br label %15
7: ; preds = %2
%8 = tail call i32 @Q_strncpyz(i8* %0, i8* %1, i32 29)
%9 = tail call i32 @Q_strcat(i8* %0, i32 64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = zext i32 %3 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -32
%13 = getelementptr inbounds i8, i8* %12, i64 3
%14 = tail call i32 @Q_strcat(i8* %0, i32 64, i8* %13)
br label %15
15: ; preds = %7, %5
ret void
}