#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 scalar_t__ ulong;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void fill_mem_with_data_equal_address(ulong *start_addr, ulong phy_addr,
                                      unsigned int length) {
  int *tmp_ptr = (int *)start_addr;
  int i;
  printf("Filling memory with content equal to last 32-bit address for [%d] "
         "Bytes\n",
         length);
  printf("[");
  for (i = 0; i < length; i += 4) {
    *tmp_ptr++ = (int)(phy_addr + i);
    printf(".");
    fflush(stdout);
  }
  printf("]\n");
  fflush(stdout);
}


x86 assembly (clang, -O0):
<fill_mem_with_data_equal_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11b5 <fill_mem_with_data_equal_address+0x95>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x20(%rbp)
mov    %ecx,(%rax)
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
jmp    1161 <fill_mem_with_data_equal_address+0x41>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_mem_with_data_equal_address>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xea9(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5b,%edi
call   1030 <putchar@plt>
test   %ebp,%ebp
je     11a3 <fill_mem_with_data_equal_address+0x63>
xor    %ebx,%ebx
mov    0x2e69(%rip),%r12
nopw   0x0(%rax,%rax,1)
lea    (%r14,%rbx,1),%eax
mov    %eax,(%r15,%rbx,1)
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    (%r12),%edi
call   1060 <fflush@plt>
add    $0x4,%rbx
cmp    %ebp,%ebx
jb     1180 <fill_mem_with_data_equal_address+0x40>
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fflush@plt>

LLVM IR (-O0):
@.str = [73 x i8] c"Filling memory with content equal to last 32-bit address for [%d] Bytes\0A\00"
@.str.1 = [2 x i8] c"[\00"
@.str.2 = [2 x i8] c".\00"
@stdout = global i32 0
@.str.3 = [3 x i8] c"]\0A\00"
define void @fill_mem_with_data_equal_address(i64* %0, i64 %1, i32 %2) {
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i64* %0, i64** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%9 = load i64*, i64** %4
%10 = bitcast i64* %9 to i32*
store i32* %10, i32** %7
%11 = load i32, i32* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %14
14: ; preds = %29, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %6
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = load i64, i64* %5
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = add nsw i64 %19, %21
%23 = trunc i64 %22 to i32
%24 = load i32*, i32** %7
%25 = getelementptr inbounds i32, i32* %24, i32 1
store i32* %25, i32** %7
store i32 %23, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = call i32 @fflush(i32 %27)
br label %29
29: ; preds = %18
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 4
store i32 %31, i32* %8
br label %14
32: ; preds = %14
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @stdout
%35 = call i32 @fflush(i32 %34)
ret void
}

LLVM IR (-O2):
@.str = [73 x i8] c"Filling memory with content equal to last 32-bit address for [%d] Bytes\0A\00"
@stdout = global i32 0
@str = [2 x i8] c"]\00"
define void @fill_mem_with_data_equal_address(i64* nocapture writeonly %0, i64 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %2)
%5 = tail call i32 @putchar(i32 91)
%6 = icmp eq i32 %2, 0
br i1 %6, label %20, label %7
7: ; preds = %3
%8 = bitcast i64* %0 to i32*
%9 = trunc i64 %1 to i32
br label %10
10: ; preds = %7, %10
%11 = phi i32 [ 0, %7 ], [ %18, %10 ]
%12 = phi i32* [ %8, %7 ], [ %14, %10 ]
%13 = add i32 %11, %9
%14 = getelementptr inbounds i32, i32* %12, i64 1
store i32 %13, i32* %12
%15 = tail call i32 @putchar(i32 46)
%16 = load i32, i32* @stdout
%17 = tail call i32 @fflush(i32 %16)
%18 = add nuw nsw i32 %11, 4
%19 = icmp ult i32 %18, %2
br i1 %19, label %10, label %20
20: ; preds = %10, %3
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%22 = load i32, i32* @stdout
%23 = tail call i32 @fflush(i32 %22)
ret void
}