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

; 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_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.9, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.10, %struct.anon.14, i8, ptr, ptr, ptr, %struct.anon.15, %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.8, i32, i64, i64, i64 }
%union.anon.8 = type { ptr }
%union.mdbx_atomic_uint32_t = type { i32 }
%struct.anon.9 = type { ptr, ptr, ptr, ptr }
%struct.anon.10 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.11, %union.anon.12 }
%struct.anon.11 = type { i16, i16, i16, i16 }
%union.anon.12 = type { i32 }
%struct.anon.14 = type { i64, i64, i64, i64, i64 }
%struct.anon.15 = type { i64 }
%struct.osal_ioring = type { i32, i32, i32, ptr, ptr, 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 }
%union.mdbx_atomic_uint64_t = type { i64 }
%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 }

@__func__.mdbx_dbi_close = external hidden unnamed_addr constant [15 x i8], align 1

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

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

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

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

declare i32 @osal_fastmutex_acquire(ptr noundef) #3

declare i32 @dbi_close_release(ptr noundef, i32 noundef) #3

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

19:                                               ; preds = %2
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = call i32 @log_if_error(i32 noundef %20, ptr noundef @__func__.mdbx_dbi_close, i32 noundef 141)
  store i32 %21, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %193

22:                                               ; preds = %2
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = icmp ult i32 %23, 2
  %25 = xor i1 %24, true
  %26 = xor i1 %25, true
  %27 = zext i1 %26 to i32
  %28 = sext i32 %27 to i64
  %29 = call i64 @llvm.expect.i64(i64 %28, i64 0)
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %39

31:                                               ; preds = %22
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  br label %37

35:                                               ; preds = %31
  %36 = call i32 @log_if_error(i32 noundef -30780, ptr noundef @__func__.mdbx_dbi_close, i32 noundef 144)
  br label %37

37:                                               ; preds = %35, %34
  %38 = phi i32 [ 0, %34 ], [ %36, %35 ]
  store i32 %38, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %193

39:                                               ; preds = %22
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.MDBX_env, ptr %41, i32 0, i32 19
  %43 = load i32, ptr %42, align 8, !tbaa !11
  %44 = icmp uge i32 %40, %43
  %45 = xor i1 %44, true
  %46 = xor i1 %45, true
  %47 = zext i1 %46 to i32
  %48 = sext i32 %47 to i64
  %49 = call i64 @llvm.expect.i64(i64 %48, i64 0)
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %39
  %52 = call i32 @log_if_error(i32 noundef -30780, ptr noundef @__func__.mdbx_dbi_close, i32 noundef 147)
  store i32 %52, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %193

53:                                               ; preds = %39
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.MDBX_env, ptr %54, i32 0, i32 41
  %56 = call i32 @osal_fastmutex_acquire(ptr noundef %55)
  store i32 %56, ptr %6, align 4, !tbaa !9
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = icmp ne i32 %57, 0
  %59 = xor i1 %58, true
  %60 = xor i1 %59, true
  %61 = zext i1 %60 to i32
  %62 = sext i32 %61 to i64
  %63 = call i64 @llvm.expect.i64(i64 %62, i64 0)
  %64 = icmp ne i64 %63, 0
  br i1 %64, label %65, label %68

65:                                               ; preds = %53
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = call i32 @log_if_error(i32 noundef %66, ptr noundef @__func__.mdbx_dbi_close, i32 noundef 151)
  store i32 %67, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %193

68:                                               ; preds = %53
  %69 = load i32, ptr %5, align 4, !tbaa !9
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.MDBX_env, ptr %70, i32 0, i32 42
  %72 = load i32, ptr %71, align 8, !tbaa !23
  %73 = icmp uge i32 %69, %72
  %74 = xor i1 %73, true
  %75 = xor i1 %74, true
  %76 = zext i1 %75 to i32
  %77 = sext i32 %76 to i64
  %78 = call i64 @llvm.expect.i64(i64 %77, i64 0)
  %79 = icmp ne i64 %78, 0
  br i1 %79, label %80, label %87

80:                                               ; preds = %68
  store i32 -30780, ptr %6, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %184, %80
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.MDBX_env, ptr %82, i32 0, i32 41
  %84 = call i32 @osal_fastmutex_release(ptr noundef %83)
  %85 = load i32, ptr %6, align 4, !tbaa !9
  %86 = call i32 @log_if_error(i32 noundef %85, ptr noundef @__func__.mdbx_dbi_close, i32 noundef 157)
  store i32 %86, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %193

87:                                               ; preds = %68
  br label %88

88:                                               ; preds = %186, %184, %87
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.MDBX_env, ptr %89, i32 0, i32 24
  %91 = load ptr, ptr %90, align 8, !tbaa !24
  %92 = icmp ne ptr %91, null
  br i1 %92, label %93, label %112

93:                                               ; preds = %88
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.MDBX_env, ptr %94, i32 0, i32 26
  %96 = load ptr, ptr %95, align 8, !tbaa !25
  %97 = load i32, ptr %5, align 4, !tbaa !9
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds i8, ptr %96, i64 %98
  %100 = load i8, ptr %99, align 1, !tbaa !26
  %101 = zext i8 %100 to i32
  %102 = and i32 %101, 128
  %103 = icmp ne i32 %102, 0
  br i1 %103, label %104, label %112

104:                                              ; preds = %93
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.MDBX_env, ptr %105, i32 0, i32 24
  %107 = load ptr, ptr %106, align 8, !tbaa !24
  %108 = getelementptr inbounds %struct.MDBX_txn, ptr %107, i32 0, i32 1
  %109 = load i32, ptr %108, align 4, !tbaa !27
  %110 = and i32 %109, 1
  %111 = icmp eq i32 %110, 0
  br label %112

112:                                              ; preds = %104, %93, %88
  %113 = phi i1 [ false, %93 ], [ false, %88 ], [ %111, %104 ]
  br i1 %113, label %114, label %187

114:                                              ; preds = %112
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %115 = load ptr, ptr %4, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.MDBX_env, ptr %115, i32 0, i32 39
  %117 = load ptr, ptr %116, align 8, !tbaa !31
  store ptr %117, ptr %8, align 8, !tbaa !5
  call void @osal_compiler_barrier()
  %118 = load ptr, ptr %4, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.MDBX_env, ptr %118, i32 0, i32 24
  %120 = load ptr, ptr %119, align 8, !tbaa !24
  %121 = load i32, ptr %5, align 4, !tbaa !9
  %122 = zext i32 %121 to i64
  %123 = call zeroext i8 @dbi_state(ptr noundef %120, i64 noundef %122)
  %124 = zext i8 %123 to i32
  %125 = and i32 %124, 137
  %126 = icmp sgt i32 %125, 128
  br i1 %126, label %127, label %128

127:                                              ; preds = %114
  store i32 -30412, ptr %6, align 4, !tbaa !9
  store i32 2, ptr %7, align 4
  br label %184

128:                                              ; preds = %114
  call void @osal_memory_barrier()
  %129 = load ptr, ptr %8, align 8, !tbaa !5
  %130 = load ptr, ptr %4, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.MDBX_env, ptr %130, i32 0, i32 39
  %132 = load ptr, ptr %131, align 8, !tbaa !31
  %133 = icmp ne ptr %129, %132
  %134 = xor i1 %133, true
  %135 = xor i1 %134, true
  %136 = zext i1 %135 to i32
  %137 = sext i32 %136 to i64
  %138 = call i64 @llvm.expect.i64(i64 %137, i64 0)
  %139 = icmp ne i64 %138, 0
  br i1 %139, label %140, label %141

140:                                              ; preds = %128
  store i32 3, ptr %7, align 4
  br label %184, !llvm.loop !32

141:                                              ; preds = %128
  %142 = load ptr, ptr %8, align 8, !tbaa !5
  %143 = load ptr, ptr %4, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.MDBX_env, ptr %143, i32 0, i32 24
  %145 = load ptr, ptr %144, align 8, !tbaa !24
  %146 = icmp ne ptr %142, %145
  br i1 %146, label %147, label %170

147:                                              ; preds = %141
  %148 = load ptr, ptr %8, align 8, !tbaa !5
  %149 = icmp ne ptr %148, null
  br i1 %149, label %150, label %170

150:                                              ; preds = %147
  %151 = load ptr, ptr %8, align 8, !tbaa !5
  %152 = getelementptr inbounds %struct.MDBX_txn, ptr %151, i32 0, i32 1
  %153 = load i32, ptr %152, align 4, !tbaa !27
  %154 = and i32 %153, 1
  %155 = icmp eq i32 %154, 0
  br i1 %155, label %156, label %170

156:                                              ; preds = %150
  %157 = load ptr, ptr %8, align 8, !tbaa !5
  %158 = getelementptr inbounds %struct.MDBX_txn, ptr %157, i32 0, i32 0
  %159 = load i32, ptr %158, align 8, !tbaa !34
  %160 = icmp eq i32 %159, 332741169
  br i1 %160, label %161, label %170

161:                                              ; preds = %156
  %162 = load ptr, ptr %8, align 8, !tbaa !5
  %163 = load i32, ptr %5, align 4, !tbaa !9
  %164 = zext i32 %163 to i64
  %165 = call zeroext i8 @dbi_state(ptr noundef %162, i64 noundef %164)
  %166 = zext i8 %165 to i32
  %167 = and i32 %166, 137
  %168 = icmp sgt i32 %167, 128
  br i1 %168, label %169, label %170

169:                                              ; preds = %161
  store i32 -30412, ptr %6, align 4, !tbaa !9
  store i32 2, ptr %7, align 4
  br label %184

170:                                              ; preds = %161, %156, %150, %147, %141
  call void @osal_compiler_barrier()
  %171 = load ptr, ptr %8, align 8, !tbaa !5
  %172 = load ptr, ptr %4, align 8, !tbaa !5
  %173 = getelementptr inbounds %struct.MDBX_env, ptr %172, i32 0, i32 39
  %174 = load ptr, ptr %173, align 8, !tbaa !31
  %175 = icmp eq ptr %171, %174
  %176 = xor i1 %175, true
  %177 = xor i1 %176, true
  %178 = zext i1 %177 to i32
  %179 = sext i32 %178 to i64
  %180 = call i64 @llvm.expect.i64(i64 %179, i64 1)
  %181 = icmp ne i64 %180, 0
  br i1 %181, label %182, label %183

182:                                              ; preds = %170
  store i32 4, ptr %7, align 4
  br label %184

183:                                              ; preds = %170
  store i32 0, ptr %7, align 4
  br label %184

184:                                              ; preds = %183, %182, %169, %140, %127
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %185 = load i32, ptr %7, align 4
  switch i32 %185, label %195 [
    i32 0, label %186
    i32 2, label %81
    i32 3, label %88
    i32 4, label %187
  ]

186:                                              ; preds = %184
  br label %88, !llvm.loop !32

187:                                              ; preds = %184, %112
  %188 = load ptr, ptr %4, align 8, !tbaa !5
  %189 = load i32, ptr %5, align 4, !tbaa !9
  %190 = call i32 @dbi_close_release(ptr noundef %188, i32 noundef %189)
  store i32 %190, ptr %6, align 4, !tbaa !9
  %191 = load i32, ptr %6, align 4, !tbaa !9
  %192 = call i32 @log_if_error(i32 noundef %191, ptr noundef @__func__.mdbx_dbi_close, i32 noundef 201)
  store i32 %192, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %193

193:                                              ; preds = %187, %81, %65, %51, %37, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %194 = load i32, ptr %3, align 4
  ret i32 %194

195:                                              ; preds = %184
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_env(ptr noundef, i1 noundef zeroext) #0

declare i32 @osal_fastmutex_release(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @osal_compiler_barrier() #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @dbi_state(ptr noundef, i64 noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @osal_memory_barrier() #0

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { 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 = { 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, !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, !10, i64 136}
!12 = !{!"MDBX_env", !7, i64 0, !10, i64 4, !10, i64 8, !13, i64 16, !10, i64 56, !10, i64 60, !13, 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, !16, 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, !14, i64 256, !17, i64 264, !20, i64 320, !18, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !21, i64 392, !7, i64 400, !10, i64 440, !10, i64 444, !6, i64 448, !22, i64 456, !7, i64 496, !7, i64 536}
!13 = !{!"osal_mmap", !7, i64 0, !10, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !14, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !10, i64 28, !10, i64 32, !18, i64 36, !18, i64 37, !18, i64 38, !19, i64 40, !7, i64 48}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!"", !15, i64 0, !15, i64 2, !15, i64 4, !15, i64 6}
!20 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!21 = !{!"", !14, i64 0}
!22 = !{!"osal_ioring", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!23 = !{!12, !10, i64 440}
!24 = !{!12, !6, i64 192}
!25 = !{!12, !6, i64 208}
!26 = !{!7, !7, i64 0}
!27 = !{!28, !10, i64 4}
!28 = !{!"MDBX_txn", !10, i64 0, !10, i64 4, !14, i64 8, !14, i64 16, !6, i64 24, !6, i64 32, !29, 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, !30, i64 128, !6, i64 160, !7, i64 168}
!29 = !{!"geo", !15, i64 0, !15, i64 2, !10, i64 4, !10, i64 8, !7, i64 12, !7, i64 16}
!30 = !{!"MDBX_canary", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!31 = !{!12, !6, i64 384}
!32 = distinct !{!32, !33}
!33 = !{!"llvm.loop.mustprogress"}
!34 = !{!28, !10, i64 0}


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

@__func__.mdbx_dbi_close = external hidden unnamed_addr constant [15 x i8], align 1

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

declare i32 @osal_fastmutex_acquire(ptr noundef) local_unnamed_addr #1

declare i32 @dbi_close_release(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mdbx_dbi_close(ptr noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = tail call i32 @check_env(ptr noundef %0, i1 noundef zeroext true)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %6, label %4, !prof !5

4:                                                ; preds = %2
  %5 = tail call i32 @log_if_error(i32 noundef %3, ptr noundef nonnull @__func__.mdbx_dbi_close, i32 noundef 141)
  br label %73

6:                                                ; preds = %2
  %7 = icmp ult i32 %1, 2
  br i1 %7, label %8, label %12, !prof !6

8:                                                ; preds = %6
  %9 = icmp eq i32 %1, 1
  br i1 %9, label %73, label %10

10:                                               ; preds = %8
  %11 = tail call i32 @log_if_error(i32 noundef -30780, ptr noundef nonnull @__func__.mdbx_dbi_close, i32 noundef 144)
  br label %73

12:                                               ; preds = %6
  %13 = getelementptr inbounds i8, ptr %0, i64 136
  %14 = load i32, ptr %13, align 8, !tbaa !7
  %.not46 = icmp ugt i32 %14, %1
  br i1 %.not46, label %17, label %15, !prof !5

15:                                               ; preds = %12
  %16 = tail call i32 @log_if_error(i32 noundef -30780, ptr noundef nonnull @__func__.mdbx_dbi_close, i32 noundef 147)
  br label %73

17:                                               ; preds = %12
  %18 = getelementptr inbounds i8, ptr %0, i64 400
  %19 = tail call i32 @osal_fastmutex_acquire(ptr noundef nonnull %18) #3
  %.not47 = icmp eq i32 %19, 0
  br i1 %.not47, label %22, label %20, !prof !5

20:                                               ; preds = %17
  %21 = tail call i32 @log_if_error(i32 noundef %19, ptr noundef nonnull @__func__.mdbx_dbi_close, i32 noundef 151)
  br label %73

22:                                               ; preds = %17
  %23 = getelementptr inbounds i8, ptr %0, i64 440
  %24 = load i32, ptr %23, align 8, !tbaa !23
  %.not48 = icmp ugt i32 %24, %1
  br i1 %.not48, label %.preheader, label %.thread, !prof !5

.preheader:                                       ; preds = %22
  %25 = getelementptr inbounds i8, ptr %0, i64 192
  %26 = load ptr, ptr %25, align 8, !tbaa !24
  %.not4957 = icmp eq ptr %26, null
  br i1 %.not4957, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %27 = getelementptr inbounds i8, ptr %0, i64 208
  %28 = zext i32 %1 to i64
  %29 = getelementptr inbounds i8, ptr %0, i64 384
  br label %32

.thread:                                          ; preds = %62, %42, %22
  %.038 = phi i32 [ -30780, %22 ], [ -30412, %42 ], [ -30412, %62 ]
  %30 = tail call i32 @osal_fastmutex_release(ptr noundef nonnull %18) #3
  %31 = tail call i32 @log_if_error(i32 noundef %.038, ptr noundef nonnull @__func__.mdbx_dbi_close, i32 noundef 157)
  br label %73

32:                                               ; preds = %.lr.ph, %69
  %33 = phi ptr [ %26, %.lr.ph ], [ %70, %69 ]
  %34 = load ptr, ptr %27, align 8, !tbaa !25
  %35 = getelementptr inbounds i8, ptr %34, i64 %28
  %36 = load i8, ptr %35, align 1, !tbaa !26
  %.not50 = icmp sgt i8 %36, -1
  br i1 %.not50, label %.critedge, label %37

37:                                               ; preds = %32
  %38 = getelementptr inbounds i8, ptr %33, i64 4
  %39 = load i32, ptr %38, align 4, !tbaa !27
  %40 = and i32 %39, 1
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %.critedge

42:                                               ; preds = %37
  %43 = load ptr, ptr %29, align 8, !tbaa !31
  tail call void @osal_compiler_barrier()
  %44 = load ptr, ptr %25, align 8, !tbaa !24
  %45 = tail call zeroext i8 @dbi_state(ptr noundef %44, i64 noundef %28)
  %46 = and i8 %45, -119
  %47 = icmp ugt i8 %46, -128
  br i1 %47, label %.thread, label %48

48:                                               ; preds = %42
  tail call void @osal_memory_barrier()
  %49 = load ptr, ptr %29, align 8, !tbaa !31
  %.not51 = icmp eq ptr %43, %49
  br i1 %.not51, label %50, label %69, !prof !5, !llvm.loop !32

50:                                               ; preds = %48
  %51 = load ptr, ptr %25, align 8, !tbaa !24
  %52 = icmp ne ptr %43, %51
  %53 = icmp ne ptr %43, null
  %or.cond = and i1 %53, %52
  br i1 %or.cond, label %54, label %66

54:                                               ; preds = %50
  %55 = getelementptr inbounds i8, ptr %43, i64 4
  %56 = load i32, ptr %55, align 4, !tbaa !27
  %57 = and i32 %56, 1
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %66

59:                                               ; preds = %54
  %60 = load i32, ptr %43, align 8, !tbaa !34
  %61 = icmp eq i32 %60, 332741169
  br i1 %61, label %62, label %66

62:                                               ; preds = %59
  %63 = tail call zeroext i8 @dbi_state(ptr noundef nonnull %43, i64 noundef %28)
  %64 = and i8 %63, -119
  %65 = icmp ugt i8 %64, -128
  br i1 %65, label %.thread, label %66

66:                                               ; preds = %62, %59, %54, %50
  tail call void @osal_compiler_barrier()
  %67 = load ptr, ptr %29, align 8, !tbaa !31
  %68 = icmp eq ptr %43, %67
  br i1 %68, label %.critedge, label %69, !prof !5

69:                                               ; preds = %66, %48
  %70 = load ptr, ptr %25, align 8, !tbaa !24
  %.not49 = icmp eq ptr %70, null
  br i1 %.not49, label %.critedge, label %32

.critedge:                                        ; preds = %37, %69, %32, %66, %.preheader
  %71 = tail call i32 @dbi_close_release(ptr noundef nonnull %0, i32 noundef %1) #3
  %72 = tail call i32 @log_if_error(i32 noundef %71, ptr noundef nonnull @__func__.mdbx_dbi_close, i32 noundef 201)
  br label %73

73:                                               ; preds = %10, %8, %.critedge, %.thread, %20, %15, %4
  %.0 = phi i32 [ %5, %4 ], [ %16, %15 ], [ %21, %20 ], [ %31, %.thread ], [ %72, %.critedge ], [ %11, %10 ], [ 0, %8 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_env(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare i32 @osal_fastmutex_release(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @osal_compiler_barrier() local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @dbi_state(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @osal_memory_barrier() local_unnamed_addr #0

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


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