#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*/ memcpy(char *, char const *, int);
int strlen(char const *);
void append_string(char *restrict dst, int *dstlen, const char *restrict src) {
  int dlen = *dstlen;
  int slen = strlen(src);
  if (dlen + slen > 260)
    slen = 260 - dlen;
  memcpy(dst + dlen, src, slen);
  *dstlen += slen;
}


x86 assembly (clang, -O0):
<append_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    $0x104,%eax
jle    1165 <append_string+0x45>
mov    $0x104,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
movslq (%rsi),%rbx
mov    %rdx,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbx,1),%ecx
mov    $0x104,%ebp
sub    %ebx,%ebp
cmp    $0x105,%ecx
cmovl  %eax,%ebp
add    %rbx,%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
add    %ebp,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @append_string(i8* noalias %0, i32* %1, i8* noalias %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
store i32 %10, i32* %7
%11 = load i8*, i8** %6
%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 = icmp sgt i32 %15, 260
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i32, i32* %7
%19 = sub nsw i32 260, %18
store i32 %19, i32* %8
br label %20
20: ; preds = %17, %3
%21 = load i8*, i8** %4
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8*, i8** %6
%26 = load i32, i32* %8
%27 = call i32 @memcpy(i8* %24, i8* %25, i32 %26)
%28 = load i32, i32* %8
%29 = load i32*, i32** %5
%30 = load i32, i32* %29
%31 = add nsw i32 %30, %28
store i32 %31, i32* %29
ret void
}

LLVM IR (-O2):
define void @append_string(i8* noalias %0, i32* nocapture %1, i8* noalias %2) {
%4 = load i32, i32* %1
%5 = tail call i32 @strlen(i8* %2)
%6 = add nsw i32 %5, %4
%7 = icmp sgt i32 %6, 260
%8 = sub nsw i32 260, %4
%9 = select i1 %7, i32 %8, i32 %5
%10 = sext i32 %4 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = tail call i32 @memcpy(i8* %11, i8* %2, i32 %9)
%13 = load i32, i32* %1
%14 = add nsw i32 %9, %13
store i32 %14, i32* %1
ret void
}