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

; 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.MBtreeNode = type { ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [77 x i8], align 1
@__FUNCTION__.BtreeOperate = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = 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 @BtreeOperate(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
  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
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %16, label %12

12:                                               ; preds = %4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = ptrtoint ptr %13 to i64
  %15 = icmp eq i64 %14, -1
  br i1 %15, label %16, label %17

16:                                               ; preds = %12, %4
  br label %84

17:                                               ; preds = %12
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %36

20:                                               ; preds = %17
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  call void %21(ptr noundef %22, ptr noundef %23)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MBtreeNode, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !9
  call void @BtreeOperate(ptr noundef %26, ptr noundef %27, ptr noundef %28, i32 noundef %29)
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.MBtreeNode, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !9
  call void @BtreeOperate(ptr noundef %32, ptr noundef %33, ptr noundef %34, i32 noundef %35)
  br label %84

36:                                               ; preds = %17
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %39, label %55

39:                                               ; preds = %36
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.MBtreeNode, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !9
  call void @BtreeOperate(ptr noundef %42, ptr noundef %43, ptr noundef %44, i32 noundef %45)
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.MBtreeNode, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !9
  call void @BtreeOperate(ptr noundef %48, ptr noundef %49, ptr noundef %50, i32 noundef %51)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  call void %52(ptr noundef %53, ptr noundef %54)
  br label %83

55:                                               ; preds = %36
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = icmp eq i32 %56, 2
  br i1 %57, label %58, label %74

58:                                               ; preds = %55
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.MBtreeNode, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  call void @BtreeOperate(ptr noundef %61, ptr noundef %62, ptr noundef %63, i32 noundef %64)
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  call void %65(ptr noundef %66, ptr noundef %67)
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.MBtreeNode, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !13
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load i32, ptr %8, align 4, !tbaa !9
  call void @BtreeOperate(ptr noundef %70, ptr noundef %71, ptr noundef %72, i32 noundef %73)
  br label %82

74:                                               ; preds = %55
  br label %75

75:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !9
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %80

78:                                               ; preds = %75
  %79 = load i32, ptr %9, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %79, i32 noundef -1, ptr noundef @.str, i32 noundef 96, ptr noundef @__FUNCTION__.BtreeOperate, ptr noundef @.str.3)
  br label %80

80:                                               ; preds = %78, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81, %58
  br label %83

83:                                               ; preds = %82, %39
  br label %84

84:                                               ; preds = %83, %20, %16
  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, !6, i64 8}
!12 = !{!"MBtreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !6, i64 16}


; 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 [77 x i8], align 1
@__FUNCTION__.BtreeOperate = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = 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 @BtreeOperate(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.backedge, %4
  %.tr = phi ptr [ %0, %4 ], [ %.tr.be, %tailrecurse.backedge ]
  %magicptr = ptrtoint ptr %.tr to i64
  switch i64 %magicptr, label %5 [
    i64 -1, label %common.ret49
    i64 0, label %common.ret49
  ]

5:                                                ; preds = %tailrecurse
  switch i32 %3, label %17 [
    i32 -1, label %6
    i32 1, label %9
    i32 2, label %14
  ]

6:                                                ; preds = %5
  tail call void %1(ptr noundef %.tr, ptr noundef %2) #2
  %7 = getelementptr inbounds i8, ptr %.tr, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  tail call void @BtreeOperate(ptr noundef %8, ptr noundef %1, ptr noundef %2, i32 noundef -1)
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %6, %14
  %.tr.be.in = getelementptr inbounds i8, ptr %.tr, i64 16
  %.tr.be = load ptr, ptr %.tr.be.in, align 8, !tbaa !10
  br label %tailrecurse

common.ret49:                                     ; preds = %17, %tailrecurse, %tailrecurse, %9
  ret void

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  tail call void @BtreeOperate(ptr noundef %11, ptr noundef %1, ptr noundef %2, i32 noundef 1)
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !10
  tail call void @BtreeOperate(ptr noundef %13, ptr noundef %1, ptr noundef %2, i32 noundef 1)
  tail call void %1(ptr noundef %0, ptr noundef %2) #2
  br label %common.ret49

14:                                               ; preds = %5
  %15 = getelementptr inbounds i8, ptr %.tr, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  tail call void @BtreeOperate(ptr noundef %16, ptr noundef %1, ptr noundef %2, i32 noundef 2)
  tail call void %1(ptr noundef %.tr, ptr noundef %2) #2
  br label %tailrecurse.backedge

17:                                               ; preds = %5
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 96, ptr noundef nonnull @__FUNCTION__.BtreeOperate, ptr noundef nonnull @.str.3) #2
  br label %common.ret49
}

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, !7, i64 8}
!6 = !{!"MBtreeNode", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass