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

; 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"

%"class.boost::unique_lock" = type <{ ptr, i8, [7 x i8] }>
%"struct.std::_Rb_tree_iterator" = type { ptr }
%"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 }
%"struct.std::pair" = type { i16, 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEES8_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9upscaledb3Env5closeEj(ptr noundef nonnull align 8 dereferenceable(248) %0, i32 noundef %1) #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"class.boost::unique_lock", align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %"struct.std::_Rb_tree_iterator", align 8
  %13 = alloca %"struct.std::_Rb_tree_iterator", align 8
  %14 = alloca %"struct.std::_Rb_tree_iterator", align 8
  %15 = alloca %"struct.std::_Rb_tree_iterator", align 8
  %16 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %17 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #6
  %18 = getelementptr inbounds %"struct.upscaledb::Env", ptr %17, i32 0, i32 1
  call void @_ZN5boost11unique_lockINS_5mutexEEC2ERS1_(ptr noundef nonnull align 8 dereferenceable(9) %7, ptr noundef nonnull align 8 dereferenceable(40) %18)
  %19 = getelementptr inbounds %"struct.upscaledb::Env", ptr %17, i32 0, i32 3
  %20 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEE3getEv(ptr noundef nonnull align 8 dereferenceable(8) %19) #6
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %82

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  br label %23

23:                                               ; preds = %77, %22
  %24 = getelementptr inbounds %"struct.upscaledb::Env", ptr %17, i32 0, i32 3
  %25 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %24) #6
  %26 = invoke noundef ptr @_ZN9upscaledb10TxnManager10oldest_txnEv(ptr noundef nonnull align 8 dereferenceable(40) %25)
          to label %27 unwind label %50

27:                                               ; preds = %23
  store ptr %26, ptr %8, align 8, !tbaa !5
  %28 = icmp ne ptr %26, null
  br i1 %28, label %29, label %78

29:                                               ; preds = %27
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = invoke noundef zeroext i1 @_ZNK9upscaledb3Txn10is_abortedEv(ptr noundef nonnull align 8 dereferenceable(136) %30)
          to label %32 unwind label %50

32:                                               ; preds = %29
  br i1 %31, label %71, label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = invoke noundef zeroext i1 @_ZNK9upscaledb3Txn12is_committedEv(ptr noundef nonnull align 8 dereferenceable(136) %34)
          to label %36 unwind label %50

36:                                               ; preds = %33
  br i1 %35, label %71, label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = and i32 %38, 8
  %40 = icmp eq i32 %39, 8
  br i1 %40, label %41, label %54

41:                                               ; preds = %37
  %42 = getelementptr inbounds %"struct.upscaledb::Env", ptr %17, i32 0, i32 3
  %43 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %42) #6
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load ptr, ptr %43, align 8, !tbaa !11
  %46 = getelementptr inbounds ptr, ptr %45, i64 3
  %47 = load ptr, ptr %46, align 8
  %48 = invoke noundef i32 %47(ptr noundef nonnull align 8 dereferenceable(40) %43, ptr noundef %44)
          to label %49 unwind label %50

49:                                               ; preds = %41
  store i32 %48, ptr %6, align 4, !tbaa !9
  br label %63

50:                                               ; preds = %71, %54, %41, %33, %29, %23
  %51 = landingpad { ptr, i32 }
          cleanup
  %52 = extractvalue { ptr, i32 } %51, 0
  store ptr %52, ptr %9, align 8
  %53 = extractvalue { ptr, i32 } %51, 1
  store i32 %53, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %145

54:                                               ; preds = %37
  %55 = getelementptr inbounds %"struct.upscaledb::Env", ptr %17, i32 0, i32 3
  %56 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %55) #6
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = load ptr, ptr %56, align 8, !tbaa !11
  %59 = getelementptr inbounds ptr, ptr %58, i64 4
  %60 = load ptr, ptr %59, align 8
  %61 = invoke noundef i32 %60(ptr noundef nonnull align 8 dereferenceable(40) %56, ptr noundef %57)
          to label %62 unwind label %50

62:                                               ; preds = %54
  store i32 %61, ptr %6, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %62, %49
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = call i64 @llvm.expect.i64(i64 %65, i64 0)
  %67 = icmp ne i64 %66, 0
  br i1 %67, label %68, label %70

68:                                               ; preds = %63
  %69 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %69, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %79

70:                                               ; preds = %63
  br label %71

71:                                               ; preds = %70, %36, %32
  %72 = getelementptr inbounds %"struct.upscaledb::Env", ptr %17, i32 0, i32 3
  %73 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %72) #6
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = getelementptr inbounds ptr, ptr %74, i64 5
  %76 = load ptr, ptr %75, align 8
  invoke void %76(ptr noundef nonnull align 8 dereferenceable(40) %73, ptr noundef null)
          to label %77 unwind label %50

77:                                               ; preds = %71
  br label %23, !llvm.loop !13

78:                                               ; preds = %27
  store i32 0, ptr %11, align 4
  br label %79

79:                                               ; preds = %78, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %80 = load i32, ptr %11, align 4
  switch i32 %80, label %143 [
    i32 0, label %81
  ]

81:                                               ; preds = %79
  br label %82

82:                                               ; preds = %81, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %83 = getelementptr inbounds %"struct.upscaledb::Env", ptr %17, i32 0, i32 4
  %84 = call ptr @_ZNSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) %83) #6
  %85 = getelementptr inbounds %"struct.std::_Rb_tree_iterator", ptr %12, i32 0, i32 0
  store ptr %84, ptr %85, align 8
  br label %86

86:                                               ; preds = %128, %82
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %87 = getelementptr inbounds %"struct.upscaledb::Env", ptr %17, i32 0, i32 4
  %88 = call ptr @_ZNSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) %87) #6
  %89 = getelementptr inbounds %"struct.std::_Rb_tree_iterator", ptr %13, i32 0, i32 0
  store ptr %88, ptr %89, align 8
  %90 = call noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEES8_(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef nonnull align 8 dereferenceable(8) %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  br i1 %90, label %91, label %129

91:                                               ; preds = %86
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %14, ptr align 8 %12, i64 8, i1 false), !tbaa.struct !15
  %92 = call ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEEppEi(ptr noundef nonnull align 8 dereferenceable(8) %12, i32 noundef 0) #6
  %93 = getelementptr inbounds %"struct.std::_Rb_tree_iterator", ptr %15, i32 0, i32 0
  store ptr %92, ptr %93, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %94 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %14) #6
  %95 = getelementptr inbounds %"struct.std::pair", ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !16
  store ptr %96, ptr %16, align 8, !tbaa !5
  %97 = load i32, ptr %5, align 4, !tbaa !9
  %98 = and i32 %97, 1
  %99 = icmp eq i32 %98, 1
  br i1 %99, label %100, label %110

100:                                              ; preds = %91
  %101 = load ptr, ptr %16, align 8, !tbaa !5
  %102 = load i32, ptr %5, align 4, !tbaa !9
  %103 = or i32 %102, -268435456
  %104 = invoke i32 @ups_db_close(ptr noundef %101, i32 noundef %103)
          to label %105 unwind label %106

105:                                              ; preds = %100
  store i32 %104, ptr %6, align 4, !tbaa !9
  br label %118

106:                                              ; preds = %110, %100
  %107 = landingpad { ptr, i32 }
          cleanup
  %108 = extractvalue { ptr, i32 } %107, 0
  store ptr %108, ptr %9, align 8
  %109 = extractvalue { ptr, i32 } %107, 1
  store i32 %109, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  br label %142

110:                                              ; preds = %91
  %111 = load ptr, ptr %16, align 8, !tbaa !5
  %112 = load i32, ptr %5, align 4, !tbaa !9
  %113 = load ptr, ptr %111, align 8, !tbaa !11
  %114 = getelementptr inbounds ptr, ptr %113, i64 13
  %115 = load ptr, ptr %114, align 8
  %116 = invoke noundef i32 %115(ptr noundef nonnull align 8 dereferenceable(160) %111, i32 noundef %112)
          to label %117 unwind label %106

117:                                              ; preds = %110
  store i32 %116, ptr %6, align 4, !tbaa !9
  br label %118

118:                                              ; preds = %117, %105
  %119 = load i32, ptr %6, align 4, !tbaa !9
  %120 = sext i32 %119 to i64
  %121 = call i64 @llvm.expect.i64(i64 %120, i64 0)
  %122 = icmp ne i64 %121, 0
  br i1 %122, label %123, label %125

123:                                              ; preds = %118
  %124 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %124, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %126

125:                                              ; preds = %118
  store i32 0, ptr %11, align 4
  br label %126

126:                                              ; preds = %125, %123
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  %127 = load i32, ptr %11, align 4
  switch i32 %127, label %141 [
    i32 0, label %128
  ]

128:                                              ; preds = %126
  br label %86, !llvm.loop !19

129:                                              ; preds = %86
  %130 = getelementptr inbounds %"struct.upscaledb::Env", ptr %17, i32 0, i32 4
  call void @_ZNSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE5clearEv(ptr noundef nonnull align 8 dereferenceable(48) %130) #6
  %131 = load i32, ptr %5, align 4, !tbaa !9
  %132 = load ptr, ptr %17, align 8, !tbaa !11
  %133 = getelementptr inbounds ptr, ptr %132, i64 16
  %134 = load ptr, ptr %133, align 8
  %135 = invoke noundef i32 %134(ptr noundef nonnull align 8 dereferenceable(248) %17, i32 noundef %131)
          to label %136 unwind label %137

136:                                              ; preds = %129
  store i32 %135, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %141

137:                                              ; preds = %129
  %138 = landingpad { ptr, i32 }
          cleanup
  %139 = extractvalue { ptr, i32 } %138, 0
  store ptr %139, ptr %9, align 8
  %140 = extractvalue { ptr, i32 } %138, 1
  store i32 %140, ptr %10, align 4
  br label %142

141:                                              ; preds = %136, %126
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %143

142:                                              ; preds = %137, %106
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %145

143:                                              ; preds = %141, %79
  call void @_ZN5boost11unique_lockINS_5mutexEED2Ev(ptr noundef nonnull align 8 dereferenceable(9) %7) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %144 = load i32, ptr %3, align 4
  ret i32 %144

145:                                              ; preds = %142, %50
  call void @_ZN5boost11unique_lockINS_5mutexEED2Ev(ptr noundef nonnull align 8 dereferenceable(9) %7) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %146

146:                                              ; preds = %145
  %147 = load ptr, ptr %9, align 8
  %148 = load i32, ptr %10, align 4
  %149 = insertvalue { ptr, i32 } poison, ptr %147, 0
  %150 = insertvalue { ptr, i32 } %149, i32 %148, 1
  resume { ptr, i32 } %150
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost11unique_lockINS_5mutexEEC2ERS1_(ptr noundef nonnull align 8 dereferenceable(9), ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEE3getEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN9upscaledb10TxnManager10oldest_txnEv(ptr noundef nonnull align 8 dereferenceable(40)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK9upscaledb3Txn10is_abortedEv(ptr noundef nonnull align 8 dereferenceable(136)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK9upscaledb3Txn12is_committedEv(ptr noundef nonnull align 8 dereferenceable(136)) #2 align 2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEEptEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

declare i32 @ups_db_close(ptr noundef, i32 noundef) #5

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5boost11unique_lockINS_5mutexEED2Ev(ptr noundef nonnull align 8 dereferenceable(9)) unnamed_addr #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 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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { "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 #6 = { 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 = !{!"vtable pointer", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i64 0, i64 8, !5}
!16 = !{!17, !6, i64 8}
!17 = !{!"_ZTSSt4pairIKtPN9upscaledb2DbEE", !18, i64 0, !6, i64 8}
!18 = !{!"short", !7, i64 0}
!19 = distinct !{!19, !14}


; 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"

%"class.boost::unique_lock" = type <{ ptr, i8, [7 x i8] }>
%"struct.std::_Rb_tree_iterator" = type { ptr }

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEES8_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9upscaledb3Env5closeEj(ptr noundef nonnull align 8 dereferenceable(248) %0, i32 noundef %1) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.boost::unique_lock", align 8
  %4 = alloca %"struct.std::_Rb_tree_iterator", align 8
  %5 = alloca %"struct.std::_Rb_tree_iterator", align 8
  %6 = alloca %"struct.std::_Rb_tree_iterator", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  call void @_ZN5boost11unique_lockINS_5mutexEEC2ERS1_(ptr noundef nonnull align 8 dereferenceable(9) %3, ptr noundef nonnull align 8 dereferenceable(40) %7)
  %8 = getelementptr inbounds i8, ptr %0, i64 192
  %9 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEE3getEv(ptr noundef nonnull align 8 dereferenceable(8) %8) #4
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %.thread, label %.preheader

.preheader:                                       ; preds = %2
  %10 = and i32 %1, 8
  %.not31 = icmp eq i32 %10, 0
  br i1 %.not31, label %.preheader.split.us, label %.preheader.split

.preheader.split.us:                              ; preds = %.preheader, %25
  %11 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %8) #4
  %12 = invoke noundef ptr @_ZN9upscaledb10TxnManager10oldest_txnEv(ptr noundef nonnull align 8 dereferenceable(40) %11)
          to label %13 unwind label %.split.us

13:                                               ; preds = %.preheader.split.us
  %.not30.us = icmp eq ptr %12, null
  br i1 %.not30.us, label %.thread, label %14

14:                                               ; preds = %13
  %15 = call noundef zeroext i1 @_ZNK9upscaledb3Txn10is_abortedEv(ptr noundef nonnull align 8 dereferenceable(136) %12)
  br i1 %15, label %25, label %16

16:                                               ; preds = %14
  %17 = call noundef zeroext i1 @_ZNK9upscaledb3Txn12is_committedEv(ptr noundef nonnull align 8 dereferenceable(136) %12)
  br i1 %17, label %25, label %18

18:                                               ; preds = %16
  %19 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %8) #4
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 32
  %22 = load ptr, ptr %21, align 8
  %23 = invoke noundef i32 %22(ptr noundef nonnull align 8 dereferenceable(40) %19, ptr noundef nonnull %12)
          to label %24 unwind label %.split.us

24:                                               ; preds = %18
  %.not32.us = icmp eq i32 %23, 0
  br i1 %.not32.us, label %25, label %.loopexit39, !prof !8

25:                                               ; preds = %24, %16, %14
  %26 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %8) #4
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 40
  %29 = load ptr, ptr %28, align 8
  invoke void %29(ptr noundef nonnull align 8 dereferenceable(40) %26, ptr noundef null)
          to label %.preheader.split.us unwind label %.split.us, !llvm.loop !9

.split.us:                                        ; preds = %25, %18, %.preheader.split.us
  %30 = landingpad { ptr, i32 }
          cleanup
  br label %88

.preheader.split:                                 ; preds = %.preheader, %46
  %31 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %8) #4
  %32 = invoke noundef ptr @_ZN9upscaledb10TxnManager10oldest_txnEv(ptr noundef nonnull align 8 dereferenceable(40) %31)
          to label %33 unwind label %.split

33:                                               ; preds = %.preheader.split
  %.not30 = icmp eq ptr %32, null
  br i1 %.not30, label %.thread, label %34

34:                                               ; preds = %33
  %35 = call noundef zeroext i1 @_ZNK9upscaledb3Txn10is_abortedEv(ptr noundef nonnull align 8 dereferenceable(136) %32)
  br i1 %35, label %46, label %36

36:                                               ; preds = %34
  %37 = call noundef zeroext i1 @_ZNK9upscaledb3Txn12is_committedEv(ptr noundef nonnull align 8 dereferenceable(136) %32)
  br i1 %37, label %46, label %38

38:                                               ; preds = %36
  %39 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %8) #4
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 24
  %42 = load ptr, ptr %41, align 8
  %43 = invoke noundef i32 %42(ptr noundef nonnull align 8 dereferenceable(40) %39, ptr noundef nonnull %32)
          to label %45 unwind label %.split

.split:                                           ; preds = %46, %38, %.preheader.split
  %44 = landingpad { ptr, i32 }
          cleanup
  br label %88

45:                                               ; preds = %38
  %.not32 = icmp eq i32 %43, 0
  br i1 %.not32, label %46, label %.loopexit39, !prof !8

46:                                               ; preds = %45, %36, %34
  %47 = call noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %8) #4
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i64 40
  %50 = load ptr, ptr %49, align 8
  invoke void %50(ptr noundef nonnull align 8 dereferenceable(40) %47, ptr noundef null)
          to label %.preheader.split unwind label %.split, !llvm.loop !9

.thread:                                          ; preds = %33, %13, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %51 = getelementptr inbounds i8, ptr %0, i64 200
  %52 = call ptr @_ZNSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) %51) #4
  store ptr %52, ptr %4, align 8
  %53 = and i32 %1, 1
  %.not33 = icmp eq i32 %53, 0
  %54 = or i32 %1, -268435456
  br i1 %.not33, label %.thread.split.us, label %.thread.split

.thread.split.us:                                 ; preds = %.thread, %67
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %55 = call ptr @_ZNSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) %51) #4
  store ptr %55, ptr %5, align 8
  %56 = call noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEES8_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br i1 %56, label %57, label %.split42.us

57:                                               ; preds = %.thread.split.us
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %58 = load i64, ptr %4, align 8, !tbaa !11
  store i64 %58, ptr %6, align 8, !tbaa !11
  %59 = call ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEEppEi(ptr noundef nonnull align 8 dereferenceable(8) %4, i32 noundef 0) #4
  %60 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %6) #4
  %61 = getelementptr inbounds i8, ptr %60, i64 8
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i64 104
  %65 = load ptr, ptr %64, align 8
  %66 = invoke noundef i32 %65(ptr noundef nonnull align 8 dereferenceable(160) %62, i32 noundef %1)
          to label %67 unwind label %.split44.us

67:                                               ; preds = %57
  %.not35.us = icmp eq i32 %66, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  br i1 %.not35.us, label %.thread.split.us, label %.loopexit, !llvm.loop !17

.split44.us:                                      ; preds = %57
  %68 = landingpad { ptr, i32 }
          cleanup
  br label %79

.thread.split:                                    ; preds = %.thread, %80
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %69 = call ptr @_ZNSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) %51) #4
  store ptr %69, ptr %5, align 8
  %70 = call noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEES8_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br i1 %70, label %71, label %.split42.us

71:                                               ; preds = %.thread.split
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %72 = load i64, ptr %4, align 8, !tbaa !11
  store i64 %72, ptr %6, align 8, !tbaa !11
  %73 = call ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEEppEi(ptr noundef nonnull align 8 dereferenceable(8) %4, i32 noundef 0) #4
  %74 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %6) #4
  %75 = getelementptr inbounds i8, ptr %74, i64 8
  %76 = load ptr, ptr %75, align 8, !tbaa !14
  %77 = invoke i32 @ups_db_close(ptr noundef %76, i32 noundef %54)
          to label %80 unwind label %.split44

.split44:                                         ; preds = %71
  %78 = landingpad { ptr, i32 }
          cleanup
  br label %79

79:                                               ; preds = %.split44.us, %.split44
  %.us-phi45 = phi { ptr, i32 } [ %78, %.split44 ], [ %68, %.split44.us ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  br label %87

80:                                               ; preds = %71
  %.not35 = icmp eq i32 %77, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  br i1 %.not35, label %.thread.split, label %.loopexit, !llvm.loop !17

.split42.us:                                      ; preds = %.thread.split, %.thread.split.us
  call void @_ZNSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE5clearEv(ptr noundef nonnull align 8 dereferenceable(48) %51) #4
  %81 = load ptr, ptr %0, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %81, i64 128
  %83 = load ptr, ptr %82, align 8
  %84 = invoke noundef i32 %83(ptr noundef nonnull align 8 dereferenceable(248) %0, i32 noundef %1)
          to label %.loopexit unwind label %85

85:                                               ; preds = %.split42.us
  %86 = landingpad { ptr, i32 }
          cleanup
  br label %87

.loopexit:                                        ; preds = %80, %67, %.split42.us
  %.4 = phi i32 [ %84, %.split42.us ], [ %66, %67 ], [ %77, %80 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %.loopexit39

87:                                               ; preds = %85, %79
  %.pn = phi { ptr, i32 } [ %.us-phi45, %79 ], [ %86, %85 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %88

.loopexit39:                                      ; preds = %45, %24, %.loopexit
  %.5 = phi i32 [ %.4, %.loopexit ], [ %23, %24 ], [ %43, %45 ]
  call void @_ZN5boost11unique_lockINS_5mutexEED2Ev(ptr noundef nonnull align 8 dereferenceable(9) %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret i32 %.5

88:                                               ; preds = %.split, %.split.us, %87
  %.pn36 = phi { ptr, i32 } [ %.pn, %87 ], [ %44, %.split ], [ %30, %.split.us ]
  call void @_ZN5boost11unique_lockINS_5mutexEED2Ev(ptr noundef nonnull align 8 dereferenceable(9) %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  resume { ptr, i32 } %.pn36
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost11unique_lockINS_5mutexEEC2ERS1_(ptr noundef nonnull align 8 dereferenceable(9), ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEE3getEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK5boost10scoped_ptrIN9upscaledb10TxnManagerEEptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK9upscaledb3Txn10is_abortedEv(ptr noundef nonnull align 8 dereferenceable(136)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK9upscaledb3Txn12is_committedEv(ptr noundef nonnull align 8 dereferenceable(136)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEEppEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKtPN9upscaledb2DbEEEptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

declare i32 @ups_db_close(ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapItPN9upscaledb2DbESt4lessItESaISt4pairIKtS2_EEE5clearEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5boost11unique_lockINS_5mutexEED2Ev(ptr noundef nonnull align 8 dereferenceable(9)) unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !13, i64 0}
!13 = !{!"omnipotent char", !7, i64 0}
!14 = !{!15, !12, i64 8}
!15 = !{!"_ZTSSt4pairIKtPN9upscaledb2DbEE", !16, i64 0, !12, i64 8}
!16 = !{!"short", !13, i64 0}
!17 = distinct !{!17, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass