#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 /*<<< orphan*/ strcpy(char *, char const *);
char *strcat(char *dest, const char *src) {
  char *ret = dest;
  size_t i;
  for (i = 0; dest[i]; i++)
    ;
  if (i)
    strcpy(dest + i - 1, src);
  else
    strcpy(dest + i, src);
  dest[i] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1158 <strcat+0x48>
jmp    1147 <strcat+0x37>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1130 <strcat+0x20>
cmpq   $0x0,-0x20(%rbp)
je     117d <strcat+0x6d>
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    118e <strcat+0x7e>
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcat>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
cmpb   $0x0,(%r14,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1120 <strcat+0x10>
cmp    $0x1,%rbx
lea    -0x2(%r14,%rbx,1),%rdi
cmove  %r14,%rdi
call   1030 <strcpy@plt>
movb   $0x0,-0x1(%r14,%rbx,1)
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 i8*
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
store i64 0, i64* %6
br label %8
8: ; preds = %15, %2
%9 = load i8*, i8** %3
%10 = load i64, i64* %6
%11 = getelementptr inbounds i8, i8* %9, i64 %10
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %8
br label %15
15: ; preds = %14
%16 = load i64, i64* %6
%17 = add i64 %16, 1
store i64 %17, i64* %6
br label %8
18: ; preds = %8
%19 = load i64, i64* %6
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = load i64, i64* %6
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 -1
%26 = load i8*, i8** %4
%27 = call i32 @strcpy(i8* %25, i8* %26)
br label %34
28: ; preds = %18
%29 = load i8*, i8** %3
%30 = load i64, i64* %6
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8*, i8** %4
%33 = call i32 @strcpy(i8* %31, i8* %32)
br label %34
34: ; preds = %28, %21
%35 = load i8*, i8** %3
%36 = load i64, i64* %6
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %5
ret i8* %38
}

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