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

; 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.0 }
%struct.anon.0 = 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.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 = type { i8, i8 }

@__func__.mdbx_dbi_dupsort_depthmask = external hidden unnamed_addr constant [27 x i8], align 1
@globals = external global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_dbi_dupsort_depthmask(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.cursor_couple, align 8
  %11 = alloca %struct.iovec, align 8
  %12 = alloca %struct.iovec, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  %18 = xor i1 %17, true
  %19 = xor i1 %18, true
  %20 = xor i1 %19, true
  %21 = zext i1 %20 to i32
  %22 = sext i32 %21 to i64
  %23 = call i64 @llvm.expect.i64(i64 %22, i64 0)
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %3
  %26 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 8)
  store i32 %26, ptr %4, align 4
  br label %156

27:                                               ; preds = %3
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %28, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call i32 @check_txn(ptr noundef %29, i32 noundef 51)
  store i32 %30, ptr %8, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = icmp ne i32 %31, 0
  %33 = xor i1 %32, true
  %34 = xor i1 %33, true
  %35 = zext i1 %34 to i32
  %36 = sext i32 %35 to i64
  %37 = call i64 @llvm.expect.i64(i64 %36, i64 0)
  %38 = icmp ne i64 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %27
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = call i32 @log_if_error(i32 noundef %40, ptr noundef @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 13)
  store i32 %41, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %155

42:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 824, ptr %10) #7
  %43 = getelementptr inbounds %struct.cursor_couple, ptr %10, i32 0, i32 0
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = call i32 @cursor_init(ptr noundef %43, ptr noundef %44, i64 noundef %46)
  store i32 %47, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  %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 = %42
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = call i32 @log_if_error(i32 noundef %57, ptr noundef @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 18)
  store i32 %58, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %154

59:                                               ; preds = %42
  %60 = getelementptr inbounds %struct.cursor_couple, ptr %10, i32 0, i32 0
  %61 = getelementptr inbounds %struct.MDBX_cursor, ptr %60, i32 0, i32 6
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = getelementptr inbounds %struct.tree, ptr %62, i32 0, i32 0
  %64 = load i16, ptr %63, align 4, !tbaa !18
  %65 = zext i16 %64 to i32
  %66 = and i32 %65, 4
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %69

68:                                               ; preds = %59
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %154

69:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #7
  %70 = getelementptr inbounds %struct.cursor_couple, ptr %10, i32 0, i32 0
  %71 = call i32 @outer_first(ptr noundef %70, ptr noundef %11, ptr noundef %12)
  store i32 %71, ptr %8, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %143, %69
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %144

75:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %76 = getelementptr inbounds %struct.cursor_couple, ptr %10, i32 0, i32 0
  %77 = getelementptr inbounds %struct.MDBX_cursor, ptr %76, i32 0, i32 9
  %78 = getelementptr inbounds %struct.cursor_couple, ptr %10, i32 0, i32 0
  %79 = getelementptr inbounds %struct.MDBX_cursor, ptr %78, i32 0, i32 1
  %80 = getelementptr inbounds %struct.anon, ptr %79, i32 0, i32 1
  %81 = load i8, ptr %80, align 1, !tbaa !19
  %82 = sext i8 %81 to i64
  %83 = getelementptr inbounds [32 x ptr], ptr %77, i64 0, i64 %82
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.cursor_couple, ptr %10, i32 0, i32 0
  %86 = getelementptr inbounds %struct.MDBX_cursor, ptr %85, i32 0, i32 10
  %87 = getelementptr inbounds %struct.cursor_couple, ptr %10, i32 0, i32 0
  %88 = getelementptr inbounds %struct.MDBX_cursor, ptr %87, i32 0, i32 1
  %89 = getelementptr inbounds %struct.anon, ptr %88, i32 0, i32 1
  %90 = load i8, ptr %89, align 1, !tbaa !19
  %91 = sext i8 %90 to i64
  %92 = getelementptr inbounds [32 x i16], ptr %86, i64 0, i64 %91
  %93 = load i16, ptr %92, align 2, !tbaa !20
  %94 = zext i16 %93 to i64
  %95 = call ptr @page_node(ptr noundef %84, i64 noundef %94) #8
  store ptr %95, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  %96 = load ptr, ptr %13, align 8, !tbaa !5
  %97 = call ptr @node_data(ptr noundef %96) #8
  store ptr %97, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  %98 = load ptr, ptr %13, align 8, !tbaa !5
  %99 = call zeroext i8 @node_flags(ptr noundef %98) #8
  %100 = zext i8 %99 to i32
  store i32 %100, ptr %15, align 4, !tbaa !9
  %101 = load i32, ptr %15, align 4, !tbaa !9
  switch i32 %101, label %121 [
    i32 1, label %102
    i32 0, label %102
    i32 4, label %106
    i32 6, label %110
  ]

102:                                              ; preds = %75, %75
  %103 = load ptr, ptr %7, align 8, !tbaa !5
  %104 = load i32, ptr %103, align 4, !tbaa !9
  %105 = or i32 %104, 1
  store i32 %105, ptr %103, align 4, !tbaa !9
  br label %138

106:                                              ; preds = %75
  %107 = load ptr, ptr %7, align 8, !tbaa !5
  %108 = load i32, ptr %107, align 4, !tbaa !9
  %109 = or i32 %108, 2
  store i32 %109, ptr %107, align 4, !tbaa !9
  br label %138

110:                                              ; preds = %75
  %111 = load ptr, ptr %14, align 8, !tbaa !5
  %112 = ptrtoint ptr %111 to i64
  %113 = add nsw i64 %112, 2
  %114 = inttoptr i64 %113 to ptr
  %115 = call zeroext i16 @unaligned_peek_u16(i64 noundef 1, ptr noundef %114) #8
  %116 = zext i16 %115 to i32
  %117 = shl i32 1, %116
  %118 = load ptr, ptr %7, align 8, !tbaa !5
  %119 = load i32, ptr %118, align 4, !tbaa !9
  %120 = or i32 %119, %117
  store i32 %120, ptr %118, align 4, !tbaa !9
  br label %138

121:                                              ; preds = %75
  br label %122

122:                                              ; preds = %121
  %123 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !21
  %124 = zext i8 %123 to i32
  %125 = icmp sle i32 1, %124
  %126 = xor i1 %125, true
  %127 = xor i1 %126, true
  %128 = zext i1 %127 to i32
  %129 = sext i32 %128 to i64
  %130 = call i64 @llvm.expect.i64(i64 %129, i64 0)
  %131 = icmp ne i64 %130, 0
  br i1 %131, label %132, label %134

132:                                              ; preds = %122
  %133 = load i32, ptr %15, align 4, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 44, ptr noundef @.str, ptr noundef @.str.1, i32 noundef -30796, ptr noundef @.str.2, i32 noundef %133)
  br label %134

134:                                              ; preds = %132, %122
  br label %135

135:                                              ; preds = %134
  br label %136

136:                                              ; preds = %135
  %137 = call i32 @log_if_error(i32 noundef -30796, ptr noundef @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 45)
  store i32 %137, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %141

138:                                              ; preds = %110, %106, %102
  %139 = getelementptr inbounds %struct.cursor_couple, ptr %10, i32 0, i32 0
  %140 = call i32 @outer_next(ptr noundef %139, ptr noundef %11, ptr noundef %12, i32 noundef 11)
  store i32 %140, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %9, align 4
  br label %141

141:                                              ; preds = %138, %136
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  %142 = load i32, ptr %9, align 4
  switch i32 %142, label %153 [
    i32 0, label %143
  ]

143:                                              ; preds = %141
  br label %72, !llvm.loop !24

144:                                              ; preds = %72
  %145 = load i32, ptr %8, align 4, !tbaa !9
  %146 = icmp eq i32 %145, -30798
  br i1 %146, label %147, label %148

147:                                              ; preds = %144
  br label %150

148:                                              ; preds = %144
  %149 = load i32, ptr %8, align 4, !tbaa !9
  br label %150

150:                                              ; preds = %148, %147
  %151 = phi i32 [ 0, %147 ], [ %149, %148 ]
  %152 = call i32 @log_if_error(i32 noundef %151, ptr noundef @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 50)
  store i32 %152, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %153

153:                                              ; preds = %150, %141
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #7
  br label %154

154:                                              ; preds = %153, %68, %56
  call void @llvm.lifetime.end.p0(i64 824, ptr %10) #7
  br label %155

155:                                              ; preds = %154, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %156

156:                                              ; preds = %155, %25
  %157 = load i32, ptr %4, align 4
  ret i32 %157
}

; 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: alwaysinline nounwind uwtable
declare hidden i32 @check_txn(ptr noundef, i32 noundef) #4

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

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

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

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

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden zeroext i16 @unaligned_peek_u16(i64 noundef, ptr noundef) #6

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

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

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

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

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

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


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.libmdbx_globals = type { %union.bin128, i32, i32, i8, i8, i8, i8, i32, %union.logger_union, %union.pthread_mutex_t, i64, ptr }
%union.bin128 = type { %struct.anon.0 }
%struct.anon.0 = 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.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_dbi_dupsort_depthmask = external hidden unnamed_addr constant [27 x i8], align 1
@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_dbi_dupsort_depthmask(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.cursor_couple, align 8
  %5 = alloca %struct.iovec, align 8
  %6 = alloca %struct.iovec, align 8
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %7, label %9, !prof !5

7:                                                ; preds = %3
  %8 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 8)
  br label %69

9:                                                ; preds = %3
  store i32 0, ptr %2, align 4, !tbaa !6
  %10 = tail call i32 @check_txn(ptr noundef %0, i32 noundef 51)
  %.not26 = icmp eq i32 %10, 0
  br i1 %.not26, label %13, label %11, !prof !10

11:                                               ; preds = %9
  %12 = tail call i32 @log_if_error(i32 noundef %10, ptr noundef nonnull @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 13)
  br label %69

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 824, ptr nonnull %4) #6
  %14 = zext i32 %1 to i64
  %15 = call i32 @cursor_init(ptr noundef nonnull %4, ptr noundef %0, i64 noundef %14) #6
  %.not27 = icmp eq i32 %15, 0
  br i1 %.not27, label %18, label %16, !prof !10

16:                                               ; preds = %13
  %17 = call i32 @log_if_error(i32 noundef %15, ptr noundef nonnull @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 18)
  br label %68

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %4, i64 24
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = load i16, ptr %20, align 4, !tbaa !19
  %22 = and i16 %21, 4
  %23 = icmp eq i16 %22, 0
  br i1 %23, label %68, label %24

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #6
  %25 = call i32 @outer_first(ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6) #6
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %24
  %27 = getelementptr inbounds i8, ptr %4, i64 48
  %28 = getelementptr inbounds i8, ptr %4, i64 5
  %29 = getelementptr inbounds i8, ptr %4, i64 304
  br label %30

30:                                               ; preds = %.lr.ph, %61
  %31 = load i8, ptr %28, align 1, !tbaa !20
  %32 = sext i8 %31 to i64
  %33 = getelementptr inbounds [32 x ptr], ptr %27, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = getelementptr inbounds [32 x i16], ptr %29, i64 0, i64 %32
  %36 = load i16, ptr %35, align 2, !tbaa !22
  %37 = zext i16 %36 to i64
  %38 = call ptr @page_node(ptr noundef %34, i64 noundef %37) #7
  %39 = call zeroext i8 @node_flags(ptr noundef %38) #7
  switch i8 %39, label %56 [
    i8 1, label %40
    i8 0, label %40
    i8 4, label %43
    i8 6, label %46
  ]

40:                                               ; preds = %30, %30
  %41 = load i32, ptr %2, align 4, !tbaa !6
  %42 = or i32 %41, 1
  br label %61

43:                                               ; preds = %30
  %44 = load i32, ptr %2, align 4, !tbaa !6
  %45 = or i32 %44, 2
  br label %61

46:                                               ; preds = %30
  %47 = call ptr @node_data(ptr noundef %38) #7
  %48 = ptrtoint ptr %47 to i64
  %49 = add nsw i64 %48, 2
  %50 = inttoptr i64 %49 to ptr
  %51 = call zeroext i16 @unaligned_peek_u16(i64 noundef 1, ptr noundef %50) #7
  %52 = zext nneg i16 %51 to i32
  %53 = shl nuw i32 1, %52
  %54 = load i32, ptr %2, align 4, !tbaa !6
  %55 = or i32 %53, %54
  br label %61

56:                                               ; preds = %30
  %57 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !23
  %.not28 = icmp eq i8 %57, 0
  br i1 %.not28, label %.thread, label %58, !prof !10

58:                                               ; preds = %56
  %59 = zext i8 %39 to i32
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 44, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef -30796, ptr noundef nonnull @.str.2, i32 noundef %59) #6
  br label %.thread

.thread:                                          ; preds = %56, %58
  %60 = call i32 @log_if_error(i32 noundef -30796, ptr noundef nonnull @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 45)
  br label %67

61:                                               ; preds = %40, %43, %46
  %.sink = phi i32 [ %42, %40 ], [ %45, %43 ], [ %55, %46 ]
  store i32 %.sink, ptr %2, align 4, !tbaa !6
  %62 = call i32 @outer_next(ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6, i32 noundef 11) #6
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %30, label %._crit_edge, !llvm.loop !26

._crit_edge:                                      ; preds = %61, %24
  %.021.lcssa = phi i32 [ %25, %24 ], [ %62, %61 ]
  %64 = icmp eq i32 %.021.lcssa, -30798
  %65 = select i1 %64, i32 0, i32 %.021.lcssa
  %66 = call i32 @log_if_error(i32 noundef %65, ptr noundef nonnull @__func__.mdbx_dbi_dupsort_depthmask, i32 noundef 50)
  br label %67

67:                                               ; preds = %.thread, %._crit_edge
  %.2 = phi i32 [ %66, %._crit_edge ], [ %60, %.thread ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #6
  br label %68

68:                                               ; preds = %18, %67, %16
  %.3 = phi i32 [ %17, %16 ], [ %.2, %67 ], [ -1, %18 ]
  call void @llvm.lifetime.end.p0(i64 824, ptr nonnull %4) #6
  br label %69

69:                                               ; preds = %11, %68, %7
  %.5 = phi i32 [ %8, %7 ], [ %12, %11 ], [ %.3, %68 ]
  ret i32 %.5
}

; 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: alwaysinline nounwind uwtable
declare hidden i32 @check_txn(ptr noundef, i32 noundef) local_unnamed_addr #3

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

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

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

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

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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden zeroext i16 @unaligned_peek_u16(i64 noundef, ptr noundef) local_unnamed_addr #5

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

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

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

attributes #0 = { cold nounwind optsize uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { 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 = { alwaysinline nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { "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 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

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

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


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