; 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 }
%struct.rthc_entry = type { ptr }
%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 }
%union.mdbx_atomic_uint32_t = type { i32 }
%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 }

@rthc_count = external hidden global i32, align 4
@rthc_table = external hidden global ptr, align 8
@globals = external global %struct.libmdbx_globals, align 8
@__func__.rthc_register = external hidden unnamed_addr constant [14 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [41 x i8], align 1
@rthc_limit = external hidden global i32, align 4
@rthc_table_static = external hidden global [1 x %struct.rthc_entry], align 8
@.str.26 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [57 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
define dso_local i32 @rthc_register(ptr noundef %0) #4 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %1
  %9 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !9
  %10 = zext i8 %9 to i32
  %11 = icmp sle i32 6, %10
  %12 = xor i1 %11, true
  %13 = xor i1 %12, true
  %14 = zext i1 %13 to i32
  %15 = sext i32 %14 to i64
  %16 = call i64 @llvm.expect.i64(i64 %15, i64 0)
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %8
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = call ptr @__Wpedantic_format_voidptr(ptr noundef %19)
  %21 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %22 = load i32, ptr @rthc_limit, align 4, !tbaa !14
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.rthc_register, i32 noundef 331, ptr noundef @.str.25, ptr noundef %20, i32 noundef %21, i32 noundef %22)
  br label %23

23:                                               ; preds = %18, %8
  br label %24

24:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  store i32 0, ptr %4, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  store i64 0, ptr %5, align 8, !tbaa !15
  br label %25

25:                                               ; preds = %47, %24
  %26 = load i64, ptr %5, align 8, !tbaa !15
  %27 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %28 = zext i32 %27 to i64
  %29 = icmp ult i64 %26, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  store i32 4, ptr %6, align 4
  br label %50

31:                                               ; preds = %25
  %32 = load ptr, ptr @rthc_table, align 8, !tbaa !5
  %33 = load i64, ptr %5, align 8, !tbaa !15
  %34 = getelementptr inbounds %struct.rthc_entry, ptr %32, i64 %33
  %35 = getelementptr inbounds %struct.rthc_entry, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = icmp eq ptr %36, %37
  %39 = xor i1 %38, true
  %40 = xor i1 %39, true
  %41 = zext i1 %40 to i32
  %42 = sext i32 %41 to i64
  %43 = call i64 @llvm.expect.i64(i64 %42, i64 0)
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %31
  store i32 -30795, ptr %4, align 4, !tbaa !14
  store i32 7, ptr %6, align 4
  br label %50

46:                                               ; preds = %31
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %5, align 8, !tbaa !15
  %49 = add i64 %48, 1
  store i64 %49, ptr %5, align 8, !tbaa !15
  br label %25, !llvm.loop !18

50:                                               ; preds = %45, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  %51 = load i32, ptr %6, align 4
  switch i32 %51, label %181 [
    i32 4, label %52
    i32 7, label %156
  ]

52:                                               ; preds = %50
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.MDBX_env, ptr %53, i32 0, i32 21
  store i32 0, ptr %54, align 8, !tbaa !20
  %55 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %56 = load i32, ptr @rthc_limit, align 4, !tbaa !14
  %57 = icmp eq i32 %55, %56
  %58 = xor i1 %57, true
  %59 = xor i1 %58, true
  %60 = zext i1 %59 to i32
  %61 = sext i32 %60 to i64
  %62 = call i64 @llvm.expect.i64(i64 %61, i64 0)
  %63 = icmp ne i64 %62, 0
  br i1 %63, label %64, label %102

64:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %65 = load ptr, ptr @rthc_table, align 8, !tbaa !5
  %66 = icmp eq ptr %65, @rthc_table_static
  br i1 %66, label %67, label %68

67:                                               ; preds = %64
  br label %70

68:                                               ; preds = %64
  %69 = load ptr, ptr @rthc_table, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %68, %67
  %71 = phi ptr [ null, %67 ], [ %69, %68 ]
  %72 = load i32, ptr @rthc_limit, align 4, !tbaa !14
  %73 = zext i32 %72 to i64
  %74 = mul i64 8, %73
  %75 = mul i64 %74, 2
  %76 = call ptr @realloc(ptr noundef %71, i64 noundef %75) #8
  store ptr %76, ptr %7, align 8, !tbaa !5
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = icmp eq ptr %77, null
  %79 = xor i1 %78, true
  %80 = xor i1 %79, true
  %81 = zext i1 %80 to i32
  %82 = sext i32 %81 to i64
  %83 = call i64 @llvm.expect.i64(i64 %82, i64 0)
  %84 = icmp ne i64 %83, 0
  br i1 %84, label %85, label %86

85:                                               ; preds = %70
  store i32 12, ptr %4, align 4, !tbaa !14
  store i32 7, ptr %6, align 4
  br label %99

86:                                               ; preds = %70
  %87 = load ptr, ptr @rthc_table, align 8, !tbaa !5
  %88 = icmp eq ptr %87, @rthc_table_static
  br i1 %88, label %89, label %95

89:                                               ; preds = %86
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = load ptr, ptr @rthc_table, align 8, !tbaa !5
  %92 = load i32, ptr @rthc_limit, align 4, !tbaa !14
  %93 = zext i32 %92 to i64
  %94 = mul i64 8, %93
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %90, ptr align 8 %91, i64 %94, i1 false)
  br label %95

95:                                               ; preds = %89, %86
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %96, ptr @rthc_table, align 8, !tbaa !5
  %97 = load i32, ptr @rthc_limit, align 4, !tbaa !14
  %98 = mul i32 %97, 2
  store i32 %98, ptr @rthc_limit, align 4, !tbaa !14
  store i32 0, ptr %6, align 4
  br label %99

99:                                               ; preds = %95, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  %100 = load i32, ptr %6, align 4
  switch i32 %100, label %181 [
    i32 0, label %101
    i32 7, label %156
  ]

101:                                              ; preds = %99
  br label %102

102:                                              ; preds = %101, %52
  %103 = load ptr, ptr %3, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.MDBX_env, ptr %103, i32 0, i32 1
  %105 = load i32, ptr %104, align 4, !tbaa !30
  %106 = and i32 %105, 2097152
  %107 = icmp eq i32 %106, 0
  br i1 %107, label %108, label %126

108:                                              ; preds = %102
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.MDBX_env, ptr %109, i32 0, i32 21
  %111 = call i32 @thread_key_create(ptr noundef %110)
  store i32 %111, ptr %4, align 4, !tbaa !14
  %112 = load i32, ptr %4, align 4, !tbaa !14
  %113 = icmp ne i32 %112, 0
  %114 = xor i1 %113, true
  %115 = xor i1 %114, true
  %116 = zext i1 %115 to i32
  %117 = sext i32 %116 to i64
  %118 = call i64 @llvm.expect.i64(i64 %117, i64 0)
  %119 = icmp ne i64 %118, 0
  br i1 %119, label %120, label %121

120:                                              ; preds = %108
  br label %156

121:                                              ; preds = %108
  %122 = load ptr, ptr %3, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct.MDBX_env, ptr %122, i32 0, i32 1
  %124 = load i32, ptr %123, align 4, !tbaa !30
  %125 = or i32 %124, 268435456
  store i32 %125, ptr %123, align 4, !tbaa !30
  br label %126

126:                                              ; preds = %121, %102
  %127 = load ptr, ptr %3, align 8, !tbaa !5
  %128 = load ptr, ptr @rthc_table, align 8, !tbaa !5
  %129 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %130 = zext i32 %129 to i64
  %131 = getelementptr inbounds %struct.rthc_entry, ptr %128, i64 %130
  %132 = getelementptr inbounds %struct.rthc_entry, ptr %131, i32 0, i32 0
  store ptr %127, ptr %132, align 8, !tbaa !16
  br label %133

133:                                              ; preds = %126
  %134 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !9
  %135 = zext i8 %134 to i32
  %136 = icmp sle i32 6, %135
  %137 = xor i1 %136, true
  %138 = xor i1 %137, true
  %139 = zext i1 %138 to i32
  %140 = sext i32 %139 to i64
  %141 = call i64 @llvm.expect.i64(i64 %140, i64 0)
  %142 = icmp ne i64 %141, 0
  br i1 %142, label %143, label %151

143:                                              ; preds = %133
  %144 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %145 = load ptr, ptr %3, align 8, !tbaa !5
  %146 = call ptr @__Wpedantic_format_voidptr(ptr noundef %145)
  %147 = load ptr, ptr %3, align 8, !tbaa !5
  %148 = getelementptr inbounds %struct.MDBX_env, ptr %147, i32 0, i32 21
  %149 = load i32, ptr %148, align 8, !tbaa !20
  %150 = zext i32 %149 to i64
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.rthc_register, i32 noundef 362, ptr noundef @.str.26, i32 noundef %144, ptr noundef %146, i64 noundef %150)
  br label %151

151:                                              ; preds = %143, %133
  br label %152

152:                                              ; preds = %151
  br label %153

153:                                              ; preds = %152
  %154 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %155 = add i32 %154, 1
  store i32 %155, ptr @rthc_count, align 4, !tbaa !14
  br label %156

156:                                              ; preds = %153, %120, %99, %50
  br label %157

157:                                              ; preds = %156
  %158 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !9
  %159 = zext i8 %158 to i32
  %160 = icmp sle i32 6, %159
  %161 = xor i1 %160, true
  %162 = xor i1 %161, true
  %163 = zext i1 %162 to i32
  %164 = sext i32 %163 to i64
  %165 = call i64 @llvm.expect.i64(i64 %164, i64 0)
  %166 = icmp ne i64 %165, 0
  br i1 %166, label %167, label %177

167:                                              ; preds = %157
  %168 = load ptr, ptr %3, align 8, !tbaa !5
  %169 = call ptr @__Wpedantic_format_voidptr(ptr noundef %168)
  %170 = load ptr, ptr %3, align 8, !tbaa !5
  %171 = getelementptr inbounds %struct.MDBX_env, ptr %170, i32 0, i32 21
  %172 = load i32, ptr %171, align 8, !tbaa !20
  %173 = zext i32 %172 to i64
  %174 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %175 = load i32, ptr @rthc_limit, align 4, !tbaa !14
  %176 = load i32, ptr %4, align 4, !tbaa !14
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.rthc_register, i32 noundef 367, ptr noundef @.str.27, ptr noundef %169, i64 noundef %173, i32 noundef %174, i32 noundef %175, i32 noundef %176)
  br label %177

177:                                              ; preds = %167, %157
  br label %178

178:                                              ; preds = %177
  br label %179

179:                                              ; preds = %178
  %180 = load i32, ptr %4, align 4, !tbaa !14
  store i32 %180, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %181

181:                                              ; preds = %179, %99, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  %182 = load i32, ptr %2, align 4
  ret i32 %182
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #5

; 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) #6

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @thread_key_create(ptr 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 allocsize(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 #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(1) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 26}
!10 = !{!"libmdbx_globals", !7, i64 0, !11, i64 16, !11, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !12, i64 27, !11, i64 28, !7, i64 32, !7, i64 40, !13, i64 80, !6, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"rthc_entry", !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !11, i64 144}
!21 = !{!"MDBX_env", !7, i64 0, !11, i64 4, !11, i64 8, !22, i64 16, !11, i64 56, !11, i64 60, !22, i64 64, !6, i64 104, !23, i64 112, !23, i64 114, !23, i64 116, !23, i64 118, !23, i64 120, !23, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !23, i64 130, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !24, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !11, i64 224, !11, i64 228, !11, i64 232, !6, i64 240, !6, i64 248, !13, i64 256, !25, i64 264, !27, i64 320, !12, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !28, i64 392, !7, i64 400, !11, i64 440, !11, i64 444, !6, i64 448, !29, i64 456, !7, i64 496, !7, i64 536}
!22 = !{!"osal_mmap", !7, i64 0, !11, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!23 = !{!"short", !7, i64 0}
!24 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!25 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !13, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !11, i64 28, !11, i64 32, !12, i64 36, !12, i64 37, !12, i64 38, !26, i64 40, !7, i64 48}
!26 = !{!"", !23, i64 0, !23, i64 2, !23, i64 4, !23, i64 6}
!27 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!28 = !{!"", !13, i64 0}
!29 = !{!"osal_ioring", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!30 = !{!21, !11, i64 4}


; 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 }
%struct.rthc_entry = type { ptr }

@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
@__func__.rthc_register = external hidden unnamed_addr constant [14 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [41 x i8], align 1
@rthc_limit = external hidden local_unnamed_addr global i32, align 4
@rthc_table_static = external hidden global [1 x %struct.rthc_entry], align 8
@.str.26 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [57 x i8], align 1

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

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @rthc_register(ptr noundef %0) local_unnamed_addr #2 {
  %2 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !5
  %3 = icmp ugt i8 %2, 5
  br i1 %3, label %4, label %8, !prof !13

4:                                                ; preds = %1
  %5 = tail call ptr @__Wpedantic_format_voidptr(ptr noundef %0)
  %6 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %7 = load i32, ptr @rthc_limit, align 4, !tbaa !14
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.rthc_register, i32 noundef 331, ptr noundef nonnull @.str.25, ptr noundef %5, i32 noundef %6, i32 noundef %7) #5
  br label %8

8:                                                ; preds = %1, %4
  %9 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %10 = zext i32 %9 to i64
  %.not39 = icmp eq i32 %9, 0
  br i1 %.not39, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %11 = load ptr, ptr @rthc_table, align 8, !tbaa !15
  br label %14

12:                                               ; preds = %14
  %13 = add nuw nsw i64 %.02338, 1
  %exitcond.not = icmp eq i64 %13, %10
  br i1 %exitcond.not, label %._crit_edge, label %14, !llvm.loop !16

14:                                               ; preds = %.lr.ph, %12
  %.02338 = phi i64 [ 0, %.lr.ph ], [ %13, %12 ]
  %15 = getelementptr inbounds %struct.rthc_entry, ptr %11, i64 %.02338
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = icmp eq ptr %16, %0
  br i1 %17, label %.loopexit, label %12, !prof !13

._crit_edge:                                      ; preds = %12, %8
  %18 = getelementptr inbounds i8, ptr %0, i64 144
  store i32 0, ptr %18, align 8, !tbaa !20
  %19 = load i32, ptr @rthc_limit, align 4, !tbaa !14
  %20 = icmp eq i32 %9, %19
  br i1 %20, label %21, label %35, !prof !13

21:                                               ; preds = %._crit_edge
  %22 = load ptr, ptr @rthc_table, align 8
  %23 = icmp eq ptr %22, @rthc_table_static
  %24 = select i1 %23, ptr null, ptr %22
  %25 = shl nuw nsw i64 %10, 4
  %26 = tail call ptr @realloc(ptr noundef %24, i64 noundef %25) #6
  %27 = icmp eq ptr %26, null
  br i1 %27, label %.loopexit, label %28, !prof !13

28:                                               ; preds = %21
  %29 = load ptr, ptr @rthc_table, align 8, !tbaa !15
  %30 = icmp eq ptr %29, @rthc_table_static
  %.pre = load i32, ptr @rthc_limit, align 4, !tbaa !14
  br i1 %30, label %31, label %.thread34

31:                                               ; preds = %28
  %32 = zext i32 %.pre to i64
  %33 = shl nuw nsw i64 %32, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %26, ptr nonnull align 8 @rthc_table_static, i64 %33, i1 false)
  br label %.thread34

.thread34:                                        ; preds = %28, %31
  store ptr %26, ptr @rthc_table, align 8, !tbaa !15
  %34 = shl i32 %.pre, 1
  store i32 %34, ptr @rthc_limit, align 4, !tbaa !14
  br label %35

35:                                               ; preds = %.thread34, %._crit_edge
  %36 = getelementptr inbounds i8, ptr %0, i64 4
  %37 = load i32, ptr %36, align 4, !tbaa !30
  %38 = and i32 %37, 2097152
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %45

40:                                               ; preds = %35
  %41 = tail call i32 @thread_key_create(ptr noundef nonnull %18)
  %.not = icmp eq i32 %41, 0
  br i1 %.not, label %42, label %.loopexit, !prof !31

42:                                               ; preds = %40
  %43 = load i32, ptr %36, align 4, !tbaa !30
  %44 = or i32 %43, 268435456
  store i32 %44, ptr %36, align 4, !tbaa !30
  br label %45

45:                                               ; preds = %42, %35
  %46 = load ptr, ptr @rthc_table, align 8, !tbaa !15
  %47 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds %struct.rthc_entry, ptr %46, i64 %48
  store ptr %0, ptr %49, align 8, !tbaa !18
  %50 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !5
  %51 = icmp ugt i8 %50, 5
  br i1 %51, label %52, label %56, !prof !13

52:                                               ; preds = %45
  %53 = tail call ptr @__Wpedantic_format_voidptr(ptr noundef nonnull %0)
  %54 = load i32, ptr %18, align 8, !tbaa !20
  %55 = zext i32 %54 to i64
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.rthc_register, i32 noundef 362, ptr noundef nonnull @.str.26, i32 noundef %47, ptr noundef %53, i64 noundef %55) #5
  %.pre40 = load i32, ptr @rthc_count, align 4, !tbaa !14
  br label %56

56:                                               ; preds = %52, %45
  %57 = phi i32 [ %.pre40, %52 ], [ %47, %45 ]
  %58 = add i32 %57, 1
  store i32 %58, ptr @rthc_count, align 4, !tbaa !14
  br label %.loopexit

.loopexit:                                        ; preds = %14, %21, %56, %40
  %.4 = phi i32 [ %41, %40 ], [ 0, %56 ], [ 12, %21 ], [ -30795, %14 ]
  %59 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !5
  %60 = icmp ugt i8 %59, 5
  br i1 %60, label %61, label %68, !prof !13

61:                                               ; preds = %.loopexit
  %62 = tail call ptr @__Wpedantic_format_voidptr(ptr noundef %0)
  %63 = getelementptr inbounds i8, ptr %0, i64 144
  %64 = load i32, ptr %63, align 8, !tbaa !20
  %65 = zext i32 %64 to i64
  %66 = load i32, ptr @rthc_count, align 4, !tbaa !14
  %67 = load i32, ptr @rthc_limit, align 4, !tbaa !14
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.rthc_register, i32 noundef 367, ptr noundef nonnull @.str.27, ptr noundef %62, i64 noundef %65, i32 noundef %66, i32 noundef %67, i32 noundef %.4) #5
  br label %68

68:                                               ; preds = %.loopexit, %61
  ret i32 %.4
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress 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: inlinehint nounwind uwtable
declare hidden i32 @thread_key_create(ptr noundef) local_unnamed_addr #1

attributes #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 #1 = { 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 #2 = { 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 #3 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 26}
!6 = !{!"libmdbx_globals", !7, i64 0, !9, i64 16, !9, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !10, i64 27, !9, i64 28, !7, i64 32, !7, i64 40, !11, i64 80, !12, i64 88}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!14 = !{!9, !9, i64 0}
!15 = !{!12, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !12, i64 0}
!19 = !{!"rthc_entry", !12, i64 0}
!20 = !{!21, !9, i64 144}
!21 = !{!"MDBX_env", !7, i64 0, !9, i64 4, !9, i64 8, !22, i64 16, !9, i64 56, !9, i64 60, !22, i64 64, !12, i64 104, !23, i64 112, !23, i64 114, !23, i64 116, !23, i64 118, !23, i64 120, !23, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !23, i64 130, !9, i64 132, !9, i64 136, !9, i64 140, !9, i64 144, !24, i64 152, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !12, i64 216, !9, i64 224, !9, i64 228, !9, i64 232, !12, i64 240, !12, i64 248, !11, i64 256, !25, i64 264, !27, i64 320, !10, i64 360, !12, i64 368, !12, i64 376, !12, i64 384, !28, i64 392, !7, i64 400, !9, i64 440, !9, i64 444, !12, i64 448, !29, i64 456, !7, i64 496, !7, i64 536}
!22 = !{!"osal_mmap", !7, i64 0, !9, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!23 = !{!"short", !7, i64 0}
!24 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!25 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !11, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !9, i64 28, !9, i64 32, !10, i64 36, !10, i64 37, !10, i64 38, !26, i64 40, !7, i64 48}
!26 = !{!"", !23, i64 0, !23, i64 2, !23, i64 4, !23, i64 6}
!27 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!28 = !{!"", !11, i64 0}
!29 = !{!"osal_ioring", !9, i64 0, !9, i64 4, !9, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!30 = !{!21, !9, i64 4}
!31 = !{!"branch_weights", !"expected", i32 2000, i32 1}


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