; LLVM IR from ponylang/ponyc :: src/libponyc/ast (ast)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@__func__.ast_reorder_children = external hidden unnamed_addr constant [21 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.50 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.51 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @ast_childcount(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @ast_pop(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @ast_append(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @ast_reorder_children(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %16

15:                                               ; preds = %3
  call void @ponyint_assert_fail(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 1621, ptr noundef @__func__.ast_reorder_children)
  br label %16

16:                                               ; preds = %15, %14
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  br label %21

20:                                               ; preds = %16
  call void @ponyint_assert_fail(ptr noundef @.str.49, ptr noundef @.str.1, i64 noundef 1622, ptr noundef @__func__.ast_reorder_children)
  br label %21

21:                                               ; preds = %20, %19
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  br label %26

25:                                               ; preds = %21
  call void @ponyint_assert_fail(ptr noundef @.str.50, ptr noundef @.str.1, i64 noundef 1623, ptr noundef @__func__.ast_reorder_children)
  br label %26

26:                                               ; preds = %25, %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call i64 @ast_childcount(ptr noundef %27)
  store i64 %28, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %40, %26
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %43

34:                                               ; preds = %29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call ptr @ast_pop(ptr noundef %35)
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = getelementptr inbounds ptr, ptr %37, i64 %38
  store ptr %36, ptr %39, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %34
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = add i64 %41, 1
  store i64 %42, ptr %8, align 8, !tbaa !9
  br label %29, !llvm.loop !11

43:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %75, %43
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = icmp ult i64 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %78

49:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i64, ptr %9, align 8, !tbaa !9
  %52 = getelementptr inbounds i64, ptr %50, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !9
  store i64 %53, ptr %10, align 8, !tbaa !9
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = icmp ult i64 %54, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %49
  br label %59

58:                                               ; preds = %49
  call void @ponyint_assert_fail(ptr noundef @.str.51, ptr noundef @.str.1, i64 noundef 1633, ptr noundef @__func__.ast_reorder_children)
  br label %59

59:                                               ; preds = %58, %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load i64, ptr %10, align 8, !tbaa !9
  %62 = getelementptr inbounds ptr, ptr %60, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  store ptr %63, ptr %11, align 8, !tbaa !5
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %67

66:                                               ; preds = %59
  br label %68

67:                                               ; preds = %59
  call void @ponyint_assert_fail(ptr noundef @.str.52, ptr noundef @.str.1, i64 noundef 1635, ptr noundef @__func__.ast_reorder_children)
  br label %68

68:                                               ; preds = %67, %66
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load ptr, ptr %11, align 8, !tbaa !5
  %71 = call ptr @ast_append(ptr noundef %69, ptr noundef %70)
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = load i64, ptr %10, align 8, !tbaa !9
  %74 = getelementptr inbounds ptr, ptr %72, i64 %73
  store ptr null, ptr %74, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %75

75:                                               ; preds = %68
  %76 = load i64, ptr %9, align 8, !tbaa !9
  %77 = add i64 %76, 1
  store i64 %77, ptr %9, align 8, !tbaa !9
  br label %44, !llvm.loop !13

78:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@__func__.ast_reorder_children = external hidden unnamed_addr constant [21 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.50 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.51 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [10 x i8], align 1

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @ast_childcount(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @ast_pop(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @ast_append(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @ast_reorder_children(ptr noundef %0, ptr noundef readonly %1, ptr noundef %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %3
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 1621, ptr noundef nonnull @__func__.ast_reorder_children) #2
  br label %5

5:                                                ; preds = %3, %4
  %.not25 = icmp eq ptr %1, null
  br i1 %.not25, label %6, label %7

6:                                                ; preds = %5
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.49, ptr noundef nonnull @.str.1, i64 noundef 1622, ptr noundef nonnull @__func__.ast_reorder_children) #2
  br label %7

7:                                                ; preds = %5, %6
  %.not26 = icmp eq ptr %2, null
  br i1 %.not26, label %8, label %9

8:                                                ; preds = %7
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.50, ptr noundef nonnull @.str.1, i64 noundef 1623, ptr noundef nonnull @__func__.ast_reorder_children) #2
  br label %9

9:                                                ; preds = %7, %8
  %10 = tail call i64 @ast_childcount(ptr noundef %0)
  %.not31 = icmp eq i64 %10, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %9, %.lr.ph
  %.028 = phi i64 [ %13, %.lr.ph ], [ 0, %9 ]
  %11 = tail call ptr @ast_pop(ptr noundef %0)
  %12 = getelementptr inbounds ptr, ptr %2, i64 %.028
  store ptr %11, ptr %12, align 8, !tbaa !5
  %13 = add nuw i64 %.028, 1
  %exitcond.not = icmp eq i64 %13, %10
  br i1 %exitcond.not, label %.lr.ph30, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %22, %9
  ret void

.lr.ph30:                                         ; preds = %.lr.ph, %22
  %.02329 = phi i64 [ %24, %22 ], [ 0, %.lr.ph ]
  %14 = getelementptr inbounds i64, ptr %1, i64 %.02329
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = icmp ult i64 %15, %10
  br i1 %16, label %18, label %17

17:                                               ; preds = %.lr.ph30
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.51, ptr noundef nonnull @.str.1, i64 noundef 1633, ptr noundef nonnull @__func__.ast_reorder_children) #2
  br label %18

18:                                               ; preds = %.lr.ph30, %17
  %19 = getelementptr inbounds ptr, ptr %2, i64 %15
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %.not27 = icmp eq ptr %20, null
  br i1 %.not27, label %21, label %22

21:                                               ; preds = %18
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.52, ptr noundef nonnull @.str.1, i64 noundef 1635, ptr noundef nonnull @__func__.ast_reorder_children) #2
  br label %22

22:                                               ; preds = %18, %21
  %23 = tail call ptr @ast_append(ptr noundef %0, ptr noundef %20)
  store ptr null, ptr %19, align 8, !tbaa !5
  %24 = add nuw i64 %.02329, 1
  %exitcond33.not = icmp eq i64 %24, %10
  br i1 %exitcond33.not, label %._crit_edge, label %.lr.ph30, !llvm.loop !13
}

attributes #0 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass