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

; 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.7 }
%struct.anon.7 = 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.1 }
%struct.geo = type { i16, i16, i32, i32, %union.anon, %union.anon.0 }
%union.anon = type { i32 }
%union.anon.0 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.1 = type { %struct.anon.2 }
%struct.anon.2 = type { %struct.troika, ptr, %struct.anon.3, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.4 }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.anon.3 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.4 = type { %struct.anon.5 }
%struct.anon.5 = type { i64, ptr }
%struct.MDBX_env = type { %union.mdbx_atomic_uint32_t, i32, i32, %struct.osal_mmap, i32, i32, %struct.osal_mmap, ptr, i16, i16, i16, i16, i16, i16, %union.mdbx_atomic_uint32_t, i8, i8, i16, i32, i32, i32, i32, %struct.anon.10, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.11, %struct.anon.15, i8, ptr, ptr, ptr, %struct.anon.16, %union.pthread_mutex_t, i32, i32, ptr, %struct.osal_ioring, %union.pthread_mutex_t, [71 x %union.mdbx_atomic_uint64_t] }
%struct.osal_mmap = type { %union.anon.9, i32, i64, i64, i64 }
%union.anon.9 = type { ptr }
%union.mdbx_atomic_uint32_t = type { i32 }
%struct.anon.10 = type { ptr, ptr, ptr, ptr }
%struct.anon.11 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.12, %union.anon.13 }
%struct.anon.12 = type { i16, i16, i16, i16 }
%union.anon.13 = type { i32 }
%struct.anon.15 = type { i64, i64, i64, i64, i64 }
%struct.anon.16 = type { i64 }
%struct.osal_ioring = type { i32, i32, i32, ptr, ptr, ptr }
%union.mdbx_atomic_uint64_t = type { i64 }
%struct.shared_lck = type { i64, i32, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, [2 x %union.mdbx_atomic_uint32_t], [16 x i8], %struct.pgops, [16 x i8], %union.pthread_mutex_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, i32, %struct.anon.19, %union.pthread_mutex_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, [16 x i8], [0 x %struct.reader_slot] }
%struct.pgops = type { %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %struct.anon.17 }
%struct.anon.17 = type { %struct.gc_prof_stat, %struct.gc_prof_stat, i32, i32, i32, i32, i32 }
%struct.gc_prof_stat = type { i64, i64, i32, i32, i32, i32, %struct.anon.18 }
%struct.anon.18 = type { i64, i64, i32 }
%struct.anon.19 = type { [4 x i32], [4 x i64] }
%struct.reader_slot = type { %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint64_t }

@globals = external global %struct.libmdbx_globals, align 8
@.str.6 = external hidden unnamed_addr constant [77 x i8], align 1
@__func__.txn_basal_end = external hidden unnamed_addr constant [14 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [67 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

declare void @pnl_free(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @txn_basal_end(ptr noundef %0, i32 noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.MDBX_txn, ptr %7, i32 0, i32 9
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  store ptr %9, ptr %5, align 8, !tbaa !5
  br label %10

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

21:                                               ; preds = %10
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MDBX_txn, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !20
  %26 = and i32 %25, 257
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %33

28:                                               ; preds = %22
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MDBX_txn, ptr %29, i32 0, i32 3
  %31 = load i64, ptr %30, align 8, !tbaa !21
  %32 = icmp ne i64 %31, 0
  br label %33

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

42:                                               ; preds = %33
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.MDBX_txn, ptr %43, i32 0, i32 9
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  call void @mdbx_assert_fail(ptr noundef %45, ptr noundef @.str.6, ptr noundef @__func__.txn_basal_end, i32 noundef 138) #7
  unreachable

46:                                               ; preds = %33
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48, %10
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.MDBX_txn, ptr %53, i32 0, i32 7
  %55 = load i64, ptr %54, align 8, !tbaa !22
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.MDBX_env, ptr %56, i32 0, i32 7
  %58 = load ptr, ptr %57, align 8, !tbaa !23
  %59 = getelementptr inbounds %struct.shared_lck, ptr %58, i32 0, i32 12
  %60 = load volatile i64, ptr %59, align 8, !tbaa !32
  %61 = icmp uge i64 %55, %60
  %62 = xor i1 %61, true
  %63 = xor i1 %62, true
  %64 = xor i1 %63, true
  %65 = zext i1 %64 to i32
  %66 = sext i32 %65 to i64
  %67 = call i64 @llvm.expect.i64(i64 %66, i64 0)
  %68 = icmp ne i64 %67, 0
  br i1 %68, label %69, label %71

69:                                               ; preds = %52
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %70, ptr noundef @.str.7, ptr noundef @__func__.txn_basal_end, i32 noundef 139) #7
  unreachable

71:                                               ; preds = %52
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  call void @dxb_sanitize_tail(ptr noundef %74, ptr noundef null)
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.MDBX_txn, ptr %75, i32 0, i32 1
  store i32 1, ptr %76, align 4, !tbaa !20
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.MDBX_env, ptr %77, i32 0, i32 39
  store ptr null, ptr %78, align 8, !tbaa !33
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.MDBX_txn, ptr %79, i32 0, i32 17
  %81 = getelementptr inbounds %struct.anon.2, ptr %80, i32 0, i32 11
  %82 = getelementptr inbounds %struct.anon.5, ptr %81, i32 0, i32 1
  %83 = load ptr, ptr %82, align 8, !tbaa !32
  call void @pnl_free(ptr noundef %83)
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.MDBX_txn, ptr %84, i32 0, i32 17
  %86 = getelementptr inbounds %struct.anon.2, ptr %85, i32 0, i32 11
  %87 = getelementptr inbounds %struct.anon.5, ptr %86, i32 0, i32 1
  store ptr null, ptr %87, align 8, !tbaa !32
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.MDBX_txn, ptr %88, i32 0, i32 17
  %90 = getelementptr inbounds %struct.anon.2, ptr %89, i32 0, i32 2
  %91 = getelementptr inbounds %struct.anon.3, ptr %90, i32 0, i32 0
  call void @rkl_clear_and_shrink(ptr noundef %91)
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.MDBX_txn, ptr %92, i32 0, i32 17
  %94 = getelementptr inbounds %struct.anon.2, ptr %93, i32 0, i32 2
  %95 = getelementptr inbounds %struct.anon.3, ptr %94, i32 0, i32 2
  call void @rkl_clear_and_shrink(ptr noundef %95)
  br label %96

96:                                               ; preds = %73
  %97 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !17
  %98 = zext i8 %97 to i32
  %99 = and i32 %98, 1
  %100 = icmp ne i32 %99, 0
  %101 = xor i1 %100, true
  %102 = xor i1 %101, true
  %103 = zext i1 %102 to i32
  %104 = sext i32 %103 to i64
  %105 = call i64 @llvm.expect.i64(i64 %104, i64 1)
  %106 = icmp ne i64 %105, 0
  br i1 %106, label %107, label %125

107:                                              ; preds = %96
  br label %108

108:                                              ; preds = %107
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.MDBX_txn, ptr %109, i32 0, i32 4
  %111 = load ptr, ptr %110, align 8, !tbaa !34
  %112 = icmp eq ptr %111, null
  %113 = xor i1 %112, true
  %114 = xor i1 %113, true
  %115 = xor i1 %114, true
  %116 = zext i1 %115 to i32
  %117 = sext i32 %116 to i64
  %118 = call i64 @llvm.expect.i64(i64 %117, i64 0)
  %119 = icmp ne i64 %118, 0
  br i1 %119, label %120, label %122

120:                                              ; preds = %108
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %121, ptr noundef @.str.8, ptr noundef @__func__.txn_basal_end, i32 noundef 149) #7
  unreachable

122:                                              ; preds = %108
  br label %123

123:                                              ; preds = %122
  br label %124

124:                                              ; preds = %123
  br label %125

125:                                              ; preds = %124, %96
  br label %126

126:                                              ; preds = %125
  br label %127

127:                                              ; preds = %126
  %128 = load ptr, ptr %3, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.MDBX_txn, ptr %128, i32 0, i32 17
  %130 = getelementptr inbounds %struct.anon.2, ptr %129, i32 0, i32 8
  call void @pnl_shrink(ptr noundef %130)
  %131 = load ptr, ptr %3, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.MDBX_txn, ptr %131, i32 0, i32 17
  %133 = getelementptr inbounds %struct.anon.2, ptr %132, i32 0, i32 1
  call void @pnl_shrink(ptr noundef %133)
  %134 = load ptr, ptr %5, align 8, !tbaa !5
  %135 = getelementptr inbounds %struct.MDBX_env, ptr %134, i32 0, i32 1
  %136 = load i32, ptr %135, align 4, !tbaa !35
  %137 = and i32 %136, 524288
  %138 = icmp ne i32 %137, 0
  br i1 %138, label %141, label %139

139:                                              ; preds = %127
  %140 = load ptr, ptr %3, align 8, !tbaa !5
  call void @dpl_release_shadows(ptr noundef %140)
  br label %141

141:                                              ; preds = %139, %127
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %142 = load ptr, ptr %3, align 8, !tbaa !5
  %143 = load i32, ptr %4, align 4, !tbaa !9
  %144 = and i32 %143, 16
  %145 = icmp ne i32 %144, 0
  %146 = call i32 @dbi_update(ptr noundef %142, i1 noundef zeroext %145)
  store i32 %146, ptr %6, align 4, !tbaa !9
  %147 = load i32, ptr %6, align 4, !tbaa !9
  %148 = icmp ne i32 %147, 0
  %149 = xor i1 %148, true
  %150 = xor i1 %149, true
  %151 = zext i1 %150 to i32
  %152 = sext i32 %151 to i64
  %153 = call i64 @llvm.expect.i64(i64 %152, i64 0)
  %154 = icmp ne i64 %153, 0
  br i1 %154, label %155, label %171

155:                                              ; preds = %141
  br label %156

156:                                              ; preds = %155
  %157 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !36
  %158 = zext i8 %157 to i32
  %159 = icmp sle i32 1, %158
  %160 = xor i1 %159, true
  %161 = xor i1 %160, true
  %162 = zext i1 %161 to i32
  %163 = sext i32 %162 to i64
  %164 = call i64 @llvm.expect.i64(i64 %163, i64 0)
  %165 = icmp ne i64 %164, 0
  br i1 %165, label %166, label %168

166:                                              ; preds = %156
  %167 = load i32, ptr %6, align 4, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.txn_basal_end, i32 noundef 158, ptr noundef @.str.9, i32 noundef %167)
  br label %168

168:                                              ; preds = %166, %156
  br label %169

169:                                              ; preds = %168
  br label %170

170:                                              ; preds = %169
  store i32 -30779, ptr %6, align 4, !tbaa !9
  br label %171

171:                                              ; preds = %170, %141
  %172 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lck_txn_unlock(ptr noundef %172)
  %173 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  ret i32 %173
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @dxb_sanitize_tail(ptr noundef, ptr noundef) #5

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

declare void @pnl_shrink(ptr noundef) #2

declare void @dpl_release_shadows(ptr noundef) #2

declare i32 @dbi_update(ptr noundef, i1 noundef zeroext) #2

declare void @lck_txn_unlock(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { "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 = { 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 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 80}
!12 = !{!"MDBX_txn", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !13, i64 64, !13, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !16, i64 128, !6, i64 160, !7, i64 168}
!13 = !{!"long", !7, i64 0}
!14 = !{!"geo", !15, i64 0, !15, i64 2, !10, i64 4, !10, i64 8, !7, i64 12, !7, i64 16}
!15 = !{!"short", !7, i64 0}
!16 = !{!"MDBX_canary", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!17 = !{!18, !7, i64 25}
!18 = !{!"libmdbx_globals", !7, i64 0, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !19, i64 27, !10, i64 28, !7, i64 32, !7, i64 40, !13, i64 80, !6, i64 88}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!12, !10, i64 4}
!21 = !{!12, !13, i64 16}
!22 = !{!12, !13, i64 64}
!23 = !{!24, !6, i64 104}
!24 = !{!"MDBX_env", !7, i64 0, !10, i64 4, !10, i64 8, !25, i64 16, !10, i64 56, !10, i64 60, !25, i64 64, !6, i64 104, !15, i64 112, !15, i64 114, !15, i64 116, !15, i64 118, !15, i64 120, !15, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !15, i64 130, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !26, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !10, i64 224, !10, i64 228, !10, i64 232, !6, i64 240, !6, i64 248, !13, i64 256, !27, i64 264, !29, i64 320, !19, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !30, i64 392, !7, i64 400, !10, i64 440, !10, i64 444, !6, i64 448, !31, i64 456, !7, i64 496, !7, i64 536}
!25 = !{!"osal_mmap", !7, i64 0, !10, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!26 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!27 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !13, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !10, i64 28, !10, i64 32, !19, i64 36, !19, i64 37, !19, i64 38, !28, i64 40, !7, i64 48}
!28 = !{!"", !15, i64 0, !15, i64 2, !15, i64 4, !15, i64 6}
!29 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!30 = !{!"", !13, i64 0}
!31 = !{!"osal_ioring", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!32 = !{!7, !7, i64 0}
!33 = !{!24, !6, i64 384}
!34 = !{!12, !6, i64 24}
!35 = !{!24, !10, i64 4}
!36 = !{!18, !7, i64 26}


; 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.7 }
%struct.anon.7 = 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.6 = external hidden unnamed_addr constant [77 x i8], align 1
@__func__.txn_basal_end = external hidden unnamed_addr constant [14 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [67 x i8], align 1

declare void @pnl_free(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -30779, 1) i32 @txn_basal_end(ptr noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 80
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !15
  %6 = and i8 %5, 1
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %16, label %7, !prof !18

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !19
  %10 = and i32 %9, 257
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %.critedge, !prof !20

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load i64, ptr %13, align 8, !tbaa !21
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %.critedge, label %16, !prof !18

.critedge:                                        ; preds = %7, %12
  tail call void @mdbx_assert_fail(ptr noundef %4, ptr noundef nonnull @.str.6, ptr noundef nonnull @__func__.txn_basal_end, i32 noundef 138) #4
  unreachable

16:                                               ; preds = %2, %12
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  %18 = load i64, ptr %17, align 8, !tbaa !22
  %19 = getelementptr inbounds i8, ptr %4, i64 104
  %20 = load ptr, ptr %19, align 8, !tbaa !23
  %21 = getelementptr inbounds i8, ptr %20, i64 360
  %22 = load volatile i64, ptr %21, align 8, !tbaa !32
  %.not26 = icmp ult i64 %18, %22
  br i1 %.not26, label %23, label %24, !prof !18

23:                                               ; preds = %16
  tail call void @mdbx_assert_fail(ptr noundef nonnull %4, ptr noundef nonnull @.str.7, ptr noundef nonnull @__func__.txn_basal_end, i32 noundef 139) #4
  unreachable

24:                                               ; preds = %16
  tail call void @dxb_sanitize_tail(ptr noundef nonnull %4, ptr noundef null)
  %25 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 1, ptr %25, align 4, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %4, i64 384
  store ptr null, ptr %26, align 8, !tbaa !33
  %27 = getelementptr inbounds i8, ptr %0, i64 536
  %28 = load ptr, ptr %27, align 8, !tbaa !32
  tail call void @pnl_free(ptr noundef %28) #5
  store ptr null, ptr %27, align 8, !tbaa !32
  %29 = getelementptr inbounds i8, ptr %0, i64 208
  tail call void @rkl_clear_and_shrink(ptr noundef nonnull %29)
  %30 = getelementptr inbounds i8, ptr %0, i64 344
  tail call void @rkl_clear_and_shrink(ptr noundef nonnull %30)
  %31 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !15
  %32 = and i8 %31, 1
  %.not27 = icmp eq i8 %32, 0
  br i1 %.not27, label %37, label %33, !prof !18

33:                                               ; preds = %24
  %34 = getelementptr inbounds i8, ptr %0, i64 24
  %35 = load ptr, ptr %34, align 8, !tbaa !34
  %.not28 = icmp eq ptr %35, null
  br i1 %.not28, label %37, label %36, !prof !20

36:                                               ; preds = %33
  tail call void @mdbx_assert_fail(ptr noundef nonnull %4, ptr noundef nonnull @.str.8, ptr noundef nonnull @__func__.txn_basal_end, i32 noundef 149) #4
  unreachable

37:                                               ; preds = %33, %24
  %38 = getelementptr inbounds i8, ptr %0, i64 504
  tail call void @pnl_shrink(ptr noundef nonnull %38) #5
  %39 = getelementptr inbounds i8, ptr %0, i64 200
  tail call void @pnl_shrink(ptr noundef nonnull %39) #5
  %40 = getelementptr inbounds i8, ptr %4, i64 4
  %41 = load i32, ptr %40, align 4, !tbaa !35
  %42 = and i32 %41, 524288
  %.not29 = icmp eq i32 %42, 0
  br i1 %.not29, label %43, label %44

43:                                               ; preds = %37
  tail call void @dpl_release_shadows(ptr noundef nonnull %0) #5
  br label %44

44:                                               ; preds = %43, %37
  %45 = and i32 %1, 16
  %46 = icmp ne i32 %45, 0
  %47 = tail call i32 @dbi_update(ptr noundef nonnull %0, i1 noundef zeroext %46) #5
  %.not30 = icmp eq i32 %47, 0
  br i1 %.not30, label %51, label %48, !prof !20

48:                                               ; preds = %44
  %49 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !36
  %.not31 = icmp eq i8 %49, 0
  br i1 %.not31, label %51, label %50, !prof !20

50:                                               ; preds = %48
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.txn_basal_end, i32 noundef 158, ptr noundef nonnull @.str.9, i32 noundef %47) #5
  br label %51

51:                                               ; preds = %48, %50, %44
  %.0 = phi i32 [ 0, %44 ], [ -30779, %50 ], [ -30779, %48 ]
  tail call void @lck_txn_unlock(ptr noundef nonnull %4) #5
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @dxb_sanitize_tail(ptr noundef, ptr noundef) local_unnamed_addr #3

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

declare void @pnl_shrink(ptr noundef) local_unnamed_addr #0

declare void @dpl_release_shadows(ptr noundef) local_unnamed_addr #0

declare i32 @dbi_update(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare void @lck_txn_unlock(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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, !11, i64 80}
!6 = !{!"MDBX_txn", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !11, i64 24, !11, i64 32, !12, i64 40, !10, i64 64, !10, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !14, i64 128, !11, i64 160, !8, i64 168}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"geo", !13, i64 0, !13, i64 2, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 16}
!13 = !{!"short", !8, i64 0}
!14 = !{!"MDBX_canary", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!15 = !{!16, !8, i64 25}
!16 = !{!"libmdbx_globals", !8, i64 0, !7, i64 16, !7, i64 20, !8, i64 24, !8, i64 25, !8, i64 26, !17, i64 27, !7, i64 28, !8, i64 32, !8, i64 40, !10, i64 80, !11, i64 88}
!17 = !{!"_Bool", !8, i64 0}
!18 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!19 = !{!6, !7, i64 4}
!20 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!21 = !{!6, !10, i64 16}
!22 = !{!6, !10, i64 64}
!23 = !{!24, !11, i64 104}
!24 = !{!"MDBX_env", !8, i64 0, !7, i64 4, !7, i64 8, !25, i64 16, !7, i64 56, !7, i64 60, !25, i64 64, !11, i64 104, !13, i64 112, !13, i64 114, !13, i64 116, !13, i64 118, !13, i64 120, !13, i64 122, !8, i64 124, !8, i64 128, !8, i64 129, !13, i64 130, !7, i64 132, !7, i64 136, !7, i64 140, !7, i64 144, !26, i64 152, !11, i64 184, !11, i64 192, !11, i64 200, !11, i64 208, !11, i64 216, !7, i64 224, !7, i64 228, !7, i64 232, !11, i64 240, !11, i64 248, !10, i64 256, !27, i64 264, !29, i64 320, !17, i64 360, !11, i64 368, !11, i64 376, !11, i64 384, !30, i64 392, !8, i64 400, !7, i64 440, !7, i64 444, !11, i64 448, !31, i64 456, !8, i64 496, !8, i64 536}
!25 = !{!"osal_mmap", !8, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!26 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!27 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !8, i64 24, !8, i64 25, !8, i64 26, !8, i64 27, !7, i64 28, !7, i64 32, !17, i64 36, !17, i64 37, !17, i64 38, !28, i64 40, !8, i64 48}
!28 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6}
!29 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!30 = !{!"", !10, i64 0}
!31 = !{!"osal_ioring", !7, i64 0, !7, i64 4, !7, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!32 = !{!8, !8, i64 0}
!33 = !{!24, !11, i64 384}
!34 = !{!6, !11, i64 24}
!35 = !{!24, !7, i64 4}
!36 = !{!16, !8, i64 26}


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