#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 */
char *StrLeft(char *, unsigned int);
unsigned int StrVisualLength(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *strcpy(char *, char *);
char *CutFilename(char *dest, char *src, unsigned int max_len) {
  unsigned int l;
  char *tmp;
  l = StrVisualLength(src);
  if (l <= max_len)
    return (strcpy(dest, src));
  else {
    tmp = StrLeft(src, max_len - 3);
    sprintf(dest, "%s...", tmp);
    free(tmp);
    return (dest);
  }
}


x86 assembly (clang, -O0):
<CutFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <StrVisualLength@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
ja     1191 <CutFilename+0x41>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    11c9 <CutFilename+0x79>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x3,%esi
call   1060 <StrLeft@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe4d(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CutFilename>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <StrVisualLength@plt>
cmp    %ebp,%eax
jbe    1194 <CutFilename+0x44>
add    $0xfffffffd,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <StrLeft@plt>
mov    %rax,%rbx
lea    0xe81(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    119f <CutFilename+0x4f>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s...\00"
define i8* @CutFilename(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = call i32 @StrVisualLength(i8* %10)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = load i32, i32* %7
%14 = icmp ule i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = call i8* @strcpy(i8* %16, i8* %17)
store i8* %18, i8** %4
br label %30
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = sub i32 %21, 3
%23 = call i8* @StrLeft(i8* %20, i32 %22)
store i8* %23, i8** %9
%24 = load i8*, i8** %5
%25 = load i8*, i8** %9
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %9
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %5
store i8* %29, i8** %4
br label %30
30: ; preds = %19, %15
%31 = load i8*, i8** %4
ret i8* %31
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s...\00"
define i8* @CutFilename(i8* returned %0, i8* %1, i32 %2) {
%4 = tail call i32 @StrVisualLength(i8* %1)
%5 = icmp ugt i32 %4, %2
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i8* @strcpy(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
br label %13
8: ; preds = %3
%9 = add i32 %2, -3
%10 = tail call i8* @StrLeft(i8* %1, i32 %9)
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @free(i8* %10)
br label %13
13: ; preds = %8, %6
ret i8* %0
}