; LLVM IR from dpt/Containers :: libraries/datastruct/bstree (remove)

; 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.bstree = type { ptr, i32, ptr, ptr, ptr, ptr }
%struct.bstree__node = type { [2 x ptr], %struct.item }
%struct.item = type { ptr, i64, ptr }

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

15:                                               ; preds = %44, %2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %45

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.bstree, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.bstree__node, ptr %23, i32 0, i32 1
  %25 = getelementptr inbounds %struct.item, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = call i32 %21(ptr noundef %22, ptr noundef %26)
  store i32 %27, ptr %7, align 4, !tbaa !16
  %28 = load i32, ptr %7, align 4, !tbaa !16
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %18
  store i32 3, ptr %8, align 4
  br label %42

31:                                               ; preds = %18
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.bstree__node, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %7, align 4, !tbaa !16
  %35 = icmp slt i32 %34, 0
  %36 = zext i1 %35 to i64
  %37 = select i1 %35, i32 0, i32 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2 x ptr], ptr %33, i64 0, i64 %38
  store ptr %39, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  store ptr %41, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %8, align 4
  br label %42

42:                                               ; preds = %31, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  %43 = load i32, ptr %8, align 4
  switch i32 %43, label %135 [
    i32 0, label %44
    i32 3, label %45
  ]

44:                                               ; preds = %42
  br label %15, !llvm.loop !17

45:                                               ; preds = %42, %15
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %49

48:                                               ; preds = %45
  store i32 1, ptr %8, align 4
  br label %132

49:                                               ; preds = %45
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  call void @bstree__node_clear(ptr noundef %50, ptr noundef %51)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.bstree__node, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds [2 x ptr], ptr %53, i64 0, i64 0
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %65

57:                                               ; preds = %49
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.bstree__node, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds [2 x ptr], ptr %59, i64 0, i64 1
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %65

63:                                               ; preds = %57
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %64, align 8, !tbaa !5
  br label %126

65:                                               ; preds = %57, %49
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.bstree__node, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds [2 x ptr], ptr %67, i64 0, i64 0
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = icmp eq ptr %69, null
  br i1 %70, label %77, label %71

71:                                               ; preds = %65
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.bstree__node, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds [2 x ptr], ptr %73, i64 0, i64 1
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  %76 = icmp eq ptr %75, null
  br i1 %76, label %77, label %96

77:                                               ; preds = %71, %65
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.bstree__node, ptr %78, i32 0, i32 0
  %80 = getelementptr inbounds [2 x ptr], ptr %79, i64 0, i64 0
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %88

83:                                               ; preds = %77
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.bstree__node, ptr %84, i32 0, i32 0
  %86 = getelementptr inbounds [2 x ptr], ptr %85, i64 0, i64 0
  %87 = load ptr, ptr %86, align 8, !tbaa !5
  br label %93

88:                                               ; preds = %77
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.bstree__node, ptr %89, i32 0, i32 0
  %91 = getelementptr inbounds [2 x ptr], ptr %90, i64 0, i64 1
  %92 = load ptr, ptr %91, align 8, !tbaa !5
  br label %93

93:                                               ; preds = %88, %83
  %94 = phi ptr [ %87, %83 ], [ %92, %88 ]
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %94, ptr %95, align 8, !tbaa !5
  br label %125

96:                                               ; preds = %71
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.bstree__node, ptr %97, i32 0, i32 0
  %99 = getelementptr inbounds [2 x ptr], ptr %98, i64 0, i64 1
  store ptr %99, ptr %9, align 8, !tbaa !5
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  %101 = load ptr, ptr %100, align 8, !tbaa !5
  store ptr %101, ptr %10, align 8, !tbaa !5
  br label %102

102:                                              ; preds = %108, %96
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.bstree__node, ptr %103, i32 0, i32 0
  %105 = getelementptr inbounds [2 x ptr], ptr %104, i64 0, i64 0
  %106 = load ptr, ptr %105, align 8, !tbaa !5
  %107 = icmp ne ptr %106, null
  br i1 %107, label %108, label %114

108:                                              ; preds = %102
  %109 = load ptr, ptr %10, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.bstree__node, ptr %109, i32 0, i32 0
  %111 = getelementptr inbounds [2 x ptr], ptr %110, i64 0, i64 0
  store ptr %111, ptr %9, align 8, !tbaa !5
  %112 = load ptr, ptr %9, align 8, !tbaa !5
  %113 = load ptr, ptr %112, align 8, !tbaa !5
  store ptr %113, ptr %10, align 8, !tbaa !5
  br label %102, !llvm.loop !19

114:                                              ; preds = %102
  %115 = load ptr, ptr %6, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.bstree__node, ptr %115, i32 0, i32 1
  %117 = load ptr, ptr %10, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.bstree__node, ptr %117, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %116, ptr align 8 %118, i64 24, i1 false), !tbaa.struct !20
  %119 = load ptr, ptr %10, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.bstree__node, ptr %119, i32 0, i32 0
  %121 = getelementptr inbounds [2 x ptr], ptr %120, i64 0, i64 1
  %122 = load ptr, ptr %121, align 8, !tbaa !5
  %123 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %122, ptr %123, align 8, !tbaa !5
  %124 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %124, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %125

125:                                              ; preds = %114, %93
  br label %126

126:                                              ; preds = %125, %63
  %127 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %127) #5
  %128 = load ptr, ptr %3, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.bstree, ptr %128, i32 0, i32 1
  %130 = load i32, ptr %129, align 8, !tbaa !22
  %131 = add nsw i32 %130, -1
  store i32 %131, ptr %129, align 8, !tbaa !22
  store i32 0, ptr %8, align 4
  br label %132

132:                                              ; preds = %126, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %133 = load i32, ptr %8, align 4
  switch i32 %133, label %135 [
    i32 0, label %134
    i32 1, label %134
  ]

134:                                              ; preds = %132, %132
  ret void

135:                                              ; preds = %132, %42
  unreachable
}

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

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

declare void @bstree__node_clear(ptr noundef, ptr noundef) #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
declare void @free(ptr noundef) #4

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind "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, !6, i64 24}
!10 = !{!"bstree", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"bstree__node", !7, i64 0, !14, i64 16}
!14 = !{!"item", !6, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{i64 0, i64 8, !5, i64 8, i64 8, !21, i64 16, i64 8, !5}
!21 = !{!15, !15, i64 0}
!22 = !{!10, !11, 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"

; Function Attrs: nounwind uwtable
define dso_local void @bstree_remove(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.03756 = load ptr, ptr %0, align 8, !tbaa !5
  %.not57 = icmp eq ptr %.03756, null
  br i1 %.not57, label %.thread50, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %.03756, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = tail call i32 %4(ptr noundef %1, ptr noundef %6) #4
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %._crit_edge, label %.lr.ph69

9:                                                ; preds = %.lr.ph69
  %10 = load ptr, ptr %3, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %.037, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = tail call i32 %10(ptr noundef %1, ptr noundef %12) #4
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %._crit_edge.loopexit, label %.lr.ph69

.lr.ph69:                                         ; preds = %.lr.ph, %9
  %15 = phi i32 [ %13, %9 ], [ %7, %.lr.ph ]
  %.0375968 = phi ptr [ %.037, %9 ], [ %.03756, %.lr.ph ]
  %16 = icmp sgt i32 %15, -1
  %17 = zext i1 %16 to i64
  %18 = getelementptr inbounds [2 x ptr], ptr %.0375968, i64 0, i64 %17
  %.037 = load ptr, ptr %18, align 8, !tbaa !5
  %.not = icmp eq ptr %.037, null
  br i1 %.not, label %.thread50, label %9

._crit_edge.loopexit:                             ; preds = %9
  %19 = getelementptr inbounds [2 x ptr], ptr %.0375968, i64 0, i64 %17
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph
  %.03759.lcssa = phi ptr [ %.03756, %.lr.ph ], [ %.037, %._crit_edge.loopexit ]
  %.03658.lcssa = phi ptr [ %0, %.lr.ph ], [ %19, %._crit_edge.loopexit ]
  %20 = getelementptr inbounds i8, ptr %.03759.lcssa, i64 16
  tail call void @bstree__node_clear(ptr noundef nonnull %0, ptr noundef nonnull %.03759.lcssa) #4
  %21 = load ptr, ptr %.03759.lcssa, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  %23 = getelementptr inbounds i8, ptr %.03759.lcssa, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %22, label %26, label %28

26:                                               ; preds = %._crit_edge
  br i1 %25, label %27, label %29

27:                                               ; preds = %26
  store ptr null, ptr %.03658.lcssa, align 8, !tbaa !5
  br label %36

28:                                               ; preds = %._crit_edge
  br i1 %25, label %29, label %.preheader

29:                                               ; preds = %26, %28
  %30 = phi ptr [ %21, %28 ], [ %24, %26 ]
  store ptr %30, ptr %.03658.lcssa, align 8, !tbaa !5
  br label %36

.preheader:                                       ; preds = %28, %.preheader
  %.034 = phi ptr [ %.0, %.preheader ], [ %23, %28 ]
  %.0 = phi ptr [ %31, %.preheader ], [ %24, %28 ]
  %31 = load ptr, ptr %.0, align 8, !tbaa !5
  %.not44 = icmp eq ptr %31, null
  br i1 %.not44, label %32, label %.preheader, !llvm.loop !16

32:                                               ; preds = %.preheader
  %33 = getelementptr inbounds i8, ptr %.0, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %20, ptr noundef nonnull align 8 dereferenceable(24) %33, i64 24, i1 false), !tbaa.struct !18
  %34 = getelementptr inbounds i8, ptr %.0, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  store ptr %35, ptr %.034, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %29, %32, %27
  %.3 = phi ptr [ %.03759.lcssa, %27 ], [ %.03759.lcssa, %29 ], [ %.0, %32 ]
  tail call void @free(ptr noundef nonnull %.3) #4
  %37 = getelementptr inbounds i8, ptr %0, i64 8
  %38 = load i32, ptr %37, align 8, !tbaa !20
  %39 = add nsw i32 %38, -1
  store i32 %39, ptr %37, align 8, !tbaa !20
  br label %.thread50

.thread50:                                        ; preds = %.lr.ph69, %2, %36
  ret void
}

declare void @bstree__node_clear(ptr noundef, ptr noundef) local_unnamed_addr #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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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, !6, i64 24}
!10 = !{!"bstree", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"bstree__node", !7, i64 0, !14, i64 16}
!14 = !{!"item", !6, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{i64 0, i64 8, !5, i64 8, i64 8, !19, i64 16, i64 8, !5}
!19 = !{!15, !15, i64 0}
!20 = !{!10, !11, i64 8}


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