char *strcat(char *dest, const char *src) {
  printf("# %s(dest=%p, src=%p)\n", __FUNCTION__, dest, src);
  delay(100000000);
  char *p = dest;
  while (*p++)
    ;
  while (*src) {
    *p++ = *src++;
  }
  return dest;
}


x86 assembly (clang, -O0):
<strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xec1(%rip),%rdi
lea    0xed1(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x5f5e100,%edi
mov    $0x0,%al
call   1040 <delay@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
cmpb   $0x0,(%rax)
je     117e <strcat+0x5e>
jmp    1161 <strcat+0x41>
jmp    1183 <strcat+0x63>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b7 <strcat+0x97>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1183 <strcat+0x63>
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
lea    0xecf(%rip),%rdi
lea    0xedf(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x5f5e100,%edi
xor    %eax,%eax
call   1040 <delay@plt>
mov    %r14,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x0,(%rax)
lea    0x1(%rax),%rax
jne    1160 <strcat+0x40>
mov    (%rbx),%cl
test   %cl,%cl
je     1190 <strcat+0x70>
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %cl,(%rax,%rdx,1)
movzbl 0x1(%rbx,%rdx,1),%ecx
add    $0x1,%rdx
test   %cl,%cl
jne    1180 <strcat+0x60>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"# %s(dest=%p, src=%p)\0A\00"
@__FUNCTION__.strcat = [7 x i8] c"strcat\00"
define i8* @strcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__FUNCTION__.strcat, i64 0, i64 0), i8* %6, i8* %7)
%9 = call i32 (i32, ...) bitcast (i32 (...)* @delay to i32 (i32, ...)*)(i32 100000000)
%10 = load i8*, i8** %3
store i8* %10, i8** %5
br label %11
11: ; preds = %16, %2
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
%14 = load i8, i8* %12
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
br label %11
17: ; preds = %11
br label %18
18: ; preds = %22, %17
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
%25 = load i8, i8* %23
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
store i8 %25, i8* %26
br label %18
28: ; preds = %18
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
@.str = [23 x i8] c"# %s(dest=%p, src=%p)\0A\00"
@__FUNCTION__.strcat = [7 x i8] c"strcat\00"
define i8* @strcat(i8* returned %0, i8* %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__FUNCTION__.strcat, i64 0, i64 0), i8* %0, i8* %1)
%4 = tail call i32 (i32, ...) bitcast (i32 (...)* @delay to i32 (i32, ...)*)(i32 100000000)
br label %5
5: ; preds = %5, %2
%6 = phi i8* [ %0, %2 ], [ %7, %5 ]
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %10, %13
%14 = phi i8 [ %19, %13 ], [ %11, %10 ]
%15 = phi i8* [ %18, %13 ], [ %7, %10 ]
%16 = phi i8* [ %17, %13 ], [ %1, %10 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %14, i8* %15
%19 = load i8, i8* %17
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %13
21: ; preds = %13, %10
ret i8* %0
}