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

; 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 }
%struct.anon = 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.1, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.2, %struct.anon.6, i8, ptr, ptr, ptr, %struct.anon.7, %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.1 = type { ptr, ptr, ptr, ptr }
%struct.anon.2 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.3, %union.anon.4 }
%struct.anon.3 = type { i16, i16, i16, i16 }
%union.anon.4 = type { i32 }
%struct.anon.6 = type { i64, i64, i64, i64, i64 }
%struct.anon.7 = 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.10, %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.8 }
%struct.anon.8 = 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.9 }
%struct.anon.9 = type { i64, i64, i32 }
%struct.anon.10 = 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 }

@globals = external global %struct.libmdbx_globals, align 8
@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@__func__.update_mlcnt = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [7 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: nounwind willreturn memory(read) uwtable
declare dso_local i32 @pgno_align2os_pgno(ptr noundef, i64 noundef) #3

; Function Attrs: cold nounwind optsize uwtable
define dso_local void @update_mlcnt(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %2) #4 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %12 = zext i1 %2 to i8
  store i8 %12, ptr %6, align 1, !tbaa !11
  br label %13

13:                                               ; preds = %279, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MDBX_env, ptr %14, i32 0, i32 14
  %16 = call i32 @atomic_load32(ptr noundef %15, i32 noundef 1)
  store i32 %16, ptr %7, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %13
  %18 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !13
  %19 = zext i8 %18 to i32
  %20 = and i32 %19, 1
  %21 = icmp ne i32 %20, 0
  %22 = xor i1 %21, true
  %23 = xor i1 %22, true
  %24 = zext i1 %23 to i32
  %25 = sext i32 %24 to i64
  %26 = call i64 @llvm.expect.i64(i64 %25, i64 1)
  %27 = icmp ne i64 %26, 0
  br i1 %27, label %28, label %48

28:                                               ; preds = %17
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = call i32 @pgno_align2os_pgno(ptr noundef %30, i64 noundef %32) #8
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = icmp eq i32 %33, %34
  %36 = xor i1 %35, true
  %37 = xor i1 %36, true
  %38 = xor i1 %37, true
  %39 = zext i1 %38 to i32
  %40 = sext i32 %39 to i64
  %41 = call i64 @llvm.expect.i64(i64 %40, i64 0)
  %42 = icmp ne i64 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %29
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %44, ptr noundef @.str.1, ptr noundef @__func__.update_mlcnt, i32 noundef 230) #9
  unreachable

45:                                               ; preds = %29
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47, %17
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  br label %51

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

62:                                               ; preds = %51
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = zext i32 %65 to i64
  %67 = call i32 @pgno_align2os_pgno(ptr noundef %64, i64 noundef %66) #8
  %68 = load i32, ptr %5, align 4, !tbaa !9
  %69 = icmp eq i32 %67, %68
  %70 = xor i1 %69, true
  %71 = xor i1 %70, true
  %72 = xor i1 %71, true
  %73 = zext i1 %72 to i32
  %74 = sext i32 %73 to i64
  %75 = call i64 @llvm.expect.i64(i64 %74, i64 0)
  %76 = icmp ne i64 %75, 0
  br i1 %76, label %77, label %79

77:                                               ; preds = %63
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %78, ptr noundef @.str.2, ptr noundef @__func__.update_mlcnt, i32 noundef 231) #9
  unreachable

79:                                               ; preds = %63
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81, %51
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  %85 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %86 = trunc i8 %85 to i1
  br i1 %86, label %87, label %91

87:                                               ; preds = %84
  %88 = load i32, ptr %7, align 4, !tbaa !9
  %89 = load i32, ptr %5, align 4, !tbaa !9
  %90 = icmp uge i32 %88, %89
  br i1 %90, label %95, label %96

91:                                               ; preds = %84
  %92 = load i32, ptr %7, align 4, !tbaa !9
  %93 = load i32, ptr %5, align 4, !tbaa !9
  %94 = icmp ule i32 %92, %93
  br i1 %94, label %95, label %96

95:                                               ; preds = %91, %87
  store i32 2, ptr %8, align 4
  br label %277

96:                                               ; preds = %91, %87
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.MDBX_env, ptr %97, i32 0, i32 14
  %99 = load i32, ptr %7, align 4, !tbaa !9
  %100 = load i32, ptr %5, align 4, !tbaa !9
  %101 = call zeroext i1 @atomic_cas32(ptr noundef %98, i32 noundef %99, i32 noundef %100)
  %102 = xor i1 %101, true
  %103 = xor i1 %102, true
  %104 = zext i1 %103 to i32
  %105 = sext i32 %104 to i64
  %106 = call i64 @llvm.expect.i64(i64 %105, i64 1)
  %107 = icmp ne i64 %106, 0
  br i1 %107, label %108, label %276

108:                                              ; preds = %96
  br label %109

109:                                              ; preds = %274, %108
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %110 = load ptr, ptr %4, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.MDBX_env, ptr %110, i32 0, i32 7
  %112 = load ptr, ptr %111, align 8, !tbaa !18
  %113 = getelementptr inbounds %struct.shared_lck, ptr %112, i32 0, i32 7
  %114 = getelementptr inbounds [2 x %union.mdbx_atomic_uint32_t], ptr %113, i64 0, i64 0
  store ptr %114, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %115 = load ptr, ptr %9, align 8, !tbaa !5
  %116 = getelementptr inbounds %union.mdbx_atomic_uint32_t, ptr %115, i64 0
  %117 = call i32 @atomic_load32(ptr noundef %116, i32 noundef 0)
  store i32 %117, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  %118 = load ptr, ptr %9, align 8, !tbaa !5
  %119 = getelementptr inbounds %union.mdbx_atomic_uint32_t, ptr %118, i64 1
  %120 = call i32 @atomic_load32(ptr noundef %119, i32 noundef 0)
  store i32 %120, ptr %11, align 4, !tbaa !9
  %121 = load i32, ptr %7, align 4, !tbaa !9
  %122 = icmp eq i32 %121, 0
  br i1 %122, label %123, label %174

123:                                              ; preds = %109
  %124 = load i32, ptr %10, align 4, !tbaa !9
  %125 = load i32, ptr %11, align 4, !tbaa !9
  %126 = sub nsw i32 %124, %125
  %127 = icmp slt i32 %126, 2147483647
  br i1 %127, label %128, label %174

128:                                              ; preds = %123
  br label %129

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

140:                                              ; preds = %129
  br label %141

141:                                              ; preds = %140
  %142 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %143 = trunc i8 %142 to i1
  %144 = xor i1 %143, true
  %145 = xor i1 %144, true
  %146 = xor i1 %145, true
  %147 = zext i1 %146 to i32
  %148 = sext i32 %147 to i64
  %149 = call i64 @llvm.expect.i64(i64 %148, i64 0)
  %150 = icmp ne i64 %149, 0
  br i1 %150, label %151, label %153

151:                                              ; preds = %141
  %152 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %152, ptr noundef @.str.3, ptr noundef @__func__.update_mlcnt, i32 noundef 241) #9
  unreachable

153:                                              ; preds = %141
  br label %154

154:                                              ; preds = %153
  br label %155

155:                                              ; preds = %154
  br label %156

156:                                              ; preds = %155, %129
  br label %157

157:                                              ; preds = %156
  br label %158

158:                                              ; preds = %157
  %159 = load ptr, ptr %9, align 8, !tbaa !5
  %160 = getelementptr inbounds %union.mdbx_atomic_uint32_t, ptr %159, i64 0
  %161 = load i32, ptr %10, align 4, !tbaa !9
  %162 = load i32, ptr %10, align 4, !tbaa !9
  %163 = add nsw i32 %162, 1
  %164 = call zeroext i1 @atomic_cas32(ptr noundef %160, i32 noundef %161, i32 noundef %163)
  %165 = xor i1 %164, true
  %166 = xor i1 %165, true
  %167 = xor i1 %166, true
  %168 = zext i1 %167 to i32
  %169 = sext i32 %168 to i64
  %170 = call i64 @llvm.expect.i64(i64 %169, i64 0)
  %171 = icmp ne i64 %170, 0
  br i1 %171, label %172, label %173

172:                                              ; preds = %158
  store i32 13, ptr %8, align 4
  br label %274

173:                                              ; preds = %158
  br label %174

174:                                              ; preds = %173, %123, %109
  %175 = load i32, ptr %5, align 4, !tbaa !9
  %176 = icmp eq i32 %175, 0
  br i1 %176, label %177, label %229

177:                                              ; preds = %174
  %178 = load i32, ptr %10, align 4, !tbaa !9
  %179 = load i32, ptr %11, align 4, !tbaa !9
  %180 = sub nsw i32 %178, %179
  %181 = icmp sgt i32 %180, 0
  br i1 %181, label %182, label %229

182:                                              ; preds = %177
  br label %183

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

194:                                              ; preds = %183
  br label %195

195:                                              ; preds = %194
  %196 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %197 = trunc i8 %196 to i1
  %198 = xor i1 %197, true
  %199 = xor i1 %198, true
  %200 = xor i1 %199, true
  %201 = xor i1 %200, true
  %202 = zext i1 %201 to i32
  %203 = sext i32 %202 to i64
  %204 = call i64 @llvm.expect.i64(i64 %203, i64 0)
  %205 = icmp ne i64 %204, 0
  br i1 %205, label %206, label %208

206:                                              ; preds = %195
  %207 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %207, ptr noundef @.str.4, ptr noundef @__func__.update_mlcnt, i32 noundef 246) #9
  unreachable

208:                                              ; preds = %195
  br label %209

209:                                              ; preds = %208
  br label %210

210:                                              ; preds = %209
  br label %211

211:                                              ; preds = %210, %183
  br label %212

212:                                              ; preds = %211
  br label %213

213:                                              ; preds = %212
  %214 = load ptr, ptr %9, align 8, !tbaa !5
  %215 = getelementptr inbounds %union.mdbx_atomic_uint32_t, ptr %214, i64 1
  %216 = load i32, ptr %11, align 4, !tbaa !9
  %217 = load i32, ptr %11, align 4, !tbaa !9
  %218 = add nsw i32 %217, 1
  %219 = call zeroext i1 @atomic_cas32(ptr noundef %215, i32 noundef %216, i32 noundef %218)
  %220 = xor i1 %219, true
  %221 = xor i1 %220, true
  %222 = xor i1 %221, true
  %223 = zext i1 %222 to i32
  %224 = sext i32 %223 to i64
  %225 = call i64 @llvm.expect.i64(i64 %224, i64 0)
  %226 = icmp ne i64 %225, 0
  br i1 %226, label %227, label %228

227:                                              ; preds = %213
  store i32 13, ptr %8, align 4
  br label %274

228:                                              ; preds = %213
  br label %229

229:                                              ; preds = %228, %177, %174
  br label %230

230:                                              ; preds = %229
  %231 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !28
  %232 = zext i8 %231 to i32
  %233 = icmp sle i32 3, %232
  %234 = xor i1 %233, true
  %235 = xor i1 %234, true
  %236 = zext i1 %235 to i32
  %237 = sext i32 %236 to i64
  %238 = call i64 @llvm.expect.i64(i64 %237, i64 0)
  %239 = icmp ne i64 %238, 0
  br i1 %239, label %240, label %271

240:                                              ; preds = %230
  %241 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %242 = trunc i8 %241 to i1
  %243 = zext i1 %242 to i64
  %244 = select i1 %242, ptr @.str.6, ptr @.str.7
  %245 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %246 = trunc i8 %245 to i1
  br i1 %246, label %247, label %249

247:                                              ; preds = %240
  %248 = load i32, ptr %7, align 4, !tbaa !9
  br label %251

249:                                              ; preds = %240
  %250 = load i32, ptr %5, align 4, !tbaa !9
  br label %251

251:                                              ; preds = %249, %247
  %252 = phi i32 [ %248, %247 ], [ %250, %249 ]
  %253 = load i8, ptr %6, align 1, !tbaa !11, !range !16, !noundef !17
  %254 = trunc i8 %253 to i1
  br i1 %254, label %255, label %257

255:                                              ; preds = %251
  %256 = load i32, ptr %5, align 4, !tbaa !9
  br label %259

257:                                              ; preds = %251
  %258 = load i32, ptr %7, align 4, !tbaa !9
  br label %259

259:                                              ; preds = %257, %255
  %260 = phi i32 [ %256, %255 ], [ %258, %257 ]
  %261 = load i32, ptr %10, align 4, !tbaa !9
  %262 = load i32, ptr %11, align 4, !tbaa !9
  %263 = sub nsw i32 %261, %262
  %264 = load ptr, ptr %9, align 8, !tbaa !5
  %265 = getelementptr inbounds %union.mdbx_atomic_uint32_t, ptr %264, i64 0
  %266 = call i32 @atomic_load32(ptr noundef %265, i32 noundef 0)
  %267 = load ptr, ptr %9, align 8, !tbaa !5
  %268 = getelementptr inbounds %union.mdbx_atomic_uint32_t, ptr %267, i64 1
  %269 = call i32 @atomic_load32(ptr noundef %268, i32 noundef 0)
  %270 = sub i32 %266, %269
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 3, ptr noundef @__func__.update_mlcnt, i32 noundef 253, ptr noundef @.str.5, ptr noundef %244, i32 noundef %252, i32 noundef %260, i32 noundef %263, i32 noundef %270)
  br label %271

271:                                              ; preds = %259, %230
  br label %272

272:                                              ; preds = %271
  br label %273

273:                                              ; preds = %272
  store i32 1, ptr %8, align 4
  br label %274

274:                                              ; preds = %273, %227, %172
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  %275 = load i32, ptr %8, align 4
  switch i32 %275, label %277 [
    i32 13, label %109
  ]

276:                                              ; preds = %96
  store i32 0, ptr %8, align 4
  br label %277

277:                                              ; preds = %276, %274, %95
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  %278 = load i32, ptr %8, align 4
  switch i32 %278, label %281 [
    i32 0, label %279
    i32 2, label %280
    i32 1, label %280
  ]

279:                                              ; preds = %277
  br label %13

280:                                              ; preds = %277, %277
  ret void

281:                                              ; preds = %277
  unreachable
}

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

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

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

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 = { nounwind willreturn memory(read) 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 = { 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 = { 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 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { 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 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !7, i64 25}
!14 = !{!"libmdbx_globals", !7, i64 0, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !12, i64 27, !10, i64 28, !7, i64 32, !7, i64 40, !15, i64 80, !6, i64 88}
!15 = !{!"long", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!19, !6, i64 104}
!19 = !{!"MDBX_env", !7, i64 0, !10, i64 4, !10, i64 8, !20, i64 16, !10, i64 56, !10, i64 60, !20, i64 64, !6, i64 104, !21, i64 112, !21, i64 114, !21, i64 116, !21, i64 118, !21, i64 120, !21, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !21, i64 130, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !22, 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, !23, i64 264, !25, i64 320, !12, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !26, i64 392, !7, i64 400, !10, i64 440, !10, i64 444, !6, i64 448, !27, i64 456, !7, i64 496, !7, i64 536}
!20 = !{!"osal_mmap", !7, i64 0, !10, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!21 = !{!"short", !7, i64 0}
!22 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!23 = !{!"", !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, !12, i64 36, !12, i64 37, !12, i64 38, !24, i64 40, !7, i64 48}
!24 = !{!"", !21, i64 0, !21, i64 2, !21, i64 4, !21, i64 6}
!25 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!26 = !{!"", !15, i64 0}
!27 = !{!"osal_ioring", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!28 = !{!14, !7, i64 26}


; 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 }
%struct.anon = 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 [64 x i8], align 1
@__func__.update_mlcnt = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(read) uwtable
declare dso_local i32 @pgno_align2os_pgno(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: cold nounwind optsize uwtable
define dso_local void @update_mlcnt(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 124
  %5 = zext i32 %1 to i64
  br label %6

6:                                                ; preds = %19, %3
  %7 = tail call i32 @atomic_load32(ptr noundef nonnull %4, i32 noundef 1)
  %8 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %9 = and i8 %8, 1
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %.thread, label %10, !prof !13

10:                                               ; preds = %6
  %11 = zext i32 %7 to i64
  %12 = tail call i32 @pgno_align2os_pgno(ptr noundef %0, i64 noundef %11) #5
  %.not48 = icmp eq i32 %12, %7
  br i1 %.not48, label %14, label %13, !prof !14

13:                                               ; preds = %10
  tail call void @mdbx_assert_fail(ptr noundef %0, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.update_mlcnt, i32 noundef 230) #6
  unreachable

14:                                               ; preds = %10
  %15 = tail call i32 @pgno_align2os_pgno(ptr noundef %0, i64 noundef %5) #5
  %.not50 = icmp eq i32 %15, %1
  br i1 %.not50, label %.thread, label %16, !prof !14

16:                                               ; preds = %14
  tail call void @mdbx_assert_fail(ptr noundef %0, ptr noundef nonnull @.str.2, ptr noundef nonnull @__func__.update_mlcnt, i32 noundef 231) #6
  unreachable

.thread:                                          ; preds = %6, %14
  br i1 %2, label %17, label %18

17:                                               ; preds = %.thread
  %.not52 = icmp ult i32 %7, %1
  br i1 %.not52, label %19, label %.thread59

18:                                               ; preds = %.thread
  %.not51 = icmp ugt i32 %7, %1
  br i1 %.not51, label %19, label %.thread59

19:                                               ; preds = %18, %17
  %20 = tail call zeroext i1 @atomic_cas32(ptr noundef nonnull %4, i32 noundef %7, i32 noundef %1)
  br i1 %20, label %.preheader, label %6, !prof !14

.preheader:                                       ; preds = %19
  %21 = getelementptr inbounds i8, ptr %0, i64 104
  %22 = icmp ne i32 %7, 0
  %23 = icmp eq i32 %1, 0
  br label %24

24:                                               ; preds = %.backedge, %.preheader
  %25 = load ptr, ptr %21, align 8, !tbaa !15
  %26 = getelementptr inbounds i8, ptr %25, i64 40
  %27 = tail call i32 @atomic_load32(ptr noundef nonnull %26, i32 noundef 0)
  %28 = getelementptr inbounds i8, ptr %25, i64 44
  %29 = tail call i32 @atomic_load32(ptr noundef nonnull %28, i32 noundef 0)
  %30 = sub nsw i32 %27, %29
  %.not53 = icmp eq i32 %30, 2147483647
  %or.cond = select i1 %22, i1 true, i1 %.not53
  br i1 %or.cond, label %38, label %31

31:                                               ; preds = %24
  %32 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %33 = and i8 %32, 1
  %.not54 = icmp eq i8 %33, 0
  %brmerge = or i1 %.not54, %2
  br i1 %brmerge, label %35, label %34, !prof !25

34:                                               ; preds = %31
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.3, ptr noundef nonnull @__func__.update_mlcnt, i32 noundef 241) #6
  unreachable

35:                                               ; preds = %31
  %36 = add nsw i32 %27, 1
  %37 = tail call zeroext i1 @atomic_cas32(ptr noundef nonnull %26, i32 noundef %27, i32 noundef %36)
  br i1 %37, label %38, label %.backedge, !prof !14

38:                                               ; preds = %35, %24
  %39 = icmp sgt i32 %27, %29
  %or.cond56 = select i1 %23, i1 %39, i1 false
  br i1 %or.cond56, label %40, label %47

40:                                               ; preds = %38
  %41 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %42 = and i8 %41, 1
  %.not55 = icmp ne i8 %42, 0
  %brmerge58.not = and i1 %.not55, %2
  br i1 %brmerge58.not, label %43, label %44, !prof !26

43:                                               ; preds = %40
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.4, ptr noundef nonnull @__func__.update_mlcnt, i32 noundef 246) #6
  unreachable

44:                                               ; preds = %40
  %45 = add nsw i32 %29, 1
  %46 = tail call zeroext i1 @atomic_cas32(ptr noundef nonnull %28, i32 noundef %29, i32 noundef %45)
  br i1 %46, label %47, label %.backedge, !prof !14

.backedge:                                        ; preds = %44, %35
  br label %24

47:                                               ; preds = %38, %44
  %48 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !27
  %49 = icmp ugt i8 %48, 2
  br i1 %49, label %50, label %.thread59, !prof !13

50:                                               ; preds = %47
  %51 = select i1 %2, ptr @.str.6, ptr @.str.7
  %52 = select i1 %2, i32 %7, i32 %1
  %53 = select i1 %2, i32 %1, i32 %7
  %54 = tail call i32 @atomic_load32(ptr noundef nonnull %26, i32 noundef 0)
  %55 = tail call i32 @atomic_load32(ptr noundef nonnull %28, i32 noundef 0)
  %56 = sub i32 %54, %55
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 3, ptr noundef nonnull @__func__.update_mlcnt, i32 noundef 253, ptr noundef nonnull @.str.5, ptr noundef nonnull %51, i32 noundef %52, i32 noundef %53, i32 noundef %30, i32 noundef %56) #7
  br label %.thread59

.thread59:                                        ; preds = %18, %17, %47, %50
  ret void
}

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

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

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

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 = { mustprogress nofree nounwind willreturn memory(read) 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 = { 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 = { 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 #5 = { nounwind willreturn memory(read) }
attributes #6 = { noreturn nounwind }
attributes #7 = { nounwind }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 25}
!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 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!15 = !{!16, !12, i64 104}
!16 = !{!"MDBX_env", !7, i64 0, !9, i64 4, !9, i64 8, !17, i64 16, !9, i64 56, !9, i64 60, !17, i64 64, !12, i64 104, !18, i64 112, !18, i64 114, !18, i64 116, !18, i64 118, !18, i64 120, !18, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !18, i64 130, !9, i64 132, !9, i64 136, !9, i64 140, !9, i64 144, !19, 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, !20, i64 264, !22, i64 320, !10, i64 360, !12, i64 368, !12, i64 376, !12, i64 384, !23, i64 392, !7, i64 400, !9, i64 440, !9, i64 444, !12, i64 448, !24, i64 456, !7, i64 496, !7, i64 536}
!17 = !{!"osal_mmap", !7, i64 0, !9, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!18 = !{!"short", !7, i64 0}
!19 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!20 = !{!"", !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, !21, i64 40, !7, i64 48}
!21 = !{!"", !18, i64 0, !18, i64 2, !18, i64 4, !18, i64 6}
!22 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!23 = !{!"", !11, i64 0}
!24 = !{!"osal_ioring", !9, i64 0, !9, i64 4, !9, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!25 = !{!"branch_weights", i32 4002001, i32 2000}
!26 = !{!"branch_weights", i32 2000, i32 4002001}
!27 = !{!6, !7, i64 26}


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