#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 strlcpy(char *, char const *, size_t);
size_t strlen(char *);
size_t strlcat(char *dst, const char *src, size_t size) {
  if (!dst || !src) {
    return 0;
  }
  const size_t length = strlen(dst);
  char *p = dst + length;
  return length + strlcpy(p, src, size - length);
}


x86 assembly (clang, -O0):
<strlcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114a <strlcat+0x2a>
cmpq   $0x0,-0x18(%rbp)
jne    1157 <strlcat+0x37>
movq   $0x0,-0x8(%rbp)
jmp    119b <strlcat+0x7b>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
sub    -0x28(%rbp),%rdx
call   1040 <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):
<strlcat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
test   %rdi,%rdi
je     115c <strlcat+0x3c>
mov    %rsi,%r14
test   %rsi,%rsi
je     115c <strlcat+0x3c>
mov    %rdx,%r15
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r12
add    %rax,%rbx
sub    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <strlcpy@plt>
add    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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