; LLVM IR from pmwkaa/monotone :: monotone/engine/storage (storage_mgr)

; 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.StorageMgr = type { %struct.List, i32, ptr }
%struct.List = type { ptr, ptr }
%struct.Storage = type { %struct.List, i32, i32, i64, i64, ptr, ptr, %struct.List }
%struct.Part = type { %struct.Id, i32, i64, i64, i8, ptr, %struct.Memtable, %struct.Memtable, %struct.File, %struct.Index, %struct.Buf, ptr, ptr, ptr, %struct.List }
%struct.Id = type { i64, i64 }
%struct.Memtable = type { ptr, %struct.Rbtree, i32, i32, i32, i64, i64, i64, %struct.List, i32, %struct.Heap }
%struct.Rbtree = type { ptr }
%struct.Heap = type { ptr, ptr, i32, ptr }
%struct.File = type { i32, i64, %struct.Str, %struct.List }
%struct.Str = type { ptr, ptr, i8 }
%struct.Index = type <{ i32, i32, i32, i32, %struct.Id, i32, i32, i64, i64, i64, i64, i32, i64, i64, i64, i32, i64, i8, i8, [4 x i32] }>
%struct.Buf = type { ptr, ptr, ptr }

; 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 uwtable
define dso_local ptr @storage_mgr_find_part(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.StorageMgr, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.List, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  store ptr %16, ptr %8, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %66, %3
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.StorageMgr, ptr %19, i32 0, i32 0
  %21 = icmp ne ptr %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  store i32 2, ptr %9, align 4
  br label %70

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 -56
  store ptr %25, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = icmp eq ptr %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %23
  store i32 4, ptr %9, align 4
  br label %63

30:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Storage, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds %struct.List, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  store ptr %34, ptr %11, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %56, %30
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Storage, ptr %37, i32 0, i32 0
  %39 = icmp ne ptr %36, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %35
  store i32 5, ptr %9, align 4
  br label %60

41:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 -520
  store ptr %43, ptr %12, align 8, !tbaa !5
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Part, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.Id, ptr %45, i32 0, i32 0
  %47 = load i64, ptr %46, align 8, !tbaa !17
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = icmp eq i64 %47, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %41
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %51, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %53

52:                                               ; preds = %41
  store i32 0, ptr %9, align 4
  br label %53

53:                                               ; preds = %52, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %54 = load i32, ptr %9, align 4
  switch i32 %54, label %60 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.List, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !28
  store ptr %59, ptr %11, align 8, !tbaa !5
  br label %35, !llvm.loop !29

60:                                               ; preds = %53, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %61 = load i32, ptr %9, align 4
  switch i32 %61, label %63 [
    i32 5, label %62
  ]

62:                                               ; preds = %60
  store i32 0, ptr %9, align 4
  br label %63

63:                                               ; preds = %62, %60, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %64 = load i32, ptr %9, align 4
  switch i32 %64, label %70 [
    i32 0, label %65
    i32 4, label %66
  ]

65:                                               ; preds = %63
  br label %66

66:                                               ; preds = %65, %63
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.List, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !28
  store ptr %69, ptr %8, align 8, !tbaa !5
  br label %17, !llvm.loop !31

70:                                               ; preds = %63, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %71 = load i32, ptr %9, align 4
  switch i32 %71, label %75 [
    i32 2, label %72
    i32 1, label %73
  ]

72:                                               ; preds = %70
  store ptr null, ptr %4, align 8
  br label %73

73:                                               ; preds = %72, %70
  %74 = load ptr, ptr %4, align 8
  ret ptr %74

75:                                               ; preds = %70
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"StorageMgr", !13, i64 0, !14, i64 16, !6, i64 24}
!13 = !{!"List", !6, i64 0, !6, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"Storage", !13, i64 0, !14, i64 16, !14, i64 20, !10, i64 24, !10, i64 32, !6, i64 40, !6, i64 48, !13, i64 56}
!17 = !{!18, !10, i64 0}
!18 = !{!"Part", !19, i64 0, !14, i64 16, !10, i64 24, !10, i64 32, !20, i64 40, !6, i64 48, !21, i64 56, !21, i64 168, !24, i64 280, !26, i64 336, !27, i64 472, !6, i64 496, !6, i64 504, !6, i64 512, !13, i64 520}
!19 = !{!"Id", !10, i64 0, !10, i64 8}
!20 = !{!"_Bool", !7, i64 0}
!21 = !{!"Memtable", !6, i64 0, !22, i64 8, !14, i64 16, !14, i64 20, !14, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !13, i64 56, !14, i64 72, !23, i64 80}
!22 = !{!"Rbtree", !6, i64 0}
!23 = !{!"Heap", !6, i64 0, !6, i64 8, !14, i64 16, !6, i64 24}
!24 = !{!"File", !14, i64 0, !10, i64 8, !25, i64 16, !13, i64 40}
!25 = !{!"Str", !6, i64 0, !6, i64 8, !20, i64 16}
!26 = !{!"Index", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !19, i64 16, !14, i64 32, !14, i64 36, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !14, i64 72, !10, i64 76, !10, i64 84, !10, i64 92, !14, i64 100, !10, i64 104, !7, i64 112, !7, i64 113, !7, i64 114}
!27 = !{!"Buf", !6, i64 0, !6, i64 8, !6, i64 16}
!28 = !{!13, !6, i64 0}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}
!31 = distinct !{!31, !30}


; 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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @storage_mgr_find_part(ptr noundef readonly %0, ptr noundef readnone %1, i64 noundef %2) local_unnamed_addr #0 {
  %.02134 = load ptr, ptr %0, align 8, !tbaa !5
  %.not35 = icmp eq ptr %.02134, %0
  br i1 %.not35, label %.loopexit33, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.loopexit
  %.02136 = phi ptr [ %.021, %.loopexit ], [ %.02134, %3 ]
  %4 = getelementptr inbounds i8, ptr %.02136, i64 -56
  %5 = icmp eq ptr %4, %1
  br i1 %5, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %6
  %.020.in = phi ptr [ %.020, %6 ], [ %4, %.lr.ph ]
  %.020 = load ptr, ptr %.020.in, align 8, !tbaa !5
  %.not27 = icmp eq ptr %.020, %4
  br i1 %.not27, label %.loopexit, label %6

6:                                                ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %.020, i64 -520
  %8 = load i64, ptr %7, align 8, !tbaa !10
  %.not28 = icmp eq i64 %8, %2
  br i1 %.not28, label %.loopexit33.loopexit, label %.preheader, !llvm.loop !23

.loopexit:                                        ; preds = %.preheader, %.lr.ph
  %.021 = load ptr, ptr %.02136, align 8, !tbaa !5
  %.not = icmp eq ptr %.021, %0
  br i1 %.not, label %.loopexit33, label %.lr.ph, !llvm.loop !25

.loopexit33.loopexit:                             ; preds = %6
  %9 = getelementptr inbounds i8, ptr %.020, i64 -520
  br label %.loopexit33

.loopexit33:                                      ; preds = %.loopexit, %.loopexit33.loopexit, %3
  %spec.select = phi ptr [ null, %3 ], [ %9, %.loopexit33.loopexit ], [ null, %.loopexit ]
  ret ptr %spec.select
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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" }

!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 = !{!"List", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !13, i64 0}
!11 = !{!"Part", !12, i64 0, !14, i64 16, !13, i64 24, !13, i64 32, !15, i64 40, !7, i64 48, !16, i64 56, !16, i64 168, !19, i64 280, !21, i64 336, !22, i64 472, !7, i64 496, !7, i64 504, !7, i64 512, !6, i64 520}
!12 = !{!"Id", !13, i64 0, !13, i64 8}
!13 = !{!"long", !8, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!"_Bool", !8, i64 0}
!16 = !{!"Memtable", !7, i64 0, !17, i64 8, !14, i64 16, !14, i64 20, !14, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !6, i64 56, !14, i64 72, !18, i64 80}
!17 = !{!"Rbtree", !7, i64 0}
!18 = !{!"Heap", !7, i64 0, !7, i64 8, !14, i64 16, !7, i64 24}
!19 = !{!"File", !14, i64 0, !13, i64 8, !20, i64 16, !6, i64 40}
!20 = !{!"Str", !7, i64 0, !7, i64 8, !15, i64 16}
!21 = !{!"Index", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !12, i64 16, !14, i64 32, !14, i64 36, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !14, i64 72, !13, i64 76, !13, i64 84, !13, i64 92, !14, i64 100, !13, i64 104, !8, i64 112, !8, i64 113, !8, i64 114}
!22 = !{!"Buf", !7, i64 0, !7, i64 8, !7, i64 16}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


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