void udma_fill_mem(char *p, int size, int rd) {
  int i = 0;
  printk("--- UDMA --->   %s: "
         "fill memory %8x\n",
         __FUNCTION__, (unsigned int)p);
  sand(rd);
  for (i = 0; i < size; i++)
    *p++ = rand();
}


x86 assembly (clang, -O0):
<udma_fill_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edx
lea    0xeaa(%rip),%rdi
lea    0xec8(%rip),%rsi
mov    $0x0,%al
call   1030 <printk@plt>
mov    -0x10(%rbp),%edi
mov    $0x0,%al
call   1040 <sand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a9 <udma_fill_mem+0x79>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <udma_fill_mem+0x45>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udma_fill_mem>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
lea    0xeba(%rip),%rdi
lea    0xed8(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1030 <printk@plt>
mov    %r14d,%edi
xor    %eax,%eax
call   1040 <sand@plt>
test   %ebp,%ebp
jle    1183 <udma_fill_mem+0x53>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1170 <udma_fill_mem+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"--- UDMA ---> %s: fill memory %8x\0A\00"
@__FUNCTION__.udma_fill_mem = [14 x i8] c"udma_fill_mem\00"
define void @udma_fill_mem(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = ptrtoint i8* %8 to i32
%10 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @printk to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__FUNCTION__.udma_fill_mem, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %6
%12 = call i32 (i32, ...) bitcast (i32 (...)* @sand to i32 (i32, ...)*)(i32 %11)
store i32 0, i32* %7
br label %13
13: ; preds = %22, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = call i32 (...) @rand()
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
store i8 %19, i8* %20
br label %22
22: ; preds = %17
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %13
25: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"--- UDMA ---> %s: fill memory %8x\0A\00"
@__FUNCTION__.udma_fill_mem = [14 x i8] c"udma_fill_mem\00"
define void @udma_fill_mem(i8* %0, i32 %1, i32 %2) {
%4 = ptrtoint i8* %0 to i64
%5 = trunc i64 %4 to i32
%6 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @printk to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__FUNCTION__.udma_fill_mem, i64 0, i64 0), i32 %5)
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @sand to i32 (i32, ...)*)(i32 %2)
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %17
9: ; preds = %3, %9
%10 = phi i32 [ %15, %9 ], [ 0, %3 ]
%11 = phi i8* [ %14, %9 ], [ %0, %3 ]
%12 = tail call i32 (...) @rand()
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %13, i8* %11
%15 = add nuw nsw i32 %10, 1
%16 = icmp eq i32 %15, %1
br i1 %16, label %17, label %9
17: ; preds = %9, %3
ret void
}