void ram_init() {
  extern long __end_of_text__;
  extern long __data_start__, __data_end__;
  extern long __bss_start__, __bss_end__;
  long *src = &__end_of_text__;
  long *dst = &__data_start__;
  while (dst < &__data_end__)
    *dst = *src;
  for (dst = &__bss_start__; dst < &__bss_end__; dst++)
    *dst = 0;
}


x86 assembly (clang, -O0):
<ram_init>:
push   %rbp
mov    %rsp,%rbp
mov    0x2ed5(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0x2ec2(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2eaf(%rip),%rax
cmp    %rax,-0x10(%rbp)
jae    113e <ram_init+0x3e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    111a <ram_init+0x1a>
mov    0x2e7b(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e78(%rip),%rax
cmp    %rax,-0x10(%rbp)
jae    1176 <ram_init+0x76>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1149 <ram_init+0x49>
pop    %rbp
ret

x86 assembly (clang, -O2):
<ram_init>:
push   %rax
mov    0x2ec0(%rip),%rax
cmp    0x2eb1(%rip),%rax
jae    112e <ram_init+0x1e>
mov    0x2eb8(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,(%rax)
mov    0x2e8b(%rip),%rdi
cmp    0x2e8c(%rip),%rdi
jae    1169 <ram_init+0x59>
lea    0x8(%rdi),%rax
mov    0x2e7f(%rip),%rcx
cmp    %rax,%rcx
cmova  %rcx,%rax
mov    %rdi,%rcx
not    %rcx
lea    (%rcx,%rax,1),%rdx
add    $0x8,%rdx
and    $0xfffffffffffffff8,%rdx
xor    %esi,%esi
call   1030 <memset@plt>
pop    %rax
ret

LLVM IR (-O0):
@__end_of_text__ = external global i64
@__data_start__ = external global i64
@__data_end__ = external global i64
@__bss_start__ = external global i64
@__bss_end__ = external global i64
define void @ram_init() {
%1 = alloca i64*
%2 = alloca i64*
store i64* @__end_of_text__, i64** %1
store i64* @__data_start__, i64** %2
br label %3
3: ; preds = %6, %0
%4 = load i64*, i64** %2
%5 = icmp ult i64* %4, @__data_end__
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i64*, i64** %1
%8 = load i64, i64* %7
%9 = load i64*, i64** %2
store i64 %8, i64* %9
br label %3
10: ; preds = %3
store i64* @__bss_start__, i64** %2
br label %11
11: ; preds = %16, %10
%12 = load i64*, i64** %2
%13 = icmp ult i64* %12, @__bss_end__
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i64*, i64** %2
store i64 0, i64* %15
br label %16
16: ; preds = %14
%17 = load i64*, i64** %2
%18 = getelementptr inbounds i64, i64* %17, i32 1
store i64* %18, i64** %2
br label %11
19: ; preds = %11
ret void
}

LLVM IR (-O2):
@__end_of_text__ = external global i64
@__data_start__ = external global i64
@__data_end__ = external global i64
@__bss_start__ = external global i64
@__bss_end__ = external global i64
define void @ram_init() {
br i1 icmp ult (i64* @__data_start__, i64* @__data_end__), label %1, label %3
1: ; preds = %0
%2 = load i64, i64* @__end_of_text__
store i64 %2, i64* @__data_start__
br label %3
3: ; preds = %1, %0
br i1 icmp ult (i64* @__bss_start__, i64* @__bss_end__), label %4, label %8
4: ; preds = %3
%5 = call i64 @llvm.umax.i64(i64 ptrtoint (i64* @__bss_end__ to i64), i64 add (i64 ptrtoint (i64* @__bss_start__ to i64), i64 8))
%6 = add i64 %5, add (i64 xor (i64 ptrtoint (i64* @__bss_start__ to i64), i64 -1), i64 8)
%7 = and i64 %6, -8
br label %8
8: ; preds = %4, %3
ret void
}