#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 */
scalar_t__ isalnum(unsigned char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void str_cutoff(char *s, int limit) {
  int ln;
  unsigned char *p;
  ln = strlen(s);
  if (ln < limit)
    return;
  p = (unsigned char *)(s + limit - 3);
  while (p > (unsigned char *)s && isalnum(*p))
    p--;
  if (p == (unsigned char *)s)
    p = (unsigned char *)(s + limit - 3);
  strcpy((char *)p, "...");
}


x86 assembly (clang, -O0):
<str_cutoff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    115c <str_cutoff+0x2c>
jmp    11ea <str_cutoff+0xba>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0xfffffffffffffffd,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jbe    1198 <str_cutoff+0x68>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a8 <str_cutoff+0x78>
jmp    11b9 <str_cutoff+0x89>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    116f <str_cutoff+0x3f>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11da <str_cutoff+0xaa>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0xfffffffffffffffd,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cutoff>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%rbp
call   1040 <strlen@plt>
cmp    %ebx,%eax
jge    1147 <str_cutoff+0x17>
pop    %rbx
pop    %r14
pop    %rbp
ret
movslq %ebx,%rax
lea    (%rax,%rbp,1),%r14
add    $0xfffffffffffffffd,%r14
mov    %r14,%rbx
cmp    %rbp,%r14
jbe    1179 <str_cutoff+0x49>
mov    %r14,%rbx
nopl   (%rax)
movzbl (%rbx),%edi
call   1050 <isalnum@plt>
test   %rax,%rax
je     1179 <str_cutoff+0x49>
add    $0xffffffffffffffff,%rbx
cmp    %rbp,%rbx
ja     1160 <str_cutoff+0x30>
mov    %rbp,%rbx
cmp    %rbp,%rbx
cmovne %rbx,%r14
lea    0xe79(%rip),%rsi
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"...\00"
define void @str_cutoff(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %2
br label %46
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -3
store i8* %18, i8** %6
br label %19
19: ; preds = %30, %13
%20 = load i8*, i8** %6
%21 = load i8*, i8** %3
%22 = icmp ugt i8* %20, %21
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = call i64 @isalnum(i8 zeroext %25)
%27 = icmp ne i64 %26, 0
br label %28
28: ; preds = %23, %19
%29 = phi i1 [ false, %19 ], [ %27, %23 ]
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %6
br label %19
33: ; preds = %28
%34 = load i8*, i8** %6
%35 = load i8*, i8** %3
%36 = icmp eq i8* %34, %35
br i1 %36, label %37, label %43
37: ; preds = %33
%38 = load i8*, i8** %3
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 -3
store i8* %42, i8** %6
br label %43
43: ; preds = %37, %33
%44 = load i8*, i8** %6
%45 = call i32 @strcpy(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %46
46: ; preds = %43, %12
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"...\00"
define void @str_cutoff(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp slt i32 %3, %1
br i1 %4, label %23, label %5
5: ; preds = %2
%6 = sext i32 %1 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 -3
%9 = icmp ugt i8* %8, %0
br i1 %9, label %10, label %18
10: ; preds = %5, %15
%11 = phi i8* [ %16, %15 ], [ %8, %5 ]
%12 = load i8, i8* %11
%13 = tail call i64 @isalnum(i8 zeroext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = getelementptr inbounds i8, i8* %11, i64 -1
%17 = icmp ugt i8* %16, %0
br i1 %17, label %10, label %18
18: ; preds = %10, %15, %5
%19 = phi i8* [ %8, %5 ], [ %0, %15 ], [ %11, %10 ]
%20 = icmp eq i8* %19, %0
%21 = select i1 %20, i8* %8, i8* %19
%22 = tail call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %2, %18
ret void
}