; LLVM IR from erthink/libmdbx :: src (api-extra)

; 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.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 }
%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 }
%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] }

@globals = external global %struct.libmdbx_globals, align 8
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1
@__func__.mdbx_thread_unregister = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [38 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: inlinehint nounwind uwtable
declare hidden i32 @check_env(ptr noundef, i1 noundef zeroext) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @log_if_error(i32 noundef, ptr noundef, i32 noundef) #1

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

; 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 @thread_rthc_get(i32 noundef) #1

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_thread_unregister(ptr noundef %0) #4 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call i32 @check_env(ptr noundef %7, i1 noundef zeroext true)
  store i32 %8, ptr %4, align 4, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp ne i32 %9, 0
  %11 = xor i1 %10, true
  %12 = xor i1 %11, true
  %13 = zext i1 %12 to i32
  %14 = sext i32 %13 to i64
  %15 = call i64 @llvm.expect.i64(i64 %14, i64 0)
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %1
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = call i32 @log_if_error(i32 noundef %18, ptr noundef @__func__.mdbx_thread_unregister, i32 noundef 104)
  store i32 %19, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %244

20:                                               ; preds = %1
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MDBX_env, ptr %21, i32 0, i32 6
  %23 = getelementptr inbounds %struct.osal_mmap, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = icmp ne ptr %24, null
  %26 = xor i1 %25, true
  %27 = xor i1 %26, true
  %28 = xor i1 %27, true
  %29 = zext i1 %28 to i32
  %30 = sext i32 %29 to i64
  %31 = call i64 @llvm.expect.i64(i64 %30, i64 0)
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %20
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %244

34:                                               ; preds = %20
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.MDBX_env, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !12
  %38 = and i32 %37, 268435456
  %39 = icmp eq i32 %38, 0
  %40 = xor i1 %39, true
  %41 = xor i1 %40, true
  %42 = zext i1 %41 to i32
  %43 = sext i32 %42 to i64
  %44 = call i64 @llvm.expect.i64(i64 %43, i64 0)
  %45 = icmp ne i64 %44, 0
  br i1 %45, label %46, label %80

46:                                               ; preds = %34
  br label %47

47:                                               ; preds = %46
  %48 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !24
  %49 = zext i8 %48 to i32
  %50 = and i32 %49, 1
  %51 = icmp ne i32 %50, 0
  %52 = xor i1 %51, true
  %53 = xor i1 %52, true
  %54 = zext i1 %53 to i32
  %55 = sext i32 %54 to i64
  %56 = call i64 @llvm.expect.i64(i64 %55, i64 1)
  %57 = icmp ne i64 %56, 0
  br i1 %57, label %58, label %77

58:                                               ; preds = %47
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MDBX_env, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 4, !tbaa !12
  %63 = and i32 %62, 2097152
  %64 = icmp ne i32 %63, 0
  %65 = xor i1 %64, true
  %66 = xor i1 %65, true
  %67 = xor i1 %66, true
  %68 = zext i1 %67 to i32
  %69 = sext i32 %68 to i64
  %70 = call i64 @llvm.expect.i64(i64 %69, i64 0)
  %71 = icmp ne i64 %70, 0
  br i1 %71, label %72, label %74

72:                                               ; preds = %59
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %73, ptr noundef @.str.1, ptr noundef @__func__.mdbx_thread_unregister, i32 noundef 110) #8
  unreachable

74:                                               ; preds = %59
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76, %47
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %244

80:                                               ; preds = %34
  br label %81

81:                                               ; preds = %80
  %82 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !24
  %83 = zext i8 %82 to i32
  %84 = and i32 %83, 1
  %85 = icmp ne i32 %84, 0
  %86 = xor i1 %85, true
  %87 = xor i1 %86, true
  %88 = zext i1 %87 to i32
  %89 = sext i32 %88 to i64
  %90 = call i64 @llvm.expect.i64(i64 %89, i64 1)
  %91 = icmp ne i64 %90, 0
  br i1 %91, label %92, label %111

92:                                               ; preds = %81
  br label %93

93:                                               ; preds = %92
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.MDBX_env, ptr %94, i32 0, i32 1
  %96 = load i32, ptr %95, align 4, !tbaa !12
  %97 = and i32 %96, 270532608
  %98 = icmp eq i32 %97, 268435456
  %99 = xor i1 %98, true
  %100 = xor i1 %99, true
  %101 = xor i1 %100, true
  %102 = zext i1 %101 to i32
  %103 = sext i32 %102 to i64
  %104 = call i64 @llvm.expect.i64(i64 %103, i64 0)
  %105 = icmp ne i64 %104, 0
  br i1 %105, label %106, label %108

106:                                              ; preds = %93
  %107 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %107, ptr noundef @.str.2, ptr noundef @__func__.mdbx_thread_unregister, i32 noundef 114) #8
  unreachable

108:                                              ; preds = %93
  br label %109

109:                                              ; preds = %108
  br label %110

110:                                              ; preds = %109
  br label %111

111:                                              ; preds = %110, %81
  br label %112

112:                                              ; preds = %111
  br label %113

113:                                              ; preds = %112
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %114 = load ptr, ptr %3, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.MDBX_env, ptr %114, i32 0, i32 21
  %116 = load i32, ptr %115, align 8, !tbaa !26
  %117 = call ptr @thread_rthc_get(i32 noundef %116)
  store ptr %117, ptr %6, align 8, !tbaa !5
  %118 = load ptr, ptr %6, align 8, !tbaa !5
  %119 = icmp eq ptr %118, null
  %120 = xor i1 %119, true
  %121 = xor i1 %120, true
  %122 = zext i1 %121 to i32
  %123 = sext i32 %122 to i64
  %124 = call i64 @llvm.expect.i64(i64 %123, i64 0)
  %125 = icmp ne i64 %124, 0
  br i1 %125, label %126, label %127

126:                                              ; preds = %113
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %243

127:                                              ; preds = %113
  br label %128

128:                                              ; preds = %127
  %129 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !24
  %130 = zext i8 %129 to i32
  %131 = and i32 %130, 1
  %132 = icmp ne i32 %131, 0
  %133 = xor i1 %132, true
  %134 = xor i1 %133, true
  %135 = zext i1 %134 to i32
  %136 = sext i32 %135 to i64
  %137 = call i64 @llvm.expect.i64(i64 %136, i64 1)
  %138 = icmp ne i64 %137, 0
  br i1 %138, label %139, label %160

139:                                              ; preds = %128
  br label %140

140:                                              ; preds = %139
  %141 = load ptr, ptr %6, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.reader_slot, ptr %141, i32 0, i32 2
  %143 = load volatile i32, ptr %142, align 8, !tbaa !11
  %144 = load ptr, ptr %3, align 8, !tbaa !5
  %145 = getelementptr inbounds %struct.MDBX_env, ptr %144, i32 0, i32 20
  %146 = load i32, ptr %145, align 4, !tbaa !27
  %147 = icmp eq i32 %143, %146
  %148 = xor i1 %147, true
  %149 = xor i1 %148, true
  %150 = xor i1 %149, true
  %151 = zext i1 %150 to i32
  %152 = sext i32 %151 to i64
  %153 = call i64 @llvm.expect.i64(i64 %152, i64 0)
  %154 = icmp ne i64 %153, 0
  br i1 %154, label %155, label %157

155:                                              ; preds = %140
  %156 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %156, ptr noundef @.str.3, ptr noundef @__func__.mdbx_thread_unregister, i32 noundef 119) #8
  unreachable

157:                                              ; preds = %140
  br label %158

158:                                              ; preds = %157
  br label %159

159:                                              ; preds = %158
  br label %160

160:                                              ; preds = %159, %128
  br label %161

161:                                              ; preds = %160
  br label %162

162:                                              ; preds = %161
  %163 = load ptr, ptr %6, align 8, !tbaa !5
  %164 = getelementptr inbounds %struct.reader_slot, ptr %163, i32 0, i32 2
  %165 = load volatile i32, ptr %164, align 8, !tbaa !11
  %166 = load ptr, ptr %3, align 8, !tbaa !5
  %167 = getelementptr inbounds %struct.MDBX_env, ptr %166, i32 0, i32 20
  %168 = load i32, ptr %167, align 4, !tbaa !27
  %169 = icmp ne i32 %165, %168
  br i1 %169, label %176, label %170

170:                                              ; preds = %162
  %171 = load ptr, ptr %6, align 8, !tbaa !5
  %172 = getelementptr inbounds %struct.reader_slot, ptr %171, i32 0, i32 1
  %173 = load volatile i64, ptr %172, align 8, !tbaa !11
  %174 = call i64 @osal_thread_self()
  %175 = icmp ne i64 %173, %174
  br label %176

176:                                              ; preds = %170, %162
  %177 = phi i1 [ true, %162 ], [ %175, %170 ]
  %178 = xor i1 %177, true
  %179 = xor i1 %178, true
  %180 = zext i1 %179 to i32
  %181 = sext i32 %180 to i64
  %182 = call i64 @llvm.expect.i64(i64 %181, i64 0)
  %183 = icmp ne i64 %182, 0
  br i1 %183, label %184, label %186

184:                                              ; preds = %176
  %185 = call i32 @log_if_error(i32 noundef -30783, ptr noundef @__func__.mdbx_thread_unregister, i32 noundef 121)
  store i32 %185, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %243

186:                                              ; preds = %176
  br label %187

187:                                              ; preds = %186
  %188 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !24
  %189 = zext i8 %188 to i32
  %190 = and i32 %189, 1
  %191 = icmp ne i32 %190, 0
  %192 = xor i1 %191, true
  %193 = xor i1 %192, true
  %194 = zext i1 %193 to i32
  %195 = sext i32 %194 to i64
  %196 = call i64 @llvm.expect.i64(i64 %195, i64 1)
  %197 = icmp ne i64 %196, 0
  br i1 %197, label %198, label %216

198:                                              ; preds = %187
  br label %199

199:                                              ; preds = %198
  %200 = load ptr, ptr %6, align 8, !tbaa !5
  %201 = getelementptr inbounds %struct.reader_slot, ptr %200, i32 0, i32 0
  %202 = load volatile i64, ptr %201, align 8, !tbaa !11
  %203 = icmp uge i64 %202, -4294967296
  %204 = xor i1 %203, true
  %205 = xor i1 %204, true
  %206 = xor i1 %205, true
  %207 = zext i1 %206 to i32
  %208 = sext i32 %207 to i64
  %209 = call i64 @llvm.expect.i64(i64 %208, i64 0)
  %210 = icmp ne i64 %209, 0
  br i1 %210, label %211, label %213

211:                                              ; preds = %199
  %212 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %212, ptr noundef @.str.5, ptr noundef @__func__.mdbx_thread_unregister, i32 noundef 123) #8
  unreachable

213:                                              ; preds = %199
  br label %214

214:                                              ; preds = %213
  br label %215

215:                                              ; preds = %214
  br label %216

216:                                              ; preds = %215, %187
  br label %217

217:                                              ; preds = %216
  br label %218

218:                                              ; preds = %217
  %219 = load ptr, ptr %6, align 8, !tbaa !5
  %220 = getelementptr inbounds %struct.reader_slot, ptr %219, i32 0, i32 0
  %221 = load volatile i64, ptr %220, align 8, !tbaa !11
  %222 = icmp ult i64 %221, -4294967296
  %223 = xor i1 %222, true
  %224 = xor i1 %223, true
  %225 = zext i1 %224 to i32
  %226 = sext i32 %225 to i64
  %227 = call i64 @llvm.expect.i64(i64 %226, i64 0)
  %228 = icmp ne i64 %227, 0
  br i1 %228, label %229, label %231

229:                                              ; preds = %218
  %230 = call i32 @log_if_error(i32 noundef -30778, ptr noundef @__func__.mdbx_thread_unregister, i32 noundef 125)
  store i32 %230, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %243

231:                                              ; preds = %218
  %232 = load ptr, ptr %6, align 8, !tbaa !5
  %233 = getelementptr inbounds %struct.reader_slot, ptr %232, i32 0, i32 2
  %234 = call i32 @atomic_store32(ptr noundef %233, i32 noundef 0, i32 noundef 0)
  %235 = load ptr, ptr %3, align 8, !tbaa !5
  %236 = getelementptr inbounds %struct.MDBX_env, ptr %235, i32 0, i32 7
  %237 = load ptr, ptr %236, align 8, !tbaa !28
  %238 = getelementptr inbounds %struct.shared_lck, ptr %237, i32 0, i32 21
  %239 = call i32 @atomic_store32(ptr noundef %238, i32 noundef 1, i32 noundef 1)
  %240 = load ptr, ptr %3, align 8, !tbaa !5
  %241 = getelementptr inbounds %struct.MDBX_env, ptr %240, i32 0, i32 21
  %242 = load i32, ptr %241, align 8, !tbaa !26
  call void @thread_rthc_set(i32 noundef %242, ptr noundef null)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %243

243:                                              ; preds = %231, %229, %184, %126
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  br label %244

244:                                              ; preds = %243, %79, %33, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  %245 = load i32, ptr %2, align 4
  ret i32 %245
}

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

declare void @thread_rthc_set(i32 noundef, ptr noundef) #6

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

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 4}
!13 = !{!"MDBX_env", !7, i64 0, !10, i64 4, !10, i64 8, !14, i64 16, !10, i64 56, !10, i64 60, !14, i64 64, !6, i64 104, !16, i64 112, !16, i64 114, !16, i64 116, !16, i64 118, !16, i64 120, !16, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !16, i64 130, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !17, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !10, i64 224, !10, i64 228, !10, i64 232, !6, i64 240, !6, i64 248, !15, i64 256, !18, i64 264, !21, i64 320, !19, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !22, i64 392, !7, i64 400, !10, i64 440, !10, i64 444, !6, i64 448, !23, i64 456, !7, i64 496, !7, i64 536}
!14 = !{!"osal_mmap", !7, i64 0, !10, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!18 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !15, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !10, i64 28, !10, i64 32, !19, i64 36, !19, i64 37, !19, i64 38, !20, i64 40, !7, i64 48}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!"", !16, i64 0, !16, i64 2, !16, i64 4, !16, i64 6}
!21 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!22 = !{!"", !15, i64 0}
!23 = !{!"osal_ioring", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!24 = !{!25, !7, i64 25}
!25 = !{!"libmdbx_globals", !7, i64 0, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !19, i64 27, !10, i64 28, !7, i64 32, !7, i64 40, !15, i64 80, !6, i64 88}
!26 = !{!13, !10, i64 144}
!27 = !{!13, !10, i64 140}
!28 = !{!13, !6, i64 104}


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

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1
@__func__.mdbx_thread_unregister = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_env(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @log_if_error(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @thread_rthc_get(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_thread_unregister(ptr noundef %0) local_unnamed_addr #2 {
  %2 = tail call i32 @check_env(ptr noundef %0, i1 noundef zeroext true)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %5, label %3, !prof !5

3:                                                ; preds = %1
  %4 = tail call i32 @log_if_error(i32 noundef %2, ptr noundef nonnull @__func__.mdbx_thread_unregister, i32 noundef 104)
  br label %63

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = load ptr, ptr %6, align 8, !tbaa !6
  %.not25 = icmp eq ptr %7, null
  br i1 %.not25, label %63, label %8, !prof !9

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !10
  %11 = and i32 %10, 268435456
  %12 = icmp eq i32 %11, 0
  %13 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !24
  %14 = and i8 %13, 1
  br i1 %12, label %15, label %18, !prof !9

15:                                               ; preds = %8
  %.not32 = icmp ne i8 %14, 0
  %16 = and i32 %10, 2097152
  %.not33 = icmp eq i32 %16, 0
  %or.cond = and i1 %.not33, %.not32
  br i1 %or.cond, label %17, label %63, !prof !26

17:                                               ; preds = %15
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.mdbx_thread_unregister, i32 noundef 110) #5
  unreachable

18:                                               ; preds = %8
  %.not26 = icmp eq i8 %14, 0
  %19 = and i32 %10, 270532608
  %.not27 = icmp eq i32 %19, 268435456
  %or.cond34 = or i1 %.not27, %.not26
  br i1 %or.cond34, label %21, label %20, !prof !27

20:                                               ; preds = %18
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.2, ptr noundef nonnull @__func__.mdbx_thread_unregister, i32 noundef 114) #5
  unreachable

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %0, i64 144
  %23 = load i32, ptr %22, align 8, !tbaa !28
  %24 = tail call ptr @thread_rthc_get(i32 noundef %23)
  %25 = icmp eq ptr %24, null
  br i1 %25, label %63, label %26, !prof !9

26:                                               ; preds = %21
  %27 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !24
  %28 = and i8 %27, 1
  %.not28 = icmp eq i8 %28, 0
  br i1 %.not28, label %._crit_edge, label %29, !prof !9

._crit_edge:                                      ; preds = %26
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 140
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !29
  br label %35

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %24, i64 16
  %31 = load volatile i32, ptr %30, align 8, !tbaa !6
  %32 = getelementptr inbounds i8, ptr %0, i64 140
  %33 = load i32, ptr %32, align 4, !tbaa !29
  %.not29 = icmp eq i32 %31, %33
  br i1 %.not29, label %35, label %34, !prof !5

34:                                               ; preds = %29
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.3, ptr noundef nonnull @__func__.mdbx_thread_unregister, i32 noundef 119) #5
  unreachable

35:                                               ; preds = %._crit_edge, %29
  %36 = phi i32 [ %.pre, %._crit_edge ], [ %31, %29 ]
  %37 = getelementptr inbounds i8, ptr %24, i64 16
  %38 = load volatile i32, ptr %37, align 8, !tbaa !6
  %.not30 = icmp eq i32 %38, %36
  br i1 %.not30, label %39, label %.critedge, !prof !5

39:                                               ; preds = %35
  %40 = getelementptr inbounds i8, ptr %24, i64 8
  %41 = load volatile i64, ptr %40, align 8, !tbaa !6
  %42 = tail call i64 @osal_thread_self()
  %.not35 = icmp eq i64 %41, %42
  br i1 %.not35, label %44, label %.critedge, !prof !5

.critedge:                                        ; preds = %35, %39
  %43 = tail call i32 @log_if_error(i32 noundef -30783, ptr noundef nonnull @__func__.mdbx_thread_unregister, i32 noundef 121)
  br label %63

44:                                               ; preds = %39
  %45 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !24
  %46 = and i8 %45, 1
  %.not31 = icmp eq i8 %46, 0
  br i1 %.not31, label %51, label %47, !prof !9

47:                                               ; preds = %44
  %48 = load volatile i64, ptr %24, align 8, !tbaa !6
  %49 = icmp ult i64 %48, -4294967296
  br i1 %49, label %50, label %51, !prof !9

50:                                               ; preds = %47
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.5, ptr noundef nonnull @__func__.mdbx_thread_unregister, i32 noundef 123) #5
  unreachable

51:                                               ; preds = %47, %44
  %52 = load volatile i64, ptr %24, align 8, !tbaa !6
  %53 = icmp ult i64 %52, -4294967296
  br i1 %53, label %54, label %56, !prof !9

54:                                               ; preds = %51
  %55 = tail call i32 @log_if_error(i32 noundef -30778, ptr noundef nonnull @__func__.mdbx_thread_unregister, i32 noundef 125)
  br label %63

56:                                               ; preds = %51
  %57 = tail call i32 @atomic_store32(ptr noundef nonnull %37, i32 noundef 0, i32 noundef 0)
  %58 = getelementptr inbounds i8, ptr %0, i64 104
  %59 = load ptr, ptr %58, align 8, !tbaa !30
  %60 = getelementptr inbounds i8, ptr %59, i64 492
  %61 = tail call i32 @atomic_store32(ptr noundef nonnull %60, i32 noundef 1, i32 noundef 1)
  %62 = load i32, ptr %22, align 8, !tbaa !28
  tail call void @thread_rthc_set(i32 noundef %62, ptr noundef null) #6
  br label %63

63:                                               ; preds = %.critedge, %54, %56, %21, %15, %5, %3
  %.1 = phi i32 [ %4, %3 ], [ -1, %5 ], [ -1, %15 ], [ %43, %.critedge ], [ %55, %54 ], [ 0, %56 ], [ -1, %21 ]
  ret i32 %.1
}

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

declare void @thread_rthc_set(i32 noundef, ptr noundef) local_unnamed_addr #4

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


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass