#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*/ strcpy(char *, char *);
int strlen(char *);
void certsizelimit(char *s, int l) {
  if (strlen(s) <= l)
    return;
  s += l - 4;
  for (l = 0; l < 3; l++, s--)
    if ((*s & 0xc0) != 0x80)
      break;
  strcpy(s, "...");
}


x86 assembly (clang, -O0):
<certsizelimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0xc(%rbp),%eax
jg     1146 <certsizelimit+0x26>
jmp    11b6 <certsizelimit+0x96>
mov    -0xc(%rbp),%ecx
sub    $0x4,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    11a6 <certsizelimit+0x86>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     1187 <certsizelimit+0x67>
jmp    11a6 <certsizelimit+0x86>
jmp    118c <certsizelimit+0x6c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1161 <certsizelimit+0x41>
mov    -0x8(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<certsizelimit>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    %ebp,%eax
jle    1181 <certsizelimit+0x61>
movslq %ebp,%rax
lea    (%rax,%rbx,1),%rdi
add    $0xfffffffffffffffc,%rdi
mov    -0x4(%rax,%rbx,1),%cl
and    $0xc0,%cl
cmp    $0x80,%cl
jne    116f <certsizelimit+0x4f>
mov    -0x1(%rdi),%cl
add    $0xffffffffffffffff,%rdi
and    $0xc0,%cl
cmp    $0x80,%cl
jne    116f <certsizelimit+0x4f>
add    %rbx,%rax
add    $0xfffffffffffffff9,%rax
mov    -0x1(%rdi),%cl
add    $0xffffffffffffffff,%rdi
and    $0xc0,%cl
cmp    $0x80,%cl
cmove  %rax,%rdi
lea    0xe8a(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <strcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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