; LLVM IR from erthink/libmdbx :: src (api-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.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.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 }

@__func__.mdbx_txn_release_all_cursors_ex = external hidden unnamed_addr constant [32 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [40 x i8], align 1

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

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

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

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

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

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @mdbx_txn_release_all_cursors_ex(ptr noundef %0, i1 noundef zeroext %1, ptr noundef %2) #6 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  %16 = zext i1 %1 to i8
  store i8 %16, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call i32 @check_txn(ptr noundef %17, i32 noundef 17)
  store i32 %18, ptr %8, align 4, !tbaa !11
  %19 = load i32, ptr %8, align 4, !tbaa !11
  %20 = icmp ne i32 %19, 0
  %21 = xor i1 %20, true
  %22 = xor i1 %21, true
  %23 = zext i1 %22 to i32
  %24 = sext i32 %23 to i64
  %25 = call i64 @llvm.expect.i64(i64 %24, i64 0)
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %3
  %28 = load i32, ptr %8, align 4, !tbaa !11
  %29 = call i32 @log_if_error(i32 noundef %28, ptr noundef @__func__.mdbx_txn_release_all_cursors_ex, i32 noundef 237)
  store i32 %29, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %156

30:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  store i64 0, ptr %10, align 8, !tbaa !13
  br label %31

31:                                               ; preds = %146, %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.MDBX_txn, ptr %32, i32 0, i32 11
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = getelementptr inbounds i32, ptr %34, i64 0
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = lshr i32 %36, 1
  %38 = zext i32 %37 to i64
  store i64 %38, ptr %11, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  store i64 1, ptr %12, align 8, !tbaa !13
  br label %39

39:                                               ; preds = %139, %31
  %40 = load i64, ptr %12, align 8, !tbaa !13
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.MDBX_txn, ptr %41, i32 0, i32 2
  %43 = load i64, ptr %42, align 8, !tbaa !20
  %44 = icmp ult i64 %40, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %39
  store i32 4, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  br label %142

46:                                               ; preds = %39
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call zeroext i1 @dbi_foreach_step(ptr noundef %47, ptr noundef %11, ptr noundef %12)
  br i1 %48, label %49, label %138

49:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.MDBX_txn, ptr %50, i32 0, i32 14
  %52 = load ptr, ptr %51, align 8, !tbaa !21
  %53 = load i64, ptr %12, align 8, !tbaa !13
  %54 = getelementptr inbounds ptr, ptr %52, i64 %53
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  store ptr %55, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  store ptr null, ptr %14, align 8, !tbaa !5
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %137

58:                                               ; preds = %49
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.MDBX_txn, ptr %59, i32 0, i32 14
  %61 = load ptr, ptr %60, align 8, !tbaa !21
  %62 = load i64, ptr %12, align 8, !tbaa !13
  %63 = getelementptr inbounds ptr, ptr %61, i64 %62
  store ptr null, ptr %63, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %133, %58
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.MDBX_cursor, ptr %65, i32 0, i32 11
  %67 = load ptr, ptr %66, align 8, !tbaa !22
  store ptr %67, ptr %14, align 8, !tbaa !5
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.MDBX_cursor, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !24
  %71 = icmp eq i32 %70, 2114311601
  br i1 %71, label %72, label %76

72:                                               ; preds = %64
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.MDBX_cursor, ptr %73, i32 0, i32 0
  store i32 283285415, ptr %74, align 8, !tbaa !24
  %75 = load ptr, ptr %13, align 8, !tbaa !5
  call void @cursor_drown(ptr noundef %75)
  br label %93

76:                                               ; preds = %64
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %13, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.MDBX_cursor, ptr %78, i32 0, i32 0
  %80 = load i32, ptr %79, align 8, !tbaa !24
  %81 = icmp eq i32 %80, 283285415
  %82 = xor i1 %81, true
  %83 = xor i1 %82, true
  %84 = xor i1 %83, true
  %85 = zext i1 %84 to i32
  %86 = sext i32 %85 to i64
  %87 = call i64 @llvm.expect.i64(i64 %86, i64 0)
  %88 = icmp ne i64 %87, 0
  br i1 %88, label %89, label %90

89:                                               ; preds = %77
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.11, ptr noundef @__func__.mdbx_txn_release_all_cursors_ex, i32 noundef 251) #8
  unreachable

90:                                               ; preds = %77
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92, %72
  %94 = load ptr, ptr %13, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.MDBX_cursor, ptr %94, i32 0, i32 12
  %96 = load ptr, ptr %95, align 8, !tbaa !25
  %97 = icmp ne ptr %96, null
  br i1 %97, label %98, label %117

98:                                               ; preds = %93
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  %99 = load ptr, ptr %13, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.MDBX_cursor, ptr %99, i32 0, i32 12
  %101 = load ptr, ptr %100, align 8, !tbaa !25
  store ptr %101, ptr %15, align 8, !tbaa !5
  %102 = load ptr, ptr %15, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.MDBX_cursor, ptr %102, i32 0, i32 11
  %104 = load ptr, ptr %103, align 8, !tbaa !22
  %105 = load ptr, ptr %13, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.MDBX_cursor, ptr %105, i32 0, i32 11
  store ptr %104, ptr %106, align 8, !tbaa !22
  %107 = load ptr, ptr %15, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.MDBX_cursor, ptr %107, i32 0, i32 12
  %109 = load ptr, ptr %108, align 8, !tbaa !25
  %110 = load ptr, ptr %13, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.MDBX_cursor, ptr %110, i32 0, i32 12
  store ptr %109, ptr %111, align 8, !tbaa !25
  %112 = load ptr, ptr %15, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.MDBX_cursor, ptr %112, i32 0, i32 12
  store ptr null, ptr %113, align 8, !tbaa !25
  %114 = load ptr, ptr %15, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.MDBX_cursor, ptr %114, i32 0, i32 0
  store i32 0, ptr %115, align 8, !tbaa !24
  %116 = load ptr, ptr %15, align 8, !tbaa !5
  call void @free(ptr noundef %116) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  br label %132

117:                                              ; preds = %93
  %118 = load ptr, ptr %13, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.MDBX_cursor, ptr %118, i32 0, i32 0
  store i32 672636999, ptr %119, align 8, !tbaa !24
  %120 = load ptr, ptr %13, align 8, !tbaa !5
  %121 = load ptr, ptr %13, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.MDBX_cursor, ptr %121, i32 0, i32 11
  store ptr %120, ptr %122, align 8, !tbaa !22
  %123 = load i64, ptr %10, align 8, !tbaa !13
  %124 = add i64 %123, 1
  store i64 %124, ptr %10, align 8, !tbaa !13
  %125 = load i8, ptr %6, align 1, !tbaa !9, !range !26, !noundef !27
  %126 = trunc i8 %125 to i1
  br i1 %126, label %131, label %127

127:                                              ; preds = %117
  %128 = load ptr, ptr %13, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.MDBX_cursor, ptr %128, i32 0, i32 0
  store i32 0, ptr %129, align 8, !tbaa !24
  %130 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %130) #7
  br label %131

131:                                              ; preds = %127, %117
  br label %132

132:                                              ; preds = %131, %98
  br label %133

133:                                              ; preds = %132
  %134 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %134, ptr %13, align 8, !tbaa !5
  %135 = icmp ne ptr %134, null
  br i1 %135, label %64, label %136, !llvm.loop !28

136:                                              ; preds = %133
  br label %137

137:                                              ; preds = %136, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  br label %138

138:                                              ; preds = %137, %46
  br label %139

139:                                              ; preds = %138
  %140 = load i64, ptr %12, align 8, !tbaa !13
  %141 = add i64 %140, 1
  store i64 %141, ptr %12, align 8, !tbaa !13
  br label %39, !llvm.loop !30

142:                                              ; preds = %45
  %143 = load ptr, ptr %5, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.MDBX_txn, ptr %143, i32 0, i32 4
  %145 = load ptr, ptr %144, align 8, !tbaa !31
  store ptr %145, ptr %5, align 8, !tbaa !5
  br label %146

146:                                              ; preds = %142
  %147 = load ptr, ptr %5, align 8, !tbaa !5
  %148 = icmp ne ptr %147, null
  br i1 %148, label %31, label %149, !llvm.loop !32

149:                                              ; preds = %146
  %150 = load ptr, ptr %7, align 8, !tbaa !5
  %151 = icmp ne ptr %150, null
  br i1 %151, label %152, label %155

152:                                              ; preds = %149
  %153 = load i64, ptr %10, align 8, !tbaa !13
  %154 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %153, ptr %154, align 8, !tbaa !13
  br label %155

155:                                              ; preds = %152, %149
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %156

156:                                              ; preds = %155, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  %157 = load i32, ptr %4, align 4
  ret i32 %157
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @dbi_foreach_step(ptr noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #5 = { nounwind "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 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 = { noreturn }

!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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 96}
!16 = !{!"MDBX_txn", !12, i64 0, !12, i64 4, !14, i64 8, !14, i64 16, !6, i64 24, !6, i64 32, !17, i64 40, !14, i64 64, !14, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !19, i64 128, !6, i64 160, !7, i64 168}
!17 = !{!"geo", !18, i64 0, !18, i64 2, !12, i64 4, !12, i64 8, !7, i64 12, !7, i64 16}
!18 = !{!"short", !7, i64 0}
!19 = !{!"MDBX_canary", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!20 = !{!16, !14, i64 8}
!21 = !{!16, !6, i64 120}
!22 = !{!23, !6, i64 368}
!23 = !{!"MDBX_cursor", !12, 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}
!24 = !{!23, !12, i64 0}
!25 = !{!23, !6, i64 376}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = distinct !{!30, !29}
!31 = !{!16, !6, i64 24}
!32 = distinct !{!32, !29}


; 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"

@__func__.mdbx_txn_release_all_cursors_ex = external hidden unnamed_addr constant [32 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [40 x i8], align 1

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

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

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

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

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local i32 @mdbx_txn_release_all_cursors_ex(ptr noundef %0, i1 noundef zeroext %1, ptr noundef writeonly %2) local_unnamed_addr #5 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = tail call i32 @check_txn(ptr noundef %0, i32 noundef 17)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.preheader, label %42, !prof !5

.preheader:                                       ; preds = %3
  br i1 %1, label %.preheader.split.us, label %.preheader.split

.preheader.split.us:                              ; preds = %.preheader, %._crit_edge.split.us.us
  %.038.us = phi ptr [ %16, %._crit_edge.split.us.us ], [ %0, %.preheader ]
  %.037.us = phi i64 [ %.1.lcssa.us, %._crit_edge.split.us.us ], [ 0, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  %7 = getelementptr inbounds i8, ptr %.038.us, i64 96
  %8 = load ptr, ptr %7, align 8, !tbaa !6
  %9 = load i32, ptr %8, align 4, !tbaa !16
  %10 = lshr i32 %9, 1
  %11 = zext nneg i32 %10 to i64
  store i64 %11, ptr %4, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  %12 = getelementptr inbounds i8, ptr %.038.us, i64 8
  store i64 1, ptr %5, align 8, !tbaa !17
  %13 = load i64, ptr %12, align 8, !tbaa !18
  %14 = icmp ugt i64 %13, 1
  br i1 %14, label %.lr.ph.us, label %._crit_edge.split.us.us

._crit_edge.split.us.us:                          ; preds = %.loopexit.split.us.us.us, %.preheader.split.us
  %.1.lcssa.us = phi i64 [ %.037.us, %.preheader.split.us ], [ %.5.us.us, %.loopexit.split.us.us.us ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  %15 = getelementptr inbounds i8, ptr %.038.us, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !19
  %.not46.us = icmp eq ptr %16, null
  br i1 %.not46.us, label %.split58.us, label %.preheader.split.us, !llvm.loop !20

.lr.ph.us:                                        ; preds = %.preheader.split.us
  %17 = getelementptr inbounds i8, ptr %.038.us, i64 120
  br label %18

18:                                               ; preds = %.loopexit.split.us.us.us, %.lr.ph.us
  %.155.us.us = phi i64 [ %.037.us, %.lr.ph.us ], [ %.5.us.us, %.loopexit.split.us.us.us ]
  %19 = call zeroext i1 @dbi_foreach_step(ptr noundef nonnull %.038.us, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %.pre63 = load i64, ptr %5, align 8, !tbaa !17
  br i1 %19, label %20, label %.loopexit.split.us.us.us

20:                                               ; preds = %18
  %21 = load ptr, ptr %17, align 8, !tbaa !22
  %22 = getelementptr inbounds ptr, ptr %21, i64 %.pre63
  %23 = load ptr, ptr %22, align 8, !tbaa !23
  %.not48.us.us = icmp eq ptr %23, null
  br i1 %.not48.us.us, label %.loopexit.split.us.us.us, label %.split.us.us.us

.split.us.us.us:                                  ; preds = %20
  store ptr null, ptr %22, align 8, !tbaa !23
  br label %28

.loopexit.split.us.us.us.loopexit:                ; preds = %41
  %.pre62 = load i64, ptr %5, align 8, !tbaa !17
  br label %.loopexit.split.us.us.us

.loopexit.split.us.us.us:                         ; preds = %.loopexit.split.us.us.us.loopexit, %20, %18
  %24 = phi i64 [ %.pre63, %18 ], [ %.pre63, %20 ], [ %.pre62, %.loopexit.split.us.us.us.loopexit ]
  %.5.us.us = phi i64 [ %.155.us.us, %18 ], [ %.155.us.us, %20 ], [ %.3.us.us.us, %.loopexit.split.us.us.us.loopexit ]
  %25 = add i64 %24, 1
  store i64 %25, ptr %5, align 8, !tbaa !17
  %26 = load i64, ptr %12, align 8, !tbaa !18
  %27 = icmp ult i64 %25, %26
  br i1 %27, label %18, label %._crit_edge.split.us.us, !llvm.loop !24

28:                                               ; preds = %41, %.split.us.us.us
  %.2.us.us.us = phi i64 [ %.155.us.us, %.split.us.us.us ], [ %.3.us.us.us, %41 ]
  %.036.us.us.us = phi ptr [ %23, %.split.us.us.us ], [ %30, %41 ]
  %29 = getelementptr inbounds i8, ptr %.036.us.us.us, i64 368
  %30 = load ptr, ptr %29, align 8, !tbaa !25
  %31 = load i32, ptr %.036.us.us.us, align 8, !tbaa !27
  switch i32 %31, label %.split54.us [
    i32 2114311601, label %32
    i32 283285415, label %33
  ], !prof !28

32:                                               ; preds = %28
  store i32 283285415, ptr %.036.us.us.us, align 8, !tbaa !27
  call void @cursor_drown(ptr noundef nonnull %.036.us.us.us)
  br label %33

33:                                               ; preds = %32, %28
  %34 = getelementptr inbounds i8, ptr %.036.us.us.us, i64 376
  %35 = load ptr, ptr %34, align 8, !tbaa !29
  %.not50.us.us.us = icmp eq ptr %35, null
  br i1 %.not50.us.us.us, label %39, label %36

36:                                               ; preds = %33
  %37 = getelementptr inbounds i8, ptr %35, i64 368
  %38 = load <2 x ptr>, ptr %37, align 8, !tbaa !23
  store <2 x ptr> %38, ptr %29, align 8, !tbaa !23
  call void @free(ptr noundef nonnull %35) #6
  br label %41

39:                                               ; preds = %33
  store i32 672636999, ptr %.036.us.us.us, align 8, !tbaa !27
  store ptr %.036.us.us.us, ptr %29, align 8, !tbaa !25
  %40 = add i64 %.2.us.us.us, 1
  br label %41

41:                                               ; preds = %39, %36
  %.3.us.us.us = phi i64 [ %.2.us.us.us, %36 ], [ %40, %39 ]
  %.not51.us.us.us = icmp eq ptr %30, null
  br i1 %.not51.us.us.us, label %.loopexit.split.us.us.us.loopexit, label %28, !llvm.loop !30

42:                                               ; preds = %3
  %43 = tail call i32 @log_if_error(i32 noundef %6, ptr noundef nonnull @__func__.mdbx_txn_release_all_cursors_ex, i32 noundef 237)
  br label %80

.preheader.split:                                 ; preds = %.preheader, %._crit_edge.split
  %.038 = phi ptr [ %54, %._crit_edge.split ], [ %0, %.preheader ]
  %.037 = phi i64 [ %.1.lcssa, %._crit_edge.split ], [ 0, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  %44 = getelementptr inbounds i8, ptr %.038, i64 96
  %45 = load ptr, ptr %44, align 8, !tbaa !6
  %46 = load i32, ptr %45, align 4, !tbaa !16
  %47 = lshr i32 %46, 1
  %48 = zext nneg i32 %47 to i64
  store i64 %48, ptr %4, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  %49 = getelementptr inbounds i8, ptr %.038, i64 8
  store i64 1, ptr %5, align 8, !tbaa !17
  %50 = load i64, ptr %49, align 8, !tbaa !18
  %51 = icmp ugt i64 %50, 1
  br i1 %51, label %.lr.ph, label %._crit_edge.split

.lr.ph:                                           ; preds = %.preheader.split
  %52 = getelementptr inbounds i8, ptr %.038, i64 120
  br label %55

._crit_edge.split:                                ; preds = %.loopexit.split, %.preheader.split
  %.1.lcssa = phi i64 [ %.037, %.preheader.split ], [ %.5, %.loopexit.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  %53 = getelementptr inbounds i8, ptr %.038, i64 24
  %54 = load ptr, ptr %53, align 8, !tbaa !19
  %.not46 = icmp eq ptr %54, null
  br i1 %.not46, label %.split58.us, label %.preheader.split, !llvm.loop !20

55:                                               ; preds = %.lr.ph, %.loopexit.split
  %.155 = phi i64 [ %.037, %.lr.ph ], [ %.5, %.loopexit.split ]
  %56 = call zeroext i1 @dbi_foreach_step(ptr noundef nonnull %.038, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %.pre61 = load i64, ptr %5, align 8, !tbaa !17
  br i1 %56, label %57, label %.loopexit.split

57:                                               ; preds = %55
  %58 = load ptr, ptr %52, align 8, !tbaa !22
  %59 = getelementptr inbounds ptr, ptr %58, i64 %.pre61
  %60 = load ptr, ptr %59, align 8, !tbaa !23
  %.not48 = icmp eq ptr %60, null
  br i1 %.not48, label %.loopexit.split, label %.split

.split:                                           ; preds = %57
  store ptr null, ptr %59, align 8, !tbaa !23
  br label %61

61:                                               ; preds = %74, %.split
  %.2 = phi i64 [ %.155, %.split ], [ %.3, %74 ]
  %.036 = phi ptr [ %60, %.split ], [ %63, %74 ]
  %62 = getelementptr inbounds i8, ptr %.036, i64 368
  %63 = load ptr, ptr %62, align 8, !tbaa !25
  %64 = load i32, ptr %.036, align 8, !tbaa !27
  switch i32 %64, label %.split54.us [
    i32 2114311601, label %65
    i32 283285415, label %66
  ], !prof !28

65:                                               ; preds = %61
  store i32 283285415, ptr %.036, align 8, !tbaa !27
  call void @cursor_drown(ptr noundef nonnull %.036)
  br label %66

.split54.us:                                      ; preds = %61, %28
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.11, ptr noundef nonnull @__func__.mdbx_txn_release_all_cursors_ex, i32 noundef 251) #7
  unreachable

66:                                               ; preds = %61, %65
  %67 = getelementptr inbounds i8, ptr %.036, i64 376
  %68 = load ptr, ptr %67, align 8, !tbaa !29
  %.not50 = icmp eq ptr %68, null
  br i1 %.not50, label %72, label %69

69:                                               ; preds = %66
  %70 = getelementptr inbounds i8, ptr %68, i64 368
  %71 = load <2 x ptr>, ptr %70, align 8, !tbaa !23
  store <2 x ptr> %71, ptr %62, align 8, !tbaa !23
  br label %74

72:                                               ; preds = %66
  %73 = add i64 %.2, 1
  br label %74

74:                                               ; preds = %69, %72
  %.sink = phi ptr [ %68, %69 ], [ %.036, %72 ]
  %.3 = phi i64 [ %.2, %69 ], [ %73, %72 ]
  call void @free(ptr noundef nonnull %.sink) #6
  %.not51 = icmp eq ptr %63, null
  br i1 %.not51, label %.loopexit.split.loopexit, label %61, !llvm.loop !30

.loopexit.split.loopexit:                         ; preds = %74
  %.pre = load i64, ptr %5, align 8, !tbaa !17
  br label %.loopexit.split

.loopexit.split:                                  ; preds = %.loopexit.split.loopexit, %57, %55
  %75 = phi i64 [ %.pre61, %55 ], [ %.pre61, %57 ], [ %.pre, %.loopexit.split.loopexit ]
  %.5 = phi i64 [ %.155, %55 ], [ %.155, %57 ], [ %.3, %.loopexit.split.loopexit ]
  %76 = add i64 %75, 1
  store i64 %76, ptr %5, align 8, !tbaa !17
  %77 = load i64, ptr %49, align 8, !tbaa !18
  %78 = icmp ult i64 %76, %77
  br i1 %78, label %55, label %._crit_edge.split, !llvm.loop !24

.split58.us:                                      ; preds = %._crit_edge.split, %._crit_edge.split.us.us
  %.us-phi = phi i64 [ %.1.lcssa.us, %._crit_edge.split.us.us ], [ %.1.lcssa, %._crit_edge.split ]
  %.not47 = icmp eq ptr %2, null
  br i1 %.not47, label %80, label %79

79:                                               ; preds = %.split58.us
  store i64 %.us-phi, ptr %2, align 8, !tbaa !17
  br label %80

80:                                               ; preds = %.split58.us, %79, %42
  %.0 = phi i32 [ %43, %42 ], [ 0, %79 ], [ 0, %.split58.us ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @dbi_foreach_step(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { alwaysinline nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { noreturn "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind 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 = { noreturn nounwind }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!6 = !{!7, !12, i64 96}
!7 = !{!"MDBX_txn", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 32, !13, 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, !15, i64 128, !12, i64 160, !9, i64 168}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"geo", !14, i64 0, !14, i64 2, !8, i64 4, !8, i64 8, !9, i64 12, !9, i64 16}
!14 = !{!"short", !9, i64 0}
!15 = !{!"MDBX_canary", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!16 = !{!8, !8, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!7, !11, i64 8}
!19 = !{!7, !12, i64 24}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!7, !12, i64 120}
!23 = !{!12, !12, i64 0}
!24 = distinct !{!24, !21}
!25 = !{!26, !12, i64 368}
!26 = !{!"MDBX_cursor", !8, i64 0, !9, i64 4, !9, i64 6, !9, i64 7, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !9, i64 48, !9, i64 304, !12, i64 368, !12, i64 376}
!27 = !{!26, !8, i64 0}
!28 = !{!"branch_weights", i32 1, i32 2001, i32 2000}
!29 = !{!26, !12, i64 376}
!30 = distinct !{!30, !21}


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