#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 int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ mem_invalidate_range(int, int);
int /*<<< orphan*/ mem_writeb_phys_dma(int, int /*<<< orphan*/ const);
void DMAPageWrite(uint32_t PhysAddress, const uint8_t *DataWrite,
                  uint32_t TotalSize) {
  int i = 0;
  for (i = 0; i < TotalSize; i++)
    mem_writeb_phys_dma(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    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1170 <DMAPageWrite+0x50>
mov    -0x4(%rbp),%edi
add    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1040 <mem_writeb_phys_dma@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1140 <DMAPageWrite+0x20>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
add    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1030 <mem_invalidate_range@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DMAPageWrite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %edi,%r15d
test   %edx,%edx
jle    1155 <DMAPageWrite+0x35>
mov    %rsi,%r12
mov    %r14d,%r13d
mov    %r15d,%ebx
xor    %ebp,%ebp
mov    (%r12,%rbp,4),%esi
lea    (%rbx,%rbp,1),%edi
call   1040 <mem_writeb_phys_dma@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1140 <DMAPageWrite+0x20>
lea    (%r15,%r14,1),%esi
add    $0xffffffff,%esi
mov    %r15d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <mem_invalidate_range@plt>

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

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