; 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.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.meta_ptr = type { i64, %union.anon.11, i64 }
%union.anon.11 = 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 }
%struct.shared_lck = type { i64, i32, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, [2 x %union.mdbx_atomic_uint32_t], [16 x i8], %struct.pgops, [16 x i8], %union.pthread_mutex_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, i32, %struct.anon.8, %union.pthread_mutex_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, [16 x i8], [0 x %struct.reader_slot] }
%struct.pgops = type { %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %struct.anon.6 }
%struct.anon.6 = type { %struct.gc_prof_stat, %struct.gc_prof_stat, i32, i32, i32, i32, i32 }
%struct.gc_prof_stat = type { i64, i64, i32, i32, i32, i32, %struct.anon.7 }
%struct.anon.7 = type { i64, i64, i32 }
%struct.anon.8 = type { [4 x i32], [4 x i64] }
%struct.reader_slot = type { %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint64_t }
%struct.meta = type { [2 x i32], %union.anon.12, i16, i8, i8, %struct.geo, %union.anon.15, %struct.MDBX_canary, %union.anon.18, [2 x %union.mdbx_atomic_uint32_t], [2 x i32], %union.bin128, %union.bin128 }
%union.anon.12 = type { i64 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.13, %union.anon.14 }
%union.anon.13 = type { i32 }
%union.anon.14 = type { i32 }
%union.anon.15 = type { %struct.anon.16 }
%struct.anon.16 = type { %struct.tree, %struct.tree }
%struct.tree = type { i16, i16, i32, i32, i32, i32, i32, i64, i64, i64 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.18 = type { i64 }

@__func__.mdbx_reader_list = external hidden unnamed_addr constant [17 x i8], align 1
@globals = external global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_reader_list(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca i64, align 8
  %22 = alloca i64, align 8
  %23 = alloca %struct.troika, align 8
  %24 = alloca %struct.meta_ptr, align 8
  %25 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i32 @check_env(ptr noundef %26, i1 noundef zeroext true)
  store i32 %27, ptr %8, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  %30 = xor i1 %29, true
  %31 = xor i1 %30, true
  %32 = zext i1 %31 to i32
  %33 = sext i32 %32 to i64
  %34 = call i64 @llvm.expect.i64(i64 %33, i64 0)
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %3
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = call i32 @log_if_error(i32 noundef %37, ptr noundef @__func__.mdbx_reader_list, i32 noundef 12)
  store i32 %38, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %262

39:                                               ; preds = %3
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  %42 = xor i1 %41, true
  %43 = xor i1 %42, true
  %44 = xor i1 %43, true
  %45 = zext i1 %44 to i32
  %46 = sext i32 %45 to i64
  %47 = call i64 @llvm.expect.i64(i64 %46, i64 0)
  %48 = icmp ne i64 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %39
  %50 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_reader_list, i32 noundef 15)
  store i32 %50, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %262

51:                                               ; preds = %39
  store i32 -1, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #8
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #8
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.MDBX_env, ptr %52, i32 0, i32 6
  %54 = getelementptr inbounds %struct.osal_mmap, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  store ptr %55, ptr %11, align 8, !tbaa !5
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  %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 1)
  %63 = icmp ne i64 %62, 0
  br i1 %63, label %64, label %259

64:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #8
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.shared_lck, ptr %65, i32 0, i32 20
  %67 = call i32 @atomic_load32(ptr noundef %66, i32 noundef 1)
  %68 = zext i32 %67 to i64
  store i64 %68, ptr %12, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #8
  store i64 0, ptr %13, align 8, !tbaa !12
  br label %69

69:                                               ; preds = %254, %64
  %70 = load i64, ptr %13, align 8, !tbaa !12
  %71 = load i64, ptr %12, align 8, !tbaa !12
  %72 = icmp ult i64 %70, %71
  br i1 %72, label %74, label %73

73:                                               ; preds = %69
  store i32 2, ptr %9, align 4
  br label %257

74:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #8
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.shared_lck, ptr %75, i32 0, i32 23
  %77 = getelementptr inbounds [0 x %struct.reader_slot], ptr %76, i64 0, i64 0
  %78 = load i64, ptr %13, align 8, !tbaa !12
  %79 = getelementptr inbounds %struct.reader_slot, ptr %77, i64 %78
  store ptr %79, ptr %14, align 8, !tbaa !5
  br label %80

80:                                               ; preds = %137, %74
  %81 = load ptr, ptr %14, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.reader_slot, ptr %81, i32 0, i32 2
  %83 = call i32 @atomic_load32(ptr noundef %82, i32 noundef 1)
  store i32 %83, ptr %15, align 4, !tbaa !9
  %84 = load i32, ptr %15, align 4, !tbaa !9
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %87, label %86

86:                                               ; preds = %80
  store i32 4, ptr %9, align 4
  br label %251

87:                                               ; preds = %80
  %88 = load ptr, ptr %14, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.reader_slot, ptr %88, i32 0, i32 0
  %90 = call i64 @safe64_read(ptr noundef %89)
  store i64 %90, ptr %16, align 8, !tbaa !12
  %91 = load ptr, ptr %14, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.reader_slot, ptr %91, i32 0, i32 1
  %93 = call i64 @atomic_load64(ptr noundef %92, i32 noundef 0)
  store i64 %93, ptr %17, align 8, !tbaa !12
  %94 = load ptr, ptr %14, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.reader_slot, ptr %94, i32 0, i32 3
  %96 = call i32 @atomic_load32(ptr noundef %95, i32 noundef 0)
  store i32 %96, ptr %18, align 4, !tbaa !9
  %97 = load ptr, ptr %14, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.reader_slot, ptr %97, i32 0, i32 4
  %99 = call i64 @atomic_load64(ptr noundef %98, i32 noundef 0)
  store i64 %99, ptr %19, align 8, !tbaa !12
  %100 = load i64, ptr %16, align 8, !tbaa !12
  %101 = load ptr, ptr %14, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.reader_slot, ptr %101, i32 0, i32 0
  %103 = call i64 @safe64_read(ptr noundef %102)
  %104 = icmp ne i64 %100, %103
  br i1 %104, label %129, label %105

105:                                              ; preds = %87
  %106 = load i32, ptr %15, align 4, !tbaa !9
  %107 = load ptr, ptr %14, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.reader_slot, ptr %107, i32 0, i32 2
  %109 = call i32 @atomic_load32(ptr noundef %108, i32 noundef 1)
  %110 = icmp ne i32 %106, %109
  br i1 %110, label %129, label %111

111:                                              ; preds = %105
  %112 = load i64, ptr %17, align 8, !tbaa !12
  %113 = load ptr, ptr %14, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.reader_slot, ptr %113, i32 0, i32 1
  %115 = call i64 @atomic_load64(ptr noundef %114, i32 noundef 0)
  %116 = icmp ne i64 %112, %115
  br i1 %116, label %129, label %117

117:                                              ; preds = %111
  %118 = load i32, ptr %18, align 4, !tbaa !9
  %119 = load ptr, ptr %14, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.reader_slot, ptr %119, i32 0, i32 3
  %121 = call i32 @atomic_load32(ptr noundef %120, i32 noundef 0)
  %122 = icmp ne i32 %118, %121
  br i1 %122, label %129, label %123

123:                                              ; preds = %117
  %124 = load i64, ptr %19, align 8, !tbaa !12
  %125 = load ptr, ptr %14, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.reader_slot, ptr %125, i32 0, i32 4
  %127 = call i64 @atomic_load64(ptr noundef %126, i32 noundef 0)
  %128 = icmp ne i64 %124, %127
  br label %129

129:                                              ; preds = %123, %117, %111, %105, %87
  %130 = phi i1 [ true, %117 ], [ true, %111 ], [ true, %105 ], [ true, %87 ], [ %128, %123 ]
  %131 = xor i1 %130, true
  %132 = xor i1 %131, true
  %133 = zext i1 %132 to i32
  %134 = sext i32 %133 to i64
  %135 = call i64 @llvm.expect.i64(i64 %134, i64 0)
  %136 = icmp ne i64 %135, 0
  br i1 %136, label %137, label %138

137:                                              ; preds = %129
  br label %80

138:                                              ; preds = %129
  br label %139

139:                                              ; preds = %138
  %140 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !14
  %141 = zext i8 %140 to i32
  %142 = and i32 %141, 1
  %143 = icmp ne i32 %142, 0
  %144 = xor i1 %143, true
  %145 = xor i1 %144, true
  %146 = zext i1 %145 to i32
  %147 = sext i32 %146 to i64
  %148 = call i64 @llvm.expect.i64(i64 %147, i64 1)
  %149 = icmp ne i64 %148, 0
  br i1 %149, label %150, label %166

150:                                              ; preds = %139
  br label %151

151:                                              ; preds = %150
  %152 = load i64, ptr %16, align 8, !tbaa !12
  %153 = icmp ugt i64 %152, 0
  %154 = xor i1 %153, true
  %155 = xor i1 %154, true
  %156 = xor i1 %155, true
  %157 = zext i1 %156 to i32
  %158 = sext i32 %157 to i64
  %159 = call i64 @llvm.expect.i64(i64 %158, i64 0)
  %160 = icmp ne i64 %159, 0
  br i1 %160, label %161, label %163

161:                                              ; preds = %151
  %162 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %162, ptr noundef @.str, ptr noundef @__func__.mdbx_reader_list, i32 noundef 38) #9
  unreachable

163:                                              ; preds = %151
  br label %164

164:                                              ; preds = %163
  br label %165

165:                                              ; preds = %164
  br label %166

166:                                              ; preds = %165, %139
  br label %167

167:                                              ; preds = %166
  br label %168

168:                                              ; preds = %167
  %169 = load i64, ptr %16, align 8, !tbaa !12
  %170 = icmp uge i64 %169, -4294967296
  br i1 %170, label %171, label %172

171:                                              ; preds = %168
  store i64 0, ptr %16, align 8, !tbaa !12
  br label %172

172:                                              ; preds = %171, %168
  store i64 0, ptr %20, align 8, !tbaa !12
  store i64 0, ptr %21, align 8, !tbaa !12
  store i64 0, ptr %22, align 8, !tbaa !12
  %173 = load i64, ptr %16, align 8, !tbaa !12
  %174 = icmp ne i64 %173, 0
  br i1 %174, label %175, label %227

175:                                              ; preds = %172
  call void @llvm.lifetime.start.p0(i64 32, ptr %23) #8
  %176 = load ptr, ptr %5, align 8, !tbaa !5
  call void @meta_tap(ptr dead_on_unwind writable sret(%struct.troika) align 8 %23, ptr noundef %176)
  br label %177

177:                                              ; preds = %202, %175
  %178 = load ptr, ptr %5, align 8, !tbaa !5
  call void @meta_recent(ptr dead_on_unwind writable sret(%struct.meta_ptr) align 8 %24, ptr noundef %178, ptr noundef %23)
  %179 = getelementptr inbounds %struct.meta_ptr, ptr %24, i32 0, i32 1
  %180 = load ptr, ptr %179, align 8, !tbaa !11
  %181 = getelementptr inbounds %struct.meta, ptr %180, i32 0, i32 10
  %182 = getelementptr inbounds [2 x i32], ptr %181, i64 0, i64 0
  %183 = call i64 @unaligned_peek_u64_volatile(i64 noundef 4, ptr noundef %182)
  store i64 %183, ptr %25, align 8, !tbaa !12
  %184 = load ptr, ptr %5, align 8, !tbaa !5
  %185 = call zeroext i1 @meta_should_retry(ptr noundef %184, ptr noundef %23)
  br i1 %185, label %194, label %186

186:                                              ; preds = %177
  %187 = load i64, ptr %25, align 8, !tbaa !12
  %188 = getelementptr inbounds %struct.meta_ptr, ptr %24, i32 0, i32 1
  %189 = load ptr, ptr %188, align 8, !tbaa !11
  %190 = getelementptr inbounds %struct.meta, ptr %189, i32 0, i32 10
  %191 = getelementptr inbounds [2 x i32], ptr %190, i64 0, i64 0
  %192 = call i64 @unaligned_peek_u64_volatile(i64 noundef 4, ptr noundef %191)
  %193 = icmp ne i64 %187, %192
  br label %194

194:                                              ; preds = %186, %177
  %195 = phi i1 [ true, %177 ], [ %193, %186 ]
  %196 = xor i1 %195, true
  %197 = xor i1 %196, true
  %198 = zext i1 %197 to i32
  %199 = sext i32 %198 to i64
  %200 = call i64 @llvm.expect.i64(i64 %199, i64 0)
  %201 = icmp ne i64 %200, 0
  br i1 %201, label %202, label %203

202:                                              ; preds = %194
  br label %177

203:                                              ; preds = %194
  %204 = getelementptr inbounds %struct.meta_ptr, ptr %24, i32 0, i32 0
  %205 = load i64, ptr %204, align 8, !tbaa !17
  %206 = load i64, ptr %16, align 8, !tbaa !12
  %207 = sub i64 %205, %206
  %208 = udiv i64 %207, 1
  store i64 %208, ptr %22, align 8, !tbaa !12
  %209 = load ptr, ptr %5, align 8, !tbaa !5
  %210 = load i32, ptr %18, align 4, !tbaa !9
  %211 = zext i32 %210 to i64
  %212 = call i64 @pgno2bytes(ptr noundef %209, i64 noundef %211) #10
  store i64 %212, ptr %20, align 8, !tbaa !12
  %213 = load i64, ptr %25, align 8, !tbaa !12
  %214 = load i64, ptr %19, align 8, !tbaa !12
  %215 = icmp ugt i64 %213, %214
  br i1 %215, label %216, label %224

216:                                              ; preds = %203
  %217 = load ptr, ptr %5, align 8, !tbaa !5
  %218 = load i64, ptr %25, align 8, !tbaa !12
  %219 = load i64, ptr %19, align 8, !tbaa !12
  %220 = sub i64 %218, %219
  %221 = trunc i64 %220 to i32
  %222 = zext i32 %221 to i64
  %223 = call i64 @pgno2bytes(ptr noundef %217, i64 noundef %222) #10
  br label %225

224:                                              ; preds = %203
  br label %225

225:                                              ; preds = %224, %216
  %226 = phi i64 [ %223, %216 ], [ 0, %224 ]
  store i64 %226, ptr %21, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 32, ptr %23) #8
  br label %227

227:                                              ; preds = %225, %172
  %228 = load ptr, ptr %6, align 8, !tbaa !5
  %229 = load ptr, ptr %7, align 8, !tbaa !5
  %230 = load i32, ptr %10, align 4, !tbaa !9
  %231 = add nsw i32 %230, 1
  store i32 %231, ptr %10, align 4, !tbaa !9
  %232 = load i64, ptr %13, align 8, !tbaa !12
  %233 = trunc i64 %232 to i32
  %234 = load i32, ptr %15, align 4, !tbaa !9
  %235 = load i64, ptr %17, align 8, !tbaa !12
  %236 = load i64, ptr %16, align 8, !tbaa !12
  %237 = load i64, ptr %22, align 8, !tbaa !12
  %238 = load i64, ptr %20, align 8, !tbaa !12
  %239 = load i64, ptr %21, align 8, !tbaa !12
  %240 = call i32 %228(ptr noundef %229, i32 noundef %231, i32 noundef %233, i32 noundef %234, i64 noundef %235, i64 noundef %236, i64 noundef %237, i64 noundef %238, i64 noundef %239)
  store i32 %240, ptr %8, align 4, !tbaa !9
  %241 = load i32, ptr %8, align 4, !tbaa !9
  %242 = icmp ne i32 %241, 0
  %243 = xor i1 %242, true
  %244 = xor i1 %243, true
  %245 = zext i1 %244 to i32
  %246 = sext i32 %245 to i64
  %247 = call i64 @llvm.expect.i64(i64 %246, i64 0)
  %248 = icmp ne i64 %247, 0
  br i1 %248, label %249, label %250

249:                                              ; preds = %227
  store i32 2, ptr %9, align 4
  br label %251

250:                                              ; preds = %227
  store i32 0, ptr %9, align 4
  br label %251

251:                                              ; preds = %250, %249, %86
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #8
  %252 = load i32, ptr %9, align 4
  switch i32 %252, label %257 [
    i32 0, label %253
    i32 4, label %254
  ]

253:                                              ; preds = %251
  br label %254

254:                                              ; preds = %253, %251
  %255 = load i64, ptr %13, align 8, !tbaa !12
  %256 = add i64 %255, 1
  store i64 %256, ptr %13, align 8, !tbaa !12
  br label %69, !llvm.loop !19

257:                                              ; preds = %251, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #8
  br label %258

258:                                              ; preds = %257
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #8
  br label %259

259:                                              ; preds = %258, %51
  %260 = load i32, ptr %8, align 4, !tbaa !9
  %261 = call i32 @log_if_error(i32 noundef %260, ptr noundef @__func__.mdbx_reader_list, i32 noundef 66)
  store i32 %261, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #8
  br label %262

262:                                              ; preds = %259, %49, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  %263 = load i32, ptr %4, align 4
  ret i32 %263
}

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

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

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

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

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @safe64_read(ptr noundef) #4

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @atomic_load64(ptr noundef, i32 noundef) #4

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

declare void @meta_tap(ptr dead_on_unwind writable sret(%struct.troika) align 8, ptr noundef) #6

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @meta_recent(ptr dead_on_unwind noalias writable sret(%struct.meta_ptr) align 8, ptr noundef, ptr noundef) #2

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

declare zeroext i1 @meta_should_retry(ptr noundef, ptr noundef) #6

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden i64 @pgno2bytes(ptr noundef, i64 noundef) #7

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #4 = { 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 #5 = { noreturn "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { "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 = { inlinehint 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 #8 = { nounwind }
attributes #9 = { noreturn }
attributes #10 = { nounwind willreturn memory(read) }

!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, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !7, i64 25}
!15 = !{!"libmdbx_globals", !7, i64 0, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !16, i64 27, !10, i64 28, !7, i64 32, !7, i64 40, !13, i64 80, !6, i64 88}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!18, !13, i64 0}
!18 = !{!"meta_ptr", !13, i64 0, !7, i64 8, !13, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.meta_ptr = type { i64, %union.anon.11, i64 }
%union.anon.11 = type { ptr }
%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 }
%union.mdbx_atomic_uint32_t = type { i32 }
%union.mdbx_atomic_uint64_t = type { i64 }

@__func__.mdbx_reader_list = external hidden unnamed_addr constant [17 x i8], align 1
@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_reader_list(ptr noundef %0, ptr noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.troika, align 8
  %5 = alloca %struct.meta_ptr, align 8
  %6 = tail call i32 @check_env(ptr noundef %0, i1 noundef zeroext true)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %9, label %7, !prof !5

7:                                                ; preds = %3
  %8 = tail call i32 @log_if_error(i32 noundef %6, ptr noundef nonnull @__func__.mdbx_reader_list, i32 noundef 12)
  br label %77

9:                                                ; preds = %3
  %.not72 = icmp eq ptr %1, null
  br i1 %.not72, label %10, label %12, !prof !6

10:                                               ; preds = %9
  %11 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_reader_list, i32 noundef 15)
  br label %77

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 64
  %14 = load ptr, ptr %13, align 8, !tbaa !7
  %.not73 = icmp eq ptr %14, null
  br i1 %.not73, label %.loopexit, label %15, !prof !6

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %14, i64 488
  %17 = tail call i32 @atomic_load32(ptr noundef nonnull %16, i32 noundef 1)
  %18 = zext i32 %17 to i64
  %.not106 = icmp eq i32 %17, 0
  br i1 %.not106, label %.loopexit, label %.lr.ph103

.lr.ph103:                                        ; preds = %15
  %19 = getelementptr inbounds i8, ptr %14, i64 512
  %20 = getelementptr inbounds i8, ptr %5, i64 8
  br label %21

21:                                               ; preds = %.lr.ph103, %select.unfold
  %.060102 = phi i32 [ -1, %.lr.ph103 ], [ %.1.ph, %select.unfold ]
  %.062101 = phi i32 [ 0, %.lr.ph103 ], [ %.163.ph, %select.unfold ]
  %.06499 = phi i64 [ 0, %.lr.ph103 ], [ %75, %select.unfold ]
  %22 = getelementptr inbounds %struct.reader_slot, ptr %19, i64 %.06499
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %24 = call i32 @atomic_load32(ptr noundef nonnull %23, i32 noundef 1)
  %.not7498 = icmp eq i32 %24, 0
  br i1 %.not7498, label %select.unfold, label %.lr.ph

.lr.ph:                                           ; preds = %21
  %25 = getelementptr inbounds i8, ptr %22, i64 8
  %26 = getelementptr inbounds i8, ptr %22, i64 20
  %27 = getelementptr inbounds i8, ptr %22, i64 24
  br label %28

28:                                               ; preds = %.lr.ph, %.backedge
  %29 = phi i32 [ %24, %.lr.ph ], [ %43, %.backedge ]
  %30 = call i64 @safe64_read(ptr noundef nonnull %22)
  %31 = call i64 @atomic_load64(ptr noundef nonnull %25, i32 noundef 0)
  %32 = call i32 @atomic_load32(ptr noundef nonnull %26, i32 noundef 0)
  %33 = call i64 @atomic_load64(ptr noundef nonnull %27, i32 noundef 0)
  %34 = call i64 @safe64_read(ptr noundef nonnull %22)
  %.not75 = icmp eq i64 %30, %34
  br i1 %.not75, label %35, label %.backedge, !prof !5

35:                                               ; preds = %28
  %36 = call i32 @atomic_load32(ptr noundef nonnull %23, i32 noundef 1)
  %.not76 = icmp eq i32 %29, %36
  br i1 %.not76, label %37, label %.backedge, !prof !5

37:                                               ; preds = %35
  %38 = call i64 @atomic_load64(ptr noundef nonnull %25, i32 noundef 0)
  %.not77 = icmp eq i64 %31, %38
  br i1 %.not77, label %39, label %.backedge, !prof !5

39:                                               ; preds = %37
  %40 = call i32 @atomic_load32(ptr noundef nonnull %26, i32 noundef 0)
  %.not78 = icmp eq i32 %32, %40
  br i1 %.not78, label %41, label %.backedge, !prof !5

41:                                               ; preds = %39
  %42 = call i64 @atomic_load64(ptr noundef nonnull %27, i32 noundef 0)
  %.not91 = icmp eq i64 %33, %42
  br i1 %.not91, label %44, label %.backedge, !prof !5

.backedge:                                        ; preds = %39, %37, %35, %28, %41
  %43 = call i32 @atomic_load32(ptr noundef nonnull %23, i32 noundef 1)
  %.not74 = icmp eq i32 %43, 0
  br i1 %.not74, label %select.unfold, label %28

44:                                               ; preds = %41
  %45 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !10
  %46 = and i8 %45, 1
  %.not79 = icmp ne i8 %46, 0
  %.not80 = icmp eq i64 %30, 0
  %or.cond = select i1 %.not79, i1 %.not80, i1 false
  br i1 %or.cond, label %47, label %48, !prof !16

47:                                               ; preds = %44
  call void @mdbx_assert_fail(ptr noundef %0, ptr noundef nonnull @.str, ptr noundef nonnull @__func__.mdbx_reader_list, i32 noundef 38) #7
  unreachable

48:                                               ; preds = %44
  %49 = icmp ugt i64 %30, -4294967297
  %spec.store.select = select i1 %49, i64 0, i64 %30
  %.not81 = icmp eq i64 %spec.store.select, 0
  br i1 %.not81, label %71, label %50

50:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #8
  call void @meta_tap(ptr dead_on_unwind nonnull writable sret(%struct.troika) align 8 %4, ptr noundef %0) #8
  br label %.critedge84

.critedge84:                                      ; preds = %.critedge84.backedge, %50
  call void @meta_recent(ptr dead_on_unwind nonnull writable sret(%struct.meta_ptr) align 8 %5, ptr noundef %0, ptr noundef nonnull %4)
  %51 = load ptr, ptr %20, align 8, !tbaa !7
  %52 = getelementptr inbounds i8, ptr %51, i64 184
  %53 = call i64 @unaligned_peek_u64_volatile(i64 noundef 4, ptr noundef nonnull %52)
  %54 = call zeroext i1 @meta_should_retry(ptr noundef %0, ptr noundef nonnull %4) #8
  br i1 %54, label %.critedge84.backedge, label %55, !prof !6

55:                                               ; preds = %.critedge84
  %56 = load ptr, ptr %20, align 8, !tbaa !7
  %57 = getelementptr inbounds i8, ptr %56, i64 184
  %58 = call i64 @unaligned_peek_u64_volatile(i64 noundef 4, ptr noundef nonnull %57)
  %.not92 = icmp eq i64 %53, %58
  br i1 %.not92, label %59, label %.critedge84.backedge, !prof !5

.critedge84.backedge:                             ; preds = %55, %.critedge84
  br label %.critedge84

59:                                               ; preds = %55
  %60 = load i64, ptr %5, align 8, !tbaa !17
  %61 = sub i64 %60, %spec.store.select
  %62 = zext i32 %32 to i64
  %63 = call i64 @pgno2bytes(ptr noundef %0, i64 noundef %62) #9
  %64 = icmp ugt i64 %53, %33
  br i1 %64, label %65, label %69

65:                                               ; preds = %59
  %66 = sub i64 %53, %33
  %67 = and i64 %66, 4294967295
  %68 = call i64 @pgno2bytes(ptr noundef %0, i64 noundef %67) #9
  br label %69

69:                                               ; preds = %59, %65
  %70 = phi i64 [ %68, %65 ], [ 0, %59 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #8
  br label %71

71:                                               ; preds = %69, %48
  %.059 = phi i64 [ %63, %69 ], [ 0, %48 ]
  %.058 = phi i64 [ %70, %69 ], [ 0, %48 ]
  %.057 = phi i64 [ %61, %69 ], [ 0, %48 ]
  %72 = add nsw i32 %.062101, 1
  %73 = trunc nuw i64 %.06499 to i32
  %74 = call i32 %1(ptr noundef %2, i32 noundef %72, i32 noundef %73, i32 noundef %29, i64 noundef %31, i64 noundef %spec.store.select, i64 noundef %.057, i64 noundef %.059, i64 noundef %.058) #8
  %.not82 = icmp eq i32 %74, 0
  br i1 %.not82, label %select.unfold, label %.loopexit, !prof !5

select.unfold:                                    ; preds = %.backedge, %21, %71
  %.163.ph = phi i32 [ %72, %71 ], [ %.062101, %21 ], [ %.062101, %.backedge ]
  %.1.ph = phi i32 [ 0, %71 ], [ %.060102, %21 ], [ %.060102, %.backedge ]
  %75 = add nuw nsw i64 %.06499, 1
  %exitcond.not = icmp eq i64 %75, %18
  br i1 %exitcond.not, label %.loopexit, label %21, !llvm.loop !19

.loopexit:                                        ; preds = %select.unfold, %71, %15, %12
  %.3 = phi i32 [ -1, %12 ], [ -1, %15 ], [ %.1.ph, %select.unfold ], [ %74, %71 ]
  %76 = call i32 @log_if_error(i32 noundef %.3, ptr noundef nonnull @__func__.mdbx_reader_list, i32 noundef 66)
  br label %77

77:                                               ; preds = %.loopexit, %10, %7
  %.0 = phi i32 [ %8, %7 ], [ %11, %10 ], [ %76, %.loopexit ]
  ret i32 %.0
}

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

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

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

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @safe64_read(ptr noundef) local_unnamed_addr #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @atomic_load64(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

declare void @meta_tap(ptr dead_on_unwind writable sret(%struct.troika) align 8, ptr noundef) local_unnamed_addr #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @meta_recent(ptr dead_on_unwind noalias writable sret(%struct.meta_ptr) align 8, ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare zeroext i1 @meta_should_retry(ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden i64 @pgno2bytes(ptr noundef, i64 noundef) local_unnamed_addr #6

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { 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 = { "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 = { inlinehint 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 #7 = { noreturn nounwind }
attributes #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(read) }

!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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !8, i64 25}
!11 = !{!"libmdbx_globals", !8, i64 0, !12, i64 16, !12, i64 20, !8, i64 24, !8, i64 25, !8, i64 26, !13, i64 27, !12, i64 28, !8, i64 32, !8, i64 40, !14, i64 80, !15, i64 88}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!"branch_weights", i32 2000, i32 4002001}
!17 = !{!18, !14, i64 0}
!18 = !{!"meta_ptr", !14, i64 0, !8, i64 8, !14, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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