; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_tree)

; 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"

%struct.MTreeNode = type { ptr, ptr, ptr, i32 }

@.str = external hidden unnamed_addr constant [76 x i8], align 1
@__FUNCTION__.TreeTraversal = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 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 @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @TreeTraversal(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %21, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = ptrtoint ptr %18 to i64
  %20 = icmp eq i64 %19, -1
  br label %21

21:                                               ; preds = %17, %14
  %22 = phi i1 [ true, %14 ], [ %20, %17 ]
  %23 = zext i1 %22 to i32
  store i32 %23, ptr %9, align 4, !tbaa !9
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %21
  %27 = load i32, ptr %9, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %27, i32 noundef -1, ptr noundef @.str, i32 noundef 124, ptr noundef @__FUNCTION__.TreeTraversal, ptr noundef @.str.3)
  br label %28

28:                                               ; preds = %26, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %58

32:                                               ; preds = %29
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  call void %33(ptr noundef %34, ptr noundef %35)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %54, %32
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.MTreeNode, ptr %38, i32 0, i32 3
  %40 = load i32, ptr %39, align 8, !tbaa !11
  %41 = icmp slt i32 %37, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %57

43:                                               ; preds = %36
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.MTreeNode, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !13
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !9
  call void @TreeTraversal(ptr noundef %50, ptr noundef %51, ptr noundef %52, i32 noundef %53)
  br label %54

54:                                               ; preds = %43
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %10, align 4, !tbaa !9
  br label %36, !llvm.loop !14

57:                                               ; preds = %42
  br label %132

58:                                               ; preds = %29
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = icmp eq i32 %59, 1
  br i1 %60, label %61, label %87

61:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %80, %61
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.MTreeNode, ptr %64, i32 0, i32 3
  %66 = load i32, ptr %65, align 8, !tbaa !11
  %67 = icmp slt i32 %63, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %83

69:                                               ; preds = %62
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.MTreeNode, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !13
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds ptr, ptr %72, i64 %74
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = load i32, ptr %8, align 4, !tbaa !9
  call void @TreeTraversal(ptr noundef %76, ptr noundef %77, ptr noundef %78, i32 noundef %79)
  br label %80

80:                                               ; preds = %69
  %81 = load i32, ptr %11, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %11, align 4, !tbaa !9
  br label %62, !llvm.loop !16

83:                                               ; preds = %68
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  call void %84(ptr noundef %85, ptr noundef %86)
  br label %131

87:                                               ; preds = %58
  %88 = load i32, ptr %8, align 4, !tbaa !9
  %89 = icmp eq i32 %88, 2
  br i1 %89, label %90, label %122

90:                                               ; preds = %87
  br label %91

91:                                               ; preds = %90
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.MTreeNode, ptr %92, i32 0, i32 3
  %94 = load i32, ptr %93, align 8, !tbaa !11
  %95 = icmp ne i32 %94, 2
  %96 = zext i1 %95 to i32
  store i32 %96, ptr %12, align 4, !tbaa !9
  %97 = load i32, ptr %12, align 4, !tbaa !9
  %98 = icmp ne i32 %97, 0
  br i1 %98, label %99, label %101

99:                                               ; preds = %91
  %100 = load i32, ptr %12, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %100, i32 noundef -1, ptr noundef @.str, i32 noundef 140, ptr noundef @__FUNCTION__.TreeTraversal, ptr noundef @.str.4)
  br label %101

101:                                              ; preds = %99, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %102

102:                                              ; preds = %101
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.MTreeNode, ptr %103, i32 0, i32 1
  %105 = load ptr, ptr %104, align 8, !tbaa !13
  %106 = getelementptr inbounds ptr, ptr %105, i64 0
  %107 = load ptr, ptr %106, align 8, !tbaa !5
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  %110 = load i32, ptr %8, align 4, !tbaa !9
  call void @TreeTraversal(ptr noundef %107, ptr noundef %108, ptr noundef %109, i32 noundef %110)
  %111 = load ptr, ptr %6, align 8, !tbaa !5
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = load ptr, ptr %7, align 8, !tbaa !5
  call void %111(ptr noundef %112, ptr noundef %113)
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.MTreeNode, ptr %114, i32 0, i32 1
  %116 = load ptr, ptr %115, align 8, !tbaa !13
  %117 = getelementptr inbounds ptr, ptr %116, i64 1
  %118 = load ptr, ptr %117, align 8, !tbaa !5
  %119 = load ptr, ptr %6, align 8, !tbaa !5
  %120 = load ptr, ptr %7, align 8, !tbaa !5
  %121 = load i32, ptr %8, align 4, !tbaa !9
  call void @TreeTraversal(ptr noundef %118, ptr noundef %119, ptr noundef %120, i32 noundef %121)
  br label %130

122:                                              ; preds = %87
  br label %123

123:                                              ; preds = %122
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 1, ptr %13, align 4, !tbaa !9
  %124 = load i32, ptr %13, align 4, !tbaa !9
  %125 = icmp ne i32 %124, 0
  br i1 %125, label %126, label %128

126:                                              ; preds = %123
  %127 = load i32, ptr %13, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %127, i32 noundef -1, ptr noundef @.str, i32 noundef 146, ptr noundef @__FUNCTION__.TreeTraversal, ptr noundef @.str.4)
  br label %128

128:                                              ; preds = %126, %123
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %129

129:                                              ; preds = %128
  br label %130

130:                                              ; preds = %129, %102
  br label %131

131:                                              ; preds = %130, %83
  br label %132

132:                                              ; preds = %131, %57
  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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"MTreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 [76 x i8], align 1
@__FUNCTION__.TreeTraversal = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 x i8], align 1

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TreeTraversal(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
tailrecurse.peel.begin:
  %magicptr.peel = ptrtoint ptr %0 to i64
  switch i64 %magicptr.peel, label %9 [
    i64 -1, label %4
    i64 0, label %4
  ]

4:                                                ; preds = %tailrecurse.peel.begin, %tailrecurse.peel.begin
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %0, inttoptr (i64 -1 to ptr)
  %7 = or i1 %5, %6
  %8 = zext i1 %7 to i32
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %8, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 124, ptr noundef nonnull @__FUNCTION__.TreeTraversal, ptr noundef nonnull @.str.3) #2
  br label %9

9:                                                ; preds = %4, %tailrecurse.peel.begin
  switch i32 %3, label %48 [
    i32 -1, label %25
    i32 1, label %.preheader
    i32 2, label %10
  ]

10:                                               ; preds = %9
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %.not.peel = icmp eq i32 %12, 2
  br i1 %.not.peel, label %tailrecurse.preheader, label %tailrecurse.sink.split

tailrecurse.sink.split:                           ; preds = %10, %47
  %.tr.sink65.ph = phi ptr [ %.tr, %47 ], [ %0, %10 ]
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 140, ptr noundef nonnull @__FUNCTION__.TreeTraversal, ptr noundef nonnull @.str.4) #2
  br label %tailrecurse.preheader

tailrecurse.preheader:                            ; preds = %10, %tailrecurse.sink.split
  %.tr.sink65.ph66 = phi ptr [ %.tr.sink65.ph, %tailrecurse.sink.split ], [ %0, %10 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.preheader, %44
  %.tr.sink65 = phi ptr [ %.tr, %44 ], [ %.tr.sink65.ph66, %tailrecurse.preheader ]
  %13 = getelementptr inbounds i8, ptr %.tr.sink65, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  tail call void @TreeTraversal(ptr noundef %15, ptr noundef %1, ptr noundef %2, i32 noundef 2)
  tail call void %1(ptr noundef nonnull %.tr.sink65, ptr noundef %2) #2
  %.pn = load ptr, ptr %13, align 8, !tbaa !11
  %.tr.in = getelementptr inbounds i8, ptr %.pn, i64 8
  %.tr = load ptr, ptr %.tr.in, align 8, !tbaa !12
  %magicptr = ptrtoint ptr %.tr to i64
  switch i64 %magicptr, label %44 [
    i64 -1, label %16
    i64 0, label %16
  ]

16:                                               ; preds = %tailrecurse, %tailrecurse
  %17 = icmp eq ptr %.tr, null
  %18 = icmp eq ptr %.tr, inttoptr (i64 -1 to ptr)
  %19 = or i1 %17, %18
  %20 = zext i1 %19 to i32
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %20, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 124, ptr noundef nonnull @__FUNCTION__.TreeTraversal, ptr noundef nonnull @.str.3) #2
  br label %44

.preheader:                                       ; preds = %9
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load i32, ptr %21, align 8, !tbaa !5
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  br label %37

25:                                               ; preds = %9
  tail call void %1(ptr noundef %0, ptr noundef %2) #2
  %26 = getelementptr inbounds i8, ptr %0, i64 24
  %27 = load i32, ptr %26, align 8, !tbaa !5
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.lr.ph54, label %.loopexit

.lr.ph54:                                         ; preds = %25
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  br label %30

30:                                               ; preds = %.lr.ph54, %30
  %indvars.iv61 = phi i64 [ 0, %.lr.ph54 ], [ %indvars.iv.next62, %30 ]
  %31 = load ptr, ptr %29, align 8, !tbaa !11
  %32 = getelementptr inbounds ptr, ptr %31, i64 %indvars.iv61
  %33 = load ptr, ptr %32, align 8, !tbaa !12
  tail call void @TreeTraversal(ptr noundef %33, ptr noundef %1, ptr noundef %2, i32 noundef -1)
  %indvars.iv.next62 = add nuw nsw i64 %indvars.iv61, 1
  %34 = load i32, ptr %26, align 8, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %indvars.iv.next62, %35
  br i1 %36, label %30, label %.loopexit, !llvm.loop !13

._crit_edge:                                      ; preds = %37, %.preheader
  tail call void %1(ptr noundef nonnull %0, ptr noundef %2) #2
  br label %.loopexit

37:                                               ; preds = %.lr.ph, %37
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %37 ]
  %38 = load ptr, ptr %24, align 8, !tbaa !11
  %39 = getelementptr inbounds ptr, ptr %38, i64 %indvars.iv
  %40 = load ptr, ptr %39, align 8, !tbaa !12
  tail call void @TreeTraversal(ptr noundef %40, ptr noundef %1, ptr noundef %2, i32 noundef 1)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %41 = load i32, ptr %21, align 8, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = icmp slt i64 %indvars.iv.next, %42
  br i1 %43, label %37, label %._crit_edge, !llvm.loop !15

44:                                               ; preds = %16, %tailrecurse
  %45 = getelementptr inbounds i8, ptr %.tr, i64 24
  %46 = load i32, ptr %45, align 8, !tbaa !5
  %.not = icmp eq i32 %46, 2
  br i1 %.not, label %tailrecurse, label %47, !llvm.loop !16

47:                                               ; preds = %44
  br label %tailrecurse.sink.split, !llvm.loop !16

48:                                               ; preds = %9
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 146, ptr noundef nonnull @__FUNCTION__.TreeTraversal, ptr noundef nonnull @.str.4) #2
  br label %.loopexit

.loopexit:                                        ; preds = %30, %25, %._crit_edge, %48
  ret void
}

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, !10, i64 24}
!6 = !{!"MTreeNode", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass