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

; 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_rkl_iter = type { ptr, i32, i32 }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }

@globals = external global %struct.libmdbx_globals, align 8
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 x i8], align 1
@__func__.rkl_find = external hidden unnamed_addr constant [9 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(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind willreturn memory(read) uwtable
declare dso_local zeroext i1 @rkl_check(ptr noundef) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

; Function Attrs: hot nounwind uwtable
define dso_local zeroext i1 @rkl_find(ptr noundef %0, i64 noundef %1, ptr noundef %2) #6 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.MDBX_rkl_iter, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %3
  %13 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %14 = zext i8 %13 to i32
  %15 = and i32 %14, 1
  %16 = icmp ne i32 %15, 0
  %17 = xor i1 %16, true
  %18 = xor i1 %17, true
  %19 = zext i1 %18 to i32
  %20 = sext i32 %19 to i64
  %21 = call i64 @llvm.expect.i64(i64 %20, i64 1)
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %37

23:                                               ; preds = %12
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call zeroext i1 @rkl_check(ptr noundef %25) #8
  %27 = xor i1 %26, true
  %28 = xor i1 %27, true
  %29 = xor i1 %28, true
  %30 = zext i1 %29 to i32
  %31 = sext i32 %30 to i64
  %32 = call i64 @llvm.expect.i64(i64 %31, i64 0)
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %24
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.1, ptr noundef @__func__.rkl_find, i32 noundef 142) #9
  unreachable

35:                                               ; preds = %24
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36, %12
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #10
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call { ptr, i64 } @rkl_iterator(ptr noundef %40, i1 noundef zeroext false)
  %42 = getelementptr inbounds { ptr, i64 }, ptr %8, i32 0, i32 0
  %43 = extractvalue { ptr, i64 } %41, 0
  store ptr %43, ptr %42, align 8
  %44 = getelementptr inbounds { ptr, i64 }, ptr %8, i32 0, i32 1
  %45 = extractvalue { ptr, i64 } %41, 1
  store i64 %45, ptr %44, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %39, ptr align 8 %8, i64 16, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #10
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.MDBX_rkl, ptr %47, i32 0, i32 0
  %49 = load i64, ptr %48, align 8, !tbaa !17
  %50 = icmp uge i64 %46, %49
  br i1 %50, label %51, label %81

51:                                               ; preds = %38
  %52 = load i64, ptr %6, align 8, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.MDBX_rkl, ptr %53, i32 0, i32 1
  %55 = load i64, ptr %54, align 8, !tbaa !19
  %56 = icmp ult i64 %52, %55
  br i1 %56, label %57, label %70

57:                                               ; preds = %51
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.MDBX_rkl_iter, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !20
  %61 = load i64, ptr %6, align 8, !tbaa !9
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.MDBX_rkl, ptr %62, i32 0, i32 0
  %64 = load i64, ptr %63, align 8, !tbaa !17
  %65 = sub i64 %61, %64
  %66 = trunc i64 %65 to i32
  %67 = add i32 %60, %66
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.MDBX_rkl_iter, ptr %68, i32 0, i32 1
  store i32 %67, ptr %69, align 8, !tbaa !22
  store i1 true, ptr %4, align 1
  br label %240

70:                                               ; preds = %51
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.MDBX_rkl, ptr %71, i32 0, i32 1
  %73 = load i64, ptr %72, align 8, !tbaa !19
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.MDBX_rkl, ptr %74, i32 0, i32 0
  %76 = load i64, ptr %75, align 8, !tbaa !17
  %77 = sub i64 %73, %76
  %78 = trunc i64 %77 to i32
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.MDBX_rkl_iter, ptr %79, i32 0, i32 1
  store i32 %78, ptr %80, align 8, !tbaa !22
  br label %81

81:                                               ; preds = %70, %38
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.MDBX_rkl, ptr %82, i32 0, i32 2
  %84 = load i32, ptr %83, align 8, !tbaa !23
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %239

86:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #10
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.MDBX_rkl, ptr %87, i32 0, i32 4
  %89 = load ptr, ptr %88, align 8, !tbaa !24
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.MDBX_rkl, ptr %90, i32 0, i32 2
  %92 = load i32, ptr %91, align 8, !tbaa !23
  %93 = zext i32 %92 to i64
  %94 = load i64, ptr %6, align 8, !tbaa !9
  %95 = call ptr @rkl_bsearch(ptr noundef %89, i64 noundef %93, i64 noundef %94)
  store ptr %95, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #10
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.MDBX_rkl, ptr %96, i32 0, i32 4
  %98 = load ptr, ptr %97, align 8, !tbaa !24
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.MDBX_rkl, ptr %99, i32 0, i32 2
  %101 = load i32, ptr %100, align 8, !tbaa !23
  %102 = zext i32 %101 to i64
  %103 = getelementptr inbounds i64, ptr %98, i64 %102
  store ptr %103, ptr %10, align 8, !tbaa !5
  br label %104

104:                                              ; preds = %86
  %105 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %106 = zext i8 %105 to i32
  %107 = and i32 %106, 1
  %108 = icmp ne i32 %107, 0
  %109 = xor i1 %108, true
  %110 = xor i1 %109, true
  %111 = zext i1 %110 to i32
  %112 = sext i32 %111 to i64
  %113 = call i64 @llvm.expect.i64(i64 %112, i64 1)
  %114 = icmp ne i64 %113, 0
  br i1 %114, label %115, label %139

115:                                              ; preds = %104
  br label %116

116:                                              ; preds = %115
  %117 = load ptr, ptr %9, align 8, !tbaa !5
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.MDBX_rkl, ptr %118, i32 0, i32 4
  %120 = load ptr, ptr %119, align 8, !tbaa !24
  %121 = icmp uge ptr %117, %120
  br i1 %121, label %122, label %126

122:                                              ; preds = %116
  %123 = load ptr, ptr %9, align 8, !tbaa !5
  %124 = load ptr, ptr %10, align 8, !tbaa !5
  %125 = icmp ule ptr %123, %124
  br label %126

126:                                              ; preds = %122, %116
  %127 = phi i1 [ false, %116 ], [ %125, %122 ]
  %128 = xor i1 %127, true
  %129 = xor i1 %128, true
  %130 = xor i1 %129, true
  %131 = zext i1 %130 to i32
  %132 = sext i32 %131 to i64
  %133 = call i64 @llvm.expect.i64(i64 %132, i64 0)
  %134 = icmp ne i64 %133, 0
  br i1 %134, label %135, label %136

135:                                              ; preds = %126
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.2, ptr noundef @__func__.rkl_find, i32 noundef 154) #9
  unreachable

136:                                              ; preds = %126
  br label %137

137:                                              ; preds = %136
  br label %138

138:                                              ; preds = %137
  br label %139

139:                                              ; preds = %138, %104
  br label %140

140:                                              ; preds = %139
  br label %141

141:                                              ; preds = %140
  %142 = load ptr, ptr %9, align 8, !tbaa !5
  %143 = load ptr, ptr %5, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.MDBX_rkl, ptr %143, i32 0, i32 4
  %145 = load ptr, ptr %144, align 8, !tbaa !24
  %146 = icmp ne ptr %142, %145
  br i1 %146, label %147, label %180

147:                                              ; preds = %141
  br label %148

148:                                              ; preds = %147
  %149 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %150 = zext i8 %149 to i32
  %151 = and i32 %150, 1
  %152 = icmp ne i32 %151, 0
  %153 = xor i1 %152, true
  %154 = xor i1 %153, true
  %155 = zext i1 %154 to i32
  %156 = sext i32 %155 to i64
  %157 = call i64 @llvm.expect.i64(i64 %156, i64 1)
  %158 = icmp ne i64 %157, 0
  br i1 %158, label %159, label %177

159:                                              ; preds = %148
  br label %160

160:                                              ; preds = %159
  %161 = load ptr, ptr %9, align 8, !tbaa !5
  %162 = getelementptr inbounds i64, ptr %161, i64 -1
  %163 = load i64, ptr %162, align 8, !tbaa !9
  %164 = load i64, ptr %6, align 8, !tbaa !9
  %165 = icmp ult i64 %163, %164
  %166 = xor i1 %165, true
  %167 = xor i1 %166, true
  %168 = xor i1 %167, true
  %169 = zext i1 %168 to i32
  %170 = sext i32 %169 to i64
  %171 = call i64 @llvm.expect.i64(i64 %170, i64 0)
  %172 = icmp ne i64 %171, 0
  br i1 %172, label %173, label %174

173:                                              ; preds = %160
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.3, ptr noundef @__func__.rkl_find, i32 noundef 156) #9
  unreachable

174:                                              ; preds = %160
  br label %175

175:                                              ; preds = %174
  br label %176

176:                                              ; preds = %175
  br label %177

177:                                              ; preds = %176, %148
  br label %178

178:                                              ; preds = %177
  br label %179

179:                                              ; preds = %178
  br label %180

180:                                              ; preds = %179, %141
  %181 = load ptr, ptr %9, align 8, !tbaa !5
  %182 = load ptr, ptr %5, align 8, !tbaa !5
  %183 = getelementptr inbounds %struct.MDBX_rkl, ptr %182, i32 0, i32 4
  %184 = load ptr, ptr %183, align 8, !tbaa !24
  %185 = ptrtoint ptr %181 to i64
  %186 = ptrtoint ptr %184 to i64
  %187 = sub i64 %185, %186
  %188 = sdiv exact i64 %187, 8
  %189 = trunc i64 %188 to i32
  %190 = load ptr, ptr %7, align 8, !tbaa !5
  %191 = getelementptr inbounds %struct.MDBX_rkl_iter, ptr %190, i32 0, i32 1
  %192 = load i32, ptr %191, align 8, !tbaa !22
  %193 = add i32 %192, %189
  store i32 %193, ptr %191, align 8, !tbaa !22
  %194 = load ptr, ptr %9, align 8, !tbaa !5
  %195 = load ptr, ptr %10, align 8, !tbaa !5
  %196 = icmp ne ptr %194, %195
  br i1 %196, label %197, label %235

197:                                              ; preds = %180
  br label %198

198:                                              ; preds = %197
  %199 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %200 = zext i8 %199 to i32
  %201 = and i32 %200, 1
  %202 = icmp ne i32 %201, 0
  %203 = xor i1 %202, true
  %204 = xor i1 %203, true
  %205 = zext i1 %204 to i32
  %206 = sext i32 %205 to i64
  %207 = call i64 @llvm.expect.i64(i64 %206, i64 1)
  %208 = icmp ne i64 %207, 0
  br i1 %208, label %209, label %228

209:                                              ; preds = %198
  br label %210

210:                                              ; preds = %209
  %211 = load ptr, ptr %9, align 8, !tbaa !5
  %212 = getelementptr inbounds i64, ptr %211, i64 0
  %213 = load i64, ptr %212, align 8, !tbaa !9
  %214 = load i64, ptr %6, align 8, !tbaa !9
  %215 = icmp ult i64 %213, %214
  %216 = xor i1 %215, true
  %217 = xor i1 %216, true
  %218 = xor i1 %217, true
  %219 = xor i1 %218, true
  %220 = zext i1 %219 to i32
  %221 = sext i32 %220 to i64
  %222 = call i64 @llvm.expect.i64(i64 %221, i64 0)
  %223 = icmp ne i64 %222, 0
  br i1 %223, label %224, label %225

224:                                              ; preds = %210
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.4, ptr noundef @__func__.rkl_find, i32 noundef 159) #9
  unreachable

225:                                              ; preds = %210
  br label %226

226:                                              ; preds = %225
  br label %227

227:                                              ; preds = %226
  br label %228

228:                                              ; preds = %227, %198
  br label %229

229:                                              ; preds = %228
  br label %230

230:                                              ; preds = %229
  %231 = load ptr, ptr %9, align 8, !tbaa !5
  %232 = load i64, ptr %231, align 8, !tbaa !9
  %233 = load i64, ptr %6, align 8, !tbaa !9
  %234 = icmp eq i64 %232, %233
  store i1 %234, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %236

235:                                              ; preds = %180
  store i32 0, ptr %11, align 4
  br label %236

236:                                              ; preds = %235, %230
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #10
  %237 = load i32, ptr %11, align 4
  switch i32 %237, label %242 [
    i32 0, label %238
    i32 1, label %240
  ]

238:                                              ; preds = %236
  br label %239

239:                                              ; preds = %238, %81
  store i1 false, ptr %4, align 1
  br label %240

240:                                              ; preds = %239, %236, %57
  %241 = load i1, ptr %4, align 1
  ret i1 %241

242:                                              ; preds = %236
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local { ptr, i64 } @rkl_iterator(ptr noundef, i1 noundef zeroext) #7

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { 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 #3 = { noreturn "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { hot 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 #7 = { 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 #8 = { nounwind willreturn memory(read) }
attributes #9 = { noreturn }
attributes #10 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !7, i64 25}
!12 = !{!"libmdbx_globals", !7, i64 0, !13, i64 16, !13, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !14, i64 27, !13, i64 28, !7, i64 32, !7, i64 40, !10, i64 80, !6, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{i64 0, i64 8, !5, i64 8, i64 4, !16, i64 12, i64 4, !16}
!16 = !{!13, !13, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"MDBX_rkl", !10, i64 0, !10, i64 8, !13, i64 16, !13, i64 20, !6, i64 24, !7, i64 32}
!19 = !{!18, !10, i64 8}
!20 = !{!21, !13, i64 12}
!21 = !{!"MDBX_rkl_iter", !6, i64 0, !13, i64 8, !13, i64 12}
!22 = !{!21, !13, i64 8}
!23 = !{!18, !13, i64 16}
!24 = !{!18, !6, i64 24}


; 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 [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [18 x i8], align 1
@__func__.rkl_find = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn memory(read) uwtable
declare dso_local zeroext i1 @rkl_check(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden ptr @rkl_bsearch(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: hot nounwind uwtable
define dso_local zeroext i1 @rkl_find(ptr noundef %0, i64 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #3 {
  %4 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %5 = and i8 %4, 1
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %9, label %6, !prof !13

6:                                                ; preds = %3
  %7 = tail call zeroext i1 @rkl_check(ptr noundef %0) #5
  br i1 %7, label %9, label %8, !prof !14

8:                                                ; preds = %6
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.rkl_find, i32 noundef 142) #6
  unreachable

9:                                                ; preds = %3, %6
  %10 = tail call { ptr, i64 } @rkl_iterator(ptr noundef %0, i1 noundef zeroext false)
  %11 = extractvalue { ptr, i64 } %10, 0
  %12 = extractvalue { ptr, i64 } %10, 1
  store ptr %11, ptr %2, align 8, !tbaa !15
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 8
  store i64 %12, ptr %.sroa.4.0..sroa_idx, align 8
  %13 = load i64, ptr %0, align 8, !tbaa !16
  %.not45 = icmp ugt i64 %13, %1
  %14 = lshr i64 %12, 32
  %15 = trunc nuw i64 %14 to i32
  br i1 %.not45, label %27, label %16

16:                                               ; preds = %9
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !18
  %19 = icmp ugt i64 %18, %1
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = sub i64 %1, %13
  %22 = trunc i64 %21 to i32
  %23 = add i32 %15, %22
  store i32 %23, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !19
  br label %.thread58

24:                                               ; preds = %16
  %25 = sub i64 %18, %13
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !19
  br label %27

27:                                               ; preds = %24, %9
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  %29 = load i32, ptr %28, align 8, !tbaa !21
  %.not46 = icmp eq i32 %29, 0
  br i1 %.not46, label %.thread58, label %30

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  %32 = load ptr, ptr %31, align 8, !tbaa !22
  %33 = zext i32 %29 to i64
  %34 = tail call ptr @rkl_bsearch(ptr noundef %32, i64 noundef %33, i64 noundef %1)
  %35 = load ptr, ptr %31, align 8, !tbaa !22
  %36 = load i32, ptr %28, align 8, !tbaa !21
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i64, ptr %35, i64 %37
  %39 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %40 = and i8 %39, 1
  %.not47 = icmp ne i8 %40, 0
  br i1 %.not47, label %41, label %49, !prof !14

41:                                               ; preds = %30
  %42 = icmp ult ptr %34, %35
  %43 = icmp ugt ptr %34, %38
  %.not50 = select i1 %42, i1 true, i1 %43
  br i1 %.not50, label %44, label %.thread, !prof !13

44:                                               ; preds = %41
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.2, ptr noundef nonnull @__func__.rkl_find, i32 noundef 154) #6
  unreachable

.thread:                                          ; preds = %41
  %.not5156 = icmp eq ptr %34, %35
  br i1 %.not5156, label %49, label %45

45:                                               ; preds = %.thread
  %46 = getelementptr inbounds i8, ptr %34, i64 -8
  %47 = load i64, ptr %46, align 8, !tbaa !23
  %.not53 = icmp ult i64 %47, %1
  br i1 %.not53, label %49, label %48, !prof !14

48:                                               ; preds = %45
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.3, ptr noundef nonnull @__func__.rkl_find, i32 noundef 156) #6
  unreachable

49:                                               ; preds = %30, %.thread, %45
  %50 = ptrtoint ptr %34 to i64
  %51 = ptrtoint ptr %35 to i64
  %52 = sub i64 %50, %51
  %53 = lshr exact i64 %52, 3
  %54 = trunc i64 %53 to i32
  %55 = load i32, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !19
  %56 = add i32 %55, %54
  store i32 %56, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !19
  %.not54.not = icmp eq ptr %34, %38
  br i1 %.not54.not, label %.thread58, label %57

57:                                               ; preds = %49
  %.pre = load i64, ptr %34, align 8, !tbaa !23
  %58 = icmp ult i64 %.pre, %1
  %or.cond = select i1 %.not47, i1 %58, i1 false
  br i1 %or.cond, label %59, label %60, !prof !24

59:                                               ; preds = %57
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.4, ptr noundef nonnull @__func__.rkl_find, i32 noundef 159) #6
  unreachable

60:                                               ; preds = %57
  %61 = icmp eq i64 %.pre, %1
  br label %.thread58

.thread58:                                        ; preds = %49, %27, %60, %20
  %.1 = phi i1 [ true, %20 ], [ %61, %60 ], [ false, %27 ], [ false, %49 ]
  ret i1 %.1
}

; Function Attrs: nounwind uwtable
declare dso_local { ptr, i64 } @rkl_iterator(ptr noundef, i1 noundef zeroext) local_unnamed_addr #4

attributes #0 = { 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 #1 = { noreturn "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { 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 #3 = { hot 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 willreturn memory(read) }
attributes #6 = { noreturn 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 = !{!12, !12, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"MDBX_rkl", !11, i64 0, !11, i64 8, !9, i64 16, !9, i64 20, !12, i64 24, !7, i64 32}
!18 = !{!17, !11, i64 8}
!19 = !{!20, !9, i64 8}
!20 = !{!"MDBX_rkl_iter", !12, i64 0, !9, i64 8, !9, i64 12}
!21 = !{!17, !9, i64 16}
!22 = !{!17, !12, i64 24}
!23 = !{!11, !11, i64 0}
!24 = !{!"branch_weights", i32 2000, i32 4002001}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass