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

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.libmdbx_globals = type { %union.bin128, i32, i32, i8, i8, i8, i8, i32, %union.logger_union, %union.pthread_mutex_t, i64, ptr }
%union.bin128 = type { %struct.anon }
%struct.anon = type { i64, i64 }
%union.logger_union = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct.MDBX_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, %union.anon.1 }
%union.anon = 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.16, i8, i8, ptr, ptr, ptr, ptr, ptr, [32 x ptr], [32 x i16], ptr, ptr }
%union.anon.16 = type { i16 }

@globals = external global %struct.libmdbx_globals, align 8
@.str.2 = external hidden unnamed_addr constant [31 x i8], align 1
@__func__.txn_shadow_cursors = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [51 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @txn_shadow_cursors(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  br label %11

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

22:                                               ; preds = %11
  br label %23

23:                                               ; preds = %22
  %24 = load i64, ptr %5, align 8, !tbaa !9
  %25 = icmp ugt i64 %24, 0
  br i1 %25, label %26, label %32

26:                                               ; preds = %23
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.MDBX_txn, ptr %28, i32 0, i32 2
  %30 = load i64, ptr %29, align 8, !tbaa !15
  %31 = icmp ult i64 %27, %30
  br label %32

32:                                               ; preds = %26, %23
  %33 = phi i1 [ false, %23 ], [ %31, %26 ]
  %34 = xor i1 %33, true
  %35 = xor i1 %34, true
  %36 = xor i1 %35, true
  %37 = zext i1 %36 to i32
  %38 = sext i32 %37 to i64
  %39 = call i64 @llvm.expect.i64(i64 %38, i64 0)
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %41, label %45

41:                                               ; preds = %32
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.MDBX_txn, ptr %42, i32 0, i32 9
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  call void @mdbx_assert_fail(ptr noundef %44, ptr noundef @.str.2, ptr noundef @__func__.txn_shadow_cursors, i32 noundef 36) #6
  unreachable

45:                                               ; preds = %32
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46, %11
  br label %48

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

57:                                               ; preds = %48
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %218

58:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.MDBX_txn, ptr %59, i32 0, i32 5
  %61 = load ptr, ptr %60, align 8, !tbaa !22
  store ptr %61, ptr %8, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %58
  %63 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %64 = zext i8 %63 to i32
  %65 = and i32 %64, 1
  %66 = icmp ne i32 %65, 0
  %67 = xor i1 %66, true
  %68 = xor i1 %67, true
  %69 = zext i1 %68 to i32
  %70 = sext i32 %69 to i64
  %71 = call i64 @llvm.expect.i64(i64 %70, i64 1)
  %72 = icmp ne i64 %71, 0
  br i1 %72, label %73, label %94

73:                                               ; preds = %62
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.MDBX_txn, ptr %75, i32 0, i32 1
  %77 = load i32, ptr %76, align 4, !tbaa !23
  %78 = and i32 %77, 256
  %79 = icmp ne i32 %78, 0
  %80 = xor i1 %79, true
  %81 = xor i1 %80, true
  %82 = xor i1 %81, true
  %83 = zext i1 %82 to i32
  %84 = sext i32 %83 to i64
  %85 = call i64 @llvm.expect.i64(i64 %84, i64 0)
  %86 = icmp ne i64 %85, 0
  br i1 %86, label %87, label %91

87:                                               ; preds = %74
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.MDBX_txn, ptr %88, i32 0, i32 9
  %90 = load ptr, ptr %89, align 8, !tbaa !20
  call void @mdbx_assert_fail(ptr noundef %90, ptr noundef @.str.3, ptr noundef @__func__.txn_shadow_cursors, i32 noundef 42) #6
  unreachable

91:                                               ; preds = %74
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93, %62
  br label %95

95:                                               ; preds = %94
  br label %96

96:                                               ; preds = %95
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  store ptr null, ptr %9, align 8, !tbaa !5
  br label %97

97:                                               ; preds = %213, %96
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.MDBX_cursor, ptr %98, i32 0, i32 11
  %100 = load ptr, ptr %99, align 8, !tbaa !24
  store ptr %100, ptr %9, align 8, !tbaa !5
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.MDBX_cursor, ptr %101, i32 0, i32 0
  %103 = load i32, ptr %102, align 8, !tbaa !26
  %104 = icmp ne i32 %103, 2114311601
  br i1 %104, label %105, label %125

105:                                              ; preds = %97
  br label %106

106:                                              ; preds = %105
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.MDBX_cursor, ptr %107, i32 0, i32 0
  %109 = load i32, ptr %108, align 8, !tbaa !26
  %110 = icmp eq i32 %109, 283285415
  %111 = xor i1 %110, true
  %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 %122

118:                                              ; preds = %106
  %119 = load ptr, ptr %4, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.MDBX_txn, ptr %119, i32 0, i32 9
  %121 = load ptr, ptr %120, align 8, !tbaa !20
  call void @mdbx_assert_fail(ptr noundef %121, ptr noundef @.str.4, ptr noundef @__func__.txn_shadow_cursors, i32 noundef 47) #6
  unreachable

122:                                              ; preds = %106
  br label %123

123:                                              ; preds = %122
  br label %124

124:                                              ; preds = %123
  br label %213

125:                                              ; preds = %97
  br label %126

126:                                              ; preds = %125
  %127 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %128 = zext i8 %127 to i32
  %129 = and i32 %128, 1
  %130 = icmp ne i32 %129, 0
  %131 = xor i1 %130, true
  %132 = xor i1 %131, true
  %133 = zext i1 %132 to i32
  %134 = sext i32 %133 to i64
  %135 = call i64 @llvm.expect.i64(i64 %134, i64 1)
  %136 = icmp ne i64 %135, 0
  br i1 %136, label %137, label %165

137:                                              ; preds = %126
  br label %138

138:                                              ; preds = %137
  %139 = load ptr, ptr %6, align 8, !tbaa !5
  %140 = getelementptr inbounds %struct.MDBX_cursor, ptr %139, i32 0, i32 5
  %141 = load ptr, ptr %140, align 8, !tbaa !27
  %142 = load ptr, ptr %4, align 8, !tbaa !5
  %143 = icmp eq ptr %141, %142
  br i1 %143, label %144, label %149

144:                                              ; preds = %138
  %145 = load i64, ptr %5, align 8, !tbaa !9
  %146 = load ptr, ptr %6, align 8, !tbaa !5
  %147 = call i64 @cursor_dbi(ptr noundef %146) #8
  %148 = icmp eq i64 %145, %147
  br label %149

149:                                              ; preds = %144, %138
  %150 = phi i1 [ false, %138 ], [ %148, %144 ]
  %151 = xor i1 %150, true
  %152 = xor i1 %151, true
  %153 = xor i1 %152, true
  %154 = zext i1 %153 to i32
  %155 = sext i32 %154 to i64
  %156 = call i64 @llvm.expect.i64(i64 %155, i64 0)
  %157 = icmp ne i64 %156, 0
  br i1 %157, label %158, label %162

158:                                              ; preds = %149
  %159 = load ptr, ptr %4, align 8, !tbaa !5
  %160 = getelementptr inbounds %struct.MDBX_txn, ptr %159, i32 0, i32 9
  %161 = load ptr, ptr %160, align 8, !tbaa !20
  call void @mdbx_assert_fail(ptr noundef %161, ptr noundef @.str.5, ptr noundef @__func__.txn_shadow_cursors, i32 noundef 50) #6
  unreachable

162:                                              ; preds = %149
  br label %163

163:                                              ; preds = %162
  br label %164

164:                                              ; preds = %163
  br label %165

165:                                              ; preds = %164, %126
  br label %166

166:                                              ; preds = %165
  br label %167

167:                                              ; preds = %166
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %168 = load ptr, ptr %6, align 8, !tbaa !5
  %169 = load ptr, ptr %8, align 8, !tbaa !5
  %170 = load i64, ptr %5, align 8, !tbaa !9
  %171 = call i32 @cursor_shadow(ptr noundef %168, ptr noundef %169, i64 noundef %170)
  store i32 %171, ptr %10, align 4, !tbaa !28
  %172 = load i32, ptr %10, align 4, !tbaa !28
  %173 = icmp ne i32 %172, 0
  %174 = xor i1 %173, true
  %175 = xor i1 %174, true
  %176 = zext i1 %175 to i32
  %177 = sext i32 %176 to i64
  %178 = call i64 @llvm.expect.i64(i64 %177, i64 0)
  %179 = icmp ne i64 %178, 0
  br i1 %179, label %180, label %191

180:                                              ; preds = %167
  %181 = load ptr, ptr %8, align 8, !tbaa !5
  %182 = getelementptr inbounds %struct.MDBX_txn, ptr %181, i32 0, i32 12
  %183 = load ptr, ptr %182, align 8, !tbaa !29
  %184 = load i64, ptr %5, align 8, !tbaa !9
  %185 = getelementptr inbounds i8, ptr %183, i64 %184
  store i8 -62, ptr %185, align 1, !tbaa !30
  %186 = load ptr, ptr %8, align 8, !tbaa !5
  %187 = getelementptr inbounds %struct.MDBX_txn, ptr %186, i32 0, i32 1
  %188 = load i32, ptr %187, align 4, !tbaa !23
  %189 = or i32 %188, 2
  store i32 %189, ptr %187, align 4, !tbaa !23
  %190 = load i32, ptr %10, align 4, !tbaa !28
  store i32 %190, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %210

191:                                              ; preds = %167
  %192 = load ptr, ptr %8, align 8, !tbaa !5
  %193 = getelementptr inbounds %struct.MDBX_txn, ptr %192, i32 0, i32 14
  %194 = load ptr, ptr %193, align 8, !tbaa !21
  %195 = load i64, ptr %5, align 8, !tbaa !9
  %196 = getelementptr inbounds ptr, ptr %194, i64 %195
  %197 = load ptr, ptr %196, align 8, !tbaa !5
  %198 = load ptr, ptr %6, align 8, !tbaa !5
  %199 = getelementptr inbounds %struct.MDBX_cursor, ptr %198, i32 0, i32 11
  store ptr %197, ptr %199, align 8, !tbaa !24
  %200 = load ptr, ptr %6, align 8, !tbaa !5
  %201 = load ptr, ptr %8, align 8, !tbaa !5
  %202 = getelementptr inbounds %struct.MDBX_txn, ptr %201, i32 0, i32 14
  %203 = load ptr, ptr %202, align 8, !tbaa !21
  %204 = load i64, ptr %5, align 8, !tbaa !9
  %205 = getelementptr inbounds ptr, ptr %203, i64 %204
  store ptr %200, ptr %205, align 8, !tbaa !5
  %206 = load ptr, ptr %8, align 8, !tbaa !5
  %207 = getelementptr inbounds %struct.MDBX_txn, ptr %206, i32 0, i32 1
  %208 = load i32, ptr %207, align 4, !tbaa !23
  %209 = or i32 %208, 256
  store i32 %209, ptr %207, align 4, !tbaa !23
  store i32 0, ptr %7, align 4
  br label %210

210:                                              ; preds = %191, %180
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  %211 = load i32, ptr %7, align 4
  switch i32 %211, label %217 [
    i32 0, label %212
  ]

212:                                              ; preds = %210
  br label %213

213:                                              ; preds = %212, %124
  %214 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %214, ptr %6, align 8, !tbaa !5
  %215 = icmp ne ptr %214, null
  br i1 %215, label %97, label %216, !llvm.loop !31

216:                                              ; preds = %213
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %217

217:                                              ; preds = %216, %210
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  br label %218

218:                                              ; preds = %217, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %219 = load i32, ptr %3, align 4
  ret i32 %219
}

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

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

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 = { nocallback nofree nosync 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 = { 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 = { noreturn }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !7, i64 25}
!12 = !{!"libmdbx_globals", !7, i64 0, !13, i64 16, !13, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !14, i64 27, !13, i64 28, !7, i64 32, !7, i64 40, !10, i64 80, !6, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"MDBX_txn", !13, i64 0, !13, i64 4, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !17, i64 40, !10, i64 64, !10, 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, !13, i64 4, !13, i64 8, !7, i64 12, !7, i64 16}
!18 = !{!"short", !7, i64 0}
!19 = !{!"MDBX_canary", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!20 = !{!16, !6, i64 80}
!21 = !{!16, !6, i64 120}
!22 = !{!16, !6, i64 32}
!23 = !{!16, !13, i64 4}
!24 = !{!25, !6, i64 368}
!25 = !{!"MDBX_cursor", !13, 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}
!26 = !{!25, !13, i64 0}
!27 = !{!25, !6, i64 16}
!28 = !{!13, !13, i64 0}
!29 = !{!16, !6, i64 104}
!30 = !{!7, !7, i64 0}
!31 = distinct !{!31, !32}
!32 = !{!"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 }
%struct.anon = type { i64, i64 }
%union.logger_union = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str.2 = external hidden unnamed_addr constant [31 x i8], align 1
@__func__.txn_shadow_cursors = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [51 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: nounwind uwtable
define dso_local i32 @txn_shadow_cursors(ptr noundef readonly %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %4 = and i8 %3, 1
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %11, label %5, !prof !13

5:                                                ; preds = %2
  %.not43 = icmp eq i64 %1, 0
  br i1 %.not43, label %.critedge, label %6, !prof !13

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !14
  %.not58 = icmp ugt i64 %8, %1
  br i1 %.not58, label %.thread, label %.critedge, !prof !19

.critedge:                                        ; preds = %5, %6
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  %10 = load ptr, ptr %9, align 8, !tbaa !20
  tail call void @mdbx_assert_fail(ptr noundef %10, ptr noundef nonnull @.str.2, ptr noundef nonnull @__func__.txn_shadow_cursors, i32 noundef 36) #4
  unreachable

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 120
  %13 = load ptr, ptr %12, align 8, !tbaa !21
  %14 = getelementptr inbounds ptr, ptr %13, i64 %1
  %15 = load ptr, ptr %14, align 8, !tbaa !22
  %.not44 = icmp eq ptr %15, null
  br i1 %.not44, label %.loopexit, label %27

.thread:                                          ; preds = %6
  %16 = getelementptr inbounds i8, ptr %0, i64 120
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %18 = getelementptr inbounds ptr, ptr %17, i64 %1
  %19 = load ptr, ptr %18, align 8, !tbaa !22
  %.not4454 = icmp eq ptr %19, null
  br i1 %.not4454, label %.loopexit, label %20

20:                                               ; preds = %.thread
  %21 = getelementptr inbounds i8, ptr %0, i64 4
  %22 = load i32, ptr %21, align 4, !tbaa !23
  %23 = and i32 %22, 256
  %.not46 = icmp eq i32 %23, 0
  br i1 %.not46, label %24, label %27, !prof !13

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %0, i64 80
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  tail call void @mdbx_assert_fail(ptr noundef %26, ptr noundef nonnull @.str.3, ptr noundef nonnull @__func__.txn_shadow_cursors, i32 noundef 42) #4
  unreachable

27:                                               ; preds = %11, %20
  %28 = phi ptr [ %19, %20 ], [ %15, %11 ]
  %.in = getelementptr inbounds i8, ptr %0, i64 32
  %29 = load ptr, ptr %.in, align 8, !tbaa !24
  %30 = getelementptr inbounds i8, ptr %29, i64 120
  %31 = getelementptr inbounds i8, ptr %29, i64 4
  br label %32

32:                                               ; preds = %64, %27
  %.036 = phi ptr [ %28, %27 ], [ %34, %64 ]
  %33 = getelementptr inbounds i8, ptr %.036, i64 368
  %34 = load ptr, ptr %33, align 8, !tbaa !25
  %35 = load i32, ptr %.036, align 8, !tbaa !27
  switch i32 %35, label %36 [
    i32 2114311601, label %39
    i32 283285415, label %64
  ], !prof !28

36:                                               ; preds = %32
  %37 = getelementptr inbounds i8, ptr %0, i64 80
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  tail call void @mdbx_assert_fail(ptr noundef %38, ptr noundef nonnull @.str.4, ptr noundef nonnull @__func__.txn_shadow_cursors, i32 noundef 47) #4
  unreachable

39:                                               ; preds = %32
  %40 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %41 = and i8 %40, 1
  %.not48 = icmp eq i8 %41, 0
  br i1 %.not48, label %51, label %42, !prof !13

42:                                               ; preds = %39
  %43 = getelementptr inbounds i8, ptr %.036, i64 16
  %44 = load ptr, ptr %43, align 8, !tbaa !29
  %45 = icmp eq ptr %44, %0
  br i1 %45, label %46, label %.critedge53, !prof !19

46:                                               ; preds = %42
  %47 = tail call i64 @cursor_dbi(ptr noundef nonnull %.036) #5
  %48 = icmp eq i64 %47, %1
  br i1 %48, label %51, label %.critedge53, !prof !19

.critedge53:                                      ; preds = %42, %46
  %49 = getelementptr inbounds i8, ptr %0, i64 80
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  tail call void @mdbx_assert_fail(ptr noundef %50, ptr noundef nonnull @.str.5, ptr noundef nonnull @__func__.txn_shadow_cursors, i32 noundef 50) #4
  unreachable

51:                                               ; preds = %46, %39
  %52 = tail call i32 @cursor_shadow(ptr noundef nonnull %.036, ptr noundef %29, i64 noundef %1) #6
  %.not49 = icmp eq i32 %52, 0
  br i1 %.not49, label %.thread56, label %58, !prof !19

.thread56:                                        ; preds = %51
  %53 = load ptr, ptr %30, align 8, !tbaa !21
  %54 = getelementptr inbounds ptr, ptr %53, i64 %1
  %55 = load ptr, ptr %54, align 8, !tbaa !22
  store ptr %55, ptr %33, align 8, !tbaa !25
  store ptr %.036, ptr %54, align 8, !tbaa !22
  %56 = load i32, ptr %31, align 4, !tbaa !23
  %57 = or i32 %56, 256
  store i32 %57, ptr %31, align 4, !tbaa !23
  br label %64

58:                                               ; preds = %51
  %59 = getelementptr inbounds i8, ptr %29, i64 104
  %60 = load ptr, ptr %59, align 8, !tbaa !30
  %61 = getelementptr inbounds i8, ptr %60, i64 %1
  store i8 -62, ptr %61, align 1, !tbaa !31
  %62 = load i32, ptr %31, align 4, !tbaa !23
  %63 = or i32 %62, 2
  store i32 %63, ptr %31, align 4, !tbaa !23
  br label %.loopexit

64:                                               ; preds = %.thread56, %32
  %.not51 = icmp eq ptr %34, null
  br i1 %.not51, label %.loopexit, label %32, !llvm.loop !32

.loopexit:                                        ; preds = %64, %58, %.thread, %11
  %.4 = phi i32 [ 0, %11 ], [ %52, %58 ], [ 0, %.thread ], [ 0, %64 ]
  ret i32 %.4
}

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

declare i32 @cursor_shadow(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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 = { 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 = { 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 #3 = { "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 nounwind }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { nounwind }

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

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


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