#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 *);
void CopyString(char *src, char *dst, int index) {
  int i;
  for (i = 0; i < strlen(src); i++) {
    dst[index + i] = src[i];
    dst[index + (i + 1)] = 0x00;
  }
}


x86 assembly (clang, -O0):
<CopyString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1185 <CopyString+0x75>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%edx
add    $0x1,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <CopyString+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CopyString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    1161 <CopyString+0x51>
movslq %ebp,%rax
lea    (%rax,%r14,1),%rbp
add    $0x1,%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rbx,1),%eax
mov    %al,-0x1(%rbp,%rbx,1)
movb   $0x0,0x0(%rbp,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1140 <CopyString+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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