#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*/ memcpy(char *, char *, int);
int strlen(char *);
char *shorten_filename(char *in, int max_len) {
  static char buffer[4096];
  int len = strlen(in);
  int cutlen, dummy;
  assert(max_len >= 0);
  if (len <= max_len)
    return in;
  cutlen = (max_len - 3) / 2;
  memcpy(buffer, in, cutlen);
  memcpy(&buffer[cutlen], "...", 3);
  dummy = max_len - (cutlen + 3);
  memcpy(&buffer[cutlen + 3], &in[len - dummy], dummy + 1);
  return buffer;
}


x86 assembly (clang, -O0):
<shorten_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1175 <shorten_filename+0x45>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11fd <shorten_filename+0xcd>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0x2ebc(%rip),%rdi
call   1050 <memcpy@plt>
movslq -0x1c(%rbp),%rax
lea    0x2eac(%rip),%rdi
add    %rax,%rdi
lea    0xe52(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x3,%ecx
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x3,%eax
cltq
lea    0x2e7b(%rip),%rdi
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%eax
sub    -0x20(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
lea    0x2e57(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shorten_filename>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %ebx,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
cmp    %ebx,%r12d
jle    11b4 <shorten_filename+0x84>
lea    -0x3(%rbx),%eax
shr    $0x1f,%eax
lea    (%rbx,%rax,1),%ebp
add    $0xfffffffd,%ebp
sar    %ebp
lea    0x2ee5(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rbp
lea    (%r15,%rbp,1),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcpy@plt>
sub    %ebp,%ebx
lea    (%r15,%rbp,1),%rdi
add    $0x3,%rdi
sub    %ebx,%r12d
add    $0x3,%r12d
movslq %r12d,%rsi
add    %r14,%rsi
add    $0xfffffffe,%ebx
mov    %ebx,%edx
call   1050 <memcpy@plt>
mov    %r15,%r14
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@shorten_filename.buffer = internal global [4096 x i8] zeroinitializer
@.str = [4 x i8] c"...\00"
define i8* @shorten_filename(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = load i8*, i8** %4
store i8* %19, i8** %3
br label %48
20: ; preds = %2
%21 = load i32, i32* %5
%22 = sub nsw i32 %21, 3
%23 = sdiv i32 %22, 2
store i32 %23, i32* %7
%24 = load i8*, i8** %4
%25 = load i32, i32* %7
%26 = call i32 @memcpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @shorten_filename.buffer, i64 0, i64 0), i8* %24, i32 %25)
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* @shorten_filename.buffer, i64 0, i64 %28
%30 = call i32 @memcpy(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%31 = load i32, i32* %5
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 3
%34 = sub nsw i32 %31, %33
store i32 %34, i32* %8
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* @shorten_filename.buffer, i64 0, i64 %37
%39 = load i8*, i8** %4
%40 = load i32, i32* %6
%41 = load i32, i32* %8
%42 = sub nsw i32 %40, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %39, i64 %43
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
%47 = call i32 @memcpy(i8* %38, i8* %44, i32 %46)
store i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @shorten_filename.buffer, i64 0, i64 0), i8** %3
br label %48
48: ; preds = %20, %18
%49 = load i8*, i8** %3
ret i8* %49
}

LLVM IR (-O2):
@shorten_filename.buffer = internal global [4096 x i8] zeroinitializer
@.str = [4 x i8] c"...\00"
define i8* @shorten_filename(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = xor i32 %1, -1
%5 = lshr i32 %4, 31
%6 = tail call i32 @assert(i32 %5)
%7 = icmp sgt i32 %3, %1
br i1 %7, label %8, label %24
8: ; preds = %2
%9 = add nsw i32 %1, -3
%10 = sdiv i32 %9, 2
%11 = tail call i32 @memcpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @shorten_filename.buffer, i64 0, i64 0), i8* %0, i32 %10)
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* @shorten_filename.buffer, i64 0, i64 %12
%14 = tail call i32 @memcpy(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%15 = add nsw i32 %10, 3
%16 = sub nsw i32 %1, %15
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* @shorten_filename.buffer, i64 0, i64 %17
%19 = sub nsw i32 %3, %16
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = add nsw i32 %16, 1
%23 = tail call i32 @memcpy(i8* %18, i8* %21, i32 %22)
br label %24
24: ; preds = %2, %8
%25 = phi i8* [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @shorten_filename.buffer, i64 0, i64 0), %8 ], [ %0, %2 ]
ret i8* %25
}