; LLVM IR from cruppstahl/upscaledb :: src/4env/env.ll (ZN9upscaledb3Env8close_dbEPNS_2DbEj)

; 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::Env" = type { ptr, %"struct.upscaledb::Mutex", %"struct.upscaledb::EnvConfig", %"struct.upscaledb::ScopedPtr", %"class.std::map" }
%"struct.upscaledb::Mutex" = type { %"class.boost::mutex" }
%"class.boost::mutex" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { 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] }
%"struct.upscaledb::ScopedPtr" = type { %"class.boost::scoped_ptr" }
%"class.boost::scoped_ptr" = type { ptr }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<unsigned short, std::pair<const unsigned short, upscaledb::Db *>, std::_Select1st<std::pair<const unsigned short, upscaledb::Db *>>, std::less<unsigned short>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<unsigned short, std::pair<const unsigned short, upscaledb::Db *>, std::_Select1st<std::pair<const unsigned short, upscaledb::Db *>>, std::less<unsigned short>>::_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 }

; 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: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9upscaledb3Env8close_dbEPNS_2DbEj(ptr noundef nonnull align 8 dereferenceable(248) %0, ptr noundef %1, i32 noundef %2) #2 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #4
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = call noundef zeroext i16 @_ZNK9upscaledb2Db4nameEv(ptr noundef nonnull align 8 dereferenceable(160) %12)
  store i16 %13, ptr %8, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %14 = load ptr, ptr %11, align 8, !tbaa !13
  %15 = getelementptr inbounds ptr, ptr %14, i64 6
  %16 = load ptr, ptr %15, align 8
  %17 = call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(248) %11, i32 noundef 1)
  store i32 %17, ptr %9, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = call i64 @llvm.expect.i64(i64 %19, i64 0)
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %3
  %23 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %23, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %59

24:                                               ; preds = %3
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load ptr, ptr %25, align 8, !tbaa !13
  %28 = getelementptr inbounds ptr, ptr %27, i64 13
  %29 = load ptr, ptr %28, align 8
  %30 = call noundef i32 %29(ptr noundef nonnull align 8 dereferenceable(160) %25, i32 noundef %26)
  store i32 %30, ptr %9, align 4, !tbaa !9
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = call i64 @llvm.expect.i64(i64 %32, i64 0)
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %24
  %36 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %36, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %59

37:                                               ; preds = %24
  %38 = getelementptr inbounds %"struct.upscaledb::Env", ptr %11, i32 0, i32 4
  %39 = call noundef i64 @_ZNSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE5eraseERS6_(ptr noundef nonnull align 8 dereferenceable(48) %38, ptr noundef nonnull align 2 dereferenceable(2) %8)
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %46, label %42

42:                                               ; preds = %37
  %43 = load ptr, ptr %40, align 8, !tbaa !13
  %44 = getelementptr inbounds ptr, ptr %43, i64 1
  %45 = load ptr, ptr %44, align 8
  call void %45(ptr noundef nonnull align 8 dereferenceable(160) %40) #4
  br label %46

46:                                               ; preds = %42, %37
  %47 = getelementptr inbounds %"struct.upscaledb::Env", ptr %11, i32 0, i32 2
  %48 = getelementptr inbounds %"struct.upscaledb::EnvConfig", ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !15
  %50 = and i32 %49, 128
  %51 = icmp eq i32 %50, 128
  br i1 %51, label %52, label %58

52:                                               ; preds = %46
  %53 = load i16, ptr %8, align 2, !tbaa !11
  %54 = load ptr, ptr %11, align 8, !tbaa !13
  %55 = getelementptr inbounds ptr, ptr %54, i64 8
  %56 = load ptr, ptr %55, align 8
  %57 = call noundef i32 %56(ptr noundef nonnull align 8 dereferenceable(248) %11, i16 noundef zeroext %53, i32 noundef 0)
  br label %58

58:                                               ; preds = %52, %46
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %59

59:                                               ; preds = %58, %35, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #4
  %60 = load i32, ptr %4, align 4
  ret i32 %60
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNK9upscaledb2Db4nameEv(ptr noundef nonnull align 8 dereferenceable(160)) #3 align 2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = !{!16, !10, i64 48}
!16 = !{!"_ZTSN9upscaledb3EnvE", !17, i64 8, !19, i64 48, !24, i64 192, !26, i64 200}
!17 = !{!"_ZTSN9upscaledb5MutexE", !18, i64 0}
!18 = !{!"_ZTSN5boost5mutexE", !7, i64 0}
!19 = !{!"_ZTSN9upscaledb9EnvConfigE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !20, i64 16, !20, i64 24, !20, i64 32, !21, i64 40, !21, i64 72, !10, i64 104, !23, i64 108, !7, i64 109, !20, i64 128, !10, i64 136}
!20 = !{!"long", !7, i64 0}
!21 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !22, i64 0, !20, i64 8, !7, i64 16}
!22 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!23 = !{!"bool", !7, i64 0}
!24 = !{!"_ZTSN9upscaledb9ScopedPtrINS_10TxnManagerEEE", !25, i64 0}
!25 = !{!"_ZTSN5boost10scoped_ptrIN9upscaledb10TxnManagerEEE", !6, i64 0}
!26 = !{!"_ZTSSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE", !27, i64 0}
!27 = !{!"_ZTSSt8_Rb_treeItSt4pairIKtPN9upscaledb2DbEESt10_Select1stIS5_ESt4lessItESaIS5_EE", !28, i64 0}
!28 = !{!"_ZTSNSt8_Rb_treeItSt4pairIKtPN9upscaledb2DbEESt10_Select1stIS5_ESt4lessItESaIS5_EE13_Rb_tree_implIS9_Lb1EEE", !29, i64 0, !31, i64 8}
!29 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessItEE", !30, i64 0}
!30 = !{!"_ZTSSt4lessItE"}
!31 = !{!"_ZTSSt15_Rb_tree_header", !32, i64 0, !20, i64 32}
!32 = !{!"_ZTSSt18_Rb_tree_node_base", !33, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!33 = !{!"_ZTSSt14_Rb_tree_color", !7, i64 0}


; 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 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: mustprogress uwtable
define dso_local noundef i32 @_ZN9upscaledb3Env8close_dbEPNS_2DbEj(ptr noundef nonnull align 8 dereferenceable(248) %0, ptr noundef nonnull %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = alloca i16, align 2
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %4) #3
  %5 = tail call noundef zeroext i16 @_ZNK9upscaledb2Db4nameEv(ptr noundef nonnull align 8 dereferenceable(160) %1)
  store i16 %5, ptr %4, align 2, !tbaa !5
  %6 = load ptr, ptr %0, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %6, i64 48
  %8 = load ptr, ptr %7, align 8
  %9 = tail call noundef i32 %8(ptr noundef nonnull align 8 dereferenceable(248) %0, i32 noundef 1)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %30, !prof !11

10:                                               ; preds = %3
  %11 = load ptr, ptr %1, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %11, i64 104
  %13 = load ptr, ptr %12, align 8
  %14 = tail call noundef i32 %13(ptr noundef nonnull align 8 dereferenceable(160) %1, i32 noundef %2)
  %.not9 = icmp eq i32 %14, 0
  br i1 %.not9, label %15, label %30, !prof !11

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %0, i64 200
  %17 = call noundef i64 @_ZNSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE5eraseERS6_(ptr noundef nonnull align 8 dereferenceable(48) %16, ptr noundef nonnull align 2 dereferenceable(2) %4)
  %18 = load ptr, ptr %1, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8
  call void %20(ptr noundef nonnull align 8 dereferenceable(160) %1) #3
  %21 = getelementptr inbounds i8, ptr %0, i64 48
  %22 = load i32, ptr %21, align 8, !tbaa !12
  %23 = and i32 %22, 128
  %.not10 = icmp eq i32 %23, 0
  br i1 %.not10, label %30, label %24

24:                                               ; preds = %15
  %25 = load i16, ptr %4, align 2, !tbaa !5
  %26 = load ptr, ptr %0, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %26, i64 64
  %28 = load ptr, ptr %27, align 8
  %29 = call noundef i32 %28(ptr noundef nonnull align 8 dereferenceable(248) %0, i16 noundef zeroext %25, i32 noundef 0)
  br label %30

30:                                               ; preds = %15, %24, %10, %3
  %.0 = phi i32 [ %9, %3 ], [ %14, %10 ], [ 0, %24 ], [ 0, %15 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %4) #3
  ret i32 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNK9upscaledb2Db4nameEv(ptr noundef nonnull align 8 dereferenceable(160)) local_unnamed_addr #2 align 2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!12 = !{!13, !17, i64 48}
!13 = !{!"_ZTSN9upscaledb3EnvE", !14, i64 8, !16, i64 48, !23, i64 192, !25, i64 200}
!14 = !{!"_ZTSN9upscaledb5MutexE", !15, i64 0}
!15 = !{!"_ZTSN5boost5mutexE", !7, i64 0}
!16 = !{!"_ZTSN9upscaledb9EnvConfigE", !17, i64 0, !17, i64 4, !17, i64 8, !17, i64 12, !18, i64 16, !18, i64 24, !18, i64 32, !19, i64 40, !19, i64 72, !17, i64 104, !22, i64 108, !7, i64 109, !18, i64 128, !17, i64 136}
!17 = !{!"int", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !20, i64 0, !18, i64 8, !7, i64 16}
!20 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !21, i64 0}
!21 = !{!"any pointer", !7, i64 0}
!22 = !{!"bool", !7, i64 0}
!23 = !{!"_ZTSN9upscaledb9ScopedPtrINS_10TxnManagerEEE", !24, i64 0}
!24 = !{!"_ZTSN5boost10scoped_ptrIN9upscaledb10TxnManagerEEE", !21, i64 0}
!25 = !{!"_ZTSSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE", !26, i64 0}
!26 = !{!"_ZTSSt8_Rb_treeItSt4pairIKtPN9upscaledb2DbEESt10_Select1stIS5_ESt4lessItESaIS5_EE", !27, i64 0}
!27 = !{!"_ZTSNSt8_Rb_treeItSt4pairIKtPN9upscaledb2DbEESt10_Select1stIS5_ESt4lessItESaIS5_EE13_Rb_tree_implIS9_Lb1EEE", !28, i64 0, !30, i64 8}
!28 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessItEE", !29, i64 0}
!29 = !{!"_ZTSSt4lessItE"}
!30 = !{!"_ZTSSt15_Rb_tree_header", !31, i64 0, !18, i64 32}
!31 = !{!"_ZTSSt18_Rb_tree_node_base", !32, i64 0, !21, i64 8, !21, i64 16, !21, i64 24}
!32 = !{!"_ZTSSt14_Rb_tree_color", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass