#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ MOA_Random_32();
int /*<<< orphan*/ MOA_Random_W(int, int);
void MOA_Fill_Random_Region(void *reg, int size) {
  uint32_t *r32;
  uint8_t *r8;
  int i;
  r32 = (uint32_t *)reg;
  r8 = (uint8_t *)reg;
  for (i = 0; i < size / 4; i++)
    r32[i] = MOA_Random_32();
  for (i *= 4; i < size; i++)
    r8[i] = MOA_Random_W(8, 1);
}


x86 assembly (clang, -O0):
<MOA_Fill_Random_Region>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    1186 <MOA_Fill_Random_Region+0x66>
mov    $0x0,%al
call   1040 <MOA_Random_32@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1146 <MOA_Fill_Random_Region+0x26>
mov    -0x24(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c5 <MOA_Fill_Random_Region+0xa5>
mov    $0x8,%edi
mov    $0x1,%esi
call   1030 <MOA_Random_W@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118f <MOA_Fill_Random_Region+0x6f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MOA_Fill_Random_Region>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x3(%r14),%r12d
test   %esi,%esi
cmovns %esi,%r12d
xor    %eax,%eax
cmp    $0x4,%esi
jl     1167 <MOA_Fill_Random_Region+0x47>
sar    $0x2,%r12d
mov    %r12d,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <MOA_Random_32@plt>
mov    %eax,(%r15,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1150 <MOA_Fill_Random_Region+0x30>
mov    %r12d,%eax
lea    0x0(,%rax,4),%ecx
cmp    %r14d,%ecx
jge    119c <MOA_Fill_Random_Region+0x7c>
mov    %eax,%ebp
shl    $0x2,%rbp
mov    %r14d,%ebx
nopl   0x0(%rax)
mov    $0x8,%edi
mov    $0x1,%esi
call   1030 <MOA_Random_W@plt>
mov    %eax,(%r15,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1180 <MOA_Fill_Random_Region+0x60>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @MOA_Fill_Random_Region(i8* nocapture writeonly %0, i32 %1) {
%3 = bitcast i8* %0 to i32*
%4 = sdiv i32 %1, 4
%5 = icmp sgt i32 %1, 3
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %12, %8 ]
%10 = tail call i32 (...) @MOA_Random_32()
%11 = getelementptr inbounds i32, i32* %3, i64 %9
store i32 %10, i32* %11
%12 = add nuw nsw i64 %9, 1
%13 = icmp eq i64 %12, %7
br i1 %13, label %14, label %8
14: ; preds = %8, %2
%15 = phi i32 [ 0, %2 ], [ %4, %8 ]
%16 = shl nsw i32 %15, 2
%17 = icmp slt i32 %16, %1
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = zext i32 %15 to i64
%20 = shl nuw nsw i64 %19, 2
%21 = zext i32 %1 to i64
br label %22
22: ; preds = %18, %22
%23 = phi i64 [ %20, %18 ], [ %26, %22 ]
%24 = tail call i32 @MOA_Random_W(i32 8, i32 1)
%25 = getelementptr inbounds i32, i32* %3, i64 %23
store i32 %24, i32* %25
%26 = add nuw nsw i64 %23, 1
%27 = icmp eq i64 %26, %21
br i1 %27, label %28, label %22
28: ; preds = %22, %14
ret void
}