#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 my_strlen(char *);
int my_strlcat(char *dest, char *src, int size) {
  if (size < my_strlen(dest))
    return (my_strlen(dest) - (my_strlen(dest) - size) + my_strlen(src));
  else
    return (size + my_strlen(src));
}


x86 assembly (clang, -O0):
<my_strlcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1179 <my_strlcat+0x69>
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    -0x1c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <my_strlcat+0x82>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_strlcat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <my_strlen@plt>
cmp    %r15d,%eax
jle    114f <my_strlcat+0x3f>
mov    %rbx,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <my_strlen@plt>
add    %r15d,%ebp
sub    %ebx,%ebp
add    %eax,%ebp
jmp    115c <my_strlcat+0x4c>
mov    %r14,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ebp
add    %r15d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @my_strlcat(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @my_strlen(i8* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %23
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = call i32 @my_strlen(i8* %13)
%15 = load i8*, i8** %5
%16 = call i32 @my_strlen(i8* %15)
%17 = load i32, i32* %7
%18 = sub nsw i32 %16, %17
%19 = sub nsw i32 %14, %18
%20 = load i8*, i8** %6
%21 = call i32 @my_strlen(i8* %20)
%22 = add nsw i32 %19, %21
store i32 %22, i32* %4
br label %28
23: ; preds = %3
%24 = load i32, i32* %7
%25 = load i8*, i8** %6
%26 = call i32 @my_strlen(i8* %25)
%27 = add nsw i32 %24, %26
store i32 %27, i32* %4
br label %28
28: ; preds = %23, %12
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @my_strlcat(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @my_strlen(i8* %0)
%5 = icmp sgt i32 %4, %2
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = tail call i32 @my_strlen(i8* %0)
%8 = tail call i32 @my_strlen(i8* %0)
%9 = tail call i32 @my_strlen(i8* %1)
%10 = add i32 %7, %2
%11 = sub i32 %10, %8
%12 = add i32 %11, %9
br label %16
13: ; preds = %3
%14 = tail call i32 @my_strlen(i8* %1)
%15 = add nsw i32 %14, %2
br label %16
16: ; preds = %13, %6
%17 = phi i32 [ %12, %6 ], [ %15, %13 ]
ret i32 %17
}