; 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__.mTreeNodeInsert = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 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

declare void @m_Free(ptr noundef) #1

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
define dso_local void @mTreeNodeInsert(ptr noundef %0, ptr noundef %1, i32 noundef %2) #4 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.MTreeNode, ptr %12, i32 0, i32 2
  store ptr %11, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MTreeNode, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !13
  store i32 %16, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %3
  %20 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %20, ptr %6, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %19, %3
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp sge i32 %22, %23
  br i1 %24, label %25, label %145

25:                                               ; preds = %21
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.MTreeNode, ptr %28, i32 0, i32 3
  store i32 %27, ptr %29, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.MTreeNode, ptr %30, i64 1
  store ptr %31, ptr %8, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds i32, ptr %33, i64 1
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = icmp ne i32 %35, -1466760809
  %37 = zext i1 %36 to i32
  store i32 %37, ptr %9, align 4, !tbaa !9
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %32
  %41 = load i32, ptr %9, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %41, i32 noundef 1, ptr noundef @.str, i32 noundef 100, ptr noundef @__FUNCTION__.mTreeNodeInsert, ptr noundef @.str.2)
  br label %42

42:                                               ; preds = %40, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MTreeNode, ptr %45, i32 0, i32 3
  %47 = load i32, ptr %46, align 8, !tbaa !13
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds i32, ptr %48, i64 0
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = icmp sgt i32 %47, %50
  br i1 %51, label %52, label %144

52:                                               ; preds = %44
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds i32, ptr %53, i64 0
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %60

57:                                               ; preds = %52
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds i32, ptr %58, i64 0
  store i32 2, ptr %59, align 4, !tbaa !9
  br label %89

60:                                               ; preds = %52
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds i32, ptr %61, i64 0
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = icmp slt i32 %63, 4
  br i1 %64, label %65, label %68

65:                                               ; preds = %60
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds i32, ptr %66, i64 0
  store i32 4, ptr %67, align 4, !tbaa !9
  br label %88

68:                                               ; preds = %60
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds i32, ptr %69, i64 0
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = icmp slt i32 %71, 16
  br i1 %72, label %73, label %78

73:                                               ; preds = %68
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds i32, ptr %74, i64 0
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = add nsw i32 %76, 4
  store i32 %77, ptr %75, align 4, !tbaa !9
  br label %87

78:                                               ; preds = %68
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = getelementptr inbounds i32, ptr %79, i64 0
  %81 = load i32, ptr %80, align 4, !tbaa !9
  %82 = sdiv i32 %81, 3
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds i32, ptr %83, i64 0
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = add nsw i32 %85, %82
  store i32 %86, ptr %84, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %78, %73
  br label %88

88:                                               ; preds = %87, %65
  br label %89

89:                                               ; preds = %88, %57
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = getelementptr inbounds i32, ptr %90, i64 0
  %92 = load i32, ptr %91, align 4, !tbaa !9
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.MTreeNode, ptr %93, i32 0, i32 3
  %95 = load i32, ptr %94, align 8, !tbaa !13
  %96 = icmp sgt i32 %92, %95
  br i1 %96, label %97, label %101

97:                                               ; preds = %89
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds i32, ptr %98, i64 0
  %100 = load i32, ptr %99, align 4, !tbaa !9
  br label %105

101:                                              ; preds = %89
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.MTreeNode, ptr %102, i32 0, i32 3
  %104 = load i32, ptr %103, align 8, !tbaa !13
  br label %105

105:                                              ; preds = %101, %97
  %106 = phi i32 [ %100, %97 ], [ %104, %101 ]
  %107 = load ptr, ptr %8, align 8, !tbaa !5
  %108 = getelementptr inbounds i32, ptr %107, i64 0
  store i32 %106, ptr %108, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = getelementptr inbounds i32, ptr %109, i64 0
  %111 = load i32, ptr %110, align 4, !tbaa !9
  %112 = sext i32 %111 to i64
  %113 = mul i64 %112, 8
  %114 = trunc i64 %113 to i32
  %115 = call ptr @m_Malloc(i32 noundef %114)
  store ptr %115, ptr %10, align 8, !tbaa !5
  %116 = load i32, ptr %7, align 4, !tbaa !9
  %117 = icmp sgt i32 %116, 0
  br i1 %117, label %118, label %129

118:                                              ; preds = %105
  %119 = load ptr, ptr %10, align 8, !tbaa !5
  %120 = load ptr, ptr %4, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.MTreeNode, ptr %120, i32 0, i32 1
  %122 = load ptr, ptr %121, align 8, !tbaa !14
  %123 = load i32, ptr %7, align 4, !tbaa !9
  %124 = sext i32 %123 to i64
  %125 = mul i64 %124, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %119, ptr align 8 %122, i64 %125, i1 false)
  %126 = load ptr, ptr %4, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.MTreeNode, ptr %126, i32 0, i32 1
  %128 = load ptr, ptr %127, align 8, !tbaa !14
  call void @m_Free(ptr noundef %128)
  br label %129

129:                                              ; preds = %118, %105
  %130 = load ptr, ptr %10, align 8, !tbaa !5
  %131 = load i32, ptr %7, align 4, !tbaa !9
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds ptr, ptr %130, i64 %132
  %134 = load ptr, ptr %8, align 8, !tbaa !5
  %135 = getelementptr inbounds i32, ptr %134, i64 0
  %136 = load i32, ptr %135, align 4, !tbaa !9
  %137 = load i32, ptr %7, align 4, !tbaa !9
  %138 = sub nsw i32 %136, %137
  %139 = sext i32 %138 to i64
  %140 = mul i64 %139, 8
  call void @llvm.memset.p0.i64(ptr align 8 %133, i8 0, i64 %140, i1 false)
  %141 = load ptr, ptr %10, align 8, !tbaa !5
  %142 = load ptr, ptr %4, align 8, !tbaa !5
  %143 = getelementptr inbounds %struct.MTreeNode, ptr %142, i32 0, i32 1
  store ptr %141, ptr %143, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %144

144:                                              ; preds = %129, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %145

145:                                              ; preds = %144, %21
  %146 = load ptr, ptr %5, align 8, !tbaa !5
  %147 = load ptr, ptr %4, align 8, !tbaa !5
  %148 = getelementptr inbounds %struct.MTreeNode, ptr %147, i32 0, i32 1
  %149 = load ptr, ptr %148, align 8, !tbaa !14
  %150 = load i32, ptr %6, align 4, !tbaa !9
  %151 = sext i32 %150 to i64
  %152 = getelementptr inbounds ptr, ptr %149, i64 %151
  store ptr %146, ptr %152, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

declare ptr @m_Malloc(i32 noundef) #1

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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, !6, i64 16}
!12 = !{!"MTreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 24}
!14 = !{!12, !6, i64 8}


; 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__.mTreeNodeInsert = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1

declare void @m_Free(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @mTreeNodeInsert(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #3 {
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %7 = icmp slt i32 %2, 0
  %spec.select = select i1 %7, i32 %6, i32 %2
  %.not = icmp slt i32 %spec.select, %6
  br i1 %.not, label %48, label %8

8:                                                ; preds = %3
  %9 = add nsw i32 %spec.select, 1
  store i32 %9, ptr %5, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = getelementptr inbounds i8, ptr %0, i64 36
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %.not47 = icmp eq i32 %12, -1466760809
  br i1 %.not47, label %14, label %13

13:                                               ; preds = %8
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef 1, ptr noundef nonnull @.str, i32 noundef 100, ptr noundef nonnull @__FUNCTION__.mTreeNodeInsert, ptr noundef nonnull @.str.2) #5
  %.pre = load i32, ptr %5, align 8, !tbaa !11
  br label %14

14:                                               ; preds = %13, %8
  %15 = phi i32 [ %.pre, %13 ], [ %9, %8 ]
  %16 = load i32, ptr %10, align 4, !tbaa !12
  %17 = icmp sgt i32 %15, %16
  br i1 %17, label %18, label %48

18:                                               ; preds = %14
  %19 = icmp eq i32 %16, 0
  br i1 %19, label %29, label %20

20:                                               ; preds = %18
  %21 = icmp slt i32 %16, 4
  br i1 %21, label %29, label %22

22:                                               ; preds = %20
  %23 = icmp ult i32 %16, 16
  br i1 %23, label %24, label %26

24:                                               ; preds = %22
  %25 = add nuw nsw i32 %16, 4
  br label %29

26:                                               ; preds = %22
  %27 = udiv i32 %16, 3
  %28 = add nuw nsw i32 %27, %16
  br label %29

29:                                               ; preds = %20, %18, %26, %24
  %30 = phi i32 [ %28, %26 ], [ %25, %24 ], [ 2, %18 ], [ 4, %20 ]
  %. = tail call i32 @llvm.smax.i32(i32 %30, i32 %15)
  store i32 %., ptr %10, align 4, !tbaa !12
  %31 = shl i32 %., 3
  %32 = tail call ptr @m_Malloc(i32 noundef %31) #5
  %33 = icmp sgt i32 %6, 0
  br i1 %33, label %34, label %40

34:                                               ; preds = %29
  %35 = getelementptr inbounds i8, ptr %0, i64 8
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = zext nneg i32 %6 to i64
  %38 = shl nuw nsw i64 %37, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %32, ptr align 8 %36, i64 %38, i1 false)
  %39 = load ptr, ptr %35, align 8, !tbaa !13
  tail call void @m_Free(ptr noundef %39) #5
  br label %40

40:                                               ; preds = %34, %29
  %41 = sext i32 %6 to i64
  %42 = getelementptr inbounds ptr, ptr %32, i64 %41
  %43 = load i32, ptr %10, align 4, !tbaa !12
  %44 = sub nsw i32 %43, %6
  %45 = sext i32 %44 to i64
  %46 = shl nsw i64 %45, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %42, i8 0, i64 %46, i1 false)
  %47 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %32, ptr %47, align 8, !tbaa !13
  br label %48

48:                                               ; preds = %14, %40, %3
  %49 = getelementptr inbounds i8, ptr %0, i64 8
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = sext i32 %spec.select to i64
  %52 = getelementptr inbounds ptr, ptr %50, i64 %51
  store ptr %1, ptr %52, align 8, !tbaa !14
  ret void
}

declare ptr @m_Malloc(i32 noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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, !7, i64 16}
!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, !10, i64 24}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass