#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*/ printf(char *, ...);
void strcat_my(char s[], char t[]) {
  int i = 0;
  int j = 0;
  printf("Searching end of first string;\n");
  while (s[i] != '\0') {
    printf("s[%d]=%c;\n", i, s[i]);
    ++i;
  };
  --i;
  printf("Copying second string to first.\n");
  while ((s[i++] = t[j++]) != '\0') {
    printf("s[%d]=%c;t[%d]=%c;\n", i, s[i], j, t[j]);
  };
}


x86 assembly (clang, -O0):
<strcat_my>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     117c <strcat_my+0x6c>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113c <strcat_my+0x2c>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %edx,%rdx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
cmp    $0x0,%eax
je     11fb <strcat_my+0xeb>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rdi
movsbl (%rax,%rdi,1),%r8d
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1193 <strcat_my+0x83>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcat_my>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%al
test   %al,%al
je     1170 <strcat_my+0x50>
lea    0xeb7(%rip),%rbx
xor    %r13d,%r13d
nopl   0x0(%rax)
movsbl %al,%edx
mov    %rbx,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%r15,%r13,1),%eax
add    $0x1,%r13
test   %al,%al
jne    1150 <strcat_my+0x30>
jmp    1173 <strcat_my+0x53>
xor    %r13d,%r13d
movslq %r13d,%rbx
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%al
mov    %al,-0x1(%rbx,%r15,1)
test   %al,%al
je     11d0 <strcat_my+0xb0>
add    %rbx,%r15
mov    $0x1,%ebx
lea    0xe6e(%rip),%r12
nopl   (%rax)
movsbl -0x1(%r15,%rbx,1),%edx
movsbl (%r14,%rbx,1),%r8d
mov    %r12,%rdi
mov    %r13d,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r14,%rbx,1),%eax
mov    %al,-0x1(%r15,%rbx,1)
add    $0x1,%rbx
add    $0x1,%r13d
test   %al,%al
jne    11a0 <strcat_my+0x80>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Searching end of first string;\0A\00"
@.str.1 = [11 x i8] c"s[%d]=%c;\0A\00"
@.str.2 = [33 x i8] c"Copying second string to first.\0A\00"
@.str.3 = [20 x i8] c"s[%d]=%c;t[%d]=%c;\0A\00"
define void @strcat_my(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %16, %2
%9 = load i8*, i8** %3
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %8
%17 = load i32, i32* %5
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %23)
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %8
27: ; preds = %8
%28 = load i32, i32* %5
%29 = add nsw i32 %28, -1
store i32 %29, i32* %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %45, %27
%32 = load i8*, i8** %4
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = load i8, i8* %36
%38 = load i8*, i8** %3
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
store i8 %37, i8* %42
%43 = sext i8 %37 to i32
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %61
45: ; preds = %31
%46 = load i32, i32* %5
%47 = load i8*, i8** %3
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = load i32, i32* %6
%54 = load i8*, i8** %4
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %52, i32 %53, i32 %59)
br label %31
61: ; preds = %31
ret void
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"s[%d]=%c;\0A\00"
@.str.3 = [20 x i8] c"s[%d]=%c;t[%d]=%c;\0A\00"
@str = [31 x i8] c"Searching end of first string;\00"
@str.4 = [32 x i8] c"Copying second string to first.\00"
define void @strcat_my(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %2, %6
%7 = phi i64 [ %12, %6 ], [ 0, %2 ]
%8 = phi i8 [ %14, %6 ], [ %4, %2 ]
%9 = sext i8 %8 to i32
%10 = trunc i64 %7 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %9)
%12 = add nuw i64 %7, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = trunc i64 %12 to i32
br label %18
18: ; preds = %16, %2
%19 = phi i32 [ 0, %2 ], [ %17, %16 ]
%20 = add nsw i32 %19, -1
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.4, i64 0, i64 0))
%22 = load i8, i8* %1
%23 = sext i32 %20 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 %22, i8* %24
%25 = icmp eq i8 %22, 0
br i1 %25, label %44, label %26
26: ; preds = %18
%27 = sext i32 %19 to i64
br label %28
28: ; preds = %26, %28
%29 = phi i64 [ 1, %26 ], [ %40, %28 ]
%30 = phi i64 [ %27, %26 ], [ %42, %28 ]
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = getelementptr inbounds i8, i8* %1, i64 %29
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = trunc i64 %30 to i32
%38 = trunc i64 %29 to i32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %33, i32 %38, i32 %36)
%40 = add nuw i64 %29, 1
%41 = load i8, i8* %34
%42 = add i64 %30, 1
store i8 %41, i8* %31
%43 = icmp eq i8 %41, 0
br i1 %43, label %44, label %28
44: ; preds = %28, %18
ret void
}