#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*/ mempeekb(short, short);
int /*<<< orphan*/ mempokeb(short, short, int /*<<< orphan*/);
void memcopy(short srcSeg, short srcOfs, short destSeg, short destOfs,
             short size) {
  for (; size > 0; size--) {
    mempokeb(destSeg, destOfs, mempeekb(srcSeg, srcOfs));
    srcOfs++;
    destOfs++;
  }
}


x86 assembly (clang, -O0):
<memcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %r8w,%ax
mov    %di,-0x2(%rbp)
mov    %si,-0x4(%rbp)
mov    %dx,-0x6(%rbp)
mov    %cx,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movswl -0xa(%rbp),%eax
cmp    $0x0,%eax
jle    11ab <memcopy+0x8b>
mov    -0x6(%rbp),%ax
mov    %ax,-0xe(%rbp)
mov    -0x8(%rbp),%ax
mov    %ax,-0xc(%rbp)
mov    -0x2(%rbp),%ax
movswl %ax,%edi
movswl -0x4(%rbp),%esi
call   1040 <mempeekb@plt>
mov    -0xe(%rbp),%cx
mov    %eax,%edx
mov    -0xc(%rbp),%ax
movswl %cx,%edi
movswl %ax,%esi
call   1030 <mempokeb@plt>
mov    -0x4(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x4(%rbp)
mov    -0x8(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x8(%rbp)
mov    -0xa(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0xa(%rbp)
jmp    1140 <memcopy+0x20>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcopy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
test   %r14w,%r14w
jle    117b <memcopy+0x5b>
mov    %ecx,%ebp
mov    %esi,%ebx
add    $0x1,%r14d
movswl %di,%r15d
movswl %dx,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movswl %bx,%esi
mov    %r15d,%edi
call   1040 <mempeekb@plt>
movswl %bp,%ebp
mov    %r12d,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1030 <mempokeb@plt>
add    $0x1,%ebx
add    $0x1,%ebp
add    $0xffffffff,%r14d
cmp    $0x1,%r14w
ja     1150 <memcopy+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @memcopy(i16 signext %0, i16 signext %1, i16 signext %2, i16 signext %3, i16 signext %4) {
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
store i16 %0, i16* %6
store i16 %1, i16* %7
store i16 %2, i16* %8
store i16 %3, i16* %9
store i16 %4, i16* %10
br label %11
11: ; preds = %26, %5
%12 = load i16, i16* %10
%13 = sext i16 %12 to i32
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = load i16, i16* %8
%17 = load i16, i16* %9
%18 = load i16, i16* %6
%19 = load i16, i16* %7
%20 = call i32 @mempeekb(i16 signext %18, i16 signext %19)
%21 = call i32 @mempokeb(i16 signext %16, i16 signext %17, i32 %20)
%22 = load i16, i16* %7
%23 = add i16 %22, 1
store i16 %23, i16* %7
%24 = load i16, i16* %9
%25 = add i16 %24, 1
store i16 %25, i16* %9
br label %26
26: ; preds = %15
%27 = load i16, i16* %10
%28 = add i16 %27, -1
store i16 %28, i16* %10
br label %11
29: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @memcopy(i16 signext %0, i16 signext %1, i16 signext %2, i16 signext %3, i16 signext %4) {
%6 = icmp sgt i16 %4, 0
br i1 %6, label %7, label %17
7: ; preds = %5, %7
%8 = phi i16 [ %15, %7 ], [ %4, %5 ]
%9 = phi i16 [ %14, %7 ], [ %3, %5 ]
%10 = phi i16 [ %13, %7 ], [ %1, %5 ]
%11 = tail call i32 @mempeekb(i16 signext %0, i16 signext %10)
%12 = tail call i32 @mempokeb(i16 signext %2, i16 signext %9, i32 %11)
%13 = add i16 %10, 1
%14 = add i16 %9, 1
%15 = add nsw i16 %8, -1
%16 = icmp ugt i16 %8, 1
br i1 %16, label %7, label %17
17: ; preds = %7, %5
ret void
}