#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*/ __constant_memcpy(void *, void const *, unsigned int);
int /*<<< orphan*/ __memcpy(void *, void const *, unsigned int);
void mgsl_load_pci_memory(char *TargetPtr, char const *SourcePtr,
                          unsigned short count) {
  unsigned short Intervalcount;
  unsigned short Index;
  unsigned long Dummy;
  {
    Intervalcount = (unsigned short)((int)count / 64);
    Index = (unsigned short)0;
    while ((int)Index < (int)Intervalcount) {
      __constant_memcpy((void *)TargetPtr, (void const *)SourcePtr, 64U);
      Dummy = (unsigned long)(*((unsigned long volatile *)TargetPtr));
      TargetPtr += 64;
      SourcePtr += 64;
      Index = (unsigned short)((int)Index + 1);
    }
    __memcpy((void *)TargetPtr, (void const *)SourcePtr,
             (unsigned int)((int)count % 64));
    return;
  }
}


x86 assembly (clang, -O0):
<mgsl_load_pci_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
mov    %ax,-0x14(%rbp)
movw   $0x0,-0x16(%rbp)
movzwl -0x16(%rbp),%eax
movzwl -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    11a2 <mgsl_load_pci_memory+0x82>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1040 <__constant_memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x10(%rbp)
movzwl -0x16(%rbp),%eax
add    $0x1,%eax
mov    %ax,-0x16(%rbp)
jmp    114d <mgsl_load_pci_memory+0x2d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movzwl -0x12(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
call   1030 <__memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mgsl_load_pci_memory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbp
cmp    $0x40,%r14w
jb     1177 <mgsl_load_pci_memory+0x57>
mov    %r14d,%r15d
shr    $0x6,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x40,%edx
call   1040 <__constant_memcpy@plt>
mov    0x0(%rbp),%rax
add    $0x40,%rbp
add    $0x40,%r12
add    $0x1,%ebx
movzwl %bx,%ebx
cmp    %r15d,%ebx
jb     1150 <mgsl_load_pci_memory+0x30>
and    $0x3f,%r14d
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <__memcpy@plt>

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

LLVM IR (-O2):
define void @mgsl_load_pci_memory(i8* %0, i8* %1, i16 zeroext %2) {
%4 = lshr i16 %2, 6
%5 = zext i16 %4 to i32
%6 = icmp ult i16 %2, 64
br i1 %6, label %19, label %7
7: ; preds = %3, %7
%8 = phi i32 [ %17, %7 ], [ 0, %3 ]
%9 = phi i8* [ %14, %7 ], [ %0, %3 ]
%10 = phi i8* [ %15, %7 ], [ %1, %3 ]
%11 = tail call i32 @__constant_memcpy(i8* %9, i8* %10, i32 64)
%12 = bitcast i8* %9 to i64*
%13 = load volatile i64, i64* %12
%14 = getelementptr inbounds i8, i8* %9, i64 64
%15 = getelementptr inbounds i8, i8* %10, i64 64
%16 = add nuw nsw i32 %8, 1
%17 = and i32 %16, 65535
%18 = icmp ult i32 %17, %5
br i1 %18, label %7, label %19
19: ; preds = %7, %3
%20 = phi i8* [ %1, %3 ], [ %15, %7 ]
%21 = phi i8* [ %0, %3 ], [ %14, %7 ]
%22 = and i16 %2, 63
%23 = zext i16 %22 to i32
%24 = tail call i32 @__memcpy(i8* %21, i8* %20, i32 %23)
ret void
}