#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 *, size_t);
size_t strlen(char const *);
size_t strlcat(char *dst, const char *src, size_t size) {
  size_t dsize = strlen(dst);
  size_t len = strlen(src);
  size_t ret = dsize + len;
  dst += dsize;
  size -= dsize;
  if (len >= size)
    len = size - 1;
  memcpy(dst, src, len);
  dst[len] = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<strlcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     118f <strlcat+0x6f>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strlcat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
add    %r12,%r15
sub    %r12,%r13
lea    -0x1(%r13),%rbp
cmp    %r13,%rax
cmovb  %rax,%rbp
add    %r12,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1040 <memcpy@plt>
movb   $0x0,0x0(%rbp,%r15,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @strlcat(i8* %0, i8* %1, i64 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = getelementptr inbounds i8, i8* %0, i64 %4
%7 = sub i64 %2, %4
%8 = icmp ult i64 %5, %7
%9 = add i64 %7, -1
%10 = select i1 %8, i64 %5, i64 %9
%11 = add i64 %5, %4
%12 = tail call i32 @memcpy(i8* %6, i8* %1, i64 %10)
%13 = getelementptr inbounds i8, i8* %6, i64 %10
store i8 0, i8* %13
ret i64 %11
}