#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*/ memcpy(void *, void *, size_t const);
void array_copy(size_t dim, const size_t *size, size_t v_size, void *from,
                void *to) {
  switch (dim) {
  case 0:
    break;
  case 1:
    memcpy(to, from, size[0] * v_size);
    break;
  default:
    for (size_t i = 0; i < size[0]; i++) {
      array_copy(dim - 1, size + 1, v_size, ((void **)from)[i],
                 ((void **)to)[i]);
    }
    break;
  }
}


x86 assembly (clang, -O0):
<array_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
test   %rax,%rax
je     1165 <array_copy+0x45>
jmp    1152 <array_copy+0x32>
mov    -0x38(%rbp),%rax
sub    $0x1,%rax
je     116a <array_copy+0x4a>
jmp    1188 <array_copy+0x68>
jmp    11e8 <array_copy+0xc8>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
imul   -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
jmp    11e8 <array_copy+0xc8>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jae    11e3 <array_copy+0xc3>
mov    -0x8(%rbp),%rdi
sub    $0x1,%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%r8
mov    (%rax,%r8,8),%r8
call   1030 <array_copy@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1190 <array_copy+0x70>
jmp    11e8 <array_copy+0xc8>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_copy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a1 <array_copy+0x81>
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%rbx
cmp    $0x1,%rdi
jne    1166 <array_copy+0x46>
imul   0x0(%rbp),%r13
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <memcpy@plt>
cmpq   $0x0,0x0(%rbp)
je     11a1 <array_copy+0x81>
add    $0xffffffffffffffff,%rbx
lea    0x8(%rbp),%rax
mov    %rax,(%rsp)
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    (%r12,%r14,8),%rcx
mov    (%r15,%r14,8),%r8
mov    %rbx,%rdi
mov    (%rsp),%rsi
mov    %r13,%rdx
call   1030 <array_copy@plt>
add    $0x1,%r14
cmp    0x0(%rbp),%r14
jb     1180 <array_copy+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @array_copy(i64 %0, i64* %1, i64 %2, i8* %3, i8* %4) {
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
store i64 %0, i64* %6
store i64* %1, i64** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%12 = load i64, i64* %6
switch i64 %12, label %23 [
i64 0, label %13
i64 1, label %14
]
13: ; preds = %5
br label %50
14: ; preds = %5
%15 = load i8*, i8** %10
%16 = load i8*, i8** %9
%17 = load i64*, i64** %7
%18 = getelementptr inbounds i64, i64* %17, i64 0
%19 = load i64, i64* %18
%20 = load i64, i64* %8
%21 = mul i64 %19, %20
%22 = call i32 @memcpy(i8* %15, i8* %16, i64 %21)
br label %50
23: ; preds = %5
store i64 0, i64* %11
br label %24
24: ; preds = %46, %23
%25 = load i64, i64* %11
%26 = load i64*, i64** %7
%27 = getelementptr inbounds i64, i64* %26, i64 0
%28 = load i64, i64* %27
%29 = icmp ult i64 %25, %28
br i1 %29, label %30, label %49
30: ; preds = %24
%31 = load i64, i64* %6
%32 = sub i64 %31, 1
%33 = load i64*, i64** %7
%34 = getelementptr inbounds i64, i64* %33, i64 1
%35 = load i64, i64* %8
%36 = load i8*, i8** %9
%37 = bitcast i8* %36 to i8**
%38 = load i64, i64* %11
%39 = getelementptr inbounds i8*, i8** %37, i64 %38
%40 = load i8*, i8** %39
%41 = load i8*, i8** %10
%42 = bitcast i8* %41 to i8**
%43 = load i64, i64* %11
%44 = getelementptr inbounds i8*, i8** %42, i64 %43
%45 = load i8*, i8** %44
br label %46
46: ; preds = %30
%47 = load i64, i64* %11
%48 = add i64 %47, 1
store i64 %48, i64* %11
br label %24
49: ; preds = %24
br label %50
50: ; preds = %49, %14, %13
ret void
}

LLVM IR (-O2):
define void @array_copy(i64 %0, i64* nocapture %1, i64 %2, i8* %3, i8* %4) {
switch i64 %0, label %6 [
i64 0, label %27
i64 1, label %14
]
6: ; preds = %5
%7 = load i64, i64* %1
%8 = icmp eq i64 %7, 0
br i1 %8, label %27, label %9
9: ; preds = %6
%10 = add i64 %0, -1
%11 = getelementptr inbounds i64, i64* %1, i64 1
%12 = bitcast i8* %3 to i8**
%13 = bitcast i8* %4 to i8**
br label %18
14: ; preds = %5
%15 = load i64, i64* %1
%16 = mul i64 %15, %2
%17 = tail call i32 @memcpy(i8* %4, i8* %3, i64 %16)
br label %27
18: ; preds = %9, %18
%19 = phi i64 [ 0, %9 ], [ %24, %18 ]
%20 = getelementptr inbounds i8*, i8** %12, i64 %19
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %13, i64 %19
%23 = load i8*, i8** %22
tail call void @array_copy(i64 %10, i64* %11, i64 %2, i8* %21, i8* %23)
%24 = add nuw i64 %19, 1
%25 = load i64, i64* %1
%26 = icmp ult i64 %24, %25
br i1 %26, label %18, label %27
27: ; preds = %18, %6, %14, %5
ret void
}