#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 arraycopy(char from[], char to[]) {
  unsigned long len = strlen(to);
  for (int i = 0; i < len; i++)
    to[i] = '\0';
  for (int i = 0; i < strlen(from); i++)
    to[i] = from[i];
}


x86 assembly (clang, -O0):
<arraycopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    115e <arraycopy+0x4e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1136 <arraycopy+0x26>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11a5 <arraycopy+0x95>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1165 <arraycopy+0x55>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arraycopy>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1144 <arraycopy+0x24>
movslq %eax,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    117c <arraycopy+0x5c>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r15,%rbx,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1160 <arraycopy+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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