#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int const);
void copy2d(uint8_t *dst, const uint8_t *src, const int w, const int h,
            const int x_off, const int y_off) {
  src += y_off * 64 + x_off;
  for (int y = 0; y < h; y++) {
    memcpy(dst, src, w);
    src += 64;
    dst += w;
  }
}


x86 assembly (clang, -O0):
<copy2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
shl    $0x6,%ecx
add    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    119d <copy2d+0x8d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x100,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1150 <copy2d+0x40>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy2d>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %ecx,%ecx
jle    115e <copy2d+0x4e>
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %rdi,%rbp
shl    $0x6,%r9d
add    %r8d,%r9d
movslq %r9d,%rax
lea    (%rsi,%rax,4),%rbx
movslq %edx,%r12
shl    $0x2,%r12
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <memcpy@plt>
add    $0x100,%rbx
add    %r12,%rbp
add    $0xffffffff,%r15d
jne    1140 <copy2d+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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