; LLVM IR from erthink/libmdbx :: src (txn-ro)

; 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.6 }
%struct.anon.6 = 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_txn = type { i32, i32, i64, i64, ptr, ptr, %struct.geo, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, %struct.MDBX_canary, ptr, %union.anon.1 }
%struct.geo = type { i16, i16, i32, i32, %union.anon, %union.anon.0 }
%union.anon = type { i32 }
%union.anon.0 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.1 = type { %struct.anon.2 }
%struct.anon.2 = type { %struct.troika, ptr, %struct.anon.3, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.4 }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.anon.3 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.4 = type { %struct.anon.5 }
%struct.anon.5 = type { i64, ptr }
%struct.anon = 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 }
%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.9, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.10, %struct.anon.14, i8, ptr, ptr, ptr, %struct.anon.15, %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.8, i32, i64, i64, i64 }
%union.anon.8 = type { ptr }
%struct.anon.9 = type { ptr, ptr, ptr, ptr }
%struct.anon.10 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.11, %union.anon.12 }
%struct.anon.11 = type { i16, i16, i16, i16 }
%union.anon.12 = type { i32 }
%struct.anon.14 = type { i64, i64, i64, i64, i64 }
%struct.anon.15 = type { i64 }
%struct.osal_ioring = type { i32, i32, i32, ptr, ptr, ptr }

@globals = external global %struct.libmdbx_globals, align 8
@.str.17 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [10 x i8], align 1
@__func__.txn_ro_unpark = external hidden unnamed_addr constant [14 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [58 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: alwaysinline nounwind uwtable
declare hidden i64 @safe64_read(ptr noundef) #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @atomic_yield() #3

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

; Function Attrs: nounwind uwtable
define dso_local i32 @txn_ro_unpark(ptr noundef %0) #4 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.MDBX_txn, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = and i32 %12, 131121
  %14 = icmp ne i32 %13, 131104
  %15 = xor i1 %14, true
  %16 = xor i1 %15, true
  %17 = zext i1 %16 to i32
  %18 = sext i32 %17 to i64
  %19 = call i64 @llvm.expect.i64(i64 %18, i64 0)
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %1
  store i32 -30782, ptr %2, align 4
  br label %224

22:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MDBX_txn, ptr %23, i32 0, i32 17
  %25 = getelementptr inbounds %struct.anon, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  store ptr %26, ptr %4, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %211, %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  store i32 2, ptr %5, align 4
  br label %212

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.reader_slot, ptr %32, i32 0, i32 2
  %34 = call i32 @atomic_load32(ptr noundef %33, i32 noundef 0)
  store i32 %34, ptr %6, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.reader_slot, ptr %35, i32 0, i32 1
  %37 = call i64 @safe64_read(ptr noundef %36)
  store i64 %37, ptr %7, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.reader_slot, ptr %38, i32 0, i32 0
  %40 = call i64 @safe64_read(ptr noundef %39)
  store i64 %40, ptr %8, align 8, !tbaa !18
  %41 = load i32, ptr %6, align 4, !tbaa !17
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.MDBX_txn, ptr %42, i32 0, i32 9
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  %45 = getelementptr inbounds %struct.MDBX_env, ptr %44, i32 0, i32 20
  %46 = load i32, ptr %45, align 4, !tbaa !20
  %47 = icmp ne i32 %41, %46
  %48 = xor i1 %47, true
  %49 = xor i1 %48, true
  %50 = zext i1 %49 to i32
  %51 = sext i32 %50 to i64
  %52 = call i64 @llvm.expect.i64(i64 %51, i64 0)
  %53 = icmp ne i64 %52, 0
  br i1 %53, label %54, label %75

54:                                               ; preds = %31
  br label %55

55:                                               ; preds = %54
  %56 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !30
  %57 = zext i8 %56 to i32
  %58 = icmp sle i32 1, %57
  %59 = xor i1 %58, true
  %60 = xor i1 %59, true
  %61 = zext i1 %60 to i32
  %62 = sext i32 %61 to i64
  %63 = call i64 @llvm.expect.i64(i64 %62, i64 0)
  %64 = icmp ne i64 %63, 0
  br i1 %64, label %65, label %72

65:                                               ; preds = %55
  %66 = load i32, ptr %6, align 4, !tbaa !17
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.MDBX_txn, ptr %67, i32 0, i32 9
  %69 = load ptr, ptr %68, align 8, !tbaa !19
  %70 = getelementptr inbounds %struct.MDBX_env, ptr %69, i32 0, i32 20
  %71 = load i32, ptr %70, align 4, !tbaa !20
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.txn_ro_unpark, i32 noundef 252, ptr noundef @.str.17, i32 noundef %66, ptr noundef @.str.20, i32 noundef %71)
  br label %72

72:                                               ; preds = %65, %55
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  store i32 -30779, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %209

75:                                               ; preds = %31
  %76 = load i64, ptr %7, align 8, !tbaa !18
  %77 = icmp eq i64 %76, -2
  br i1 %77, label %81, label %78

78:                                               ; preds = %75
  %79 = load i64, ptr %8, align 8, !tbaa !18
  %80 = icmp uge i64 %79, -4294967296
  br label %81

81:                                               ; preds = %78, %75
  %82 = phi i1 [ true, %75 ], [ %80, %78 ]
  %83 = xor i1 %82, true
  %84 = xor i1 %83, true
  %85 = zext i1 %84 to i32
  %86 = sext i32 %85 to i64
  %87 = call i64 @llvm.expect.i64(i64 %86, i64 0)
  %88 = icmp ne i64 %87, 0
  br i1 %88, label %89, label %90

89:                                               ; preds = %81
  store i32 2, ptr %5, align 4
  br label %209

90:                                               ; preds = %81
  %91 = load i64, ptr %7, align 8, !tbaa !18
  %92 = icmp ne i64 %91, -1
  br i1 %92, label %99, label %93

93:                                               ; preds = %90
  %94 = load i64, ptr %8, align 8, !tbaa !18
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.MDBX_txn, ptr %95, i32 0, i32 7
  %97 = load i64, ptr %96, align 8, !tbaa !32
  %98 = icmp ne i64 %94, %97
  br label %99

99:                                               ; preds = %93, %90
  %100 = phi i1 [ true, %90 ], [ %98, %93 ]
  %101 = xor i1 %100, true
  %102 = xor i1 %101, true
  %103 = zext i1 %102 to i32
  %104 = sext i32 %103 to i64
  %105 = call i64 @llvm.expect.i64(i64 %104, i64 0)
  %106 = icmp ne i64 %105, 0
  br i1 %106, label %107, label %127

107:                                              ; preds = %99
  br label %108

108:                                              ; preds = %107
  %109 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !30
  %110 = zext i8 %109 to i32
  %111 = icmp sle i32 1, %110
  %112 = xor i1 %111, true
  %113 = xor i1 %112, true
  %114 = zext i1 %113 to i32
  %115 = sext i32 %114 to i64
  %116 = call i64 @llvm.expect.i64(i64 %115, i64 0)
  %117 = icmp ne i64 %116, 0
  br i1 %117, label %118, label %124

118:                                              ; preds = %108
  %119 = load i64, ptr %7, align 8, !tbaa !18
  %120 = load i64, ptr %8, align 8, !tbaa !18
  %121 = load ptr, ptr %3, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.MDBX_txn, ptr %121, i32 0, i32 7
  %123 = load i64, ptr %122, align 8, !tbaa !32
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.txn_ro_unpark, i32 noundef 259, ptr noundef @.str.21, i64 noundef %119, ptr noundef @.str.18, i64 noundef -2, i64 noundef %120, ptr noundef @.str.18, i64 noundef %123)
  br label %124

124:                                              ; preds = %118, %108
  br label %125

125:                                              ; preds = %124
  br label %126

126:                                              ; preds = %125
  store i32 2, ptr %5, align 4
  br label %209

127:                                              ; preds = %99
  %128 = load ptr, ptr %3, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.MDBX_txn, ptr %128, i32 0, i32 1
  %130 = load i32, ptr %129, align 4, !tbaa !9
  %131 = and i32 %130, 2
  %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 0)
  %138 = icmp ne i64 %137, 0
  br i1 %138, label %139, label %140

139:                                              ; preds = %127
  store i32 2, ptr %5, align 4
  br label %209

140:                                              ; preds = %127
  %141 = load ptr, ptr %4, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.reader_slot, ptr %141, i32 0, i32 1
  %143 = load ptr, ptr %3, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.MDBX_txn, ptr %143, i32 0, i32 3
  %145 = load i64, ptr %144, align 8, !tbaa !33
  %146 = call zeroext i1 @atomic_cas64(ptr noundef %142, i64 noundef -1, i64 noundef %145)
  %147 = xor i1 %146, true
  %148 = xor i1 %147, true
  %149 = xor i1 %148, true
  %150 = zext i1 %149 to i32
  %151 = sext i32 %150 to i64
  %152 = call i64 @llvm.expect.i64(i64 %151, i64 0)
  %153 = icmp ne i64 %152, 0
  br i1 %153, label %154, label %155

154:                                              ; preds = %140
  store i32 4, ptr %5, align 4
  br label %209

155:                                              ; preds = %140
  %156 = load ptr, ptr %4, align 8, !tbaa !5
  %157 = getelementptr inbounds %struct.reader_slot, ptr %156, i32 0, i32 0
  %158 = call i64 @safe64_read(ptr noundef %157)
  store i64 %158, ptr %8, align 8, !tbaa !18
  %159 = load ptr, ptr %4, align 8, !tbaa !5
  %160 = getelementptr inbounds %struct.reader_slot, ptr %159, i32 0, i32 1
  %161 = call i64 @safe64_read(ptr noundef %160)
  store i64 %161, ptr %7, align 8, !tbaa !18
  %162 = load i64, ptr %8, align 8, !tbaa !18
  %163 = load ptr, ptr %3, align 8, !tbaa !5
  %164 = getelementptr inbounds %struct.MDBX_txn, ptr %163, i32 0, i32 7
  %165 = load i64, ptr %164, align 8, !tbaa !32
  %166 = icmp ne i64 %162, %165
  br i1 %166, label %173, label %167

167:                                              ; preds = %155
  %168 = load i64, ptr %7, align 8, !tbaa !18
  %169 = load ptr, ptr %3, align 8, !tbaa !5
  %170 = getelementptr inbounds %struct.MDBX_txn, ptr %169, i32 0, i32 3
  %171 = load i64, ptr %170, align 8, !tbaa !33
  %172 = icmp ne i64 %168, %171
  br label %173

173:                                              ; preds = %167, %155
  %174 = phi i1 [ true, %155 ], [ %172, %167 ]
  %175 = xor i1 %174, true
  %176 = xor i1 %175, true
  %177 = zext i1 %176 to i32
  %178 = sext i32 %177 to i64
  %179 = call i64 @llvm.expect.i64(i64 %178, i64 0)
  %180 = icmp ne i64 %179, 0
  br i1 %180, label %181, label %204

181:                                              ; preds = %173
  br label %182

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

192:                                              ; preds = %182
  %193 = load i64, ptr %7, align 8, !tbaa !18
  %194 = load ptr, ptr %3, align 8, !tbaa !5
  %195 = getelementptr inbounds %struct.MDBX_txn, ptr %194, i32 0, i32 3
  %196 = load i64, ptr %195, align 8, !tbaa !33
  %197 = load i64, ptr %8, align 8, !tbaa !18
  %198 = load ptr, ptr %3, align 8, !tbaa !5
  %199 = getelementptr inbounds %struct.MDBX_txn, ptr %198, i32 0, i32 7
  %200 = load i64, ptr %199, align 8, !tbaa !32
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.txn_ro_unpark, i32 noundef 280, ptr noundef @.str.22, i64 noundef %193, ptr noundef @.str.18, i64 noundef %196, i64 noundef %197, ptr noundef @.str.18, i64 noundef %200)
  br label %201

201:                                              ; preds = %192, %182
  br label %202

202:                                              ; preds = %201
  br label %203

203:                                              ; preds = %202
  store i32 2, ptr %5, align 4
  br label %209

204:                                              ; preds = %173
  %205 = load ptr, ptr %3, align 8, !tbaa !5
  %206 = getelementptr inbounds %struct.MDBX_txn, ptr %205, i32 0, i32 1
  %207 = load i32, ptr %206, align 4, !tbaa !9
  %208 = and i32 %207, -97
  store i32 %208, ptr %206, align 4, !tbaa !9
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %209

209:                                              ; preds = %204, %203, %154, %139, %126, %89, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %210 = load i32, ptr %5, align 4
  switch i32 %210, label %212 [
    i32 4, label %211
  ]

211:                                              ; preds = %209
  call void @atomic_yield()
  br label %27, !llvm.loop !34

212:                                              ; preds = %209, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %213 = load i32, ptr %5, align 4
  switch i32 %213, label %226 [
    i32 2, label %214
    i32 1, label %224
  ]

214:                                              ; preds = %212
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %215 = load ptr, ptr %3, align 8, !tbaa !5
  %216 = call i32 @txn_end(ptr noundef %215, i32 noundef 23)
  store i32 %216, ptr %9, align 4, !tbaa !17
  %217 = load i32, ptr %9, align 4, !tbaa !17
  %218 = icmp ne i32 %217, 0
  br i1 %218, label %219, label %221

219:                                              ; preds = %214
  %220 = load i32, ptr %9, align 4, !tbaa !17
  br label %222

221:                                              ; preds = %214
  br label %222

222:                                              ; preds = %221, %219
  %223 = phi i32 [ %220, %219 ], [ -30411, %221 ]
  store i32 %223, ptr %2, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %224

224:                                              ; preds = %222, %212, %21
  %225 = load i32, ptr %2, align 4
  ret i32 %225

226:                                              ; preds = %212
  unreachable
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden zeroext i1 @atomic_cas64(ptr noundef, i64 noundef, i64 noundef) #3

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

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 = { 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 = { 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 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"MDBX_txn", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !12, i64 64, !12, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !15, i64 128, !6, i64 160, !7, i64 168}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"geo", !14, i64 0, !14, i64 2, !11, i64 4, !11, i64 8, !7, i64 12, !7, i64 16}
!14 = !{!"short", !7, i64 0}
!15 = !{!"MDBX_canary", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!16 = !{!7, !7, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!12, !12, i64 0}
!19 = !{!10, !6, i64 80}
!20 = !{!21, !11, i64 140}
!21 = !{!"MDBX_env", !7, i64 0, !11, i64 4, !11, i64 8, !22, i64 16, !11, i64 56, !11, i64 60, !22, i64 64, !6, i64 104, !14, i64 112, !14, i64 114, !14, i64 116, !14, i64 118, !14, i64 120, !14, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !14, i64 130, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !23, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !11, i64 224, !11, i64 228, !11, i64 232, !6, i64 240, !6, i64 248, !12, i64 256, !24, i64 264, !27, i64 320, !25, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !28, i64 392, !7, i64 400, !11, i64 440, !11, i64 444, !6, i64 448, !29, i64 456, !7, i64 496, !7, i64 536}
!22 = !{!"osal_mmap", !7, i64 0, !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!23 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!24 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !12, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !11, i64 28, !11, i64 32, !25, i64 36, !25, i64 37, !25, i64 38, !26, i64 40, !7, i64 48}
!25 = !{!"_Bool", !7, i64 0}
!26 = !{!"", !14, i64 0, !14, i64 2, !14, i64 4, !14, i64 6}
!27 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!28 = !{!"", !12, i64 0}
!29 = !{!"osal_ioring", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!30 = !{!31, !7, i64 26}
!31 = !{!"libmdbx_globals", !7, i64 0, !11, i64 16, !11, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !25, i64 27, !11, i64 28, !7, i64 32, !7, i64 40, !12, i64 80, !6, i64 88}
!32 = !{!10, !12, i64 64}
!33 = !{!10, !12, i64 16}
!34 = distinct !{!34, !35}
!35 = !{!"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.6 }
%struct.anon.6 = 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.17 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [10 x i8], align 1
@__func__.txn_ro_unpark = external hidden unnamed_addr constant [14 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [58 x i8], align 1

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

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @atomic_yield() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @txn_ro_unpark(ptr noundef %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = and i32 %3, 131121
  %.not = icmp eq i32 %4, 131104
  br i1 %.not, label %5, label %58, !prof !15

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 168
  %7 = load ptr, ptr %6, align 8, !tbaa !16
  %.not44 = icmp eq ptr %7, null
  br i1 %.not44, label %.thread58, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  %10 = getelementptr inbounds i8, ptr %0, i64 80
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = tail call i32 @atomic_load32(ptr noundef nonnull %8, i32 noundef 0)
  %14 = tail call i64 @safe64_read(ptr noundef nonnull %9)
  %15 = tail call i64 @safe64_read(ptr noundef nonnull %7)
  %16 = load ptr, ptr %10, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %16, i64 140
  %18 = load i32, ptr %17, align 4, !tbaa !18
  %.not4595 = icmp eq i32 %13, %18
  br i1 %.not4595, label %.lr.ph96, label %.split, !prof !28

.split:                                           ; preds = %49, %.lr.ph
  %.lcssa82 = phi i32 [ %13, %.lr.ph ], [ %50, %49 ]
  %.lcssa = phi i32 [ %18, %.lr.ph ], [ %55, %49 ]
  %19 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !29
  %.not51 = icmp eq i8 %19, 0
  br i1 %.not51, label %58, label %20, !prof !15

20:                                               ; preds = %.split
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.txn_ro_unpark, i32 noundef 252, ptr noundef nonnull @.str.17, i32 noundef %.lcssa82, ptr noundef nonnull @.str.20, i32 noundef %.lcssa) #3
  br label %58

.lr.ph96:                                         ; preds = %.lr.ph, %49
  %21 = phi i64 [ %52, %49 ], [ %15, %.lr.ph ]
  %22 = phi i64 [ %51, %49 ], [ %14, %.lr.ph ]
  %23 = icmp eq i64 %22, -2
  %24 = icmp ugt i64 %21, -4294967297
  %25 = select i1 %23, i1 true, i1 %24, !prof !31
  br i1 %25, label %.thread58, label %26, !prof !31

26:                                               ; preds = %.lr.ph96
  %.not46 = icmp eq i64 %22, -1
  br i1 %.not46, label %27, label %.critedge, !prof !15

27:                                               ; preds = %26
  %28 = load i64, ptr %11, align 8, !tbaa !32
  %.not69 = icmp eq i64 %21, %28
  br i1 %.not69, label %32, label %.critedge, !prof !15

.critedge:                                        ; preds = %27, %26
  %29 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !29
  %.not50 = icmp eq i8 %29, 0
  br i1 %.not50, label %.thread58, label %30, !prof !15

30:                                               ; preds = %.critedge
  %31 = load i64, ptr %11, align 8, !tbaa !32
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.txn_ro_unpark, i32 noundef 259, ptr noundef nonnull @.str.21, i64 noundef %22, ptr noundef nonnull @.str.18, i64 noundef -2, i64 noundef %21, ptr noundef nonnull @.str.18, i64 noundef %31) #3
  br label %.thread58

32:                                               ; preds = %27
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = and i32 %33, 2
  %.not47 = icmp eq i32 %34, 0
  br i1 %.not47, label %35, label %.thread58, !prof !15

35:                                               ; preds = %32
  %36 = load i64, ptr %12, align 8, !tbaa !33
  %37 = tail call zeroext i1 @atomic_cas64(ptr noundef nonnull %9, i64 noundef -1, i64 noundef %36)
  br i1 %37, label %.split93, label %49, !prof !15

.split93:                                         ; preds = %35
  %38 = tail call i64 @safe64_read(ptr noundef nonnull %7)
  %39 = tail call i64 @safe64_read(ptr noundef nonnull %9)
  %40 = load i64, ptr %11, align 8, !tbaa !32
  %.not48 = icmp eq i64 %38, %40
  br i1 %.not48, label %41, label %.critedge54, !prof !15

41:                                               ; preds = %.split93
  %42 = load i64, ptr %12, align 8, !tbaa !33
  %.not70 = icmp eq i64 %39, %42
  br i1 %.not70, label %46, label %.critedge54, !prof !15

.critedge54:                                      ; preds = %.split93, %41
  %43 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !29
  %.not49 = icmp eq i8 %43, 0
  br i1 %.not49, label %.thread58, label %44, !prof !15

44:                                               ; preds = %.critedge54
  %45 = load i64, ptr %12, align 8, !tbaa !33
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.txn_ro_unpark, i32 noundef 280, ptr noundef nonnull @.str.22, i64 noundef %39, ptr noundef nonnull @.str.18, i64 noundef %45, i64 noundef %38, ptr noundef nonnull @.str.18, i64 noundef %40) #3
  br label %.thread58

46:                                               ; preds = %41
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = and i32 %47, -97
  store i32 %48, ptr %2, align 4, !tbaa !5
  br label %58

49:                                               ; preds = %35
  tail call void @atomic_yield()
  %50 = tail call i32 @atomic_load32(ptr noundef nonnull %8, i32 noundef 0)
  %51 = tail call i64 @safe64_read(ptr noundef nonnull %9)
  %52 = tail call i64 @safe64_read(ptr noundef nonnull %7)
  %53 = load ptr, ptr %10, align 8, !tbaa !17
  %54 = getelementptr inbounds i8, ptr %53, i64 140
  %55 = load i32, ptr %54, align 4, !tbaa !18
  %.not45 = icmp eq i32 %50, %55
  br i1 %.not45, label %.lr.ph96, label %.split, !prof !34

.thread58:                                        ; preds = %32, %.lr.ph96, %5, %30, %.critedge, %44, %.critedge54
  %56 = tail call i32 @txn_end(ptr noundef nonnull %0, i32 noundef 23) #3
  %.not52 = icmp eq i32 %56, 0
  %57 = select i1 %.not52, i32 -30411, i32 %56
  br label %58

58:                                               ; preds = %.split, %20, %46, %1, %.thread58
  %.3 = phi i32 [ %57, %.thread58 ], [ -30782, %1 ], [ -30779, %.split ], [ -30779, %20 ], [ 0, %46 ]
  ret i32 %.3
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden zeroext i1 @atomic_cas64(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

declare i32 @txn_end(ptr noundef, i32 noundef) local_unnamed_addr #0

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


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