#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 strcpy_my(char *dest, char *source) {
  int i = 0;
  char exit = 0;
  printf("--\n");
  while (exit == 0) {
    printf("* ( source + i ) = %c;\n", *(source + i));
    *(dest + i) = *(source + i);
    printf("* ( dest + %d ) = * ( source + %d ) = %c;\n", i, i, *(dest + i));
    if (*(source + i) == '\0') {
      i++;
      *(dest + i) = *(source + i);
      exit = 1;
    }
    i++;
  };
}


x86 assembly (clang, -O0):
<strcpy_my>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
jne    11dc <strcpy_my+0xcc>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11ce <strcpy_my+0xbe>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movb   $0x1,-0x15(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <strcpy_my+0x29>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcpy_my>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %rdi,%r14
lea    0xf0d(%rip),%rdi
call   1030 <puts@plt>
lea    0xebe(%rip),%r15
lea    0xecf(%rip),%r12
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
mov    %rax,%rbx
movsbl 0x0(%r13,%rax,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0x0(%r13,%rbx,1),%ecx
mov    %cl,(%r14,%rbx,1)
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%rbx),%rax
cmpb   $0x0,0x0(%r13,%rbx,1)
jne    1150 <strcpy_my+0x30>
mov    0x0(%r13,%rax,1),%cl
mov    %cl,(%r14,%rax,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str.1 = [24 x i8] c"* ( source + i ) = %c;\0A\00"
@.str.2 = [43 x i8] c"* ( dest + %d ) = * ( source + %d ) = %c;\0A\00"
@str = [3 x i8] c"--\00"
define void @strcpy_my(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %4, %2
%5 = phi i32 [ 0, %2 ], [ %17, %4 ]
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i8, i8* %7
%12 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 %11, i8* %12
%13 = sext i8 %11 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %5, i32 %13)
%15 = load i8, i8* %7
%16 = icmp eq i8 %15, 0
%17 = add nuw nsw i32 %5, 1
br i1 %16, label %18, label %4
18: ; preds = %4
%19 = add nuw nsw i32 %5, 1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %1, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 %22, i8* %23
ret void
}