; LLVM IR from cruppstahl/upscaledb :: src/3page_manager/freelist.ll (ZN9upscaledb8Freelist12decode_stateEPh)

; 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.upscaledb::Freelist" = type { ptr, %"class.std::map", i64, i64 }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<unsigned long, std::pair<const unsigned long, unsigned long>, std::_Select1st<std::pair<const unsigned long, unsigned long>>, std::less<unsigned long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<unsigned long, std::pair<const unsigned long, unsigned long>, std::_Select1st<std::pair<const unsigned long, unsigned long>>, std::less<unsigned long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"struct.upscaledb::EnvConfig" = type <{ i32, i32, i32, i32, i64, i64, i64, %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", i32, i8, [16 x i8], [3 x i8], i64, i32, [4 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@.str.1 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__._ZN9upscaledb8Freelist12decode_stateEPh = external hidden unnamed_addr constant [50 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [15 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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9upscaledb8Freelist12decode_stateEPh(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %13 = getelementptr inbounds %"struct.upscaledb::Freelist", ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %"struct.upscaledb::EnvConfig", ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 4, !tbaa !20
  store i32 %16, ptr %5, align 4, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !26
  store i32 %18, ptr %6, align 4, !tbaa !26
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 4
  store ptr %20, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !26
  br label %21

21:                                               ; preds = %66, %2
  %22 = load i32, ptr %7, align 4, !tbaa !26
  %23 = load i32, ptr %6, align 4, !tbaa !26
  %24 = icmp ult i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %69

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i8, ptr %27, align 1, !tbaa !27
  %29 = zext i8 %28 to i32
  %30 = and i32 %29, 240
  %31 = ashr i32 %30, 4
  store i32 %31, ptr %8, align 4, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !27
  %34 = zext i8 %33 to i32
  %35 = and i32 %34, 15
  store i32 %35, ptr %9, align 4, !tbaa !26
  %36 = load i32, ptr %8, align 4, !tbaa !26
  %37 = icmp sgt i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %26
  br label %41

39:                                               ; preds = %26
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 108, ptr noundef @__PRETTY_FUNCTION__._ZN9upscaledb8Freelist12decode_stateEPh) #5
  unreachable

40:                                               ; No predecessors!
  br label %41

41:                                               ; preds = %40, %38
  %42 = load i32, ptr %9, align 4, !tbaa !26
  %43 = icmp sle i32 %42, 8
  br i1 %43, label %44, label %45

44:                                               ; preds = %41
  br label %47

45:                                               ; preds = %41
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 109, ptr noundef @__PRETTY_FUNCTION__._ZN9upscaledb8Freelist12decode_stateEPh) #5
  unreachable

46:                                               ; No predecessors!
  br label %47

47:                                               ; preds = %46, %44
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i64 1
  store ptr %49, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %50 = load i32, ptr %9, align 4, !tbaa !26
  %51 = sext i32 %50 to i64
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = call noundef i64 @_ZN9upscaledb6Pickle10decode_u64EmPh(i64 noundef %51, ptr noundef %52)
  store i64 %53, ptr %10, align 8, !tbaa !28
  %54 = load i32, ptr %9, align 4, !tbaa !26
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = sext i32 %54 to i64
  %57 = getelementptr inbounds i8, ptr %55, i64 %56
  store ptr %57, ptr %4, align 8, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !26
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds %"struct.upscaledb::Freelist", ptr %12, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %61 = load i64, ptr %10, align 8, !tbaa !28
  %62 = load i32, ptr %5, align 4, !tbaa !26
  %63 = zext i32 %62 to i64
  %64 = mul i64 %61, %63
  store i64 %64, ptr %11, align 8, !tbaa !28
  %65 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapImmSt4lessImESaISt4pairIKmmEEEixEOm(ptr noundef nonnull align 8 dereferenceable(48) %60, ptr noundef nonnull align 8 dereferenceable(8) %11)
  store i64 %59, ptr %65, align 8, !tbaa !28
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %66

66:                                               ; preds = %47
  %67 = load i32, ptr %7, align 4, !tbaa !26
  %68 = add i32 %67, 1
  store i32 %68, ptr %7, align 4, !tbaa !26
  br label %21, !llvm.loop !29

69:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN9upscaledb6Pickle10decode_u64EmPh(i64 noundef, ptr noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapImmSt4lessImESaISt4pairIKmmEEEixEOm(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 = { mustprogress 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 = { mustprogress 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 }
attributes #5 = { noreturn 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++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN9upscaledb8FreelistE", !6, i64 0, !11, i64 8, !19, i64 56, !19, i64 64}
!11 = !{!"_ZTSSt3mapImmSt4lessImESaISt4pairIKmmEEE", !12, i64 0}
!12 = !{!"_ZTSSt8_Rb_treeImSt4pairIKmmESt10_Select1stIS2_ESt4lessImESaIS2_EE", !13, i64 0}
!13 = !{!"_ZTSNSt8_Rb_treeImSt4pairIKmmESt10_Select1stIS2_ESt4lessImESaIS2_EE13_Rb_tree_implIS6_Lb1EEE", !14, i64 0, !16, i64 8}
!14 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessImEE", !15, i64 0}
!15 = !{!"_ZTSSt4lessImE"}
!16 = !{!"_ZTSSt15_Rb_tree_header", !17, i64 0, !19, i64 32}
!17 = !{!"_ZTSSt18_Rb_tree_node_base", !18, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!18 = !{!"_ZTSSt14_Rb_tree_color", !7, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!21, !22, i64 12}
!21 = !{!"_ZTSN9upscaledb9EnvConfigE", !22, i64 0, !22, i64 4, !22, i64 8, !22, i64 12, !19, i64 16, !19, i64 24, !19, i64 32, !23, i64 40, !23, i64 72, !22, i64 104, !25, i64 108, !7, i64 109, !19, i64 128, !22, i64 136}
!22 = !{!"int", !7, i64 0}
!23 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !24, i64 0, !19, i64 8, !7, i64 16}
!24 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!25 = !{!"bool", !7, i64 0}
!26 = !{!22, !22, i64 0}
!27 = !{!7, !7, i64 0}
!28 = !{!19, !19, i64 0}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


; 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.1 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__._ZN9upscaledb8Freelist12decode_stateEPh = external hidden unnamed_addr constant [50 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [15 x i8], align 1

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

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9upscaledb8Freelist12decode_stateEPh(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %3 = alloca i64, align 8
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %.not22 = icmp eq i32 %4, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load ptr, ptr %0, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %6, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !21
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = zext i32 %8 to i64
  br label %11

._crit_edge:                                      ; preds = %20, %2
  ret void

11:                                               ; preds = %.lr.ph, %20
  %.021 = phi ptr [ %5, %.lr.ph ], [ %24, %20 ]
  %.01720 = phi i32 [ 0, %.lr.ph ], [ %28, %20 ]
  %12 = load i8, ptr %.021, align 1, !tbaa !26
  %13 = zext i8 %12 to i32
  %14 = lshr i32 %13, 4
  %15 = and i32 %13, 15
  %.not = icmp ult i8 %12, 16
  br i1 %.not, label %16, label %17

16:                                               ; preds = %11
  call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 108, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN9upscaledb8Freelist12decode_stateEPh) #4
  unreachable

17:                                               ; preds = %11
  %18 = icmp ult i32 %15, 9
  br i1 %18, label %20, label %19

19:                                               ; preds = %17
  call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 109, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN9upscaledb8Freelist12decode_stateEPh) #4
  unreachable

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %.021, i64 1
  %22 = zext nneg i32 %15 to i64
  %23 = call noundef i64 @_ZN9upscaledb6Pickle10decode_u64EmPh(i64 noundef %22, ptr noundef nonnull %21)
  %24 = getelementptr inbounds i8, ptr %21, i64 %22
  %25 = zext nneg i32 %14 to i64
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %26 = mul i64 %23, %10
  store i64 %26, ptr %3, align 8, !tbaa !27
  %27 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapImmSt4lessImESaISt4pairIKmmEEEixEOm(ptr noundef nonnull align 8 dereferenceable(48) %9, ptr noundef nonnull align 8 dereferenceable(8) %3)
  store i64 %25, ptr %27, align 8, !tbaa !27
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  %28 = add nuw i32 %.01720, 1
  %exitcond.not = icmp eq i32 %28, %4
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !28
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN9upscaledb6Pickle10decode_u64EmPh(i64 noundef, ptr noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapImmSt4lessImESaISt4pairIKmmEEEixEOm(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 = { mustprogress 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 = { mustprogress 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 = { noreturn nounwind }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN9upscaledb8FreelistE", !11, i64 0, !12, i64 8, !20, i64 56, !20, i64 64}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_ZTSSt3mapImmSt4lessImESaISt4pairIKmmEEE", !13, i64 0}
!13 = !{!"_ZTSSt8_Rb_treeImSt4pairIKmmESt10_Select1stIS2_ESt4lessImESaIS2_EE", !14, i64 0}
!14 = !{!"_ZTSNSt8_Rb_treeImSt4pairIKmmESt10_Select1stIS2_ESt4lessImESaIS2_EE13_Rb_tree_implIS6_Lb1EEE", !15, i64 0, !17, i64 8}
!15 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessImEE", !16, i64 0}
!16 = !{!"_ZTSSt4lessImE"}
!17 = !{!"_ZTSSt15_Rb_tree_header", !18, i64 0, !20, i64 32}
!18 = !{!"_ZTSSt18_Rb_tree_node_base", !19, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!19 = !{!"_ZTSSt14_Rb_tree_color", !7, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = !{!22, !6, i64 12}
!22 = !{!"_ZTSN9upscaledb9EnvConfigE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !20, i64 16, !20, i64 24, !20, i64 32, !23, i64 40, !23, i64 72, !6, i64 104, !25, i64 108, !7, i64 109, !20, i64 128, !6, i64 136}
!23 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !24, i64 0, !20, i64 8, !7, i64 16}
!24 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !11, i64 0}
!25 = !{!"bool", !7, i64 0}
!26 = !{!7, !7, i64 0}
!27 = !{!20, !20, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}


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