#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;
typedef size_t uint32_t;

/* Variables and functions */
int /*<<< orphan*/ mem_invalidate_range(size_t, size_t);
int /*<<< orphan*/ mem_writeb_phys(size_t, int /*<<< orphan*/ const);
void DMAPageWrite(uint32_t PhysAddress, const uint8_t *DataWrite,
                  uint32_t TotalSize) {
  uint32_t i = 0;
  for (i = 0; i < TotalSize; i++)
    mem_writeb_phys(PhysAddress + i, DataWrite[i]);
  mem_invalidate_range(PhysAddress, PhysAddress + TotalSize - 1);
}


x86 assembly (clang, -O0):
<DMAPageWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    117b <DMAPageWrite+0x5b>
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1040 <mem_writeb_phys@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1144 <DMAPageWrite+0x24>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x18(%rbp),%rsi
sub    $0x1,%rsi
call   1030 <mem_invalidate_range@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DMAPageWrite>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%r12
test   %rdx,%rdx
je     1156 <DMAPageWrite+0x36>
mov    %rsi,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%rdi
mov    (%r15,%rbx,4),%esi
call   1040 <mem_writeb_phys@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <DMAPageWrite+0x20>
lea    (%r12,%r14,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <mem_invalidate_range@plt>

LLVM IR (-O0):
define void @DMAPageWrite(i64 %0, i32* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %4
store i32* %1, i32** %5
store i64 %2, i64* %6
store i64 0, i64* %7
store i64 0, i64* %7
br label %8
8: ; preds = %21, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %6
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load i64, i64* %4
%14 = load i64, i64* %7
%15 = add i64 %13, %14
%16 = load i32*, i32** %5
%17 = load i64, i64* %7
%18 = getelementptr inbounds i32, i32* %16, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @mem_writeb_phys(i64 %15, i32 %19)
br label %21
21: ; preds = %12
%22 = load i64, i64* %7
%23 = add i64 %22, 1
store i64 %23, i64* %7
br label %8
24: ; preds = %8
%25 = load i64, i64* %4
%26 = load i64, i64* %4
%27 = load i64, i64* %6
%28 = add i64 %26, %27
%29 = sub i64 %28, 1
%30 = call i32 @mem_invalidate_range(i64 %25, i64 %29)
ret void
}

LLVM IR (-O2):
define void @DMAPageWrite(i64 %0, i32* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %13, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %11, %5 ], [ 0, %3 ]
%7 = add i64 %6, %0
%8 = getelementptr inbounds i32, i32* %1, i64 %6
%9 = load i32, i32* %8
%10 = tail call i32 @mem_writeb_phys(i64 %7, i32 %9)
%11 = add nuw i64 %6, 1
%12 = icmp eq i64 %11, %2
br i1 %12, label %13, label %5
13: ; preds = %5, %3
%14 = add i64 %0, -1
%15 = add i64 %14, %2
%16 = tail call i32 @mem_invalidate_range(i64 %0, i64 %15)
ret void
}