; LLVM IR from erthink/libmdbx :: src (tls)

; 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.libmdbx_globals = type { %union.bin128, i32, i32, i8, i8, i8, i8, i32, %union.logger_union, %union.pthread_mutex_t, i64, ptr }
%union.bin128 = type { %struct.anon.9 }
%struct.anon.9 = type { i64, i64 }
%union.logger_union = type { ptr }
%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 }
%union.mdbx_atomic_uint32_t = type { i32 }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }
%struct.rthc_entry = type { ptr }
%struct.timespec = type { i64, i64 }
%struct.MDBX_env = type { %union.mdbx_atomic_uint32_t, i32, i32, %struct.osal_mmap, i32, i32, %struct.osal_mmap, ptr, i16, i16, i16, i16, i16, i16, %union.mdbx_atomic_uint32_t, i8, i8, i16, i32, i32, i32, i32, %struct.anon, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.0, %struct.anon.4, i8, ptr, ptr, ptr, %struct.anon.5, %union.pthread_mutex_t, i32, i32, ptr, %struct.osal_ioring, %union.pthread_mutex_t, [71 x %union.mdbx_atomic_uint64_t] }
%struct.osal_mmap = type { %union.anon, i32, i64, i64, i64 }
%union.anon = type { ptr }
%struct.anon = type { ptr, ptr, ptr, ptr }
%struct.anon.0 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.1, %union.anon.2 }
%struct.anon.1 = type { i16, i16, i16, i16 }
%union.anon.2 = type { i32 }
%struct.anon.4 = type { i64, i64, i64, i64, i64 }
%struct.anon.5 = type { i64 }
%struct.osal_ioring = type { i32, i32, i32, ptr, ptr, ptr }
%union.mdbx_atomic_uint64_t = type { i64 }
%struct.shared_lck = type { i64, i32, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, [2 x %union.mdbx_atomic_uint32_t], [16 x i8], %struct.pgops, [16 x i8], %union.pthread_mutex_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, i32, %struct.anon.8, %union.pthread_mutex_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, [16 x i8], [0 x %struct.reader_slot] }
%struct.pgops = type { %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %struct.anon.6 }
%struct.anon.6 = type { %struct.gc_prof_stat, %struct.gc_prof_stat, i32, i32, i32, i32, i32 }
%struct.gc_prof_stat = type { i64, i64, i32, i32, i32, i32, %struct.anon.7 }
%struct.anon.7 = type { i64, i64, i32 }
%struct.anon.8 = type { [4 x i32], [4 x i64] }
%struct.reader_slot = type { %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint64_t }

@rthc_count = external hidden global i32, align 4
@rthc_table = external hidden global ptr, align 8
@globals = external global %struct.libmdbx_globals, align 8
@rthc_mutex = external hidden global %union.pthread_mutex_t, align 8
@rthc_key = external hidden global i32, align 4
@rthc_pending = external hidden global %union.mdbx_atomic_uint32_t, align 4
@.str.16 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [6 x i8], align 1
@rthc_cond = external hidden global %union.pthread_cond_t, align 8
@rthc_limit = external hidden global i32, align 4
@rthc_table_static = external hidden global [1 x %struct.rthc_entry], align 8
@__func__.rthc_dtor = external hidden unnamed_addr constant [10 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.39 = 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(none)
declare i64 @llvm.expect.i64(i64, i64) #1

declare void @debug_log(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @__Wpedantic_format_voidptr(ptr noundef) #3

; Function Attrs: cold nounwind optsize uwtable
declare dso_local void @workaround_glibc_bug21031() #4

; Function Attrs: nounwind uwtable
declare dso_local void @rthc_lock() #5

; Function Attrs: noreturn
declare void @mdbx_assert_fail(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #6

; Function Attrs: nounwind uwtable
declare dso_local void @rthc_unlock() #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @rthc_signature(ptr noundef, i8 noundef zeroext) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @osal_thread_self() #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @atomic_add32(ptr noundef, i32 noundef) #7

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @atomic_load32(ptr noundef, i32 noundef) #7

; Function Attrs: alwaysinline nounwind uwtable
declare hidden zeroext i1 @atomic_cas32(ptr noundef, i32 noundef, i32 noundef) #7

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @atomic_store32(ptr noundef, i32 noundef, i32 noundef) #7

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @rthc_read(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @rthc_compare_and_clean(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #8

; Function Attrs: cold nounwind optsize uwtable
define dso_local void @rthc_dtor(i32 noundef %0) #4 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.timespec, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i8, align 1
  %16 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @rthc_lock()
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #9
  %17 = load i32, ptr @rthc_key, align 4, !tbaa !5
  %18 = call ptr @pthread_getspecific(i32 noundef %17) #9
  store ptr %18, ptr %3, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %1
  %20 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = icmp sle i32 6, %21
  %23 = xor i1 %22, true
  %24 = xor i1 %23, true
  %25 = zext i1 %24 to i32
  %26 = sext i32 %25 to i64
  %27 = call i64 @llvm.expect.i64(i64 %26, i64 0)
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %43

29:                                               ; preds = %19
  %30 = call i64 @osal_thread_self()
  %31 = load ptr, ptr %3, align 8, !tbaa !9
  %32 = call ptr @__Wpedantic_format_voidptr(ptr noundef %31)
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !9
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %39

36:                                               ; preds = %29
  %37 = load ptr, ptr %3, align 8, !tbaa !9
  %38 = call i64 @rthc_read(ptr noundef %37)
  br label %40

39:                                               ; preds = %29
  br label %40

40:                                               ; preds = %39, %36
  %41 = phi i64 [ %38, %36 ], [ -1, %39 ]
  %42 = call i32 @atomic_load32(ptr noundef @rthc_pending, i32 noundef 0)
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.rthc_dtor, i32 noundef 474, ptr noundef @.str.35, i64 noundef %30, ptr noundef %32, i32 noundef %33, i64 noundef %41, i32 noundef %42)
  br label %43

43:                                               ; preds = %40, %19
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %3, align 8, !tbaa !9
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %148

48:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #9
  %49 = load ptr, ptr %3, align 8, !tbaa !9
  %50 = call i64 @rthc_signature(ptr noundef %49, i8 noundef zeroext 13)
  store i64 %50, ptr %4, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #9
  %51 = load ptr, ptr %3, align 8, !tbaa !9
  %52 = call i64 @rthc_signature(ptr noundef %51, i8 noundef zeroext -64)
  store i64 %52, ptr %5, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #9
  %53 = load ptr, ptr %3, align 8, !tbaa !9
  %54 = call i64 @rthc_read(ptr noundef %53)
  store i64 %54, ptr %6, align 8, !tbaa !15
  %55 = load i64, ptr %6, align 8, !tbaa !15
  %56 = load i64, ptr %4, align 8, !tbaa !15
  %57 = icmp eq i64 %55, %56
  br i1 %57, label %58, label %83

58:                                               ; preds = %48
  %59 = load ptr, ptr %3, align 8, !tbaa !9
  %60 = load i64, ptr %4, align 8, !tbaa !15
  %61 = call i64 @rthc_compare_and_clean(ptr noundef %59, i64 noundef %60)
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %63, label %83

63:                                               ; preds = %58
  br label %64

64:                                               ; preds = %63
  %65 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !11
  %66 = zext i8 %65 to i32
  %67 = icmp sle i32 6, %66
  %68 = xor i1 %67, true
  %69 = xor i1 %68, true
  %70 = zext i1 %69 to i32
  %71 = sext i32 %70 to i64
  %72 = call i64 @llvm.expect.i64(i64 %71, i64 0)
  %73 = icmp ne i64 %72, 0
  br i1 %73, label %74, label %80

74:                                               ; preds = %64
  %75 = call i64 @osal_thread_self()
  %76 = load ptr, ptr %3, align 8, !tbaa !9
  %77 = call ptr @__Wpedantic_format_voidptr(ptr noundef %76)
  %78 = load i32, ptr %2, align 4, !tbaa !5
  %79 = load i64, ptr %6, align 8, !tbaa !15
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.rthc_dtor, i32 noundef 481, ptr noundef @.str.16, i64 noundef %75, ptr noundef %77, i32 noundef %78, ptr noundef @.str.17, i64 noundef %79)
  br label %80

80:                                               ; preds = %74, %64
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81
  br label %147

83:                                               ; preds = %58, %48
  %84 = load i64, ptr %6, align 8, !tbaa !15
  %85 = load i64, ptr %5, align 8, !tbaa !15
  %86 = icmp eq i64 %84, %85
  br i1 %86, label %87, label %126

87:                                               ; preds = %83
  %88 = load ptr, ptr %3, align 8, !tbaa !9
  %89 = load i64, ptr %5, align 8, !tbaa !15
  %90 = call i64 @rthc_compare_and_clean(ptr noundef %88, i64 noundef %89)
  %91 = icmp ne i64 %90, 0
  br i1 %91, label %92, label %126

92:                                               ; preds = %87
  br label %93

93:                                               ; preds = %92
  %94 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !11
  %95 = zext i8 %94 to i32
  %96 = icmp sle i32 6, %95
  %97 = xor i1 %96, true
  %98 = xor i1 %97, true
  %99 = zext i1 %98 to i32
  %100 = sext i32 %99 to i64
  %101 = call i64 @llvm.expect.i64(i64 %100, i64 0)
  %102 = icmp ne i64 %101, 0
  br i1 %102, label %103, label %109

103:                                              ; preds = %93
  %104 = call i64 @osal_thread_self()
  %105 = load ptr, ptr %3, align 8, !tbaa !9
  %106 = call ptr @__Wpedantic_format_voidptr(ptr noundef %105)
  %107 = load i32, ptr %2, align 4, !tbaa !5
  %108 = load i64, ptr %6, align 8, !tbaa !15
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.rthc_dtor, i32 noundef 484, ptr noundef @.str.16, i64 noundef %104, ptr noundef %106, i32 noundef %107, ptr noundef @.str.18, i64 noundef %108)
  br label %109

109:                                              ; preds = %103, %93
  br label %110

110:                                              ; preds = %109
  br label %111

111:                                              ; preds = %110
  br label %112

112:                                              ; preds = %111
  %113 = call i32 @atomic_add32(ptr noundef @rthc_pending, i32 noundef -1)
  %114 = icmp ugt i32 %113, 0
  %115 = xor i1 %114, true
  %116 = xor i1 %115, true
  %117 = xor i1 %116, true
  %118 = zext i1 %117 to i32
  %119 = sext i32 %118 to i64
  %120 = call i64 @llvm.expect.i64(i64 %119, i64 0)
  %121 = icmp ne i64 %120, 0
  br i1 %121, label %122, label %123

122:                                              ; preds = %112
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.19, ptr noundef @__func__.rthc_dtor, i32 noundef 485) #10
  unreachable

123:                                              ; preds = %112
  br label %124

124:                                              ; preds = %123
  br label %125

125:                                              ; preds = %124
  br label %146

126:                                              ; preds = %87, %83
  br label %127

127:                                              ; preds = %126
  %128 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !11
  %129 = zext i8 %128 to i32
  %130 = icmp sle i32 2, %129
  %131 = xor i1 %130, true
  %132 = xor i1 %131, true
  %133 = zext i1 %132 to i32
  %134 = sext i32 %133 to i64
  %135 = call i64 @llvm.expect.i64(i64 %134, i64 0)
  %136 = icmp ne i64 %135, 0
  br i1 %136, label %137, label %143

137:                                              ; preds = %127
  %138 = call i64 @osal_thread_self()
  %139 = load ptr, ptr %3, align 8, !tbaa !9
  %140 = call ptr @__Wpedantic_format_voidptr(ptr noundef %139)
  %141 = load i32, ptr %2, align 4, !tbaa !5
  %142 = load i64, ptr %6, align 8, !tbaa !15
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef @__func__.rthc_dtor, i32 noundef 488, ptr noundef @.str.20, i64 noundef %138, ptr noundef %140, i32 noundef %141, ptr noundef @.str.21, i64 noundef %142)
  br label %143

143:                                              ; preds = %137, %127
  br label %144

144:                                              ; preds = %143
  br label %145

145:                                              ; preds = %144
  br label %146

146:                                              ; preds = %145, %125
  br label %147

147:                                              ; preds = %146, %82
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #9
  br label %148

148:                                              ; preds = %147, %45
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #9
  br label %149

149:                                              ; preds = %148
  %150 = call i32 @clock_gettime(i32 noundef 0, ptr noundef %7) #9
  %151 = icmp eq i32 %150, 0
  %152 = xor i1 %151, true
  %153 = xor i1 %152, true
  %154 = xor i1 %153, true
  %155 = zext i1 %154 to i32
  %156 = sext i32 %155 to i64
  %157 = call i64 @llvm.expect.i64(i64 %156, i64 0)
  %158 = icmp ne i64 %157, 0
  br i1 %158, label %159, label %160

159:                                              ; preds = %149
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.36, ptr noundef @__func__.rthc_dtor, i32 noundef 493) #10
  unreachable

160:                                              ; preds = %149
  br label %161

161:                                              ; preds = %160
  br label %162

162:                                              ; preds = %161
  %163 = getelementptr inbounds %struct.timespec, ptr %7, i32 0, i32 1
  %164 = load i64, ptr %163, align 8, !tbaa !16
  %165 = add nsw i64 %164, 100000000
  store i64 %165, ptr %163, align 8, !tbaa !16
  %166 = getelementptr inbounds %struct.timespec, ptr %7, i32 0, i32 1
  %167 = load i64, ptr %166, align 8, !tbaa !16
  %168 = icmp sge i64 %167, 1000000000
  br i1 %168, label %169, label %176

169:                                              ; preds = %162
  %170 = getelementptr inbounds %struct.timespec, ptr %7, i32 0, i32 1
  %171 = load i64, ptr %170, align 8, !tbaa !16
  %172 = sub nsw i64 %171, 1000000000
  store i64 %172, ptr %170, align 8, !tbaa !16
  %173 = getelementptr inbounds %struct.timespec, ptr %7, i32 0, i32 0
  %174 = load i64, ptr %173, align 8, !tbaa !18
  %175 = add nsw i64 %174, 1
  store i64 %175, ptr %173, align 8, !tbaa !18
  br label %176

176:                                              ; preds = %169, %162
  %177 = getelementptr inbounds %struct.timespec, ptr %7, i32 0, i32 0
  %178 = load i64, ptr %177, align 8, !tbaa !18
  %179 = add nsw i64 %178, 600
  store i64 %179, ptr %177, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #9
  br label %180

180:                                              ; preds = %211, %176
  %181 = call i32 @atomic_load32(ptr noundef @rthc_pending, i32 noundef 1)
  store i32 %181, ptr %8, align 4, !tbaa !5
  %182 = icmp ugt i32 %181, 0
  br i1 %182, label %184, label %183

183:                                              ; preds = %180
  store i32 14, ptr %9, align 4
  br label %212

184:                                              ; preds = %180
  br label %185

185:                                              ; preds = %184
  %186 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !11
  %187 = zext i8 %186 to i32
  %188 = icmp sle i32 3, %187
  %189 = xor i1 %188, true
  %190 = xor i1 %189, true
  %191 = zext i1 %190 to i32
  %192 = sext i32 %191 to i64
  %193 = call i64 @llvm.expect.i64(i64 %192, i64 0)
  %194 = icmp ne i64 %193, 0
  br i1 %194, label %195, label %198

195:                                              ; preds = %185
  %196 = load i32, ptr %2, align 4, !tbaa !5
  %197 = load i32, ptr %8, align 4, !tbaa !5
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 3, ptr noundef @__func__.rthc_dtor, i32 noundef 504, ptr noundef @.str.37, i32 noundef %196, i32 noundef %197)
  br label %198

198:                                              ; preds = %195, %185
  br label %199

199:                                              ; preds = %198
  br label %200

200:                                              ; preds = %199
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #9
  %201 = call i32 @pthread_cond_timedwait(ptr noundef @rthc_cond, ptr noundef @rthc_mutex, ptr noundef %7)
  store i32 %201, ptr %10, align 4, !tbaa !5
  %202 = load i32, ptr %10, align 4, !tbaa !5
  %203 = icmp ne i32 %202, 0
  br i1 %203, label %204, label %208

204:                                              ; preds = %200
  %205 = load i32, ptr %10, align 4, !tbaa !5
  %206 = icmp ne i32 %205, 4
  br i1 %206, label %207, label %208

207:                                              ; preds = %204
  store i32 14, ptr %9, align 4
  br label %209

208:                                              ; preds = %204, %200
  store i32 0, ptr %9, align 4
  br label %209

209:                                              ; preds = %208, %207
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #9
  %210 = load i32, ptr %9, align 4
  switch i32 %210, label %212 [
    i32 0, label %211
  ]

211:                                              ; preds = %209
  br label %180, !llvm.loop !19

212:                                              ; preds = %209, %183
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #9
  br label %213

213:                                              ; preds = %212
  %214 = load i32, ptr @rthc_key, align 4, !tbaa !5
  call void @thread_key_delete(i32 noundef %214)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #9
  store i64 0, ptr %11, align 8, !tbaa !15
  br label %215

215:                                              ; preds = %350, %213
  %216 = load i64, ptr %11, align 8, !tbaa !15
  %217 = load i32, ptr @rthc_count, align 4, !tbaa !5
  %218 = zext i32 %217 to i64
  %219 = icmp ult i64 %216, %218
  br i1 %219, label %221, label %220

220:                                              ; preds = %215
  store i32 18, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #9
  br label %353

221:                                              ; preds = %215
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #9
  %222 = load ptr, ptr @rthc_table, align 8, !tbaa !9
  %223 = load i64, ptr %11, align 8, !tbaa !15
  %224 = getelementptr inbounds %struct.rthc_entry, ptr %222, i64 %223
  %225 = getelementptr inbounds %struct.rthc_entry, ptr %224, i32 0, i32 0
  %226 = load ptr, ptr %225, align 8, !tbaa !21
  store ptr %226, ptr %12, align 8, !tbaa !9
  %227 = load ptr, ptr %12, align 8, !tbaa !9
  %228 = getelementptr inbounds %struct.MDBX_env, ptr %227, i32 0, i32 20
  %229 = load i32, ptr %228, align 4, !tbaa !23
  %230 = load i32, ptr %2, align 4, !tbaa !5
  %231 = icmp ne i32 %229, %230
  br i1 %231, label %232, label %233

232:                                              ; preds = %221
  store i32 20, ptr %9, align 4
  br label %347

233:                                              ; preds = %221
  %234 = load ptr, ptr %12, align 8, !tbaa !9
  %235 = getelementptr inbounds %struct.MDBX_env, ptr %234, i32 0, i32 1
  %236 = load i32, ptr %235, align 4, !tbaa !33
  %237 = and i32 %236, 268435456
  %238 = icmp ne i32 %237, 0
  br i1 %238, label %240, label %239

239:                                              ; preds = %233
  store i32 20, ptr %9, align 4
  br label %347

240:                                              ; preds = %233
  %241 = load ptr, ptr %12, align 8, !tbaa !9
  %242 = getelementptr inbounds %struct.MDBX_env, ptr %241, i32 0, i32 1
  %243 = load i32, ptr %242, align 4, !tbaa !33
  %244 = sub i32 %243, 268435456
  store i32 %244, ptr %242, align 4, !tbaa !33
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #9
  %245 = load ptr, ptr %12, align 8, !tbaa !9
  %246 = getelementptr inbounds %struct.MDBX_env, ptr %245, i32 0, i32 6
  %247 = getelementptr inbounds %struct.osal_mmap, ptr %246, i32 0, i32 0
  %248 = load ptr, ptr %247, align 8, !tbaa !34
  %249 = getelementptr inbounds %struct.shared_lck, ptr %248, i32 0, i32 23
  %250 = getelementptr inbounds [0 x %struct.reader_slot], ptr %249, i64 0, i64 0
  store ptr %250, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #9
  %251 = load ptr, ptr %12, align 8, !tbaa !9
  %252 = getelementptr inbounds %struct.MDBX_env, ptr %251, i32 0, i32 6
  %253 = getelementptr inbounds %struct.osal_mmap, ptr %252, i32 0, i32 0
  %254 = load ptr, ptr %253, align 8, !tbaa !34
  %255 = getelementptr inbounds %struct.shared_lck, ptr %254, i32 0, i32 23
  %256 = load ptr, ptr %12, align 8, !tbaa !9
  %257 = getelementptr inbounds %struct.MDBX_env, ptr %256, i32 0, i32 18
  %258 = load i32, ptr %257, align 4, !tbaa !35
  %259 = zext i32 %258 to i64
  %260 = getelementptr inbounds [0 x %struct.reader_slot], ptr %255, i64 0, i64 %259
  store ptr %260, ptr %14, align 8, !tbaa !9
  %261 = load ptr, ptr %12, align 8, !tbaa !9
  %262 = getelementptr inbounds %struct.MDBX_env, ptr %261, i32 0, i32 21
  %263 = load i32, ptr %262, align 8, !tbaa !36
  call void @thread_key_delete(i32 noundef %263)
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #9
  store i8 0, ptr %15, align 1, !tbaa !37
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #9
  %264 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %264, ptr %16, align 8, !tbaa !9
  br label %265

265:                                              ; preds = %334, %240
  %266 = load ptr, ptr %16, align 8, !tbaa !9
  %267 = load ptr, ptr %14, align 8, !tbaa !9
  %268 = icmp ult ptr %266, %267
  br i1 %268, label %270, label %269

269:                                              ; preds = %265
  store i32 21, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #9
  br label %337

270:                                              ; preds = %265
  br label %271

271:                                              ; preds = %270
  %272 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !11
  %273 = zext i8 %272 to i32
  %274 = icmp sle i32 6, %273
  %275 = xor i1 %274, true
  %276 = xor i1 %275, true
  %277 = zext i1 %276 to i32
  %278 = sext i32 %277 to i64
  %279 = call i64 @llvm.expect.i64(i64 %278, i64 0)
  %280 = icmp ne i64 %279, 0
  br i1 %280, label %281, label %304

281:                                              ; preds = %271
  %282 = load i64, ptr %11, align 8, !tbaa !15
  %283 = load ptr, ptr %12, align 8, !tbaa !9
  %284 = getelementptr inbounds %struct.MDBX_env, ptr %283, i32 0, i32 21
  %285 = load i32, ptr %284, align 8, !tbaa !36
  %286 = zext i32 %285 to i64
  %287 = load ptr, ptr %13, align 8, !tbaa !9
  %288 = call ptr @__Wpedantic_format_voidptr(ptr noundef %287)
  %289 = load ptr, ptr %14, align 8, !tbaa !9
  %290 = call ptr @__Wpedantic_format_voidptr(ptr noundef %289)
  %291 = load ptr, ptr %16, align 8, !tbaa !9
  %292 = call ptr @__Wpedantic_format_voidptr(ptr noundef %291)
  %293 = load ptr, ptr %16, align 8, !tbaa !9
  %294 = load ptr, ptr %13, align 8, !tbaa !9
  %295 = ptrtoint ptr %293 to i64
  %296 = ptrtoint ptr %294 to i64
  %297 = sub i64 %295, %296
  %298 = sdiv exact i64 %297, 32
  %299 = trunc i64 %298 to i32
  %300 = load ptr, ptr %16, align 8, !tbaa !9
  %301 = getelementptr inbounds %struct.reader_slot, ptr %300, i32 0, i32 2
  %302 = load volatile i32, ptr %301, align 8, !tbaa !34
  %303 = load i32, ptr %2, align 4, !tbaa !5
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.rthc_dtor, i32 noundef 527, ptr noundef @.str.38, i64 noundef %282, i64 noundef %286, ptr noundef %288, ptr noundef %290, ptr noundef %292, i32 noundef %299, i32 noundef %302, i32 noundef %303)
  br label %304

304:                                              ; preds = %281, %271
  br label %305

305:                                              ; preds = %304
  br label %306

306:                                              ; preds = %305
  %307 = load ptr, ptr %16, align 8, !tbaa !9
  %308 = getelementptr inbounds %struct.reader_slot, ptr %307, i32 0, i32 2
  %309 = call i32 @atomic_load32(ptr noundef %308, i32 noundef 0)
  %310 = load i32, ptr %2, align 4, !tbaa !5
  %311 = icmp eq i32 %309, %310
  br i1 %311, label %312, label %333

312:                                              ; preds = %306
  %313 = load ptr, ptr %16, align 8, !tbaa !9
  %314 = getelementptr inbounds %struct.reader_slot, ptr %313, i32 0, i32 2
  %315 = load i32, ptr %2, align 4, !tbaa !5
  %316 = call zeroext i1 @atomic_cas32(ptr noundef %314, i32 noundef %315, i32 noundef 0)
  br label %317

317:                                              ; preds = %312
  %318 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !11
  %319 = zext i8 %318 to i32
  %320 = icmp sle i32 6, %319
  %321 = xor i1 %320, true
  %322 = xor i1 %321, true
  %323 = zext i1 %322 to i32
  %324 = sext i32 %323 to i64
  %325 = call i64 @llvm.expect.i64(i64 %324, i64 0)
  %326 = icmp ne i64 %325, 0
  br i1 %326, label %327, label %330

327:                                              ; preds = %317
  %328 = load ptr, ptr %16, align 8, !tbaa !9
  %329 = call ptr @__Wpedantic_format_voidptr(ptr noundef %328)
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.rthc_dtor, i32 noundef 530, ptr noundef @.str.39, ptr noundef %329)
  br label %330

330:                                              ; preds = %327, %317
  br label %331

331:                                              ; preds = %330
  br label %332

332:                                              ; preds = %331
  store i8 1, ptr %15, align 1, !tbaa !37
  br label %333

333:                                              ; preds = %332, %306
  br label %334

334:                                              ; preds = %333
  %335 = load ptr, ptr %16, align 8, !tbaa !9
  %336 = getelementptr inbounds %struct.reader_slot, ptr %335, i32 1
  store ptr %336, ptr %16, align 8, !tbaa !9
  br label %265, !llvm.loop !38

337:                                              ; preds = %269
  %338 = load i8, ptr %15, align 1, !tbaa !37, !range !39, !noundef !40
  %339 = trunc i8 %338 to i1
  br i1 %339, label %340, label %346

340:                                              ; preds = %337
  %341 = load ptr, ptr %12, align 8, !tbaa !9
  %342 = getelementptr inbounds %struct.MDBX_env, ptr %341, i32 0, i32 7
  %343 = load ptr, ptr %342, align 8, !tbaa !41
  %344 = getelementptr inbounds %struct.shared_lck, ptr %343, i32 0, i32 21
  %345 = call i32 @atomic_store32(ptr noundef %344, i32 noundef 1, i32 noundef 0)
  br label %346

346:                                              ; preds = %340, %337
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #9
  store i32 0, ptr %9, align 4
  br label %347

347:                                              ; preds = %346, %239, %232
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #9
  %348 = load i32, ptr %9, align 4
  switch i32 %348, label %359 [
    i32 0, label %349
    i32 20, label %350
  ]

349:                                              ; preds = %347
  br label %350

350:                                              ; preds = %349, %347
  %351 = load i64, ptr %11, align 8, !tbaa !15
  %352 = add i64 %351, 1
  store i64 %352, ptr %11, align 8, !tbaa !15
  br label %215, !llvm.loop !42

353:                                              ; preds = %220
  store i32 0, ptr @rthc_count, align 4, !tbaa !5
  store i32 0, ptr @rthc_limit, align 4, !tbaa !5
  %354 = load ptr, ptr @rthc_table, align 8, !tbaa !9
  %355 = icmp ne ptr %354, @rthc_table_static
  br i1 %355, label %356, label %358

356:                                              ; preds = %353
  %357 = load ptr, ptr @rthc_table, align 8, !tbaa !9
  call void @free(ptr noundef %357) #9
  br label %358

358:                                              ; preds = %356, %353
  store ptr null, ptr @rthc_table, align 8, !tbaa !9
  call void @rthc_unlock()
  call void @workaround_glibc_bug21031() #11
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #9
  ret void

359:                                              ; preds = %347
  unreachable
}

; Function Attrs: nounwind
declare ptr @pthread_getspecific(i32 noundef) #8

; Function Attrs: nounwind
declare i32 @clock_gettime(i32 noundef, ptr noundef) #8

declare i32 @pthread_cond_timedwait(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @thread_key_delete(i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { "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 = { inlinehint 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 = { cold nounwind optsize 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 #5 = { 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 #6 = { noreturn "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 #7 = { alwaysinline 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 #8 = { 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 #9 = { nounwind }
attributes #10 = { noreturn }
attributes #11 = { cold }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !7, i64 26}
!12 = !{!"libmdbx_globals", !7, i64 0, !6, i64 16, !6, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !13, i64 27, !6, i64 28, !7, i64 32, !7, i64 40, !14, i64 80, !10, i64 88}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!17, !14, i64 8}
!17 = !{!"timespec", !14, i64 0, !14, i64 8}
!18 = !{!17, !14, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!22, !10, i64 0}
!22 = !{!"rthc_entry", !10, i64 0}
!23 = !{!24, !6, i64 140}
!24 = !{!"MDBX_env", !7, i64 0, !6, i64 4, !6, i64 8, !25, i64 16, !6, i64 56, !6, i64 60, !25, i64 64, !10, i64 104, !26, i64 112, !26, i64 114, !26, i64 116, !26, i64 118, !26, i64 120, !26, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !26, i64 130, !6, i64 132, !6, i64 136, !6, i64 140, !6, i64 144, !27, i64 152, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !6, i64 224, !6, i64 228, !6, i64 232, !10, i64 240, !10, i64 248, !14, i64 256, !28, i64 264, !30, i64 320, !13, i64 360, !10, i64 368, !10, i64 376, !10, i64 384, !31, i64 392, !7, i64 400, !6, i64 440, !6, i64 444, !10, i64 448, !32, i64 456, !7, i64 496, !7, i64 536}
!25 = !{!"osal_mmap", !7, i64 0, !6, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!26 = !{!"short", !7, i64 0}
!27 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!28 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !14, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !6, i64 28, !6, i64 32, !13, i64 36, !13, i64 37, !13, i64 38, !29, i64 40, !7, i64 48}
!29 = !{!"", !26, i64 0, !26, i64 2, !26, i64 4, !26, i64 6}
!30 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!31 = !{!"", !14, i64 0}
!32 = !{!"osal_ioring", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!33 = !{!24, !6, i64 4}
!34 = !{!7, !7, i64 0}
!35 = !{!24, !6, i64 132}
!36 = !{!24, !6, i64 144}
!37 = !{!13, !13, i64 0}
!38 = distinct !{!38, !20}
!39 = !{i8 0, i8 2}
!40 = !{}
!41 = !{!24, !10, i64 104}
!42 = distinct !{!42, !20}


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

%struct.libmdbx_globals = type { %union.bin128, i32, i32, i8, i8, i8, i8, i32, %union.logger_union, %union.pthread_mutex_t, i64, ptr }
%union.bin128 = type { %struct.anon.9 }
%struct.anon.9 = type { i64, i64 }
%union.logger_union = type { ptr }
%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 }
%union.mdbx_atomic_uint32_t = type { i32 }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }
%struct.rthc_entry = type { ptr }
%struct.timespec = type { i64, i64 }

@rthc_count = external hidden local_unnamed_addr global i32, align 4
@rthc_table = external hidden local_unnamed_addr global ptr, align 8
@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@rthc_mutex = external hidden global %union.pthread_mutex_t, align 8
@rthc_key = external hidden local_unnamed_addr global i32, align 4
@rthc_pending = external hidden global %union.mdbx_atomic_uint32_t, align 4
@.str.16 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [6 x i8], align 1
@rthc_cond = external hidden global %union.pthread_cond_t, align 8
@rthc_limit = external hidden local_unnamed_addr global i32, align 4
@rthc_table_static = external hidden global [1 x %struct.rthc_entry], align 8
@__func__.rthc_dtor = external hidden unnamed_addr constant [10 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.39 = 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

declare void @debug_log(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @__Wpedantic_format_voidptr(ptr noundef) local_unnamed_addr #2

; Function Attrs: cold nounwind optsize uwtable
declare dso_local void @workaround_glibc_bug21031() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @rthc_lock() local_unnamed_addr #4

; Function Attrs: noreturn
declare void @mdbx_assert_fail(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare dso_local void @rthc_unlock() local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @rthc_signature(ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @osal_thread_self() local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @atomic_add32(ptr noundef, i32 noundef) local_unnamed_addr #6

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @atomic_load32(ptr noundef, i32 noundef) local_unnamed_addr #6

; Function Attrs: alwaysinline nounwind uwtable
declare hidden zeroext i1 @atomic_cas32(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #6

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @atomic_store32(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #6

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @rthc_read(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @rthc_compare_and_clean(ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local void @rthc_dtor(i32 noundef %0) local_unnamed_addr #3 {
  %2 = alloca %struct.timespec, align 8
  tail call void @rthc_lock()
  %3 = load i32, ptr @rthc_key, align 4, !tbaa !5
  %4 = tail call ptr @pthread_getspecific(i32 noundef %3) #9
  %5 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !9
  %6 = icmp ugt i8 %5, 5
  br i1 %6, label %7, label %15, !prof !14

7:                                                ; preds = %1
  %8 = tail call i64 @osal_thread_self()
  %9 = tail call ptr @__Wpedantic_format_voidptr(ptr noundef %4)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %12, label %10

10:                                               ; preds = %7
  %11 = tail call i64 @rthc_read(ptr noundef nonnull %4)
  br label %12

12:                                               ; preds = %7, %10
  %13 = phi i64 [ %11, %10 ], [ -1, %7 ]
  %14 = tail call i32 @atomic_load32(ptr noundef nonnull @rthc_pending, i32 noundef 0)
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.rthc_dtor, i32 noundef 474, ptr noundef nonnull @.str.35, i64 noundef %8, ptr noundef %9, i32 noundef %0, i64 noundef %13, i32 noundef %14) #9
  br label %15

15:                                               ; preds = %12, %1
  %.not75 = icmp eq ptr %4, null
  br i1 %.not75, label %48, label %16

16:                                               ; preds = %15
  %17 = tail call i64 @rthc_signature(ptr noundef nonnull %4, i8 noundef zeroext 13)
  %18 = tail call i64 @rthc_signature(ptr noundef nonnull %4, i8 noundef zeroext -64)
  %19 = tail call i64 @rthc_read(ptr noundef nonnull %4)
  %20 = icmp eq i64 %19, %17
  br i1 %20, label %21, label %29

21:                                               ; preds = %16
  %22 = tail call i64 @rthc_compare_and_clean(ptr noundef nonnull %4, i64 noundef %17)
  %.not76 = icmp eq i64 %22, 0
  br i1 %.not76, label %29, label %23

23:                                               ; preds = %21
  %24 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !9
  %25 = icmp ugt i8 %24, 5
  br i1 %25, label %26, label %48, !prof !14

26:                                               ; preds = %23
  %27 = tail call i64 @osal_thread_self()
  %28 = tail call ptr @__Wpedantic_format_voidptr(ptr noundef nonnull %4)
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.rthc_dtor, i32 noundef 481, ptr noundef nonnull @.str.16, i64 noundef %27, ptr noundef %28, i32 noundef %0, ptr noundef nonnull @.str.17, i64 noundef %17) #9
  br label %48

29:                                               ; preds = %21, %16
  %30 = icmp eq i64 %19, %18
  br i1 %30, label %31, label %42

31:                                               ; preds = %29
  %32 = tail call i64 @rthc_compare_and_clean(ptr noundef nonnull %4, i64 noundef %18)
  %.not77 = icmp eq i64 %32, 0
  br i1 %.not77, label %42, label %33

33:                                               ; preds = %31
  %34 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !9
  %35 = icmp ugt i8 %34, 5
  br i1 %35, label %36, label %39, !prof !14

36:                                               ; preds = %33
  %37 = tail call i64 @osal_thread_self()
  %38 = tail call ptr @__Wpedantic_format_voidptr(ptr noundef nonnull %4)
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.rthc_dtor, i32 noundef 484, ptr noundef nonnull @.str.16, i64 noundef %37, ptr noundef %38, i32 noundef %0, ptr noundef nonnull @.str.18, i64 noundef %18) #9
  br label %39

39:                                               ; preds = %33, %36
  %40 = tail call i32 @atomic_add32(ptr noundef nonnull @rthc_pending, i32 noundef -1)
  %.not78 = icmp eq i32 %40, 0
  br i1 %.not78, label %41, label %48, !prof !14

41:                                               ; preds = %39
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.19, ptr noundef nonnull @__func__.rthc_dtor, i32 noundef 485) #10
  unreachable

42:                                               ; preds = %29, %31
  %43 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !9
  %44 = icmp ugt i8 %43, 1
  br i1 %44, label %45, label %48, !prof !14

45:                                               ; preds = %42
  %46 = tail call i64 @osal_thread_self()
  %47 = tail call ptr @__Wpedantic_format_voidptr(ptr noundef nonnull %4)
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef nonnull @__func__.rthc_dtor, i32 noundef 488, ptr noundef nonnull @.str.20, i64 noundef %46, ptr noundef %47, i32 noundef %0, ptr noundef nonnull @.str.21, i64 noundef %19) #9
  br label %48

48:                                               ; preds = %26, %23, %42, %45, %39, %15
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #9
  %49 = call i32 @clock_gettime(i32 noundef 0, ptr noundef nonnull %2) #9
  %.not79 = icmp eq i32 %49, 0
  br i1 %.not79, label %51, label %50, !prof !15

50:                                               ; preds = %48
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.36, ptr noundef nonnull @__func__.rthc_dtor, i32 noundef 493) #10
  unreachable

51:                                               ; preds = %48
  %52 = getelementptr inbounds i8, ptr %2, i64 8
  %53 = load i64, ptr %52, align 8, !tbaa !16
  %54 = add nsw i64 %53, 100000000
  store i64 %54, ptr %52, align 8, !tbaa !16
  %55 = icmp sgt i64 %53, 899999999
  %.pre = load i64, ptr %2, align 8, !tbaa !18
  br i1 %55, label %56, label %59

56:                                               ; preds = %51
  %57 = add nsw i64 %53, -900000000
  store i64 %57, ptr %52, align 8, !tbaa !16
  %58 = add nsw i64 %.pre, 1
  br label %59

59:                                               ; preds = %56, %51
  %60 = phi i64 [ %58, %56 ], [ %.pre, %51 ]
  %61 = add nsw i64 %60, 600
  store i64 %61, ptr %2, align 8, !tbaa !18
  br label %62

62:                                               ; preds = %68, %59
  %63 = call i32 @atomic_load32(ptr noundef nonnull @rthc_pending, i32 noundef 1)
  %.not80 = icmp eq i32 %63, 0
  br i1 %.not80, label %71, label %64

64:                                               ; preds = %62
  %65 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !9
  %66 = icmp ugt i8 %65, 2
  br i1 %66, label %67, label %68, !prof !14

67:                                               ; preds = %64
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 3, ptr noundef nonnull @__func__.rthc_dtor, i32 noundef 504, ptr noundef nonnull @.str.37, i32 noundef %0, i32 noundef %63) #9
  br label %68

68:                                               ; preds = %67, %64
  %69 = call i32 @pthread_cond_timedwait(ptr noundef nonnull @rthc_cond, ptr noundef nonnull @rthc_mutex, ptr noundef nonnull %2) #9
  %70 = and i32 %69, -5
  %or.cond.not = icmp eq i32 %70, 0
  br i1 %or.cond.not, label %62, label %71, !llvm.loop !19

71:                                               ; preds = %62, %68
  %72 = load i32, ptr @rthc_key, align 4, !tbaa !5
  call void @thread_key_delete(i32 noundef %72)
  %73 = load i32, ptr @rthc_count, align 4, !tbaa !5
  %.not90 = icmp eq i32 %73, 0
  br i1 %.not90, label %._crit_edge89, label %.lr.ph88

._crit_edge89:                                    ; preds = %.critedge, %71
  store i32 0, ptr @rthc_count, align 4, !tbaa !5
  store i32 0, ptr @rthc_limit, align 4, !tbaa !5
  %74 = load ptr, ptr @rthc_table, align 8, !tbaa !21
  %.not81 = icmp eq ptr %74, @rthc_table_static
  br i1 %.not81, label %133, label %132

.lr.ph88:                                         ; preds = %71, %.critedge
  %.06386 = phi i64 [ %128, %.critedge ], [ 0, %71 ]
  %75 = load ptr, ptr @rthc_table, align 8, !tbaa !21
  %76 = getelementptr inbounds %struct.rthc_entry, ptr %75, i64 %.06386
  %77 = load ptr, ptr %76, align 8, !tbaa !22
  %78 = getelementptr inbounds i8, ptr %77, i64 140
  %79 = load i32, ptr %78, align 4, !tbaa !24
  %.not82 = icmp eq i32 %79, %0
  br i1 %.not82, label %80, label %.critedge

80:                                               ; preds = %.lr.ph88
  %81 = getelementptr inbounds i8, ptr %77, i64 4
  %82 = load i32, ptr %81, align 4, !tbaa !34
  %83 = and i32 %82, 268435456
  %.not83 = icmp eq i32 %83, 0
  br i1 %.not83, label %.critedge, label %84

84:                                               ; preds = %80
  %85 = add nsw i32 %82, -268435456
  store i32 %85, ptr %81, align 4, !tbaa !34
  %86 = getelementptr inbounds i8, ptr %77, i64 64
  %87 = load ptr, ptr %86, align 8, !tbaa !35
  %.ptr = getelementptr inbounds i8, ptr %87, i64 512
  %88 = getelementptr inbounds i8, ptr %77, i64 132
  %89 = load i32, ptr %88, align 4, !tbaa !36
  %90 = zext i32 %89 to i64
  %.idx = shl nuw nsw i64 %90, 5
  %91 = getelementptr inbounds i8, ptr %87, i64 %.idx
  %.ptr91 = getelementptr inbounds i8, ptr %91, i64 512
  %92 = getelementptr inbounds i8, ptr %77, i64 144
  %93 = load i32, ptr %92, align 8, !tbaa !37
  call void @thread_key_delete(i32 noundef %93)
  %.not92 = icmp eq i32 %89, 0
  br i1 %.not92, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %84
  %94 = ptrtoint ptr %.ptr to i64
  br label %95

._crit_edge:                                      ; preds = %120
  br i1 %.1, label %123, label %.critedge

95:                                               ; preds = %.lr.ph, %120
  %.085 = phi ptr [ %.ptr, %.lr.ph ], [ %121, %120 ]
  %.06184 = phi i1 [ false, %.lr.ph ], [ %.1, %120 ]
  %96 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !9
  %97 = icmp ugt i8 %96, 5
  br i1 %97, label %98, label %110, !prof !14

98:                                               ; preds = %95
  %99 = load i32, ptr %92, align 8, !tbaa !37
  %100 = zext i32 %99 to i64
  %101 = call ptr @__Wpedantic_format_voidptr(ptr noundef nonnull %.ptr)
  %102 = call ptr @__Wpedantic_format_voidptr(ptr noundef nonnull %.ptr91)
  %103 = call ptr @__Wpedantic_format_voidptr(ptr noundef nonnull %.085)
  %104 = ptrtoint ptr %.085 to i64
  %105 = sub i64 %104, %94
  %106 = lshr exact i64 %105, 5
  %107 = trunc i64 %106 to i32
  %108 = getelementptr inbounds i8, ptr %.085, i64 16
  %109 = load volatile i32, ptr %108, align 8, !tbaa !35
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.rthc_dtor, i32 noundef 527, ptr noundef nonnull @.str.38, i64 noundef %.06386, i64 noundef %100, ptr noundef %101, ptr noundef %102, ptr noundef %103, i32 noundef %107, i32 noundef %109, i32 noundef %0) #9
  br label %110

110:                                              ; preds = %98, %95
  %111 = getelementptr inbounds i8, ptr %.085, i64 16
  %112 = call i32 @atomic_load32(ptr noundef nonnull %111, i32 noundef 0)
  %113 = icmp eq i32 %112, %0
  br i1 %113, label %114, label %120

114:                                              ; preds = %110
  %115 = call zeroext i1 @atomic_cas32(ptr noundef nonnull %111, i32 noundef %0, i32 noundef 0)
  %116 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !9
  %117 = icmp ugt i8 %116, 5
  br i1 %117, label %118, label %120, !prof !14

118:                                              ; preds = %114
  %119 = call ptr @__Wpedantic_format_voidptr(ptr noundef nonnull %.085)
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.rthc_dtor, i32 noundef 530, ptr noundef nonnull @.str.39, ptr noundef %119) #9
  br label %120

120:                                              ; preds = %114, %118, %110
  %.1 = phi i1 [ %.06184, %110 ], [ true, %118 ], [ true, %114 ]
  %121 = getelementptr inbounds i8, ptr %.085, i64 32
  %122 = icmp ult ptr %121, %.ptr91
  br i1 %122, label %95, label %._crit_edge, !llvm.loop !38

123:                                              ; preds = %._crit_edge
  %124 = getelementptr inbounds i8, ptr %77, i64 104
  %125 = load ptr, ptr %124, align 8, !tbaa !39
  %126 = getelementptr inbounds i8, ptr %125, i64 492
  %127 = call i32 @atomic_store32(ptr noundef nonnull %126, i32 noundef 1, i32 noundef 0)
  br label %.critedge

.critedge:                                        ; preds = %84, %._crit_edge, %123, %80, %.lr.ph88
  %128 = add nuw nsw i64 %.06386, 1
  %129 = load i32, ptr @rthc_count, align 4, !tbaa !5
  %130 = zext i32 %129 to i64
  %131 = icmp ult i64 %128, %130
  br i1 %131, label %.lr.ph88, label %._crit_edge89, !llvm.loop !40

132:                                              ; preds = %._crit_edge89
  call void @free(ptr noundef %74) #9
  br label %133

133:                                              ; preds = %132, %._crit_edge89
  store ptr null, ptr @rthc_table, align 8, !tbaa !21
  call void @rthc_unlock()
  call void @workaround_glibc_bug21031() #11
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #9
  ret void
}

; Function Attrs: nounwind
declare ptr @pthread_getspecific(i32 noundef) local_unnamed_addr #8

; Function Attrs: nounwind
declare i32 @clock_gettime(i32 noundef, ptr noundef) local_unnamed_addr #8

declare i32 @pthread_cond_timedwait(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @thread_key_delete(i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { inlinehint 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 = { cold nounwind optsize 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 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 #5 = { noreturn "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 = { alwaysinline 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 #7 = { 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 #8 = { 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 #9 = { nounwind }
attributes #10 = { noreturn nounwind }
attributes #11 = { cold }

!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/C++ TBAA"}
!9 = !{!10, !7, i64 26}
!10 = !{!"libmdbx_globals", !7, i64 0, !6, i64 16, !6, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !11, i64 27, !6, i64 28, !7, i64 32, !7, i64 40, !12, i64 80, !13, i64 88}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!15 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!16 = !{!17, !12, i64 8}
!17 = !{!"timespec", !12, i64 0, !12, i64 8}
!18 = !{!17, !12, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!13, !13, i64 0}
!22 = !{!23, !13, i64 0}
!23 = !{!"rthc_entry", !13, i64 0}
!24 = !{!25, !6, i64 140}
!25 = !{!"MDBX_env", !7, i64 0, !6, i64 4, !6, i64 8, !26, i64 16, !6, i64 56, !6, i64 60, !26, i64 64, !13, i64 104, !27, i64 112, !27, i64 114, !27, i64 116, !27, i64 118, !27, i64 120, !27, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !27, i64 130, !6, i64 132, !6, i64 136, !6, i64 140, !6, i64 144, !28, i64 152, !13, i64 184, !13, i64 192, !13, i64 200, !13, i64 208, !13, i64 216, !6, i64 224, !6, i64 228, !6, i64 232, !13, i64 240, !13, i64 248, !12, i64 256, !29, i64 264, !31, i64 320, !11, i64 360, !13, i64 368, !13, i64 376, !13, i64 384, !32, i64 392, !7, i64 400, !6, i64 440, !6, i64 444, !13, i64 448, !33, i64 456, !7, i64 496, !7, i64 536}
!26 = !{!"osal_mmap", !7, i64 0, !6, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!27 = !{!"short", !7, i64 0}
!28 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!29 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !12, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !6, i64 28, !6, i64 32, !11, i64 36, !11, i64 37, !11, i64 38, !30, i64 40, !7, i64 48}
!30 = !{!"", !27, i64 0, !27, i64 2, !27, i64 4, !27, i64 6}
!31 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!32 = !{!"", !12, i64 0}
!33 = !{!"osal_ioring", !6, i64 0, !6, i64 4, !6, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!34 = !{!25, !6, i64 4}
!35 = !{!7, !7, i64 0}
!36 = !{!25, !6, i64 132}
!37 = !{!25, !6, i64 144}
!38 = distinct !{!38, !20}
!39 = !{!25, !13, i64 104}
!40 = distinct !{!40, !20}


; Effective O3 passes: AggressiveInstCombinePass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass