; LLVM IR from seppo0010/rlite :: src (page_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.rl_btree_node = type { ptr, ptr, ptr, i64 }

; 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: nounwind
declare void @free(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_btree_node_destroy(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %9, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %76

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.rl_btree_node, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %39

18:                                               ; preds = %13
  store i64 0, ptr %8, align 8, !tbaa !12
  br label %19

19:                                               ; preds = %32, %18
  %20 = load i64, ptr %8, align 8, !tbaa !12
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.rl_btree_node, ptr %21, i32 0, i32 3
  %23 = load i64, ptr %22, align 8, !tbaa !13
  %24 = icmp slt i64 %20, %23
  br i1 %24, label %25, label %35

25:                                               ; preds = %19
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.rl_btree_node, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = load i64, ptr %8, align 8, !tbaa !12
  %30 = getelementptr inbounds ptr, ptr %28, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  call void @free(ptr noundef %31) #3
  br label %32

32:                                               ; preds = %25
  %33 = load i64, ptr %8, align 8, !tbaa !12
  %34 = add nsw i64 %33, 1
  store i64 %34, ptr %8, align 8, !tbaa !12
  br label %19, !llvm.loop !14

35:                                               ; preds = %19
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.rl_btree_node, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  call void @free(ptr noundef %38) #3
  br label %39

39:                                               ; preds = %35, %13
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.rl_btree_node, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %65

44:                                               ; preds = %39
  store i64 0, ptr %8, align 8, !tbaa !12
  br label %45

45:                                               ; preds = %58, %44
  %46 = load i64, ptr %8, align 8, !tbaa !12
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.rl_btree_node, ptr %47, i32 0, i32 3
  %49 = load i64, ptr %48, align 8, !tbaa !13
  %50 = icmp slt i64 %46, %49
  br i1 %50, label %51, label %61

51:                                               ; preds = %45
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.rl_btree_node, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load i64, ptr %8, align 8, !tbaa !12
  %56 = getelementptr inbounds ptr, ptr %54, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  call void @free(ptr noundef %57) #3
  br label %58

58:                                               ; preds = %51
  %59 = load i64, ptr %8, align 8, !tbaa !12
  %60 = add nsw i64 %59, 1
  store i64 %60, ptr %8, align 8, !tbaa !12
  br label %45, !llvm.loop !17

61:                                               ; preds = %45
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.rl_btree_node, ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !16
  call void @free(ptr noundef %64) #3
  br label %65

65:                                               ; preds = %61, %39
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.rl_btree_node, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !18
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %74

70:                                               ; preds = %65
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.rl_btree_node, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !18
  call void @free(ptr noundef %73) #3
  br label %74

74:                                               ; preds = %70, %65
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %75) #3
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %76

76:                                               ; preds = %74, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %77 = load i32, ptr %3, align 4
  ret i32 %77
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 0}
!10 = !{!"rl_btree_node", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!10, !6, i64 16}
!17 = distinct !{!17, !15}
!18 = !{!10, !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"

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @rl_btree_node_destroy(ptr nocapture noundef readnone %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %34, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %16, label %.preheader24

.preheader24:                                     ; preds = %4
  %6 = getelementptr inbounds i8, ptr %1, i64 24
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = icmp sgt i64 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader24, %.lr.ph
  %.025 = phi i64 [ %12, %.lr.ph ], [ 0, %.preheader24 ]
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = getelementptr inbounds ptr, ptr %9, i64 %.025
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  tail call void @free(ptr noundef %11) #2
  %12 = add nuw nsw i64 %.025, 1
  %13 = load i64, ptr %6, align 8, !tbaa !11
  %14 = icmp slt i64 %12, %13
  br i1 %14, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !13

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load ptr, ptr %1, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader24
  %15 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %5, %.preheader24 ]
  tail call void @free(ptr noundef %15) #2
  br label %16

16:                                               ; preds = %._crit_edge, %4
  %17 = getelementptr inbounds i8, ptr %1, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %.not22 = icmp eq ptr %18, null
  br i1 %.not22, label %29, label %.preheader

.preheader:                                       ; preds = %16
  %19 = getelementptr inbounds i8, ptr %1, i64 24
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = icmp sgt i64 %20, 0
  br i1 %21, label %.lr.ph27, label %._crit_edge28

.lr.ph27:                                         ; preds = %.preheader, %.lr.ph27
  %.126 = phi i64 [ %25, %.lr.ph27 ], [ 0, %.preheader ]
  %22 = load ptr, ptr %17, align 8, !tbaa !15
  %23 = getelementptr inbounds ptr, ptr %22, i64 %.126
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  tail call void @free(ptr noundef %24) #2
  %25 = add nuw nsw i64 %.126, 1
  %26 = load i64, ptr %19, align 8, !tbaa !11
  %27 = icmp slt i64 %25, %26
  br i1 %27, label %.lr.ph27, label %._crit_edge28.loopexit, !llvm.loop !16

._crit_edge28.loopexit:                           ; preds = %.lr.ph27
  %.pre29 = load ptr, ptr %17, align 8, !tbaa !15
  br label %._crit_edge28

._crit_edge28:                                    ; preds = %._crit_edge28.loopexit, %.preheader
  %28 = phi ptr [ %.pre29, %._crit_edge28.loopexit ], [ %18, %.preheader ]
  tail call void @free(ptr noundef %28) #2
  br label %29

29:                                               ; preds = %._crit_edge28, %16
  %30 = getelementptr inbounds i8, ptr %1, i64 8
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %.not23 = icmp eq ptr %31, null
  br i1 %.not23, label %33, label %32

32:                                               ; preds = %29
  tail call void @free(ptr noundef nonnull %31) #2
  br label %33

33:                                               ; preds = %32, %29
  tail call void @free(ptr noundef nonnull %1) #2
  br label %34

34:                                               ; preds = %2, %33
  ret i32 0
}

attributes #0 = { 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 #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 0}
!6 = !{!"rl_btree_node", !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 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !7, i64 16}
!16 = distinct !{!16, !14}
!17 = !{!6, !7, i64 8}


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