void startup() {
  extern void _etext();
  extern unsigned __data_start, _edata, _end;
  unsigned *src = (unsigned *)&_etext;
  unsigned *dest = &__data_start;
  while (dest < &_edata)
    *dest++ = *src++;
  dest = &_edata;
  while (dest < &_end)
    *dest++ = 0;
  extern int main();
  main();
  *(volatile unsigned *)(0x1fbf0004) = 42;
}


x86 assembly (clang, -O0):
<startup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb9(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0x2ea6(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e93(%rip),%rax
cmp    %rax,-0x10(%rbp)
jae    1166 <startup+0x56>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
jmp    112e <startup+0x1e>
mov    0x2e5b(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e70(%rip),%rax
cmp    %rax,-0x10(%rbp)
jae    119c <startup+0x8c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movl   $0x0,(%rax)
jmp    1171 <startup+0x61>
mov    $0x0,%al
call   1030 <main@plt>
mov    $0x1fbf0004,%eax
movl   $0x2a,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startup>:
push   %rax
mov    0x2e98(%rip),%rdi
cmp    0x2e89(%rip),%rdi
jae    1171 <startup+0x41>
lea    0x4(%rdi),%rax
mov    0x2e7c(%rip),%rcx
cmp    %rax,%rcx
cmova  %rcx,%rax
mov    %rdi,%rcx
not    %rcx
lea    (%rcx,%rax,1),%rdx
add    $0x4,%rdx
and    $0xfffffffffffffffc,%rdx
mov    0x2e6c(%rip),%rsi
call   1040 <memcpy@plt>
mov    0x2e50(%rip),%rdi
cmp    0x2e69(%rip),%rdi
jae    11ac <startup+0x7c>
lea    0x4(%rdi),%rax
mov    0x2e5c(%rip),%rcx
cmp    %rax,%rcx
cmova  %rcx,%rax
mov    %rdi,%rcx
not    %rcx
lea    (%rcx,%rax,1),%rdx
add    $0x4,%rdx
and    $0xfffffffffffffffc,%rdx
xor    %esi,%esi
call   1030 <memset@plt>
xor    %eax,%eax
call   1050 <main@plt>
movl   $0x2a,0x1fbf0004
pop    %rax
ret

LLVM IR (-O0):
@__data_start = external global i32
@_edata = external global i32
@_end = external global i32
define void @startup() {
%1 = alloca i32*
%2 = alloca i32*
store i32* bitcast (void (...)* @_etext to i32*), i32** %1
store i32* @__data_start, i32** %2
br label %3
3: ; preds = %6, %0
%4 = load i32*, i32** %2
%5 = icmp ult i32* %4, @_edata
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = load i32*, i32** %1
%8 = getelementptr inbounds i32, i32* %7, i32 1
store i32* %8, i32** %1
%9 = load i32, i32* %7
%10 = load i32*, i32** %2
%11 = getelementptr inbounds i32, i32* %10, i32 1
store i32* %11, i32** %2
store i32 %9, i32* %10
br label %3
12: ; preds = %3
store i32* @_edata, i32** %2
br label %13
13: ; preds = %16, %12
%14 = load i32*, i32** %2
%15 = icmp ult i32* %14, @_end
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32*, i32** %2
%18 = getelementptr inbounds i32, i32* %17, i32 1
store i32* %18, i32** %2
store i32 0, i32* %17
br label %13
19: ; preds = %13
%20 = call i32 (...) @main()
store volatile i32 42, i32* inttoptr (i64 532611076 to i32*)
ret void
}

LLVM IR (-O2):
@__data_start = external global i32
@_edata = external global i32
@_end = external global i32
define void @startup() {
br i1 icmp ult (i32* @__data_start, i32* @_edata), label %1, label %5
1: ; preds = %0
%2 = call i64 @llvm.umax.i64(i64 ptrtoint (i32* @_edata to i64), i64 add (i64 ptrtoint (i32* @__data_start to i64), i64 4))
%3 = add i64 %2, add (i64 xor (i64 ptrtoint (i32* @__data_start to i64), i64 -1), i64 4)
%4 = and i64 %3, -4
br label %5
5: ; preds = %1, %0
br i1 icmp ult (i32* @_edata, i32* @_end), label %6, label %10
6: ; preds = %5
%7 = call i64 @llvm.umax.i64(i64 ptrtoint (i32* @_end to i64), i64 add (i64 ptrtoint (i32* @_edata to i64), i64 4))
%8 = add i64 %7, add (i64 xor (i64 ptrtoint (i32* @_edata to i64), i64 -1), i64 4)
%9 = and i64 %8, -4
br label %10
10: ; preds = %6, %5
%11 = tail call i32 (...) @main()
store volatile i32 42, i32* inttoptr (i64 532611076 to i32*)
ret void
}