#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 const *);
char *strcat(char *s, const char *ct) {
  size_t s_length = strlen(s);
  size_t ct_length = strlen(ct);
  for (size_t i = 0; ct[i] != '\0'; ++i) {
    s[s_length + i] = ct[i];
  }
  s[s_length + ct_length] = '\0';
  return (s);
}


x86 assembly (clang, -O0):
<strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1182 <strcat+0x72>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1142 <strcat+0x32>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcat>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    (%rbx),%cl
test   %cl,%cl
je     1150 <strcat+0x40>
lea    (%r14,%r15,1),%rdx
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
mov    %cl,(%rdx,%rsi,1)
movzbl 0x1(%rbx,%rsi,1),%ecx
add    $0x1,%rsi
test   %cl,%cl
jne    1140 <strcat+0x30>
add    %r15,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %5
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
store i64 0, i64* %7
br label %12
12: ; preds = %29, %2
%13 = load i8*, i8** %4
%14 = load i64, i64* %7
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = load i64, i64* %7
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %3
%25 = load i64, i64* %5
%26 = load i64, i64* %7
%27 = add i64 %25, %26
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 %23, i8* %28
br label %29
29: ; preds = %19
%30 = load i64, i64* %7
%31 = add i64 %30, 1
store i64 %31, i64* %7
br label %12
32: ; preds = %12
%33 = load i8*, i8** %3
%34 = load i64, i64* %5
%35 = load i64, i64* %6
%36 = add i64 %34, %35
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %3
ret i8* %38
}

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