; LLVM IR from Water-Melon/Melon :: src (mln_rbtree)

; 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.rbtree_s = type { ptr, ptr, ptr, ptr, ptr, %struct.mln_rbtree_node_s, ptr, ptr, ptr, ptr, ptr, i64, i8 }
%struct.mln_rbtree_node_s = type { ptr, ptr, ptr, ptr, ptr, ptr, i32 }

; 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_rbtree_chain_del(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @mln_rbtree_node_free(ptr noundef nonnull, ptr noundef nonnull) #3

; Function Attrs: nounwind uwtable
define dso_local void @mln_rbtree_reset(ptr noundef nonnull %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  br label %5

5:                                                ; preds = %56, %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.rbtree_s, ptr %6, i32 0, i32 9
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %57

10:                                               ; preds = %5
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.rbtree_s, ptr %11, i32 0, i32 8
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.rbtree_s, ptr %13, i32 0, i32 9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mln_rbtree_chain_del(ptr noundef %12, ptr noundef %14, ptr noundef %15)
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.rbtree_s, ptr %16, i32 0, i32 4
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %53

20:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %21, i32 0, i32 6
  %23 = load i32, ptr %22, align 8
  %24 = and i32 %23, 1
  store i32 %24, ptr %4, align 4, !tbaa !15
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %36

29:                                               ; preds = %20
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.rbtree_s, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  call void %32(ptr noundef %35)
  br label %36

36:                                               ; preds = %29, %20
  %37 = load i32, ptr %4, align 4, !tbaa !15
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %52, label %39

39:                                               ; preds = %36
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.rbtree_s, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %49

44:                                               ; preds = %39
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.rbtree_s, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  call void %47(ptr noundef %48)
  br label %51

49:                                               ; preds = %39
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %50) #4
  br label %51

51:                                               ; preds = %49, %44
  br label %52

52:                                               ; preds = %51, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %56

53:                                               ; preds = %10
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mln_rbtree_node_free(ptr noundef %54, ptr noundef %55)
  br label %56

56:                                               ; preds = %53, %52
  br label %5, !llvm.loop !19

57:                                               ; preds = %5
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.rbtree_s, ptr %58, i32 0, i32 5
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.rbtree_s, ptr %60, i32 0, i32 6
  store ptr %59, ptr %61, align 8, !tbaa !21
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.rbtree_s, ptr %62, i32 0, i32 5
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.rbtree_s, ptr %64, i32 0, i32 7
  store ptr %63, ptr %65, align 8, !tbaa !22
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.rbtree_s, ptr %66, i32 0, i32 10
  store ptr null, ptr %67, align 8, !tbaa !23
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.rbtree_s, ptr %68, i32 0, i32 11
  store i64 0, ptr %69, align 8, !tbaa !24
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.rbtree_s, ptr %70, i32 0, i32 12
  %72 = load i8, ptr %71, align 8
  %73 = and i8 %72, -2
  %74 = or i8 %73, 0
  store i8 %74, ptr %71, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 "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 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 = { 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 120}
!10 = !{!"rbtree_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !13, i64 136, !12, i64 144}
!11 = !{!"mln_rbtree_node_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !12, i64 48, !12, i64 48}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !6, i64 32}
!15 = !{!12, !12, i64 0}
!16 = !{!11, !6, i64 0}
!17 = !{!10, !6, i64 0}
!18 = !{!10, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!10, !6, i64 96}
!22 = !{!10, !6, i64 104}
!23 = !{!10, !6, i64 128}
!24 = !{!10, !13, i64 136}


; 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: inlinehint nounwind uwtable
declare hidden void @mln_rbtree_chain_del(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mln_rbtree_node_free(ptr noundef nonnull, ptr noundef nonnull) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @mln_rbtree_reset(ptr noundef nonnull %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 120
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not28 = icmp eq ptr %3, null
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 112
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  br label %7

7:                                                ; preds = %.lr.ph, %23
  %8 = phi ptr [ %3, %.lr.ph ], [ %24, %23 ]
  tail call void @mln_rbtree_chain_del(ptr noundef nonnull %4, ptr noundef nonnull %2, ptr noundef nonnull %8)
  %9 = load ptr, ptr %5, align 8, !tbaa !13
  %.not24 = icmp eq ptr %9, null
  br i1 %.not24, label %22, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %8, i64 48
  %12 = load i32, ptr %11, align 8
  %13 = and i32 %12, 1
  %14 = load ptr, ptr %8, align 8, !tbaa !14
  %.not25 = icmp eq ptr %14, null
  br i1 %.not25, label %16, label %15

15:                                               ; preds = %10
  tail call void %9(ptr noundef nonnull %14) #4
  br label %16

16:                                               ; preds = %15, %10
  %.not26 = icmp eq i32 %13, 0
  br i1 %.not26, label %17, label %23

17:                                               ; preds = %16
  %18 = load ptr, ptr %0, align 8, !tbaa !15
  %.not27 = icmp eq ptr %18, null
  br i1 %.not27, label %21, label %19

19:                                               ; preds = %17
  %20 = load ptr, ptr %6, align 8, !tbaa !16
  tail call void %20(ptr noundef nonnull %8) #4
  br label %23

21:                                               ; preds = %17
  tail call void @free(ptr noundef nonnull %8) #4
  br label %23

22:                                               ; preds = %7
  tail call void @mln_rbtree_node_free(ptr noundef %0, ptr noundef %8)
  br label %23

23:                                               ; preds = %16, %21, %19, %22
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !17

._crit_edge:                                      ; preds = %23, %1
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = getelementptr inbounds i8, ptr %0, i64 96
  store ptr %25, ptr %26, align 8, !tbaa !19
  %27 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr %25, ptr %27, align 8, !tbaa !20
  %28 = getelementptr inbounds i8, ptr %0, i64 128
  %29 = getelementptr inbounds i8, ptr %0, i64 144
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %28, i8 0, i64 16, i1 false)
  %30 = load i8, ptr %29, align 8
  %31 = and i8 %30, -2
  store i8 %31, ptr %29, align 8
  ret void
}

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

attributes #0 = { inlinehint 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 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 120}
!6 = !{!"rbtree_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !12, i64 136, !11, i64 144}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"mln_rbtree_node_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !11, i64 48, !11, i64 48}
!11 = !{!"int", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !7, i64 32}
!14 = !{!10, !7, i64 0}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !7, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !7, i64 96}
!20 = !{!6, !7, i64 104}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass