#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 strlen(char const *);
char *mystrcpy(char *dest, const char *src) {
  int i = 0;
  *dest = *src;
  while (*(src + i))
    *(dest + i) = *(src + i++);
  *(dest + strlen(src)) = *(src + strlen(src));
  return dest;
}


x86 assembly (clang, -O0):
<mystrcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     116a <mystrcpy+0x5a>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1133 <mystrcpy+0x23>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x21(%rbp),%dl
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mystrcpy>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%al
mov    %al,(%rdi)
mov    (%rsi),%al
test   %al,%al
je     1140 <mystrcpy+0x30>
mov    $0x1,%ecx
nopl   0x0(%rax)
mov    %al,(%r14,%rcx,1)
movzbl (%rbx,%rcx,1),%eax
add    $0x1,%rcx
test   %al,%al
jne    1130 <mystrcpy+0x20>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
mov    (%rbx,%rax,1),%bpl
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
mov    %bpl,(%r14,%rax,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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