; ModuleID = 'ExceptionTest'
	%Object = type {}
	%UnwindInfo = type { i64, void (i32, %UnwindInfo *)*, i16, i16 }
	%Throwable = type { %Object, %UnwindInfo }

define i32 @main(i32, i8**) nounwind {
entry:
	invoke fastcc void @throwSomething() to label %nounwind unwind label %catch

catch:
	ret i32 0

nounwind:
	ret i32 -1
}

define internal fastcc void @throwSomething() noreturn {
entry:
	%throwable = malloc %Throwable
	call fastcc void @Throwable.construct(%Throwable* %throwable)
	%unwindInfo = getelementptr %Throwable* %throwable, i32 0, i32 1
	%throw = call i32 @_Unwind_RaiseException(%UnwindInfo* %unwindInfo)
	unreachable
}

define internal fastcc void @Throwable.construct(%Throwable* %self) nounwind {
entry:
	%exceptionClass = getelementptr %Throwable* %self, i32 0, i32 1, i32 0
	store i64 0, i64* %exceptionClass
	%exceptionCleanup = getelementptr %Throwable* %self, i32 0, i32 1, i32 1
	store void (i32, %UnwindInfo *)* @exceptionCleanupFn, void (i32, %UnwindInfo *)** %exceptionCleanup
	%private1 = getelementptr %Throwable* %self, i32 0, i32 1, i32 2
	store i16 0, i16* %private1
	%private2 = getelementptr %Throwable* %self, i32 0, i32 1, i32 3
	store i16 0, i16* %private2
	ret void
}

define internal void @exceptionCleanupFn(i32 %reason, %UnwindInfo * %exc) {
  ret void
}

declare i32 @_Unwind_RaiseException(%UnwindInfo*) noreturn
