void IMAGE_COPY(unsigned char *dest_ptr, int dest_dx, int dest_dy,
                int dest_pitch, int dest_bpp, unsigned char *src_ptr,
                int src_dx, int src_dy, int src_pitch, int src_bpp,
                void (*row_func)(unsigned char *, int, unsigned char *, int),
                void (*row2x_func)(unsigned char *, unsigned char *,
                                   unsigned char *, int, unsigned char *,
                                   int)) {
  register unsigned char *d = dest_ptr;
  register unsigned char *s = src_ptr;
  register int count = dest_dy;
  if (count) {
    do {
      (*row_func)(d, dest_dx, s, src_dx);
      s += src_pitch;
      d += dest_pitch;
    } while (--count);
  }
}


x86 assembly (clang, -O0):
<IMAGE_COPY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x38(%rbp),%rax
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11a3 <IMAGE_COPY+0xa3>
jmp    1156 <IMAGE_COPY+0x56>
mov    0x30(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    0x10(%rbp),%ecx
call   *%rax
mov    0x20(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jne    1156 <IMAGE_COPY+0x56>
jmp    11a3 <IMAGE_COPY+0xa3>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IMAGE_COPY>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     114d <IMAGE_COPY+0x4d>
mov    %r9,%rbx
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbp
movslq 0x50(%rsp),%r13
movslq %ecx,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
mov    0x40(%rsp),%ecx
call   *0x60(%rsp)
add    %r13,%rbx
add    %r12,%rbp
add    $0xffffffff,%r15d
jne    1130 <IMAGE_COPY+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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