// #target: macos-x64
module test;
faultdef OH_NO;
const C = 1;
fn void main() => do_thing()!!;

fn void? do_thing()
{
    int* a_value = mem::alloc_array(int, may_fault()!);
}
macro may_fault()
{
	return OH_NO~;
}

/* #expect: test.ll

define void @test.main() #0 {
entry:
  %error_var = alloca i64, align 8
  %varargslots = alloca [1 x %any], align 16
  %indirectarg = alloca %"any[]", align 8
  %0 = call i64 @test.do_thing()
  %not_err = icmp eq i64 %0, 0
  %1 = call i1 @llvm.expect.i1(i1 %not_err, i1 true)
  br i1 %1, label %after_check, label %assign_optional

assign_optional:                                  ; preds = %entry
  store i64 %0, ptr %error_var, align 8
  br label %panic_block

after_check:                                      ; preds = %entry
  br label %noerr_block

panic_block:                                      ; preds = %assign_optional
  %2 = insertvalue %any undef, ptr %error_var, 0
  %3 = insertvalue %any %2, i64 ptrtoint (ptr @"$ct.fault" to i64), 1
  store %any %3, ptr %varargslots, align 16
  %4 = insertvalue %"any[]" undef, ptr %varargslots, 0
  %"$$temp" = insertvalue %"any[]" %4, i64 1, 1
  store %"any[]" %"$$temp", ptr %indirectarg, align 8
  call void @std.core.builtin.panicf(ptr @.panic_msg, i64 36, ptr @.file, i64 22, ptr @.func, i64 4, i32 4, ptr byval(%"any[]") align 8 %indirectarg) #2
  unreachable

noerr_block:                                      ; preds = %after_check
  ret void
}

define i64 @test.do_thing() #0 {
entry:
  %a_value = alloca ptr, align 8
  %error_var = alloca i64, align 8
  store i64 ptrtoint (ptr @test.OH_NO to i64), ptr %error_var, align 8
  br label %guard_block

guard_block:                                      ; preds = %entry
  %0 = load i64, ptr %error_var, align 8
  ret i64 %0

after_macro:                                      ; No predecessors!
  store ptr poison, ptr %a_value, align 8
  ret i64 0
}
