// #target: linux-x64
module test;
import std::io;

fn void main()
{
	io::printn("Hello, world!");
}
extern fn void puts(char*);

fn void startup2() @init(300)
{
	puts("Hello startup2");
}
fn void start_main() @init
{
	puts("Let's start main...");
}
fn void startup1() @init(200)
{
	puts("Hello startup");
}

fn void empty_startup() @init
{}

fn void shutdown() @finalizer
{
	puts("Bye bye");
}

/* #expect: test.ll

@llvm.global_ctors = appending global [5 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 300, ptr @test.startup2, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @test.start_main, ptr null }, { i32, ptr, ptr } { i32 200, ptr @test.startup1, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @test.empty_startup, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @.__c3_atexit_test.shutdown, ptr null }]

define void @test.startup2() #0 {
entry:
  call void @puts(ptr @.str.1)
  ret void
}

define void @test.start_main() #0 {
entry:
  call void @puts(ptr @.str.2)
  ret void
}

define void @test.startup1() #0 {
entry:
  call void @puts(ptr @.str.3)
  ret void
}
define void @test.empty_startup() #0 {
entry:
  ret void
}

define void @test.shutdown() #0 {
entry:
  call void @puts(ptr @.str.4)
  ret void
}
define weak void @.__c3_atexit_test.shutdown() comdat {
entry:
  call void @atexit(ptr @test.shutdown)
  ret void
}