#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 */

/* Variables and functions */
int /*<<< orphan*/ kprintf(char *, ...);
int /*<<< orphan*/ memcpy(int *, int *, long);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, long);
int mem_init(void) {
  extern int erodata;
  extern int stext, etext, sdata, edata, sbss, ebss;
  kprintf("Memory Initialize ...\n");
  kprintf(" Text Area: %08x-%08x (%d bytes)\n", &stext, &etext,
          (long)&etext - (long)&stext);
  kprintf(" Data Area: %08x-%08x (%d bytes)\n", &sdata, &edata,
          (long)&edata - (long)&sdata);
  kprintf(" BSS  Area: %08x-%08x (%d bytes)\n", &sbss, &ebss,
          (long)&ebss - (long)&sbss);
  memcpy(&sdata, &erodata, (long)&edata - (long)&sdata);
  memset(&sbss, 0, (long)&ebss - (long)&sbss);
  return 0;
}


x86 assembly (clang, -O0):
<mem_init>:
push   %rbp
mov    %rsp,%rbp
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1050 <kprintf@plt>
lea    0xece(%rip),%rdi
mov    0x2e70(%rip),%rsi
mov    0x2e79(%rip),%rdx
mov    %rdx,%rcx
sub    %rsi,%rcx
mov    $0x0,%al
call   1050 <kprintf@plt>
lea    0xece(%rip),%rdi
mov    0x2e6e(%rip),%rsi
mov    0x2e2f(%rip),%rdx
mov    %rdx,%rcx
sub    %rsi,%rcx
mov    $0x0,%al
call   1050 <kprintf@plt>
lea    0xece(%rip),%rdi
mov    0x2e34(%rip),%rsi
mov    0x2e4d(%rip),%rdx
mov    %rdx,%rcx
sub    %rsi,%rcx
mov    $0x0,%al
call   1050 <kprintf@plt>
mov    0x2e31(%rip),%rdi
mov    0x2df2(%rip),%rdx
sub    %rdi,%rdx
mov    0x2e18(%rip),%rsi
call   1040 <memcpy@plt>
mov    0x2dfc(%rip),%rdi
mov    0x2e15(%rip),%rdx
sub    %rdi,%rdx
xor    %esi,%esi
call   1030 <memset@plt>
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_init>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1050 <kprintf@plt>
mov    0x2e73(%rip),%rsi
mov    0x2e7c(%rip),%rdx
mov    %rdx,%rcx
sub    %rsi,%rcx
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1050 <kprintf@plt>
mov    0x2e71(%rip),%r14
mov    0x2e32(%rip),%rdx
mov    %rdx,%r12
sub    %r14,%r12
lea    0xeb6(%rip),%rdi
mov    %r14,%rsi
mov    %r12,%rcx
xor    %eax,%eax
call   1050 <kprintf@plt>
mov    0x2e31(%rip),%r15
mov    0x2e4a(%rip),%rdx
mov    %rdx,%rbx
sub    %r15,%rbx
lea    0xeb0(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <kprintf@plt>
mov    0x2e19(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
call   1040 <memcpy@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Memory Initialize ...\0A\00"
@.str.1 = [34 x i8] c" Text Area: %08x-%08x (%d bytes)\0A\00"
@stext = external global i32
@etext = external global i32
@.str.2 = [34 x i8] c" Data Area: %08x-%08x (%d bytes)\0A\00"
@sdata = external global i32
@edata = external global i32
@.str.3 = [34 x i8] c" BSS Area: %08x-%08x (%d bytes)\0A\00"
@sbss = external global i32
@ebss = external global i32
@erodata = external global i32
define i32 @mem_init() {
%1 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%2 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32* @stext, i32* @etext, i64 sub nsw (i64 ptrtoint (i32* @etext to i64), i64 ptrtoint (i32* @stext to i64)))
%3 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32* @sdata, i32* @edata, i64 sub nsw (i64 ptrtoint (i32* @edata to i64), i64 ptrtoint (i32* @sdata to i64)))
%4 = call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32* @sbss, i32* @ebss, i64 sub nsw (i64 ptrtoint (i32* @ebss to i64), i64 ptrtoint (i32* @sbss to i64)))
%5 = call i32 @memcpy(i32* @sdata, i32* @erodata, i64 sub nsw (i64 ptrtoint (i32* @edata to i64), i64 ptrtoint (i32* @sdata to i64)))
%6 = call i32 @memset(i32* @sbss, i32 0, i64 sub nsw (i64 ptrtoint (i32* @ebss to i64), i64 ptrtoint (i32* @sbss to i64)))
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Memory Initialize ...\0A\00"
@.str.1 = [34 x i8] c" Text Area: %08x-%08x (%d bytes)\0A\00"
@stext = external global i32
@etext = external global i32
@.str.2 = [34 x i8] c" Data Area: %08x-%08x (%d bytes)\0A\00"
@sdata = external global i32
@edata = external global i32
@.str.3 = [34 x i8] c" BSS Area: %08x-%08x (%d bytes)\0A\00"
@sbss = external global i32
@ebss = external global i32
@erodata = external global i32
define i32 @mem_init() {
%1 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32* @stext, i32* @etext, i64 sub (i64 ptrtoint (i32* @etext to i64), i64 ptrtoint (i32* @stext to i64)))
%3 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32* @sdata, i32* @edata, i64 sub (i64 ptrtoint (i32* @edata to i64), i64 ptrtoint (i32* @sdata to i64)))
%4 = tail call i32 (i8*, ...) @kprintf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32* @sbss, i32* @ebss, i64 sub (i64 ptrtoint (i32* @ebss to i64), i64 ptrtoint (i32* @sbss to i64)))
%5 = tail call i32 @memcpy(i32* @sdata, i32* @erodata, i64 sub (i64 ptrtoint (i32* @edata to i64), i64 ptrtoint (i32* @sdata to i64)))
%6 = tail call i32 @memset(i32* @sbss, i32 0, i64 sub (i64 ptrtoint (i32* @ebss to i64), i64 ptrtoint (i32* @sbss to i64)))
ret i32 0
}