#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 short strlen(char *);
char *strcat(char *destination, const char *source) {
  unsigned short len = strlen(destination);
  destination += len;
  while (*source != 0)
    *(destination++) = *(source++);
  return destination;
}


x86 assembly (clang, -O0):
<strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1176 <strcat+0x66>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    113f <strcat+0x2f>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcat>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
movzwl %ax,%eax
add    %r14,%rax
mov    (%rbx),%cl
test   %cl,%cl
je     1141 <strcat+0x31>
add    $0x1,%rbx
nop
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1130 <strcat+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @strcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i16
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call zeroext i16 @strlen(i8* %6)
store i16 %7, i16* %5
%8 = load i16, i16* %5
%9 = zext i16 %8 to i32
%10 = load i8*, i8** %3
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %10, i64 %11
store i8* %12, i8** %3
br label %13
13: ; preds = %18, %2
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
%21 = load i8, i8* %19
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
store i8 %21, i8* %22
br label %13
24: ; preds = %13
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
define i8* @strcat(i8* %0, i8* nocapture %1) {
%3 = tail call zeroext i16 @strlen(i8* %0)
%4 = zext i16 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %2, %8
%9 = phi i8 [ %14, %8 ], [ %6, %2 ]
%10 = phi i8* [ %13, %8 ], [ %5, %2 ]
%11 = phi i8* [ %12, %8 ], [ %1, %2 ]
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %9, i8* %10
%14 = load i8, i8* %12
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8, %2
%17 = phi i8* [ %5, %2 ], [ %13, %8 ]
ret i8* %17
}