char *shortenstring(s, m)
register const char *s;
int m;
{
  int l;
  static char buf[203 + 1];
  l = strlen(s);
  if (l < m)
    return (char *)s;
  if (m > 203)
    m = 203;
  else if (m < 10) {
    if (m < 5) {
      strncpy(buf, s, m);
      buf[m] = '\0';
      return buf;
    }
    strncpy(buf, s, m - 3);
    strcpy(buf + m - 3, "...");
    return buf;
  }
  m = (m - 3) / 2;
  strncpy(buf, s, m);
  strcpy(buf + m, "...");
  strcpy(buf + m + 3, s + l - m);
  return buf;
}


x86 assembly (clang, -O0):
<shortenstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1164 <shortenstring+0x34>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1288 <shortenstring+0x158>
cmpl   $0xcb,-0x14(%rbp)
jle    117d <shortenstring+0x4d>
movl   $0xcb,-0x14(%rbp)
jmp    1210 <shortenstring+0xe0>
cmpl   $0xa,-0x14(%rbp)
jge    120b <shortenstring+0xdb>
cmpl   $0x5,-0x14(%rbp)
jge    11c4 <shortenstring+0x94>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rdx
lea    0x2eb0(%rip),%rdi
call   1030 <strncpy@plt>
movslq -0x14(%rbp),%rcx
lea    0x2ea0(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e95(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1288 <shortenstring+0x158>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
movslq %eax,%rdx
lea    0x2e78(%rip),%rdi
call   1030 <strncpy@plt>
movslq -0x14(%rbp),%rax
lea    0x2e68(%rip),%rdi
add    %rax,%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xe0a(%rip),%rsi
call   1040 <strcpy@plt>
lea    0x2e4e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1288 <shortenstring+0x158>
jmp    1210 <shortenstring+0xe0>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rdx
lea    0x2e20(%rip),%rdi
call   1030 <strncpy@plt>
movslq -0x14(%rbp),%rax
lea    0x2e10(%rip),%rdi
add    %rax,%rdi
lea    0xdb6(%rip),%rsi
call   1040 <strcpy@plt>
movslq -0x14(%rbp),%rax
lea    0x2df6(%rip),%rdi
add    %rax,%rdi
add    $0x3,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
movslq -0x14(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rsi
call   1040 <strcpy@plt>
lea    0x2dcc(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shortenstring>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %rax,%r14
cmp    %r12d,%r14d
jl     11cf <shortenstring+0x9f>
mov    $0xcb,%ebx
cmp    $0xcb,%r12d
jg     118e <shortenstring+0x5e>
cmp    $0x9,%r12d
jg     118b <shortenstring+0x5b>
cmp    $0x4,%r12d
jg     11de <shortenstring+0xae>
movslq %r12d,%rbx
lea    0x2edd(%rip),%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%r14,1)
mov    %r14,%r15
jmp    11cf <shortenstring+0x9f>
mov    %r12d,%ebx
add    $0xfd,%ebx
shr    %ebx
and    $0x7f,%ebx
lea    0x2eb0(%rip),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movl   $0x2e2e2e,(%rbx,%r12,1)
lea    (%rbx,%r12,1),%rdi
add    $0x3,%rdi
movslq %r14d,%rsi
add    %r15,%rsi
sub    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r12,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    -0x3(%r12),%edx
lea    0x2e66(%rip),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strncpy@plt>
mov    %r12d,%eax
movl   $0x2e2e2e,-0x3(%rax,%rbx,1)
mov    %rbx,%r15
jmp    11cf <shortenstring+0x9f>

LLVM IR (-O0):
@shortenstring.buf = internal global [204 x i8] zeroinitializer
@.str = [4 x i8] c"...\00"
define i8* @shortenstring(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i8*, i8** %4
store i8* %14, i8** %3
br label %70
15: ; preds = %2
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 203
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 203, i32* %5
br label %45
19: ; preds = %15
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 10
br i1 %21, label %22, label %44
22: ; preds = %19
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 5
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = call i8* @strncpy(i8* getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i8* %26, i64 %28)
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 %31
store i8 0, i8* %32
store i8* getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i8** %3
br label %70
33: ; preds = %22
%34 = load i8*, i8** %4
%35 = load i32, i32* %5
%36 = sub nsw i32 %35, 3
%37 = sext i32 %36 to i64
%38 = call i8* @strncpy(i8* getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i8* %34, i64 %37)
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 -3
%43 = call i8* @strcpy(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i8** %3
br label %70
44: ; preds = %19
br label %45
45: ; preds = %44, %18
%46 = load i32, i32* %5
%47 = sub nsw i32 %46, 3
%48 = sdiv i32 %47, 2
store i32 %48, i32* %5
%49 = load i8*, i8** %4
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = call i8* @strncpy(i8* getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i8* %49, i64 %51)
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i64 %54
%56 = call i8* @strcpy(i8* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i64 %58
%60 = getelementptr inbounds i8, i8* %59, i64 3
%61 = load i8*, i8** %4
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = sub i64 0, %66
%68 = getelementptr inbounds i8, i8* %64, i64 %67
%69 = call i8* @strcpy(i8* %60, i8* %68)
store i8* getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i8** %3
br label %70
70: ; preds = %45, %33, %25, %13
%71 = load i8*, i8** %3
ret i8* %71
}

LLVM IR (-O2):
@shortenstring.buf = internal global [204 x i8] zeroinitializer
define i8* @shortenstring(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = icmp slt i32 %4, %1
br i1 %5, label %40, label %6
6: ; preds = %2
%7 = icmp sgt i32 %1, 203
br i1 %7, label %24, label %8
8: ; preds = %6
%9 = icmp slt i32 %1, 10
br i1 %9, label %10, label %24
10: ; preds = %8
%11 = icmp slt i32 %1, 5
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = sext i32 %1 to i64
%14 = tail call i8* @strncpy(i8* dereferenceable(1) getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i8* %0, i64 %13)
%15 = getelementptr inbounds [204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 %13
store i8 0, i8* %15
br label %40
16: ; preds = %10
%17 = add nsw i32 %1, -3
%18 = zext i32 %17 to i64
%19 = tail call i8* @strncpy(i8* dereferenceable(1) getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i8* %0, i64 %18)
%20 = zext i32 %1 to i64
%21 = getelementptr inbounds [204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 -3
%23 = bitcast i8* %22 to i32*
store i32 3026478, i32* %23
br label %40
24: ; preds = %6, %8
%25 = phi i32 [ %1, %8 ], [ 203, %6 ]
%26 = add nuw nsw i32 %25, 253
%27 = lshr i32 %26, 1
%28 = and i32 %27, 127
%29 = zext i32 %28 to i64
%30 = tail call i8* @strncpy(i8* dereferenceable(1) getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), i8* %0, i64 %29)
%31 = getelementptr inbounds [204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 %29
%32 = bitcast i8* %31 to i32*
store i32 3026478, i32* %32
%33 = getelementptr inbounds i8, i8* %31, i64 3
%34 = shl i64 %3, 32
%35 = ashr exact i64 %34, 32
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = sub nsw i64 0, %29
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = tail call i8* @strcpy(i8* %33, i8* dereferenceable(1) %38)
br label %40
40: ; preds = %2, %24, %16, %12
%41 = phi i8* [ getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), %24 ], [ getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), %12 ], [ getelementptr inbounds ([204 x i8], [204 x i8]* @shortenstring.buf, i64 0, i64 0), %16 ], [ %0, %2 ]
ret i8* %41
}