void __main(void) {
  static int initialized;
  if (!initialized) {
    typedef void (*pfunc)();
    extern pfunc __ctors_start[];
    extern pfunc __ctors_end[];
    pfunc *p;
    initialized = 1;
    for (p = __ctors_end; p > __ctors_start;)
      (*--p)();
  }
}


x86 assembly (clang, -O0):
<__main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2f15(%rip)
jne    1159 <__main+0x59>
movl   $0x1,0x2f05(%rip)
mov    0x2eba(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0x2eb7(%rip),%rax
cmp    %rax,-0x8(%rbp)
jbe    1154 <__main+0x54>
mov    -0x8(%rbp),%rcx
mov    %rcx,%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   *-0x8(%rcx)
jmp    112a <__main+0x2a>
jmp    1159 <__main+0x59>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__main>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,0x2f19(%rip)
jne    1141 <__main+0x41>
movb   $0x1,0x2f10(%rip)
mov    0x2ec5(%rip),%rcx
cmp    0x2ec6(%rip),%rcx
jbe    1141 <__main+0x41>
mov    0x2ebd(%rip),%r14
nopl   0x0(%rax,%rax,1)
lea    -0x8(%rcx),%rbx
xor    %eax,%eax
call   *-0x8(%rcx)
mov    %rbx,%rcx
cmp    %r14,%rbx
ja     1130 <__main+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__main.initialized = internal global i32 0
@__ctors_end = external global [0 x void (...)*]
@__ctors_start = external global [0 x void (...)*]
define void @__main() {
%1 = alloca void (...)**
%2 = load i32, i32* @__main.initialized
%3 = icmp ne i32 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %0
store i32 1, i32* @__main.initialized
store void (...)** getelementptr inbounds ([0 x void (...)*], [0 x void (...)*]* @__ctors_end, i64 0, i64 0), void (...)*** %1
br label %5
5: ; preds = %8, %4
%6 = load void (...)**, void (...)*** %1
%7 = icmp ugt void (...)** %6, getelementptr inbounds ([0 x void (...)*], [0 x void (...)*]* @__ctors_start, i64 0, i64 0)
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load void (...)**, void (...)*** %1
%10 = getelementptr inbounds void (...)*, void (...)** %9, i32 -1
store void (...)** %10, void (...)*** %1
%11 = load void (...)*, void (...)** %10
br label %5
12: ; preds = %5
br label %13
13: ; preds = %12, %0
ret void
}

LLVM IR (-O2):
@__main.initialized = internal unnamed_addr global i1 false
@__ctors_end = external global [0 x void (...)*]
@__ctors_start = external global [0 x void (...)*]
define void @__main() {
%1 = load i1, i1* @__main.initialized
br i1 %1, label %8, label %2
2: ; preds = %0
store i1 true, i1* @__main.initialized
br i1 icmp ugt (void (...)** getelementptr inbounds ([0 x void (...)*], [0 x void (...)*]* @__ctors_end, i64 0, i64 0), void (...)** getelementptr inbounds ([0 x void (...)*], [0 x void (...)*]* @__ctors_start, i64 0, i64 0)), label %3, label %8
3: ; preds = %2, %3
%4 = phi void (...)** [ %5, %3 ], [ getelementptr inbounds ([0 x void (...)*], [0 x void (...)*]* @__ctors_end, i64 0, i64 0), %2 ]
%5 = getelementptr inbounds void (...)*, void (...)** %4, i64 -1
%6 = load void (...)*, void (...)** %5
tail call void (...) %6()
%7 = icmp ugt void (...)** %5, getelementptr inbounds ([0 x void (...)*], [0 x void (...)*]* @__ctors_start, i64 0, i64 0)
br i1 %7, label %3, label %8
8: ; preds = %3, %2, %0
ret void
}