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

; 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.8 }
%struct.anon.8 = 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_cursor = type { i32, %union.anon, i8, i8, ptr, ptr, ptr, ptr, ptr, [32 x ptr], [32 x i16], ptr, ptr }
%union.anon = type { i16 }
%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.2 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.0, %union.anon.1 }
%union.anon.0 = type { i32 }
%union.anon.1 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.2 = type { %struct.anon.4 }
%struct.anon.4 = type { %struct.troika, ptr, %struct.anon.5, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.6 }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.anon.5 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.6 = type { %struct.anon.7 }
%struct.anon.7 = type { i64, ptr }
%struct.inner_cursor = type { %struct.MDBX_cursor, %struct.tree }
%struct.tree = type { i16, i16, i32, i32, i32, i32, i32, i64, i64, i64 }
%struct.page = type <{ i64, i16, i16, %union.anon.18, i32, [0 x i16] }>
%union.anon.18 = type { i32 }
%struct.clc2 = type { %struct.clc, %struct.clc }
%struct.clc = type { ptr, i64, i64 }

@globals = external global %struct.libmdbx_globals, align 8
@.str.28 = external hidden unnamed_addr constant [15 x i8], align 1
@__func__.cursor_dupsort_setup = external hidden unnamed_addr constant [21 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [73 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [30 x i8], align 1

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

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden zeroext i1 @is_pointed(ptr noundef) #2

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden i64 @page_numkeys(ptr noundef) #2

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden zeroext i8 @node_flags(ptr noalias noundef) #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden i64 @cursor_dbi(ptr noundef) #2

; 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: nounwind uwtable
define dso_local i32 @cursor_dupsort_setup(ptr noundef %0, ptr noundef %1, ptr noundef %2) #5 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i64, align 8
  %12 = alloca ptr, 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
  br label %13

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

24:                                               ; preds = %13
  br label %25

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

35:                                               ; preds = %25
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.MDBX_cursor, ptr %36, i32 0, i32 5
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = getelementptr inbounds %struct.MDBX_txn, ptr %38, i32 0, i32 9
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  call void @mdbx_assert_fail(ptr noundef %40, ptr noundef @.str.28, ptr noundef @__func__.cursor_dupsort_setup, i32 noundef 322) #10
  unreachable

41:                                               ; preds = %25
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42, %13
  br label %44

44:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #11
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MDBX_cursor, ptr %45, i32 0, i32 8
  %47 = load ptr, ptr %46, align 8, !tbaa !21
  store ptr %47, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  %50 = xor i1 %49, true
  %51 = xor i1 %50, true
  %52 = zext i1 %51 to i32
  %53 = sext i32 %52 to i64
  %54 = call i64 @llvm.expect.i64(i64 %53, i64 0)
  %55 = icmp ne i64 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %44
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = call i32 @unexpected_dupsort(ptr noundef %57) #12
  store i32 %58, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %495

59:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #11
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = call zeroext i8 @node_flags(ptr noundef %60) #9
  store i8 %61, ptr %10, align 1, !tbaa !22
  %62 = load i8, ptr %10, align 1, !tbaa !22
  %63 = zext i8 %62 to i32
  switch i32 %63, label %64 [
    i32 6, label %81
    i32 4, label %152
  ]

64:                                               ; preds = %59
  br label %65

65:                                               ; preds = %64
  %66 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !23
  %67 = zext i8 %66 to i32
  %68 = icmp sle i32 1, %67
  %69 = xor i1 %68, true
  %70 = xor i1 %69, true
  %71 = zext i1 %70 to i32
  %72 = sext i32 %71 to i64
  %73 = call i64 @llvm.expect.i64(i64 %72, i64 0)
  %74 = icmp ne i64 %73, 0
  br i1 %74, label %75, label %78

75:                                               ; preds = %65
  %76 = load i8, ptr %10, align 1, !tbaa !22
  %77 = zext i8 %76 to i32
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.cursor_dupsort_setup, i32 noundef 330, ptr noundef @.str.29, i32 noundef %77)
  br label %78

78:                                               ; preds = %75, %65
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  br label %490

81:                                               ; preds = %59
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = call i64 @node_ds(ptr noundef %82) #9
  %84 = icmp ne i64 %83, 48
  %85 = xor i1 %84, true
  %86 = xor i1 %85, true
  %87 = zext i1 %86 to i32
  %88 = sext i32 %87 to i64
  %89 = call i64 @llvm.expect.i64(i64 %88, i64 0)
  %90 = icmp ne i64 %89, 0
  br i1 %90, label %91, label %108

91:                                               ; preds = %81
  br label %92

92:                                               ; preds = %91
  %93 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !23
  %94 = zext i8 %93 to i32
  %95 = icmp sle i32 1, %94
  %96 = xor i1 %95, true
  %97 = xor i1 %96, true
  %98 = zext i1 %97 to i32
  %99 = sext i32 %98 to i64
  %100 = call i64 @llvm.expect.i64(i64 %99, i64 0)
  %101 = icmp ne i64 %100, 0
  br i1 %101, label %102, label %105

102:                                              ; preds = %92
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = call i64 @node_ds(ptr noundef %103) #9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.cursor_dupsort_setup, i32 noundef 334, ptr noundef @.str.30, i64 noundef %104, i64 noundef 48)
  br label %105

105:                                              ; preds = %102, %92
  br label %106

106:                                              ; preds = %105
  br label %107

107:                                              ; preds = %106
  br label %490

108:                                              ; preds = %81
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.inner_cursor, ptr %109, i32 0, i32 1
  %111 = load ptr, ptr %6, align 8, !tbaa !5
  %112 = call ptr @node_data(ptr noundef %111) #9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %110, ptr align 1 %112, i64 48, i1 false)
  %113 = load ptr, ptr %7, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.page, ptr %113, i32 0, i32 0
  %115 = load i64, ptr %114, align 1, !tbaa !24
  store i64 %115, ptr %11, align 8, !tbaa !24
  %116 = load ptr, ptr %8, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.inner_cursor, ptr %116, i32 0, i32 1
  %118 = getelementptr inbounds %struct.tree, ptr %117, i32 0, i32 9
  %119 = load i64, ptr %118, align 8, !tbaa !25
  %120 = load i64, ptr %11, align 8, !tbaa !24
  %121 = icmp ugt i64 %119, %120
  %122 = xor i1 %121, true
  %123 = xor i1 %122, true
  %124 = zext i1 %123 to i32
  %125 = sext i32 %124 to i64
  %126 = call i64 @llvm.expect.i64(i64 %125, i64 0)
  %127 = icmp ne i64 %126, 0
  br i1 %127, label %128, label %148

128:                                              ; preds = %108
  br label %129

129:                                              ; preds = %128
  %130 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !23
  %131 = zext i8 %130 to i32
  %132 = icmp sle i32 1, %131
  %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 %145

139:                                              ; preds = %129
  %140 = load ptr, ptr %8, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.inner_cursor, ptr %140, i32 0, i32 1
  %142 = getelementptr inbounds %struct.tree, ptr %141, i32 0, i32 9
  %143 = load i64, ptr %142, align 8, !tbaa !25
  %144 = load i64, ptr %11, align 8, !tbaa !24
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.cursor_dupsort_setup, i32 noundef 340, ptr noundef @.str.31, i64 noundef %143, i64 noundef %144)
  br label %145

145:                                              ; preds = %139, %129
  br label %146

146:                                              ; preds = %145
  br label %147

147:                                              ; preds = %146
  br label %490

148:                                              ; preds = %108
  %149 = load ptr, ptr %8, align 8, !tbaa !5
  %150 = getelementptr inbounds %struct.inner_cursor, ptr %149, i32 0, i32 0
  %151 = getelementptr inbounds %struct.MDBX_cursor, ptr %150, i32 0, i32 1
  store i16 -43, ptr %151, align 4, !tbaa !22
  br label %248

152:                                              ; preds = %59
  %153 = load ptr, ptr %6, align 8, !tbaa !5
  %154 = call i64 @node_ds(ptr noundef %153) #9
  %155 = icmp ule i64 %154, 20
  %156 = xor i1 %155, true
  %157 = xor i1 %156, true
  %158 = zext i1 %157 to i32
  %159 = sext i32 %158 to i64
  %160 = call i64 @llvm.expect.i64(i64 %159, i64 0)
  %161 = icmp ne i64 %160, 0
  br i1 %161, label %162, label %179

162:                                              ; preds = %152
  br label %163

163:                                              ; preds = %162
  %164 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !23
  %165 = zext i8 %164 to i32
  %166 = icmp sle i32 1, %165
  %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 %176

173:                                              ; preds = %163
  %174 = load ptr, ptr %6, align 8, !tbaa !5
  %175 = call i64 @node_ds(ptr noundef %174) #9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.cursor_dupsort_setup, i32 noundef 347, ptr noundef @.str.32, i64 noundef %175)
  br label %176

176:                                              ; preds = %173, %163
  br label %177

177:                                              ; preds = %176
  br label %178

178:                                              ; preds = %177
  br label %490

179:                                              ; preds = %152
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #11
  %180 = load ptr, ptr %6, align 8, !tbaa !5
  %181 = call ptr @node_data(ptr noundef %180) #9
  store ptr %181, ptr %12, align 8, !tbaa !5
  %182 = load ptr, ptr %8, align 8, !tbaa !5
  %183 = getelementptr inbounds %struct.inner_cursor, ptr %182, i32 0, i32 1
  %184 = getelementptr inbounds %struct.tree, ptr %183, i32 0, i32 1
  store i16 1, ptr %184, align 2, !tbaa !28
  %185 = load ptr, ptr %8, align 8, !tbaa !5
  %186 = getelementptr inbounds %struct.inner_cursor, ptr %185, i32 0, i32 1
  %187 = getelementptr inbounds %struct.tree, ptr %186, i32 0, i32 4
  store i32 0, ptr %187, align 4, !tbaa !29
  %188 = load ptr, ptr %8, align 8, !tbaa !5
  %189 = getelementptr inbounds %struct.inner_cursor, ptr %188, i32 0, i32 1
  %190 = getelementptr inbounds %struct.tree, ptr %189, i32 0, i32 5
  store i32 1, ptr %190, align 8, !tbaa !30
  %191 = load ptr, ptr %8, align 8, !tbaa !5
  %192 = getelementptr inbounds %struct.inner_cursor, ptr %191, i32 0, i32 1
  %193 = getelementptr inbounds %struct.tree, ptr %192, i32 0, i32 6
  store i32 0, ptr %193, align 4, !tbaa !31
  %194 = load ptr, ptr %12, align 8, !tbaa !5
  %195 = call i64 @page_numkeys(ptr noundef %194) #9
  %196 = load ptr, ptr %8, align 8, !tbaa !5
  %197 = getelementptr inbounds %struct.inner_cursor, ptr %196, i32 0, i32 1
  %198 = getelementptr inbounds %struct.tree, ptr %197, i32 0, i32 8
  store i64 %195, ptr %198, align 8, !tbaa !32
  %199 = load ptr, ptr %8, align 8, !tbaa !5
  %200 = getelementptr inbounds %struct.inner_cursor, ptr %199, i32 0, i32 1
  %201 = getelementptr inbounds %struct.tree, ptr %200, i32 0, i32 3
  store i32 0, ptr %201, align 8, !tbaa !33
  %202 = load ptr, ptr %7, align 8, !tbaa !5
  %203 = getelementptr inbounds %struct.page, ptr %202, i32 0, i32 0
  %204 = load i64, ptr %203, align 1, !tbaa !24
  %205 = load ptr, ptr %8, align 8, !tbaa !5
  %206 = getelementptr inbounds %struct.inner_cursor, ptr %205, i32 0, i32 1
  %207 = getelementptr inbounds %struct.tree, ptr %206, i32 0, i32 9
  store i64 %204, ptr %207, align 8, !tbaa !25
  %208 = load ptr, ptr %8, align 8, !tbaa !5
  %209 = getelementptr inbounds %struct.inner_cursor, ptr %208, i32 0, i32 0
  %210 = getelementptr inbounds %struct.MDBX_cursor, ptr %209, i32 0, i32 1
  store i16 1, ptr %210, align 4, !tbaa !22
  %211 = load ptr, ptr %12, align 8, !tbaa !5
  %212 = load ptr, ptr %8, align 8, !tbaa !5
  %213 = getelementptr inbounds %struct.inner_cursor, ptr %212, i32 0, i32 0
  %214 = getelementptr inbounds %struct.MDBX_cursor, ptr %213, i32 0, i32 9
  %215 = getelementptr inbounds [32 x ptr], ptr %214, i64 0, i64 0
  store ptr %211, ptr %215, align 8, !tbaa !5
  %216 = load ptr, ptr %8, align 8, !tbaa !5
  %217 = getelementptr inbounds %struct.inner_cursor, ptr %216, i32 0, i32 0
  %218 = getelementptr inbounds %struct.MDBX_cursor, ptr %217, i32 0, i32 10
  %219 = getelementptr inbounds [32 x i16], ptr %218, i64 0, i64 0
  store i16 0, ptr %219, align 8, !tbaa !34
  %220 = load ptr, ptr %5, align 8, !tbaa !5
  %221 = getelementptr inbounds %struct.MDBX_cursor, ptr %220, i32 0, i32 6
  %222 = load ptr, ptr %221, align 8, !tbaa !35
  %223 = getelementptr inbounds %struct.tree, ptr %222, i32 0, i32 0
  %224 = load i16, ptr %223, align 4, !tbaa !36
  %225 = call zeroext i16 @flags_db2sub(i16 noundef zeroext %224) #13
  %226 = load ptr, ptr %8, align 8, !tbaa !5
  %227 = getelementptr inbounds %struct.inner_cursor, ptr %226, i32 0, i32 1
  %228 = getelementptr inbounds %struct.tree, ptr %227, i32 0, i32 0
  store i16 %225, ptr %228, align 8, !tbaa !37
  %229 = load ptr, ptr %5, align 8, !tbaa !5
  %230 = getelementptr inbounds %struct.MDBX_cursor, ptr %229, i32 0, i32 6
  %231 = load ptr, ptr %230, align 8, !tbaa !35
  %232 = getelementptr inbounds %struct.tree, ptr %231, i32 0, i32 0
  %233 = load i16, ptr %232, align 4, !tbaa !36
  %234 = zext i16 %233 to i32
  %235 = and i32 %234, 16
  %236 = icmp ne i32 %235, 0
  br i1 %236, label %237, label %242

237:                                              ; preds = %179
  %238 = load ptr, ptr %12, align 8, !tbaa !5
  %239 = getelementptr inbounds %struct.page, ptr %238, i32 0, i32 1
  %240 = load i16, ptr %239, align 1, !tbaa !34
  %241 = zext i16 %240 to i32
  br label %243

242:                                              ; preds = %179
  br label %243

243:                                              ; preds = %242, %237
  %244 = phi i32 [ %241, %237 ], [ 0, %242 ]
  %245 = load ptr, ptr %8, align 8, !tbaa !5
  %246 = getelementptr inbounds %struct.inner_cursor, ptr %245, i32 0, i32 1
  %247 = getelementptr inbounds %struct.tree, ptr %246, i32 0, i32 2
  store i32 %244, ptr %247, align 4, !tbaa !38
  store i32 6, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #11
  br label %248

248:                                              ; preds = %243, %148
  %249 = load ptr, ptr %8, align 8, !tbaa !5
  %250 = getelementptr inbounds %struct.inner_cursor, ptr %249, i32 0, i32 1
  %251 = getelementptr inbounds %struct.tree, ptr %250, i32 0, i32 2
  %252 = load i32, ptr %251, align 4, !tbaa !38
  %253 = load ptr, ptr %5, align 8, !tbaa !5
  %254 = getelementptr inbounds %struct.MDBX_cursor, ptr %253, i32 0, i32 6
  %255 = load ptr, ptr %254, align 8, !tbaa !35
  %256 = getelementptr inbounds %struct.tree, ptr %255, i32 0, i32 2
  %257 = load i32, ptr %256, align 4, !tbaa !39
  %258 = icmp ne i32 %252, %257
  %259 = xor i1 %258, true
  %260 = xor i1 %259, true
  %261 = zext i1 %260 to i32
  %262 = sext i32 %261 to i64
  %263 = call i64 @llvm.expect.i64(i64 %262, i64 0)
  %264 = icmp ne i64 %263, 0
  br i1 %264, label %265, label %468

265:                                              ; preds = %248
  %266 = load ptr, ptr %5, align 8, !tbaa !5
  %267 = getelementptr inbounds %struct.MDBX_cursor, ptr %266, i32 0, i32 6
  %268 = load ptr, ptr %267, align 8, !tbaa !35
  %269 = getelementptr inbounds %struct.tree, ptr %268, i32 0, i32 2
  %270 = load i32, ptr %269, align 4, !tbaa !39
  %271 = icmp ne i32 %270, 0
  %272 = xor i1 %271, true
  %273 = xor i1 %272, true
  %274 = zext i1 %273 to i32
  %275 = sext i32 %274 to i64
  %276 = call i64 @llvm.expect.i64(i64 %275, i64 0)
  %277 = icmp ne i64 %276, 0
  br i1 %277, label %278, label %298

278:                                              ; preds = %265
  br label %279

279:                                              ; preds = %278
  %280 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !23
  %281 = zext i8 %280 to i32
  %282 = icmp sle i32 1, %281
  %283 = xor i1 %282, true
  %284 = xor i1 %283, true
  %285 = zext i1 %284 to i32
  %286 = sext i32 %285 to i64
  %287 = call i64 @llvm.expect.i64(i64 %286, i64 0)
  %288 = icmp ne i64 %287, 0
  br i1 %288, label %289, label %295

289:                                              ; preds = %279
  %290 = load ptr, ptr %5, align 8, !tbaa !5
  %291 = getelementptr inbounds %struct.MDBX_cursor, ptr %290, i32 0, i32 6
  %292 = load ptr, ptr %291, align 8, !tbaa !35
  %293 = getelementptr inbounds %struct.tree, ptr %292, i32 0, i32 2
  %294 = load i32, ptr %293, align 4, !tbaa !39
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.cursor_dupsort_setup, i32 noundef 368, ptr noundef @.str.33, i32 noundef %294)
  br label %295

295:                                              ; preds = %289, %279
  br label %296

296:                                              ; preds = %295
  br label %297

297:                                              ; preds = %296
  br label %490

298:                                              ; preds = %265
  %299 = load ptr, ptr %5, align 8, !tbaa !5
  %300 = getelementptr inbounds %struct.MDBX_cursor, ptr %299, i32 0, i32 6
  %301 = load ptr, ptr %300, align 8, !tbaa !35
  %302 = getelementptr inbounds %struct.tree, ptr %301, i32 0, i32 0
  %303 = load i16, ptr %302, align 4, !tbaa !36
  %304 = zext i16 %303 to i32
  %305 = and i32 %304, 16
  %306 = icmp eq i32 %305, 0
  %307 = xor i1 %306, true
  %308 = xor i1 %307, true
  %309 = zext i1 %308 to i32
  %310 = sext i32 %309 to i64
  %311 = call i64 @llvm.expect.i64(i64 %310, i64 0)
  %312 = icmp ne i64 %311, 0
  br i1 %312, label %313, label %334

313:                                              ; preds = %298
  br label %314

314:                                              ; preds = %313
  %315 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !23
  %316 = zext i8 %315 to i32
  %317 = icmp sle i32 1, %316
  %318 = xor i1 %317, true
  %319 = xor i1 %318, true
  %320 = zext i1 %319 to i32
  %321 = sext i32 %320 to i64
  %322 = call i64 @llvm.expect.i64(i64 %321, i64 0)
  %323 = icmp ne i64 %322, 0
  br i1 %323, label %324, label %331

324:                                              ; preds = %314
  %325 = load ptr, ptr %5, align 8, !tbaa !5
  %326 = getelementptr inbounds %struct.MDBX_cursor, ptr %325, i32 0, i32 6
  %327 = load ptr, ptr %326, align 8, !tbaa !35
  %328 = getelementptr inbounds %struct.tree, ptr %327, i32 0, i32 0
  %329 = load i16, ptr %328, align 4, !tbaa !36
  %330 = zext i16 %329 to i32
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.cursor_dupsort_setup, i32 noundef 372, ptr noundef @.str.34, i32 noundef %330)
  br label %331

331:                                              ; preds = %324, %314
  br label %332

332:                                              ; preds = %331
  br label %333

333:                                              ; preds = %332
  br label %490

334:                                              ; preds = %298
  %335 = load ptr, ptr %8, align 8, !tbaa !5
  %336 = getelementptr inbounds %struct.inner_cursor, ptr %335, i32 0, i32 1
  %337 = getelementptr inbounds %struct.tree, ptr %336, i32 0, i32 2
  %338 = load i32, ptr %337, align 4, !tbaa !38
  %339 = zext i32 %338 to i64
  %340 = load ptr, ptr %5, align 8, !tbaa !5
  %341 = getelementptr inbounds %struct.MDBX_cursor, ptr %340, i32 0, i32 7
  %342 = load ptr, ptr %341, align 8, !tbaa !40
  %343 = getelementptr inbounds %struct.clc2, ptr %342, i32 0, i32 1
  %344 = getelementptr inbounds %struct.clc, ptr %343, i32 0, i32 1
  %345 = load i64, ptr %344, align 8, !tbaa !41
  %346 = icmp ult i64 %339, %345
  br i1 %346, label %360, label %347

347:                                              ; preds = %334
  %348 = load ptr, ptr %8, align 8, !tbaa !5
  %349 = getelementptr inbounds %struct.inner_cursor, ptr %348, i32 0, i32 1
  %350 = getelementptr inbounds %struct.tree, ptr %349, i32 0, i32 2
  %351 = load i32, ptr %350, align 4, !tbaa !38
  %352 = zext i32 %351 to i64
  %353 = load ptr, ptr %5, align 8, !tbaa !5
  %354 = getelementptr inbounds %struct.MDBX_cursor, ptr %353, i32 0, i32 7
  %355 = load ptr, ptr %354, align 8, !tbaa !40
  %356 = getelementptr inbounds %struct.clc2, ptr %355, i32 0, i32 1
  %357 = getelementptr inbounds %struct.clc, ptr %356, i32 0, i32 2
  %358 = load i64, ptr %357, align 8, !tbaa !44
  %359 = icmp ugt i64 %352, %358
  br label %360

360:                                              ; preds = %347, %334
  %361 = phi i1 [ true, %334 ], [ %359, %347 ]
  %362 = xor i1 %361, true
  %363 = xor i1 %362, true
  %364 = zext i1 %363 to i32
  %365 = sext i32 %364 to i64
  %366 = call i64 @llvm.expect.i64(i64 %365, i64 0)
  %367 = icmp ne i64 %366, 0
  br i1 %367, label %368, label %399

368:                                              ; preds = %360
  br label %369

369:                                              ; preds = %368
  %370 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !23
  %371 = zext i8 %370 to i32
  %372 = icmp sle i32 1, %371
  %373 = xor i1 %372, true
  %374 = xor i1 %373, true
  %375 = zext i1 %374 to i32
  %376 = sext i32 %375 to i64
  %377 = call i64 @llvm.expect.i64(i64 %376, i64 0)
  %378 = icmp ne i64 %377, 0
  br i1 %378, label %379, label %396

379:                                              ; preds = %369
  %380 = load ptr, ptr %8, align 8, !tbaa !5
  %381 = getelementptr inbounds %struct.inner_cursor, ptr %380, i32 0, i32 1
  %382 = getelementptr inbounds %struct.tree, ptr %381, i32 0, i32 2
  %383 = load i32, ptr %382, align 4, !tbaa !38
  %384 = load ptr, ptr %5, align 8, !tbaa !5
  %385 = getelementptr inbounds %struct.MDBX_cursor, ptr %384, i32 0, i32 7
  %386 = load ptr, ptr %385, align 8, !tbaa !40
  %387 = getelementptr inbounds %struct.clc2, ptr %386, i32 0, i32 1
  %388 = getelementptr inbounds %struct.clc, ptr %387, i32 0, i32 1
  %389 = load i64, ptr %388, align 8, !tbaa !41
  %390 = load ptr, ptr %5, align 8, !tbaa !5
  %391 = getelementptr inbounds %struct.MDBX_cursor, ptr %390, i32 0, i32 7
  %392 = load ptr, ptr %391, align 8, !tbaa !40
  %393 = getelementptr inbounds %struct.clc2, ptr %392, i32 0, i32 1
  %394 = getelementptr inbounds %struct.clc, ptr %393, i32 0, i32 2
  %395 = load i64, ptr %394, align 8, !tbaa !44
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.cursor_dupsort_setup, i32 noundef 379, ptr noundef @.str.35, i32 noundef %383, i64 noundef %389, i64 noundef %395)
  br label %396

396:                                              ; preds = %379, %369
  br label %397

397:                                              ; preds = %396
  br label %398

398:                                              ; preds = %397
  br label %490

399:                                              ; preds = %360
  %400 = load ptr, ptr %8, align 8, !tbaa !5
  %401 = getelementptr inbounds %struct.inner_cursor, ptr %400, i32 0, i32 1
  %402 = getelementptr inbounds %struct.tree, ptr %401, i32 0, i32 2
  %403 = load i32, ptr %402, align 4, !tbaa !38
  %404 = load ptr, ptr %5, align 8, !tbaa !5
  %405 = getelementptr inbounds %struct.MDBX_cursor, ptr %404, i32 0, i32 6
  %406 = load ptr, ptr %405, align 8, !tbaa !35
  %407 = getelementptr inbounds %struct.tree, ptr %406, i32 0, i32 2
  store i32 %403, ptr %407, align 4, !tbaa !39
  %408 = load ptr, ptr %8, align 8, !tbaa !5
  %409 = getelementptr inbounds %struct.inner_cursor, ptr %408, i32 0, i32 1
  %410 = getelementptr inbounds %struct.tree, ptr %409, i32 0, i32 2
  %411 = load i32, ptr %410, align 4, !tbaa !38
  %412 = zext i32 %411 to i64
  %413 = load ptr, ptr %5, align 8, !tbaa !5
  %414 = getelementptr inbounds %struct.MDBX_cursor, ptr %413, i32 0, i32 7
  %415 = load ptr, ptr %414, align 8, !tbaa !40
  %416 = getelementptr inbounds %struct.clc2, ptr %415, i32 0, i32 1
  %417 = getelementptr inbounds %struct.clc, ptr %416, i32 0, i32 2
  store i64 %412, ptr %417, align 8, !tbaa !44
  %418 = load ptr, ptr %5, align 8, !tbaa !5
  %419 = getelementptr inbounds %struct.MDBX_cursor, ptr %418, i32 0, i32 7
  %420 = load ptr, ptr %419, align 8, !tbaa !40
  %421 = getelementptr inbounds %struct.clc2, ptr %420, i32 0, i32 1
  %422 = getelementptr inbounds %struct.clc, ptr %421, i32 0, i32 1
  store i64 %412, ptr %422, align 8, !tbaa !41
  br label %423

423:                                              ; preds = %399
  %424 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !9
  %425 = zext i8 %424 to i32
  %426 = and i32 %425, 1
  %427 = icmp ne i32 %426, 0
  %428 = xor i1 %427, true
  %429 = xor i1 %428, true
  %430 = zext i1 %429 to i32
  %431 = sext i32 %430 to i64
  %432 = call i64 @llvm.expect.i64(i64 %431, i64 1)
  %433 = icmp ne i64 %432, 0
  br i1 %433, label %434, label %465

434:                                              ; preds = %423
  br label %435

435:                                              ; preds = %434
  %436 = load ptr, ptr %5, align 8, !tbaa !5
  %437 = getelementptr inbounds %struct.MDBX_cursor, ptr %436, i32 0, i32 7
  %438 = load ptr, ptr %437, align 8, !tbaa !40
  %439 = getelementptr inbounds %struct.clc2, ptr %438, i32 0, i32 1
  %440 = getelementptr inbounds %struct.clc, ptr %439, i32 0, i32 2
  %441 = load i64, ptr %440, align 8, !tbaa !44
  %442 = load ptr, ptr %5, align 8, !tbaa !5
  %443 = getelementptr inbounds %struct.MDBX_cursor, ptr %442, i32 0, i32 7
  %444 = load ptr, ptr %443, align 8, !tbaa !40
  %445 = getelementptr inbounds %struct.clc2, ptr %444, i32 0, i32 1
  %446 = getelementptr inbounds %struct.clc, ptr %445, i32 0, i32 1
  %447 = load i64, ptr %446, align 8, !tbaa !41
  %448 = icmp uge i64 %441, %447
  %449 = xor i1 %448, true
  %450 = xor i1 %449, true
  %451 = xor i1 %450, true
  %452 = zext i1 %451 to i32
  %453 = sext i32 %452 to i64
  %454 = call i64 @llvm.expect.i64(i64 %453, i64 0)
  %455 = icmp ne i64 %454, 0
  br i1 %455, label %456, label %462

456:                                              ; preds = %435
  %457 = load ptr, ptr %5, align 8, !tbaa !5
  %458 = getelementptr inbounds %struct.MDBX_cursor, ptr %457, i32 0, i32 5
  %459 = load ptr, ptr %458, align 8, !tbaa !14
  %460 = getelementptr inbounds %struct.MDBX_txn, ptr %459, i32 0, i32 9
  %461 = load ptr, ptr %460, align 8, !tbaa !16
  call void @mdbx_assert_fail(ptr noundef %461, ptr noundef @.str.36, ptr noundef @__func__.cursor_dupsort_setup, i32 noundef 384) #10
  unreachable

462:                                              ; preds = %435
  br label %463

463:                                              ; preds = %462
  br label %464

464:                                              ; preds = %463
  br label %465

465:                                              ; preds = %464, %423
  br label %466

466:                                              ; preds = %465
  br label %467

467:                                              ; preds = %466
  br label %468

468:                                              ; preds = %467, %248
  br label %469

469:                                              ; preds = %468
  %470 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !23
  %471 = zext i8 %470 to i32
  %472 = icmp sle i32 5, %471
  %473 = xor i1 %472, true
  %474 = xor i1 %473, true
  %475 = zext i1 %474 to i32
  %476 = sext i32 %475 to i64
  %477 = call i64 @llvm.expect.i64(i64 %476, i64 0)
  %478 = icmp ne i64 %477, 0
  br i1 %478, label %479, label %487

479:                                              ; preds = %469
  %480 = load ptr, ptr %8, align 8, !tbaa !5
  %481 = getelementptr inbounds %struct.inner_cursor, ptr %480, i32 0, i32 0
  %482 = call i64 @cursor_dbi(ptr noundef %481) #9
  %483 = load ptr, ptr %8, align 8, !tbaa !5
  %484 = getelementptr inbounds %struct.inner_cursor, ptr %483, i32 0, i32 1
  %485 = getelementptr inbounds %struct.tree, ptr %484, i32 0, i32 3
  %486 = load i32, ptr %485, align 8, !tbaa !33
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef @__func__.cursor_dupsort_setup, i32 noundef 387, ptr noundef @.str.37, i64 noundef %482, i32 noundef %486)
  br label %487

487:                                              ; preds = %479, %469
  br label %488

488:                                              ; preds = %487
  br label %489

489:                                              ; preds = %488
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %494

490:                                              ; preds = %398, %333, %297, %178, %147, %107, %80
  %491 = load ptr, ptr %8, align 8, !tbaa !5
  %492 = getelementptr inbounds %struct.inner_cursor, ptr %491, i32 0, i32 0
  %493 = getelementptr inbounds %struct.MDBX_cursor, ptr %492, i32 0, i32 1
  store i16 -47, ptr %493, align 4, !tbaa !22
  store i32 -30796, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %494

494:                                              ; preds = %490, %489
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #11
  br label %495

495:                                              ; preds = %494, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #11
  %496 = load i32, ptr %4, align 4
  ret i32 %496
}

; Function Attrs: cold nounwind optsize uwtable
declare hidden i32 @unexpected_dupsort(ptr noundef) #6

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden i64 @node_ds(ptr noalias noundef) #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden ptr @node_data(ptr noalias noundef) #2

; Function Attrs: inlinehint nounwind willreturn memory(none) uwtable
declare hidden zeroext i16 @flags_db2sub(i16 noundef zeroext) #8

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = { 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 #7 = { "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 = { inlinehint nounwind willreturn memory(none) 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 #9 = { nounwind willreturn memory(read) }
attributes #10 = { noreturn }
attributes #11 = { nounwind }
attributes #12 = { cold }
attributes #13 = { nounwind willreturn memory(none) }

!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, !7, i64 25}
!10 = !{!"libmdbx_globals", !7, i64 0, !11, i64 16, !11, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !12, i64 27, !11, i64 28, !7, i64 32, !7, i64 40, !13, i64 80, !6, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"MDBX_cursor", !11, i64 0, !7, i64 4, !7, i64 6, !7, i64 7, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !7, i64 48, !7, i64 304, !6, i64 368, !6, i64 376}
!16 = !{!17, !6, i64 80}
!17 = !{!"MDBX_txn", !11, i64 0, !11, i64 4, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !18, i64 40, !13, i64 64, !13, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !20, i64 128, !6, i64 160, !7, i64 168}
!18 = !{!"geo", !19, i64 0, !19, i64 2, !11, i64 4, !11, i64 8, !7, i64 12, !7, i64 16}
!19 = !{!"short", !7, i64 0}
!20 = !{!"MDBX_canary", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!21 = !{!15, !6, i64 40}
!22 = !{!7, !7, i64 0}
!23 = !{!10, !7, i64 26}
!24 = !{!13, !13, i64 0}
!25 = !{!26, !13, i64 424}
!26 = !{!"inner_cursor", !15, i64 0, !27, i64 384}
!27 = !{!"tree", !19, i64 0, !19, i64 2, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !13, i64 24, !13, i64 32, !13, i64 40}
!28 = !{!26, !19, i64 386}
!29 = !{!26, !11, i64 396}
!30 = !{!26, !11, i64 400}
!31 = !{!26, !11, i64 404}
!32 = !{!26, !13, i64 416}
!33 = !{!26, !11, i64 392}
!34 = !{!19, !19, i64 0}
!35 = !{!15, !6, i64 24}
!36 = !{!27, !19, i64 0}
!37 = !{!26, !19, i64 384}
!38 = !{!26, !11, i64 388}
!39 = !{!27, !11, i64 4}
!40 = !{!15, !6, i64 32}
!41 = !{!42, !13, i64 32}
!42 = !{!"clc2", !43, i64 0, !43, i64 24}
!43 = !{!"clc", !6, i64 0, !13, i64 8, !13, i64 16}
!44 = !{!42, !13, i64 40}


; 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.8 }
%struct.anon.8 = 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.28 = external hidden unnamed_addr constant [15 x i8], align 1
@__func__.cursor_dupsort_setup = external hidden unnamed_addr constant [21 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [73 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [30 x i8], align 1

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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden zeroext i1 @is_pointed(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden zeroext i8 @node_flags(ptr noalias noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress 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) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @cursor_dupsort_setup(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %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 %13, label %6, !prof !13

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

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %10, i64 80
  %12 = load ptr, ptr %11, align 8, !tbaa !17
  tail call void @mdbx_assert_fail(ptr noundef %12, ptr noundef nonnull @.str.28, ptr noundef nonnull @__func__.cursor_dupsort_setup, i32 noundef 322) #8
  unreachable

13:                                               ; preds = %3, %6
  %14 = getelementptr inbounds i8, ptr %0, i64 40
  %15 = load ptr, ptr %14, align 8, !tbaa !22
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %19, !prof !13

17:                                               ; preds = %13
  %18 = tail call i32 @unexpected_dupsort(ptr noundef nonnull %0) #9
  br label %121

19:                                               ; preds = %13
  %20 = tail call zeroext i8 @node_flags(ptr noundef %1) #7
  %21 = zext i8 %20 to i32
  switch i8 %20, label %22 [
    i8 6, label %25
    i8 4, label %42
  ]

22:                                               ; preds = %19
  %23 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !23
  %.not83 = icmp eq i8 %23, 0
  br i1 %.not83, label %119, label %24, !prof !14

24:                                               ; preds = %22
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.cursor_dupsort_setup, i32 noundef 330, ptr noundef nonnull @.str.29, i32 noundef %21) #10
  br label %119

25:                                               ; preds = %19
  %26 = tail call i64 @node_ds(ptr noundef %1) #7
  %.not73 = icmp eq i64 %26, 48
  br i1 %.not73, label %30, label %27, !prof !14

27:                                               ; preds = %25
  %28 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !23
  %.not82 = icmp eq i8 %28, 0
  br i1 %.not82, label %119, label %29, !prof !14

29:                                               ; preds = %27
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.cursor_dupsort_setup, i32 noundef 334, ptr noundef nonnull @.str.30, i64 noundef %26, i64 noundef 48) #10
  br label %119

30:                                               ; preds = %25
  %31 = getelementptr inbounds i8, ptr %15, i64 384
  %32 = tail call ptr @node_data(ptr noundef %1) #7
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %31, ptr noundef nonnull align 1 dereferenceable(48) %32, i64 48, i1 false)
  %33 = load i64, ptr %2, align 1, !tbaa !24
  %34 = getelementptr inbounds i8, ptr %15, i64 424
  %35 = load i64, ptr %34, align 8, !tbaa !25
  %36 = icmp ugt i64 %35, %33
  br i1 %36, label %37, label %40, !prof !13

37:                                               ; preds = %30
  %38 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !23
  %.not81 = icmp eq i8 %38, 0
  br i1 %.not81, label %119, label %39, !prof !14

39:                                               ; preds = %37
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.cursor_dupsort_setup, i32 noundef 340, ptr noundef nonnull @.str.31, i64 noundef %35, i64 noundef %33) #10
  br label %119

40:                                               ; preds = %30
  %41 = getelementptr inbounds i8, ptr %15, i64 4
  store i16 -43, ptr %41, align 4, !tbaa !28
  %.phi.trans.insert = getelementptr inbounds i8, ptr %15, i64 388
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !29
  %.phi.trans.insert84 = getelementptr inbounds i8, ptr %0, i64 24
  %.pre85 = load ptr, ptr %.phi.trans.insert84, align 8, !tbaa !30
  br label %76

42:                                               ; preds = %19
  %43 = tail call i64 @node_ds(ptr noundef %1) #7
  %44 = icmp ult i64 %43, 21
  br i1 %44, label %45, label %48, !prof !13

45:                                               ; preds = %42
  %46 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !23
  %.not72 = icmp eq i8 %46, 0
  br i1 %.not72, label %119, label %47, !prof !14

47:                                               ; preds = %45
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.cursor_dupsort_setup, i32 noundef 347, ptr noundef nonnull @.str.32, i64 noundef %43) #10
  br label %119

48:                                               ; preds = %42
  %49 = tail call ptr @node_data(ptr noundef %1) #7
  %50 = getelementptr inbounds i8, ptr %15, i64 384
  %51 = getelementptr inbounds i8, ptr %15, i64 386
  store i16 1, ptr %51, align 2, !tbaa !31
  %52 = getelementptr inbounds i8, ptr %15, i64 396
  store i32 0, ptr %52, align 4, !tbaa !32
  %53 = getelementptr inbounds i8, ptr %15, i64 400
  store i32 1, ptr %53, align 8, !tbaa !33
  %54 = getelementptr inbounds i8, ptr %15, i64 404
  store i32 0, ptr %54, align 4, !tbaa !34
  %55 = tail call i64 @page_numkeys(ptr noundef %49) #7
  %56 = getelementptr inbounds i8, ptr %15, i64 416
  store i64 %55, ptr %56, align 8, !tbaa !35
  %57 = getelementptr inbounds i8, ptr %15, i64 392
  store i32 0, ptr %57, align 8, !tbaa !36
  %58 = load i64, ptr %2, align 1, !tbaa !24
  %59 = getelementptr inbounds i8, ptr %15, i64 424
  store i64 %58, ptr %59, align 8, !tbaa !25
  %60 = getelementptr inbounds i8, ptr %15, i64 4
  store i16 1, ptr %60, align 4, !tbaa !28
  %61 = getelementptr inbounds i8, ptr %15, i64 48
  store ptr %49, ptr %61, align 8, !tbaa !37
  %62 = getelementptr inbounds i8, ptr %15, i64 304
  store i16 0, ptr %62, align 8, !tbaa !38
  %63 = getelementptr inbounds i8, ptr %0, i64 24
  %64 = load ptr, ptr %63, align 8, !tbaa !30
  %65 = load i16, ptr %64, align 4, !tbaa !39
  %66 = tail call zeroext i16 @flags_db2sub(i16 noundef zeroext %65) #11
  store i16 %66, ptr %50, align 8, !tbaa !40
  %67 = load i16, ptr %64, align 4, !tbaa !39
  %68 = and i16 %67, 16
  %.not71 = icmp eq i16 %68, 0
  br i1 %.not71, label %73, label %69

69:                                               ; preds = %48
  %70 = getelementptr inbounds i8, ptr %49, i64 8
  %71 = load i16, ptr %70, align 1, !tbaa !38
  %72 = zext i16 %71 to i32
  br label %73

73:                                               ; preds = %48, %69
  %74 = phi i32 [ %72, %69 ], [ 0, %48 ]
  %75 = getelementptr inbounds i8, ptr %15, i64 388
  store i32 %74, ptr %75, align 4, !tbaa !29
  br label %76

76:                                               ; preds = %73, %40
  %77 = phi ptr [ %64, %73 ], [ %.pre85, %40 ]
  %78 = phi i32 [ %74, %73 ], [ %.pre, %40 ]
  %79 = getelementptr inbounds i8, ptr %15, i64 388
  %80 = getelementptr inbounds i8, ptr %77, i64 4
  %81 = load i32, ptr %80, align 4, !tbaa !41
  %.not74 = icmp eq i32 %78, %81
  br i1 %.not74, label %112, label %82, !prof !14

82:                                               ; preds = %76
  %.not75 = icmp eq i32 %81, 0
  br i1 %.not75, label %86, label %83, !prof !14

83:                                               ; preds = %82
  %84 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !23
  %.not80 = icmp eq i8 %84, 0
  br i1 %.not80, label %119, label %85, !prof !14

85:                                               ; preds = %83
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.cursor_dupsort_setup, i32 noundef 368, ptr noundef nonnull @.str.33, i32 noundef %81) #10
  br label %119

86:                                               ; preds = %82
  %87 = load i16, ptr %77, align 4, !tbaa !39
  %88 = zext i16 %87 to i32
  %89 = and i32 %88, 16
  %90 = icmp eq i32 %89, 0
  br i1 %90, label %91, label %94, !prof !13

91:                                               ; preds = %86
  %92 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !23
  %.not79 = icmp eq i8 %92, 0
  br i1 %.not79, label %119, label %93, !prof !14

93:                                               ; preds = %91
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.cursor_dupsort_setup, i32 noundef 372, ptr noundef nonnull @.str.34, i32 noundef %88) #10
  br label %119

94:                                               ; preds = %86
  %95 = zext i32 %78 to i64
  %96 = getelementptr inbounds i8, ptr %0, i64 32
  %97 = load ptr, ptr %96, align 8, !tbaa !42
  %98 = getelementptr inbounds i8, ptr %97, i64 32
  %99 = load i64, ptr %98, align 8, !tbaa !43
  %100 = icmp ugt i64 %99, %95
  br i1 %100, label %.critedge, label %101, !prof !13

101:                                              ; preds = %94
  %102 = getelementptr inbounds i8, ptr %97, i64 40
  %103 = load i64, ptr %102, align 8, !tbaa !46
  %104 = icmp ult i64 %103, %95
  br i1 %104, label %.critedge, label %109, !prof !13

.critedge:                                        ; preds = %94, %101
  %105 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !23
  %.not78 = icmp eq i8 %105, 0
  br i1 %.not78, label %119, label %106, !prof !14

106:                                              ; preds = %.critedge
  %107 = getelementptr inbounds i8, ptr %97, i64 40
  %108 = load i64, ptr %107, align 8, !tbaa !46
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.cursor_dupsort_setup, i32 noundef 379, ptr noundef nonnull @.str.35, i32 noundef %78, i64 noundef %99, i64 noundef %108) #10
  br label %119

109:                                              ; preds = %101
  store i32 %78, ptr %80, align 4, !tbaa !41
  %110 = load i32, ptr %79, align 4, !tbaa !29
  %111 = zext i32 %110 to i64
  store i64 %111, ptr %102, align 8, !tbaa !46
  store i64 %111, ptr %98, align 8, !tbaa !43
  br label %112

112:                                              ; preds = %109, %76
  %113 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !23
  %114 = icmp ugt i8 %113, 4
  br i1 %114, label %115, label %121, !prof !13

115:                                              ; preds = %112
  %116 = tail call i64 @cursor_dbi(ptr noundef nonnull %15) #7
  %117 = getelementptr inbounds i8, ptr %15, i64 392
  %118 = load i32, ptr %117, align 8, !tbaa !36
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef nonnull @__func__.cursor_dupsort_setup, i32 noundef 387, ptr noundef nonnull @.str.37, i64 noundef %116, i32 noundef %118) #10
  br label %121

119:                                              ; preds = %.critedge, %106, %91, %93, %83, %85, %45, %47, %37, %39, %27, %29, %22, %24
  %120 = getelementptr inbounds i8, ptr %15, i64 4
  store i16 -47, ptr %120, align 4, !tbaa !28
  br label %121

121:                                              ; preds = %119, %115, %112, %17
  %.1 = phi i32 [ %18, %17 ], [ -30796, %119 ], [ 0, %115 ], [ 0, %112 ]
  ret i32 %.1
}

; Function Attrs: cold nounwind optsize uwtable
declare hidden i32 @unexpected_dupsort(ptr noundef) local_unnamed_addr #4

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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden i64 @node_ds(ptr noalias noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden ptr @node_data(ptr noalias noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare hidden zeroext i16 @flags_db2sub(i16 noundef zeroext) local_unnamed_addr #6

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

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 25}
!6 = !{!"libmdbx_globals", !7, i64 0, !9, i64 16, !9, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !10, i64 27, !9, i64 28, !7, i64 32, !7, i64 40, !11, i64 80, !12, i64 88}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!14 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!15 = !{!16, !12, i64 16}
!16 = !{!"MDBX_cursor", !9, i64 0, !7, i64 4, !7, i64 6, !7, i64 7, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !7, i64 48, !7, i64 304, !12, i64 368, !12, i64 376}
!17 = !{!18, !12, i64 80}
!18 = !{!"MDBX_txn", !9, i64 0, !9, i64 4, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 32, !19, i64 40, !11, i64 64, !11, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !21, i64 128, !12, i64 160, !7, i64 168}
!19 = !{!"geo", !20, i64 0, !20, i64 2, !9, i64 4, !9, i64 8, !7, i64 12, !7, i64 16}
!20 = !{!"short", !7, i64 0}
!21 = !{!"MDBX_canary", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!22 = !{!16, !12, i64 40}
!23 = !{!6, !7, i64 26}
!24 = !{!11, !11, i64 0}
!25 = !{!26, !11, i64 424}
!26 = !{!"inner_cursor", !16, i64 0, !27, i64 384}
!27 = !{!"tree", !20, i64 0, !20, i64 2, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !9, i64 20, !11, i64 24, !11, i64 32, !11, i64 40}
!28 = !{!7, !7, i64 0}
!29 = !{!26, !9, i64 388}
!30 = !{!16, !12, i64 24}
!31 = !{!26, !20, i64 386}
!32 = !{!26, !9, i64 396}
!33 = !{!26, !9, i64 400}
!34 = !{!26, !9, i64 404}
!35 = !{!26, !11, i64 416}
!36 = !{!26, !9, i64 392}
!37 = !{!12, !12, i64 0}
!38 = !{!20, !20, i64 0}
!39 = !{!27, !20, i64 0}
!40 = !{!26, !20, i64 384}
!41 = !{!27, !9, i64 4}
!42 = !{!16, !12, i64 32}
!43 = !{!44, !11, i64 32}
!44 = !{!"clc2", !45, i64 0, !45, i64 24}
!45 = !{!"clc", !12, i64 0, !11, i64 8, !11, i64 16}
!46 = !{!44, !11, i64 40}


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