// #target: macos-x64
module test;
import std;

fn void test1()
{
	int[] $x = { 1, 2, 3, 4 };
	var $y = $x +++ 5;
	io::printn($y);
}

fn void test2()
{
	int[] $x = {  };
	var $y = $x +++ 5;
	io::printn($y);
	$y = $y +++ 1;
	io::printn($y);
}

fn void test3()
{
	int[] $x = { [5] = 2 };
	var $y = $x +++ 5;
	io::printn($y);
}

fn void test4()
{
	int[4] $x = { [1] = 2 };
	var $y = $x +++ 5;
	io::printn($y);
}

fn void test5()
{
	int[4] $x = {  };
	var $y = $x +++ 5;
	io::printn($y);
}

fn int main()
{
	test1();
	test2();
	test3();
	test4();
	test5();
	return 0;
}

/* #expect: test.ll

@.__const = private unnamed_addr constant [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5], align 16
@.__const.1 = private unnamed_addr constant [1 x i32] [i32 5], align 4
@.__const.3 = private unnamed_addr constant [2 x i32] [i32 5, i32 1], align 4
@.__const.5 = private unnamed_addr constant { [5 x i32], i32, i32 } { [5 x i32] zeroinitializer, i32 2, i32 5 }, align 16
@.__const.7 = private unnamed_addr constant { i32, i32, [2 x i32], i32 } { i32 0, i32 2, [2 x i32] zeroinitializer, i32 5 }, align 16
@.__const.9 = private unnamed_addr constant { [4 x i32], i32 } { [4 x i32] zeroinitializer, i32 5 }, align 16

define void @test.test1() #0 {
entry:
  %literal = alloca [5 x i32], align 16
  %len = alloca i64, align 8
  %error_var = alloca i64, align 8
  %varargslots = alloca [1 x %any], align 16
  %taddr = alloca %"int[]", align 8
  %retparam = alloca i64, align 8
  %taddr2 = alloca %any, align 8
  %indirectarg = alloca %"any[]", align 8
  %error_var3 = alloca i64, align 8
  %error_var9 = alloca i64, align 8

define void @test.test2() #0 {
entry:
  %literal = alloca [1 x i32], align 4
  %len = alloca i64, align 8
  %error_var = alloca i64, align 8
  %varargslots = alloca [1 x %any], align 16
  %taddr = alloca %"int[]", align 8
  %retparam = alloca i64, align 8
  %taddr2 = alloca %any, align 8
  %indirectarg = alloca %"any[]", align 8
  %error_var3 = alloca i64, align 8
  %error_var9 = alloca i64, align 8
  %literal15 = alloca [2 x i32], align 4
  %len16 = alloca i64, align 8
  %error_var17 = alloca i64, align 8
  %varargslots19 = alloca [1 x %any], align 16
  %taddr20 = alloca %"int[]", align 8
  %retparam22 = alloca i64, align 8
  %taddr23 = alloca %any, align 8
  %indirectarg27 = alloca %"any[]", align 8
  %error_var33 = alloca i64, align 8
  %error_var39 = alloca i64, align 8
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %literal, ptr align 4 @.__const.1, i32 4, i1 false)
  %0 = insertvalue %"int[]" undef, ptr %literal, 0
  %1 = insertvalue %"int[]" %0, i64 1, 1
  %2 = call ptr @std.io.stdout()
  %3 = insertvalue %any undef, ptr %2, 0
  %4 = insertvalue %any %3, i64 ptrtoint (ptr @"$ct.std.io.File" to i64), 1
  store %"int[]" %1, ptr %taddr, align 8
  %5 = insertvalue %any undef, ptr %taddr, 0
  %6 = insertvalue %any %5, i64 ptrtoint (ptr @"$ct.sa$int" to i64), 1
  store %any %6, ptr %varargslots, align 16
  %7 = insertvalue %"any[]" undef, ptr %varargslots, 0
  %"$$temp" = insertvalue %"any[]" %7, i64 1, 1
  store %any %4, ptr %taddr2, align 8
  %lo = load i64, ptr %taddr2, align 8
  %ptradd = getelementptr inbounds i8, ptr %taddr2, i64 8
  %hi = load ptr, ptr %ptradd, align 8
  store %"any[]" %"$$temp", ptr %indirectarg, align 8
  %8 = call i64 @std.io.fprintf(ptr %retparam, i64 %lo, ptr %hi, ptr @.str.2, i64 2, ptr byval(%"any[]") align 8 %indirectarg)
  %not_err = icmp eq i64 %8, 0
  %9 = call i1 @llvm.expect.i1(i1 %not_err, i1 true)
  br i1 %9, label %after_check, label %assign_optional

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

after_check:                                      ; preds = %entry
  br label %noerr_block

guard_block:                                      ; preds = %assign_optional
  br label %voiderr

noerr_block:                                      ; preds = %after_check
  %10 = load i64, ptr %retparam, align 8
  store i64 %10, ptr %len, align 8
  %11 = call i64 @std.io.File.write_byte(ptr %2, i8 zeroext 10)
  %not_err4 = icmp eq i64 %11, 0
  %12 = call i1 @llvm.expect.i1(i1 %not_err4, i1 true)
  br i1 %12, label %after_check6, label %assign_optional5

assign_optional5:                                 ; preds = %noerr_block
  store i64 %11, ptr %error_var3, align 8
  br label %guard_block7

after_check6:                                     ; preds = %noerr_block
  br label %noerr_block8

guard_block7:                                     ; preds = %assign_optional5
  br label %voiderr

noerr_block8:                                     ; preds = %after_check6
  %13 = call i64 @std.io.File.flush(ptr %2)
  %not_err10 = icmp eq i64 %13, 0
  %14 = call i1 @llvm.expect.i1(i1 %not_err10, i1 true)
  br i1 %14, label %after_check12, label %assign_optional11

assign_optional11:                                ; preds = %noerr_block8
  store i64 %13, ptr %error_var9, align 8
  br label %guard_block13

after_check12:                                    ; preds = %noerr_block8
  br label %noerr_block14

guard_block13:                                    ; preds = %assign_optional11
  br label %voiderr

noerr_block14:                                    ; preds = %after_check12
  %15 = load i64, ptr %len, align 8
  %add = add i64 %15, 1
  br label %voiderr

voiderr:                                          ; preds = %noerr_block14, %guard_block13, %guard_block7, %guard_block
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %literal15, ptr align 4 @.__const.3, i32 8, i1 false)
  %16 = insertvalue %"int[]" undef, ptr %literal15, 0
  %17 = insertvalue %"int[]" %16, i64 2, 1
  %18 = call ptr @std.io.stdout()
  %19 = insertvalue %any undef, ptr %18, 0
  %20 = insertvalue %any %19, i64 ptrtoint (ptr @"$ct.std.io.File" to i64), 1
  store %"int[]" %17, ptr %taddr20, align 8
  %21 = insertvalue %any undef, ptr %taddr20, 0
  %22 = insertvalue %any %21, i64 ptrtoint (ptr @"$ct.sa$int" to i64), 1
  store %any %22, ptr %varargslots19, align 16
  %23 = insertvalue %"any[]" undef, ptr %varargslots19, 0
  %"$$temp21" = insertvalue %"any[]" %23, i64 1, 1
  store %any %20, ptr %taddr23, align 8
  %lo24 = load i64, ptr %taddr23, align 8
  %ptradd25 = getelementptr inbounds i8, ptr %taddr23, i64 8
  %hi26 = load ptr, ptr %ptradd25, align 8
  store %"any[]" %"$$temp21", ptr %indirectarg27, align 8
  %24 = call i64 @std.io.fprintf(ptr %retparam22, i64 %lo24, ptr %hi26, ptr @.str.4, i64 2, ptr byval(%"any[]") align 8 %indirectarg27)
  %not_err28 = icmp eq i64 %24, 0
  %25 = call i1 @llvm.expect.i1(i1 %not_err28, i1 true)
  br i1 %25, label %after_check30, label %assign_optional29

assign_optional29:                                ; preds = %voiderr
  store i64 %24, ptr %error_var17, align 8
  br label %guard_block31

after_check30:                                    ; preds = %voiderr
  br label %noerr_block32

guard_block31:                                    ; preds = %assign_optional29
  br label %voiderr46

noerr_block32:                                    ; preds = %after_check30
  %26 = load i64, ptr %retparam22, align 8
  store i64 %26, ptr %len16, align 8
  %27 = call i64 @std.io.File.write_byte(ptr %18, i8 zeroext 10)
  %not_err34 = icmp eq i64 %27, 0
  %28 = call i1 @llvm.expect.i1(i1 %not_err34, i1 true)
  br i1 %28, label %after_check36, label %assign_optional35

assign_optional35:                                ; preds = %noerr_block32
  store i64 %27, ptr %error_var33, align 8
  br label %guard_block37

after_check36:                                    ; preds = %noerr_block32
  br label %noerr_block38

guard_block37:                                    ; preds = %assign_optional35
  br label %voiderr46

noerr_block38:                                    ; preds = %after_check36
  %29 = call i64 @std.io.File.flush(ptr %18)
  %not_err40 = icmp eq i64 %29, 0
  %30 = call i1 @llvm.expect.i1(i1 %not_err40, i1 true)
  br i1 %30, label %after_check42, label %assign_optional41

assign_optional41:                                ; preds = %noerr_block38
  store i64 %29, ptr %error_var39, align 8
  br label %guard_block43

after_check42:                                    ; preds = %noerr_block38
  br label %noerr_block44

guard_block43:                                    ; preds = %assign_optional41
  br label %voiderr46

noerr_block44:                                    ; preds = %after_check42
  %31 = load i64, ptr %len16, align 8
  %add45 = add i64 %31, 1
  br label %voiderr46

voiderr46:                                        ; preds = %noerr_block44, %guard_block43, %guard_block37, %guard_block31
  ret void
}

define void @test.test3() #0 {
entry:
  %literal = alloca [7 x i32], align 16
  %len = alloca i64, align 8
  %error_var = alloca i64, align 8
  %varargslots = alloca [1 x %any], align 16
  %taddr = alloca %"int[]", align 8
  %retparam = alloca i64, align 8
  %taddr2 = alloca %any, align 8
  %indirectarg = alloca %"any[]", align 8
  %error_var3 = alloca i64, align 8
  %error_var9 = alloca i64, align 8
  call void @llvm.memcpy.p0.p0.i32(ptr align 16 %literal, ptr align 16 @.__const.5, i32 28, i1 false)
  %0 = insertvalue %"int[]" undef, ptr %literal, 0
  %1 = insertvalue %"int[]" %0, i64 7, 1
  %2 = call ptr @std.io.stdout()
  %3 = insertvalue %any undef, ptr %2, 0
  %4 = insertvalue %any %3, i64 ptrtoint (ptr @"$ct.std.io.File" to i64), 1
  store %"int[]" %1, ptr %taddr, align 8
  %5 = insertvalue %any undef, ptr %taddr, 0
  %6 = insertvalue %any %5, i64 ptrtoint (ptr @"$ct.sa$int" to i64), 1
  store %any %6, ptr %varargslots, align 16
  %7 = insertvalue %"any[]" undef, ptr %varargslots, 0
  %"$$temp" = insertvalue %"any[]" %7, i64 1, 1
  store %any %4, ptr %taddr2, align 8
  %lo = load i64, ptr %taddr2, align 8
  %ptradd = getelementptr inbounds i8, ptr %taddr2, i64 8
  %hi = load ptr, ptr %ptradd, align 8
  store %"any[]" %"$$temp", ptr %indirectarg, align 8
  %8 = call i64 @std.io.fprintf(ptr %retparam, i64 %lo, ptr %hi, ptr @.str.6, i64 2, ptr byval(%"any[]") align 8 %indirectarg)
  %not_err = icmp eq i64 %8, 0
  %9 = call i1 @llvm.expect.i1(i1 %not_err, i1 true)
  br i1 %9, label %after_check, label %assign_optional

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

after_check:                                      ; preds = %entry
  br label %noerr_block

guard_block:                                      ; preds = %assign_optional
  br label %voiderr

noerr_block:                                      ; preds = %after_check
  %10 = load i64, ptr %retparam, align 8
  store i64 %10, ptr %len, align 8
  %11 = call i64 @std.io.File.write_byte(ptr %2, i8 zeroext 10)
  %not_err4 = icmp eq i64 %11, 0
  %12 = call i1 @llvm.expect.i1(i1 %not_err4, i1 true)
  br i1 %12, label %after_check6, label %assign_optional5

assign_optional5:                                 ; preds = %noerr_block
  store i64 %11, ptr %error_var3, align 8
  br label %guard_block7

after_check6:                                     ; preds = %noerr_block
  br label %noerr_block8

guard_block7:                                     ; preds = %assign_optional5
  br label %voiderr

noerr_block8:                                     ; preds = %after_check6
  %13 = call i64 @std.io.File.flush(ptr %2)
  %not_err10 = icmp eq i64 %13, 0
  %14 = call i1 @llvm.expect.i1(i1 %not_err10, i1 true)
  br i1 %14, label %after_check12, label %assign_optional11

assign_optional11:                                ; preds = %noerr_block8
  store i64 %13, ptr %error_var9, align 8
  br label %guard_block13

after_check12:                                    ; preds = %noerr_block8
  br label %noerr_block14

guard_block13:                                    ; preds = %assign_optional11
  br label %voiderr

noerr_block14:                                    ; preds = %after_check12
  %15 = load i64, ptr %len, align 8
  %add = add i64 %15, 1
  br label %voiderr

voiderr:                                          ; preds = %noerr_block14, %guard_block13, %guard_block7, %guard_block
  ret void
}

define void @test.test4() #0 {
entry:
  %literal = alloca [5 x i32], align 16
  %x = alloca [5 x i32], align 16
  %x1 = alloca [5 x i32], align 16
  %len = alloca i64, align 8
  %error_var = alloca i64, align 8
  %x2 = alloca [5 x i32], align 16
  %varargslots = alloca [1 x %any], align 16
  %retparam = alloca i64, align 8
  %taddr = alloca %any, align 8
  %indirectarg = alloca %"any[]", align 8
  %error_var4 = alloca i64, align 8
  %error_var10 = alloca i64, align 8
  call void @llvm.memcpy.p0.p0.i32(ptr align 16 %literal, ptr align 16 @.__const.7, i32 20, i1 false)
  call void @llvm.memcpy.p0.p0.i32(ptr align 16 %x, ptr align 16 %literal, i32 20, i1 false)
  %0 = call ptr @std.io.stdout()
  call void @llvm.memcpy.p0.p0.i32(ptr align 16 %x1, ptr align 16 %x, i32 20, i1 false)
  call void @llvm.memcpy.p0.p0.i32(ptr align 16 %x2, ptr align 16 %x1, i32 20, i1 false)
  %1 = insertvalue %any undef, ptr %0, 0
  %2 = insertvalue %any %1, i64 ptrtoint (ptr @"$ct.std.io.File" to i64), 1
  %3 = insertvalue %any undef, ptr %x2, 0
  %4 = insertvalue %any %3, i64 ptrtoint (ptr @"$ct.a5$int" to i64), 1
  store %any %4, ptr %varargslots, align 16
  %5 = insertvalue %"any[]" undef, ptr %varargslots, 0
  %"$$temp" = insertvalue %"any[]" %5, i64 1, 1
  store %any %2, ptr %taddr, align 8
  %lo = load i64, ptr %taddr, align 8
  %ptradd = getelementptr inbounds i8, ptr %taddr, i64 8
  %hi = load ptr, ptr %ptradd, align 8
  store %"any[]" %"$$temp", ptr %indirectarg, align 8
  %6 = call i64 @std.io.fprintf(ptr %retparam, i64 %lo, ptr %hi, ptr @.str.8, i64 2, ptr byval(%"any[]") align 8 %indirectarg)
  %not_err = icmp eq i64 %6, 0
  %7 = call i1 @llvm.expect.i1(i1 %not_err, i1 true)
  br i1 %7, label %after_check, label %assign_optional

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

after_check:                                      ; preds = %entry
  br label %noerr_block

guard_block:                                      ; preds = %assign_optional
  br label %voiderr

noerr_block:                                      ; preds = %after_check
  %8 = load i64, ptr %retparam, align 8
  store i64 %8, ptr %len, align 8
  %9 = call i64 @std.io.File.write_byte(ptr %0, i8 zeroext 10)
  %not_err5 = icmp eq i64 %9, 0
  %10 = call i1 @llvm.expect.i1(i1 %not_err5, i1 true)
  br i1 %10, label %after_check7, label %assign_optional6

assign_optional6:                                 ; preds = %noerr_block
  store i64 %9, ptr %error_var4, align 8
  br label %guard_block8

after_check7:                                     ; preds = %noerr_block
  br label %noerr_block9

guard_block8:                                     ; preds = %assign_optional6
  br label %voiderr

noerr_block9:                                     ; preds = %after_check7
  %11 = call i64 @std.io.File.flush(ptr %0)
  %not_err11 = icmp eq i64 %11, 0
  %12 = call i1 @llvm.expect.i1(i1 %not_err11, i1 true)
  br i1 %12, label %after_check13, label %assign_optional12

assign_optional12:                                ; preds = %noerr_block9
  store i64 %11, ptr %error_var10, align 8
  br label %guard_block14

after_check13:                                    ; preds = %noerr_block9
  br label %noerr_block15

guard_block14:                                    ; preds = %assign_optional12
  br label %voiderr

noerr_block15:                                    ; preds = %after_check13
  %13 = load i64, ptr %len, align 8
  %add = add i64 %13, 1
  br label %voiderr

voiderr:                                          ; preds = %noerr_block15, %guard_block14, %guard_block8, %guard_block
  ret void
}

define void @test.test5() #0 {
entry:
  %literal = alloca [5 x i32], align 16
  %x = alloca [5 x i32], align 16
  %x1 = alloca [5 x i32], align 16
  %len = alloca i64, align 8
  %error_var = alloca i64, align 8
  %x2 = alloca [5 x i32], align 16
  %varargslots = alloca [1 x %any], align 16
  %retparam = alloca i64, align 8
  %taddr = alloca %any, align 8
  %indirectarg = alloca %"any[]", align 8
  %error_var4 = alloca i64, align 8
  %error_var10 = alloca i64, align 8
  call void @llvm.memcpy.p0.p0.i32(ptr align 16 %literal, ptr align 16 @.__const.9, i32 20, i1 false)
  call void @llvm.memcpy.p0.p0.i32(ptr align 16 %x, ptr align 16 %literal, i32 20, i1 false)
  %0 = call ptr @std.io.stdout()
  call void @llvm.memcpy.p0.p0.i32(ptr align 16 %x1, ptr align 16 %x, i32 20, i1 false)
  call void @llvm.memcpy.p0.p0.i32(ptr align 16 %x2, ptr align 16 %x1, i32 20, i1 false)
  %1 = insertvalue %any undef, ptr %0, 0
  %2 = insertvalue %any %1, i64 ptrtoint (ptr @"$ct.std.io.File" to i64), 1
  %3 = insertvalue %any undef, ptr %x2, 0
  %4 = insertvalue %any %3, i64 ptrtoint (ptr @"$ct.a5$int" to i64), 1
  store %any %4, ptr %varargslots, align 16
  %5 = insertvalue %"any[]" undef, ptr %varargslots, 0
  %"$$temp" = insertvalue %"any[]" %5, i64 1, 1
  store %any %2, ptr %taddr, align 8
  %lo = load i64, ptr %taddr, align 8
  %ptradd = getelementptr inbounds i8, ptr %taddr, i64 8
  %hi = load ptr, ptr %ptradd, align 8
  store %"any[]" %"$$temp", ptr %indirectarg, align 8
  %6 = call i64 @std.io.fprintf(ptr %retparam, i64 %lo, ptr %hi, ptr @.str.10, i64 2, ptr byval(%"any[]") align 8 %indirectarg)
  %not_err = icmp eq i64 %6, 0
  %7 = call i1 @llvm.expect.i1(i1 %not_err, i1 true)
  br i1 %7, label %after_check, label %assign_optional

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

after_check:                                      ; preds = %entry
  br label %noerr_block

guard_block:                                      ; preds = %assign_optional
  br label %voiderr

noerr_block:                                      ; preds = %after_check
  %8 = load i64, ptr %retparam, align 8
  store i64 %8, ptr %len, align 8
  %9 = call i64 @std.io.File.write_byte(ptr %0, i8 zeroext 10)
  %not_err5 = icmp eq i64 %9, 0
  %10 = call i1 @llvm.expect.i1(i1 %not_err5, i1 true)
  br i1 %10, label %after_check7, label %assign_optional6

assign_optional6:                                 ; preds = %noerr_block
  store i64 %9, ptr %error_var4, align 8
  br label %guard_block8

after_check7:                                     ; preds = %noerr_block
  br label %noerr_block9

guard_block8:                                     ; preds = %assign_optional6
  br label %voiderr

noerr_block9:                                     ; preds = %after_check7
  %11 = call i64 @std.io.File.flush(ptr %0)
  %not_err11 = icmp eq i64 %11, 0
  %12 = call i1 @llvm.expect.i1(i1 %not_err11, i1 true)
  br i1 %12, label %after_check13, label %assign_optional12

assign_optional12:                                ; preds = %noerr_block9
  store i64 %11, ptr %error_var10, align 8
  br label %guard_block14

after_check13:                                    ; preds = %noerr_block9
  br label %noerr_block15

guard_block14:                                    ; preds = %assign_optional12
  br label %voiderr

noerr_block15:                                    ; preds = %after_check13
  %13 = load i64, ptr %len, align 8
  %add = add i64 %13, 1
  br label %voiderr

voiderr:                                          ; preds = %noerr_block15, %guard_block14, %guard_block8, %guard_block
  ret void
}
