#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 */
size_t av_strlcpy(char *, char const *, size_t);
size_t strlen(char const *);
size_t c_strlcat(char *dst, const char *src, size_t size) {
  size_t len = strlen(dst);
  if (size <= len + 1) {
    return len + strlen(src);
  }
  return len + av_strlcpy(dst + len, src, size - len);
}


x86 assembly (clang, -O0):
<c_strlcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
ja     117a <c_strlcat+0x5a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11a9 <c_strlcat+0x89>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
sub    -0x28(%rbp),%rdx
call   1040 <av_strlcpy@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_strlcat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
add    $0x1,%rax
cmp    %r12,%rax
jae    1158 <c_strlcat+0x38>
add    %r15,%rbx
sub    %r15,%r12
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <av_strlcpy@plt>
jmp    1160 <c_strlcat+0x40>
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @c_strlcat(i8* %0, i8* %1, i64 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add i64 %4, 1
%6 = icmp ult i64 %5, %2
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
br label %13
9: ; preds = %3
%10 = getelementptr inbounds i8, i8* %0, i64 %4
%11 = sub i64 %2, %4
%12 = tail call i64 @av_strlcpy(i8* %10, i8* %1, i64 %11)
br label %13
13: ; preds = %9, %7
%14 = phi i64 [ %8, %7 ], [ %12, %9 ]
%15 = add i64 %14, %4
ret i64 %15
}