#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*/ strcat(char *, char *);
int strlen(char *);
void StringAppendDots(char *s1, char *s2, int maxlen) {
  int len1, len2;
  len1 = strlen(s1);
  len2 = strlen(s1);
  if ((len1 + len2 + 1) > maxlen) {
    if ((len1 + 4) <= maxlen) {
      strcat(s1, "...");
    }
  } else {
    strcat(s1, s2);
  }
}


x86 assembly (clang, -O0):
<StringAppendDots>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
jle    1181 <StringAppendDots+0x61>
mov    -0x18(%rbp),%eax
add    $0x4,%eax
cmp    -0x14(%rbp),%eax
jg     117c <StringAppendDots+0x5c>
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1040 <strcat@plt>
jmp    118e <StringAppendDots+0x6e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StringAppendDots>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
cmp    %r15d,%eax
jl     1160 <StringAppendDots+0x40>
add    $0x4,%ebp
cmp    %r15d,%ebp
jle    1159 <StringAppendDots+0x39>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xea0(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strcat@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"...\00"
define void @StringAppendDots(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, %4
%7 = icmp slt i32 %6, %2
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = add nsw i32 %4, 4
%10 = icmp sgt i32 %9, %2
br i1 %10, label %14, label %11
11: ; preds = %3, %8
%12 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %8 ], [ %1, %3 ]
%13 = tail call i32 @strcat(i8* %0, i8* %12)
br label %14
14: ; preds = %11, %8
ret void
}