#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 strlen(char *);
char *strcat(char *dest, char const *src) {
  size_t len;
  char *dest_ori;
  len = strlen(dest);
  dest_ori = dest;
  dest += len;
  while (*src) {
    *dest = *src;
    ++dest;
    ++src;
  }
  *dest = '\0';
  return (dest_ori);
}


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    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1177 <strcat+0x67>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1141 <strcat+0x31>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%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>
add    %r14,%rax
mov    (%rbx),%cl
test   %cl,%cl
je     1141 <strcat+0x31>
add    $0x1,%rbx
nopl   0x0(%rax)
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1130 <strcat+0x20>
movb   $0x0,(%rax)
mov    %r14,%rax
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 i64
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %5
%9 = load i8*, i8** %3
store i8* %9, i8** %6
%10 = load i64, i64* %5
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 %10
store i8* %12, i8** %3
br label %13
13: ; preds = %17, %2
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = load i8*, i8** %3
store i8 %19, i8* %20
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
br label %13
25: ; preds = %13
%26 = load i8*, i8** %3
store i8 0, i8* %26
%27 = load i8*, i8** %6
ret i8* %27
}

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