#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 */
unsigned int ft_strlen(char *);
int /*<<< orphan*/ ft_strncpy(char *, char *, unsigned int);
unsigned int ft_strnlen(char *, unsigned int);
unsigned int ft_strlcat(char *dest, char *src, unsigned int size) {
  unsigned int s_dest;
  unsigned int s_src;
  unsigned int n_size;
  s_dest = ft_strnlen(dest, size);
  s_src = ft_strlen(src);
  n_size = size - s_dest;
  dest += s_dest;
  if (n_size > 0) {
    ft_strncpy(dest, src, n_size);
    dest[n_size - 1] = '\0';
  }
  return (s_dest + s_src);
}


x86 assembly (clang, -O0):
<ft_strlcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <ft_strnlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
cmpl   $0x0,-0x20(%rbp)
jbe    11a1 <ft_strlcat+0x71>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1050 <ft_strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strlcat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %edx,%esi
call   1040 <ft_strnlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%ebp
sub    %r12d,%ebx
je     1174 <ft_strlcat+0x44>
mov    %r12d,%eax
add    %rax,%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <ft_strncpy@plt>
add    $0xffffffff,%ebx
movb   $0x0,(%r14,%rbx,1)
add    %r12d,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ft_strlcat(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @ft_strnlen(i8* %0, i32 %2)
%5 = tail call i32 @ft_strlen(i8* %1)
%6 = sub i32 %2, %4
%7 = zext i32 %4 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = icmp eq i32 %6, 0
br i1 %9, label %15, label %10
10: ; preds = %3
%11 = tail call i32 @ft_strncpy(i8* %8, i8* %1, i32 %6)
%12 = add i32 %6, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 0, i8* %14
br label %15
15: ; preds = %10, %3
%16 = add i32 %5, %4
ret i32 %16
}