; LLVM IR from erthink/libmdbx :: src (api-range-estimate)

; 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.cursor_couple = type { %struct.MDBX_cursor, ptr, %struct.inner_cursor }
%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.inner_cursor = type { %struct.MDBX_cursor, %struct.tree }
%struct.tree = type { i16, i16, i32, i32, i32, i32, i32, i64, i64, i64 }
%struct.iovec = type { ptr, i64 }
%struct.anon.1 = type { i8, i8 }

@__func__.mdbx_estimate_move = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: hot nounwind uwtable
declare dso_local i32 @mdbx_estimate_distance(ptr noundef, ptr noundef, ptr noundef) #0

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @log_if_error(i32 noundef, ptr noundef, i32 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: hot nounwind uwtable
define dso_local i32 @mdbx_estimate_move(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca %struct.cursor_couple, align 8
  %15 = alloca ptr, align 8
  %16 = alloca %struct.iovec, align 8
  %17 = alloca i32, align 4
  %18 = alloca %struct.iovec, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %28

22:                                               ; preds = %5
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 4
  br i1 %24, label %28, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 5
  br label %28

28:                                               ; preds = %25, %22, %5
  %29 = phi i1 [ true, %22 ], [ true, %5 ], [ %27, %25 ]
  %30 = xor i1 %29, true
  %31 = xor i1 %30, true
  %32 = zext i1 %31 to i32
  %33 = sext i32 %32 to i64
  %34 = call i64 @llvm.expect.i64(i64 %33, i64 0)
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %28
  %37 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_estimate_move, i32 noundef 178)
  store i32 %37, ptr %6, align 4
  br label %206

38:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = call i32 @cursor_check_ro(ptr noundef %39)
  store i32 %40, ptr %12, align 4, !tbaa !9
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = icmp ne i32 %41, 0
  %43 = xor i1 %42, true
  %44 = xor i1 %43, true
  %45 = zext i1 %44 to i32
  %46 = sext i32 %45 to i64
  %47 = call i64 @llvm.expect.i64(i64 %46, i64 0)
  %48 = icmp ne i64 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %38
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = call i32 @log_if_error(i32 noundef %50, ptr noundef @__func__.mdbx_estimate_move, i32 noundef 182)
  store i32 %51, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %205

52:                                               ; preds = %38
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = call zeroext i1 @is_pointed(ptr noundef %53) #7
  %55 = xor i1 %54, true
  %56 = xor i1 %55, true
  %57 = xor i1 %56, true
  %58 = zext i1 %57 to i32
  %59 = sext i32 %58 to i64
  %60 = call i64 @llvm.expect.i64(i64 %59, i64 0)
  %61 = icmp ne i64 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %52
  %63 = call i32 @log_if_error(i32 noundef 61, ptr noundef @__func__.mdbx_estimate_move, i32 noundef 185)
  store i32 %63, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %205

64:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 824, ptr %14) #6
  %65 = getelementptr inbounds %struct.cursor_couple, ptr %14, i32 0, i32 0
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.MDBX_cursor, ptr %66, i32 0, i32 5
  %68 = load ptr, ptr %67, align 8, !tbaa !11
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = call i64 @cursor_dbi(ptr noundef %69) #7
  %71 = call i32 @cursor_init(ptr noundef %65, ptr noundef %68, i64 noundef %70)
  store i32 %71, ptr %12, align 4, !tbaa !9
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = icmp ne i32 %72, 0
  %74 = xor i1 %73, true
  %75 = xor i1 %74, true
  %76 = zext i1 %75 to i32
  %77 = sext i32 %76 to i64
  %78 = call i64 @llvm.expect.i64(i64 %77, i64 0)
  %79 = icmp ne i64 %78, 0
  br i1 %79, label %80, label %83

80:                                               ; preds = %64
  %81 = load i32, ptr %12, align 4, !tbaa !9
  %82 = call i32 @log_if_error(i32 noundef %81, ptr noundef @__func__.mdbx_estimate_move, i32 noundef 190)
  store i32 %82, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %204

83:                                               ; preds = %64
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.cursor_couple, ptr %14, i32 0, i32 0
  %86 = call ptr @cursor_cpstk(ptr noundef %84, ptr noundef %85)
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.MDBX_cursor, ptr %87, i32 0, i32 6
  %89 = load ptr, ptr %88, align 8, !tbaa !13
  %90 = getelementptr inbounds %struct.tree, ptr %89, i32 0, i32 0
  %91 = load i16, ptr %90, align 4, !tbaa !14
  %92 = zext i16 %91 to i32
  %93 = and i32 %92, 4
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %95, label %104

95:                                               ; preds = %83
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = getelementptr inbounds i8, ptr %96, i64 0
  %98 = getelementptr inbounds %struct.cursor_couple, ptr %97, i32 0, i32 2
  store ptr %98, ptr %15, align 8, !tbaa !5
  %99 = load ptr, ptr %15, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.inner_cursor, ptr %99, i32 0, i32 0
  %101 = getelementptr inbounds %struct.cursor_couple, ptr %14, i32 0, i32 2
  %102 = getelementptr inbounds %struct.inner_cursor, ptr %101, i32 0, i32 0
  %103 = call ptr @cursor_cpstk(ptr noundef %100, ptr noundef %102)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  br label %104

104:                                              ; preds = %95, %83
  call void @llvm.lifetime.start.p0(i64 16, ptr %16) #6
  %105 = load ptr, ptr %9, align 8, !tbaa !5
  %106 = icmp eq ptr %105, null
  br i1 %106, label %107, label %126

107:                                              ; preds = %104
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  store i32 65548, ptr %17, align 4, !tbaa !9
  %108 = load i32, ptr %10, align 4, !tbaa !9
  %109 = shl i32 1, %108
  %110 = and i32 65548, %109
  %111 = icmp ne i32 %110, 0
  %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 %120

118:                                              ; preds = %107
  %119 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_estimate_move, i32 noundef 202)
  store i32 %119, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %123

120:                                              ; preds = %107
  %121 = getelementptr inbounds %struct.iovec, ptr %16, i32 0, i32 0
  store ptr null, ptr %121, align 8, !tbaa !18
  %122 = getelementptr inbounds %struct.iovec, ptr %16, i32 0, i32 1
  store i64 0, ptr %122, align 8, !tbaa !20
  store ptr %16, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %13, align 4
  br label %123

123:                                              ; preds = %120, %118
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  %124 = load i32, ptr %13, align 4
  switch i32 %124, label %203 [
    i32 0, label %125
  ]

125:                                              ; preds = %123
  br label %126

126:                                              ; preds = %125, %104
  call void @llvm.lifetime.start.p0(i64 16, ptr %18) #6
  %127 = load ptr, ptr %8, align 8, !tbaa !5
  %128 = icmp eq ptr %127, null
  br i1 %128, label %129, label %148

129:                                              ; preds = %126
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #6
  store i32 229388, ptr %19, align 4, !tbaa !9
  %130 = load i32, ptr %10, align 4, !tbaa !9
  %131 = shl i32 1, %130
  %132 = and i32 229388, %131
  %133 = icmp ne i32 %132, 0
  %134 = xor i1 %133, true
  %135 = xor i1 %134, true
  %136 = zext i1 %135 to i32
  %137 = sext i32 %136 to i64
  %138 = call i64 @llvm.expect.i64(i64 %137, i64 0)
  %139 = icmp ne i64 %138, 0
  br i1 %139, label %140, label %142

140:                                              ; preds = %129
  %141 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_estimate_move, i32 noundef 213)
  store i32 %141, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %145

142:                                              ; preds = %129
  %143 = getelementptr inbounds %struct.iovec, ptr %18, i32 0, i32 0
  store ptr null, ptr %143, align 8, !tbaa !18
  %144 = getelementptr inbounds %struct.iovec, ptr %18, i32 0, i32 1
  store i64 0, ptr %144, align 8, !tbaa !20
  store ptr %18, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %13, align 4
  br label %145

145:                                              ; preds = %142, %140
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #6
  %146 = load i32, ptr %13, align 4
  switch i32 %146, label %202 [
    i32 0, label %147
  ]

147:                                              ; preds = %145
  br label %148

148:                                              ; preds = %147, %126
  %149 = getelementptr inbounds %struct.cursor_couple, ptr %14, i32 0, i32 0
  %150 = getelementptr inbounds %struct.MDBX_cursor, ptr %149, i32 0, i32 0
  store i32 2114311601, ptr %150, align 8, !tbaa !21
  %151 = getelementptr inbounds %struct.cursor_couple, ptr %14, i32 0, i32 0
  %152 = load ptr, ptr %8, align 8, !tbaa !5
  %153 = load ptr, ptr %9, align 8, !tbaa !5
  %154 = load i32, ptr %10, align 4, !tbaa !9
  %155 = call i32 @cursor_ops(ptr noundef %151, ptr noundef %152, ptr noundef %153, i32 noundef %154)
  store i32 %155, ptr %12, align 4, !tbaa !9
  %156 = load i32, ptr %12, align 4, !tbaa !9
  %157 = icmp ne i32 %156, 0
  br i1 %157, label %158, label %167

158:                                              ; preds = %148
  %159 = load i32, ptr %12, align 4, !tbaa !9
  %160 = icmp ne i32 %159, -30798
  br i1 %160, label %165, label %161

161:                                              ; preds = %158
  %162 = getelementptr inbounds %struct.cursor_couple, ptr %14, i32 0, i32 0
  %163 = call zeroext i1 @is_pointed(ptr noundef %162) #7
  %164 = xor i1 %163, true
  br label %165

165:                                              ; preds = %161, %158
  %166 = phi i1 [ true, %158 ], [ %164, %161 ]
  br label %167

167:                                              ; preds = %165, %148
  %168 = phi i1 [ false, %148 ], [ %166, %165 ]
  %169 = xor i1 %168, true
  %170 = xor i1 %169, true
  %171 = zext i1 %170 to i32
  %172 = sext i32 %171 to i64
  %173 = call i64 @llvm.expect.i64(i64 %172, i64 0)
  %174 = icmp ne i64 %173, 0
  br i1 %174, label %175, label %178

175:                                              ; preds = %167
  %176 = load i32, ptr %12, align 4, !tbaa !9
  %177 = call i32 @log_if_error(i32 noundef %176, ptr noundef @__func__.mdbx_estimate_move, i32 noundef 222)
  store i32 %177, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %202

178:                                              ; preds = %167
  %179 = load i32, ptr %10, align 4, !tbaa !9
  %180 = icmp eq i32 %179, 6
  br i1 %180, label %181, label %197

181:                                              ; preds = %178
  %182 = getelementptr inbounds %struct.cursor_couple, ptr %14, i32 0, i32 0
  %183 = getelementptr inbounds %struct.MDBX_cursor, ptr %182, i32 0, i32 1
  %184 = getelementptr inbounds %struct.anon.1, ptr %183, i32 0, i32 0
  %185 = load i8, ptr %184, align 4, !tbaa !24
  %186 = sext i8 %185 to i32
  %187 = or i32 %186, 64
  %188 = trunc i32 %187 to i8
  store i8 %188, ptr %184, align 4, !tbaa !24
  %189 = getelementptr inbounds %struct.cursor_couple, ptr %14, i32 0, i32 2
  %190 = getelementptr inbounds %struct.inner_cursor, ptr %189, i32 0, i32 0
  %191 = getelementptr inbounds %struct.MDBX_cursor, ptr %190, i32 0, i32 1
  %192 = getelementptr inbounds %struct.anon.1, ptr %191, i32 0, i32 0
  %193 = load i8, ptr %192, align 4, !tbaa !24
  %194 = sext i8 %193 to i32
  %195 = or i32 %194, 64
  %196 = trunc i32 %195 to i8
  store i8 %196, ptr %192, align 4, !tbaa !24
  br label %197

197:                                              ; preds = %181, %178
  %198 = load ptr, ptr %7, align 8, !tbaa !5
  %199 = getelementptr inbounds %struct.cursor_couple, ptr %14, i32 0, i32 0
  %200 = load ptr, ptr %11, align 8, !tbaa !5
  %201 = call i32 @mdbx_estimate_distance(ptr noundef %198, ptr noundef %199, ptr noundef %200) #8
  store i32 %201, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %202

202:                                              ; preds = %197, %175, %145
  call void @llvm.lifetime.end.p0(i64 16, ptr %18) #6
  br label %203

203:                                              ; preds = %202, %123
  call void @llvm.lifetime.end.p0(i64 16, ptr %16) #6
  br label %204

204:                                              ; preds = %203, %80
  call void @llvm.lifetime.end.p0(i64 824, ptr %14) #6
  br label %205

205:                                              ; preds = %204, %62, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %206

206:                                              ; preds = %205, %36
  %207 = load i32, ptr %6, align 4
  ret i32 %207
}

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

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

declare i32 @cursor_init(ptr noundef, ptr noundef, i64 noundef) #5

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

declare ptr @cursor_cpstk(ptr noundef, ptr noundef) #5

declare i32 @cursor_ops(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #5

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

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"MDBX_cursor", !10, 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}
!13 = !{!12, !6, i64 24}
!14 = !{!15, !16, i64 0}
!15 = !{!"tree", !16, i64 0, !16, i64 2, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !17, i64 24, !17, i64 32, !17, i64 40}
!16 = !{!"short", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !6, i64 0}
!19 = !{!"iovec", !6, i64 0, !17, i64 8}
!20 = !{!19, !17, i64 8}
!21 = !{!22, !10, i64 0}
!22 = !{!"cursor_couple", !12, i64 0, !6, i64 384, !23, i64 392}
!23 = !{!"inner_cursor", !12, i64 0, !15, i64 384}
!24 = !{!7, !7, i64 0}


; 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.cursor_couple = type { %struct.MDBX_cursor, ptr, %struct.inner_cursor }
%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.inner_cursor = type { %struct.MDBX_cursor, %struct.tree }
%struct.tree = type { i16, i16, i32, i32, i32, i32, i32, i64, i64, i64 }
%struct.iovec = type { ptr, i64 }

@__func__.mdbx_estimate_move = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: hot nounwind uwtable
declare dso_local i32 @mdbx_estimate_distance(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: hot nounwind uwtable
define dso_local i32 @mdbx_estimate_move(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca %struct.cursor_couple, align 8
  %7 = alloca %struct.iovec, align 8
  %8 = alloca %struct.iovec, align 8
  %9 = icmp eq ptr %4, null
  %10 = and i32 %3, -2
  %11 = icmp eq i32 %10, 4
  %spec.select = or i1 %9, %11
  br i1 %spec.select, label %12, label %14, !prof !5

12:                                               ; preds = %5
  %13 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_estimate_move, i32 noundef 178)
  br label %71

14:                                               ; preds = %5
  %15 = tail call i32 @cursor_check_ro(ptr noundef %0)
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %18, label %16, !prof !6

16:                                               ; preds = %14
  %17 = tail call i32 @log_if_error(i32 noundef %15, ptr noundef nonnull @__func__.mdbx_estimate_move, i32 noundef 182)
  br label %71

18:                                               ; preds = %14
  %19 = tail call zeroext i1 @is_pointed(ptr noundef %0) #6
  br i1 %19, label %22, label %20, !prof !6

20:                                               ; preds = %18
  %21 = tail call i32 @log_if_error(i32 noundef 61, ptr noundef nonnull @__func__.mdbx_estimate_move, i32 noundef 185)
  br label %71

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 824, ptr nonnull %6) #7
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !7
  %25 = tail call i64 @cursor_dbi(ptr noundef %0) #6
  %26 = call i32 @cursor_init(ptr noundef nonnull %6, ptr noundef %24, i64 noundef %25) #7
  %.not46 = icmp eq i32 %26, 0
  br i1 %.not46, label %29, label %27, !prof !6

27:                                               ; preds = %22
  %28 = call i32 @log_if_error(i32 noundef %26, ptr noundef nonnull @__func__.mdbx_estimate_move, i32 noundef 190)
  br label %70

29:                                               ; preds = %22
  %30 = call ptr @cursor_cpstk(ptr noundef nonnull %0, ptr noundef nonnull %6) #7
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load i16, ptr %32, align 4, !tbaa !14
  %34 = and i16 %33, 4
  %.not47 = icmp eq i16 %34, 0
  br i1 %.not47, label %39, label %35

35:                                               ; preds = %29
  %36 = getelementptr inbounds i8, ptr %0, i64 392
  %37 = getelementptr inbounds i8, ptr %6, i64 392
  %38 = call ptr @cursor_cpstk(ptr noundef nonnull %36, ptr noundef nonnull %37) #7
  br label %39

39:                                               ; preds = %35, %29
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #7
  %40 = icmp eq ptr %2, null
  br i1 %40, label %41, label %46

41:                                               ; preds = %39
  %42 = shl nuw i32 1, %3
  %43 = and i32 %42, 65548
  %.not48 = icmp eq i32 %43, 0
  br i1 %.not48, label %.thread, label %44, !prof !6

.thread:                                          ; preds = %41
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %7, i8 0, i64 16, i1 false)
  br label %46

44:                                               ; preds = %41
  %45 = call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_estimate_move, i32 noundef 202)
  br label %69

46:                                               ; preds = %.thread, %39
  %.135 = phi ptr [ %2, %39 ], [ %7, %.thread ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #7
  %47 = icmp eq ptr %1, null
  br i1 %47, label %48, label %53

48:                                               ; preds = %46
  %49 = shl nuw i32 1, %3
  %50 = and i32 %49, 229388
  %.not49 = icmp eq i32 %50, 0
  br i1 %.not49, label %.thread56, label %51, !prof !6

.thread56:                                        ; preds = %48
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %8, i8 0, i64 16, i1 false)
  br label %53

51:                                               ; preds = %48
  %52 = call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_estimate_move, i32 noundef 213)
  br label %68

53:                                               ; preds = %.thread56, %46
  %.133 = phi ptr [ %1, %46 ], [ %8, %.thread56 ]
  store i32 2114311601, ptr %6, align 8, !tbaa !18
  %54 = call i32 @cursor_ops(ptr noundef nonnull %6, ptr noundef nonnull %.133, ptr noundef nonnull %.135, i32 noundef %3) #7
  switch i32 %54, label %.fold.split [
    i32 0, label %.critedge
    i32 -30798, label %55
  ]

55:                                               ; preds = %53
  %56 = call zeroext i1 @is_pointed(ptr noundef nonnull %6) #6
  br i1 %56, label %.critedge, label %.fold.split, !prof !6

.fold.split:                                      ; preds = %53, %55
  %57 = call i32 @log_if_error(i32 noundef %54, ptr noundef nonnull @__func__.mdbx_estimate_move, i32 noundef 222)
  br label %68

.critedge:                                        ; preds = %53, %55
  %58 = icmp eq i32 %3, 6
  br i1 %58, label %59, label %66

59:                                               ; preds = %.critedge
  %60 = getelementptr inbounds i8, ptr %6, i64 4
  %61 = load i8, ptr %60, align 4, !tbaa !21
  %62 = or i8 %61, 64
  store i8 %62, ptr %60, align 4, !tbaa !21
  %63 = getelementptr inbounds i8, ptr %6, i64 396
  %64 = load i8, ptr %63, align 4, !tbaa !21
  %65 = or i8 %64, 64
  store i8 %65, ptr %63, align 4, !tbaa !21
  br label %66

66:                                               ; preds = %59, %.critedge
  %67 = call i32 @mdbx_estimate_distance(ptr noundef nonnull %0, ptr noundef nonnull %6, ptr noundef nonnull %4) #8
  br label %68

68:                                               ; preds = %51, %66, %.fold.split
  %.3 = phi i32 [ %57, %.fold.split ], [ %67, %66 ], [ %52, %51 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #7
  br label %69

69:                                               ; preds = %44, %68
  %.4 = phi i32 [ %.3, %68 ], [ %45, %44 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #7
  br label %70

70:                                               ; preds = %69, %27
  %.5 = phi i32 [ %28, %27 ], [ %.4, %69 ]
  call void @llvm.lifetime.end.p0(i64 824, ptr nonnull %6) #7
  br label %71

71:                                               ; preds = %16, %20, %70, %12
  %.7 = phi i32 [ %13, %12 ], [ %17, %16 ], [ %21, %20 ], [ %.5, %70 ]
  ret i32 %.7
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cursor_check_ro(ptr noundef) local_unnamed_addr #1

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

declare i32 @cursor_init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #4

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

declare ptr @cursor_cpstk(ptr noundef, ptr noundef) local_unnamed_addr #4

declare i32 @cursor_ops(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!7 = !{!8, !12, i64 16}
!8 = !{!"MDBX_cursor", !9, i64 0, !10, i64 4, !10, i64 6, !10, i64 7, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !10, i64 48, !10, i64 304, !12, i64 368, !12, i64 376}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"any pointer", !10, i64 0}
!13 = !{!8, !12, i64 24}
!14 = !{!15, !16, i64 0}
!15 = !{!"tree", !16, i64 0, !16, i64 2, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !9, i64 20, !17, i64 24, !17, i64 32, !17, i64 40}
!16 = !{!"short", !10, i64 0}
!17 = !{!"long", !10, i64 0}
!18 = !{!19, !9, i64 0}
!19 = !{!"cursor_couple", !8, i64 0, !12, i64 384, !20, i64 392}
!20 = !{!"inner_cursor", !8, i64 0, !15, i64 384}
!21 = !{!10, !10, i64 0}


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