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

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void fill_memory_with_user_input(ulong *start_addr, ulong data,
                                 unsigned int length) {
  int *tmp_ptr = (int *)start_addr;
  printf("Filling memory with user input [0x%x] for [%d] Bytes\n", data,
         length);
  printf("[");
  while (length > 0) {
    *tmp_ptr++ = (int)data;
    printf(".");
    fflush(stdout);
    length -= sizeof(int);
  }
  printf("]\n");
  fflush(stdout);
}


x86 assembly (clang, -O0):
<fill_memory_with_user_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jbe    11a5 <fill_memory_with_user_input+0x85>
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x10(%rbp),%eax
sub    $0x4,%rax
mov    %eax,-0x10(%rbp)
jmp    115c <fill_memory_with_user_input+0x3c>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_memory_with_user_input>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xea9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5b,%edi
call   1030 <putchar@plt>
test   %ebp,%ebp
je     119f <fill_memory_with_user_input+0x5f>
mov    %ebp,%ebp
xor    %ebx,%ebx
mov    0x2e69(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15d,(%r14,%rbx,1)
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    (%r12),%edi
call   1060 <fflush@plt>
add    $0x4,%rbx
cmp    %ebx,%ebp
jne    1180 <fill_memory_with_user_input+0x40>
lea    0xe90(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fflush@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"Filling memory with user input [0x%x] 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_memory_with_user_input(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
%8 = load i32*, i32** %4
store i32* %8, i32** %7
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %16, %3
%14 = load i32, i32* %6
%15 = icmp ugt i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i32, i32* %5
%18 = load i32*, i32** %7
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %7
store i32 %17, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @stdout
%22 = call i32 @fflush(i32 %21)
%23 = load i32, i32* %6
%24 = zext i32 %23 to i64
%25 = sub i64 %24, 4
%26 = trunc i64 %25 to i32
store i32 %26, i32* %6
br label %13
27: ; preds = %13
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* @stdout
%30 = call i32 @fflush(i32 %29)
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"Filling memory with user input [0x%x] for [%d] Bytes\0A\00"
@stdout = global i32 0
@str = [2 x i8] c"]\00"
define void @fill_memory_with_user_input(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%5 = tail call i32 @putchar(i32 91)
%6 = icmp eq i32 %2, 0
br i1 %6, label %16, label %7
7: ; preds = %3, %7
%8 = phi i32* [ %10, %7 ], [ %0, %3 ]
%9 = phi i32 [ %14, %7 ], [ %2, %3 ]
%10 = getelementptr inbounds i32, i32* %8, i64 1
store i32 %1, i32* %8
%11 = tail call i32 @putchar(i32 46)
%12 = load i32, i32* @stdout
%13 = tail call i32 @fflush(i32 %12)
%14 = add i32 %9, -4
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %7
16: ; preds = %7, %3
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%18 = load i32, i32* @stdout
%19 = tail call i32 @fflush(i32 %18)
ret void
}