#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 *strcpy(char *, char *);
unsigned int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, unsigned int);
char *CutPathname(char *dest, char *src, unsigned int max_len) {
  unsigned int l;
  l = strlen(src);
  if (l <= max_len)
    return (strcpy(dest, src));
  else {
    (void)strcpy(dest, "...");
    (void)strncat(dest, &src[l - max_len + 3], max_len - 3);
    return (dest);
  }
}


x86 assembly (clang, -O0):
<CutPathname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
ja     1171 <CutPathname+0x41>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    11aa <CutPathname+0x7a>
mov    -0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%eax
sub    -0x1c(%rbp),%eax
add    $0x3,%eax
mov    %eax,%eax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
sub    $0x3,%edx
call   1050 <strncat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CutPathname>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
sub    %ebp,%eax
jbe    1167 <CutPathname+0x37>
movl   $0x2e2e2e,(%r14)
add    $0x3,%eax
add    %rax,%rbx
add    $0xfffffffd,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <strncat@plt>
jmp    1172 <CutPathname+0x42>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @CutPathname(i8* returned %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(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 %16
8: ; preds = %3
%9 = bitcast i8* %0 to i32*
store i32 3026478, i32* %9
%10 = sub i32 3, %2
%11 = add i32 %10, %4
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = add i32 %2, -3
%15 = tail call i32 @strncat(i8* %0, i8* %13, i32 %14)
br label %16
16: ; preds = %8, %6
ret i8* %0
}