#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*/ memset(char *, char, int);
size_t strlen(char *);
void blog_show_post_shorten(char *content, size_t newlen) {
  size_t len = strlen(content);
  if (len - 3 < newlen) {
    newlen = len - 3;
  }
  memset((char *)(content + newlen), '\0', len - newlen);
  if (newlen >= 3)
    memset((char *)(content + newlen - 3), '.', 3);
}


x86 assembly (clang, -O0):
<blog_show_post_shorten>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x3,%rax
cmp    -0x10(%rbp),%rax
jae    115b <blog_show_post_shorten+0x3b>
mov    -0x18(%rbp),%rax
sub    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
cmpq   $0x3,-0x10(%rbp)
jb     119a <blog_show_post_shorten+0x7a>
mov    -0x8(%rbp),%rdi
add    -0x10(%rbp),%rdi
add    $0xfffffffffffffffd,%rdi
mov    $0x2e,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blog_show_post_shorten>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    -0x3(%rax),%rcx
cmp    %rbx,%rcx
cmovb  %rcx,%rbx
add    %rbx,%r14
sub    %ebx,%eax
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1040 <memset@plt>
cmp    $0x3,%rbx
jb     116e <blog_show_post_shorten+0x4e>
add    $0xfffffffffffffffd,%r14
mov    %r14,%rdi
mov    $0x2e,%esi
mov    $0x3,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <memset@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @blog_show_post_shorten(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = sub i64 %8, 3
%10 = load i64, i64* %4
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i64, i64* %5
%14 = sub i64 %13, 3
store i64 %14, i64* %4
br label %15
15: ; preds = %12, %2
%16 = load i8*, i8** %3
%17 = load i64, i64* %4
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i64, i64* %5
%20 = load i64, i64* %4
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = call i32 @memset(i8* %18, i8 signext 0, i32 %22)
%24 = load i64, i64* %4
%25 = icmp uge i64 %24, 3
br i1 %25, label %26, label %32
26: ; preds = %15
%27 = load i8*, i8** %3
%28 = load i64, i64* %4
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = getelementptr inbounds i8, i8* %29, i64 -3
%31 = call i32 @memset(i8* %30, i8 signext 46, i32 3)
br label %32
32: ; preds = %26, %15
ret void
}

LLVM IR (-O2):
define void @blog_show_post_shorten(i8* %0, i64 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add i64 %3, -3
%5 = icmp ult i64 %4, %1
%6 = select i1 %5, i64 %4, i64 %1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = sub i64 %3, %6
%9 = trunc i64 %8 to i32
%10 = tail call i32 @memset(i8* %7, i8 signext 0, i32 %9)
%11 = icmp ugt i64 %6, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = getelementptr inbounds i8, i8* %7, i64 -3
%14 = tail call i32 @memset(i8* %13, i8 signext 46, i32 3)
br label %15
15: ; preds = %12, %2
ret void
}