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

; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }
%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.1, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.2, %struct.anon.6, i8, ptr, ptr, ptr, %struct.anon.7, %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, i32, i64, i64, i64 }
%union.anon = type { ptr }
%union.mdbx_atomic_uint32_t = type { i32 }
%struct.anon.1 = type { ptr, ptr, ptr, ptr }
%struct.anon.2 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.3, %union.anon.4 }
%struct.anon.3 = type { i16, i16, i16, i16 }
%union.anon.4 = type { i32 }
%struct.anon.6 = type { i64, i64, i64, i64, i64 }
%struct.anon.7 = type { i64 }
%struct.osal_ioring = type { i32, i32, i32, ptr, 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.18 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.12, %union.anon.13 }
%union.anon.12 = type { i32 }
%union.anon.13 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.18 = type { %struct.anon.20 }
%struct.anon.20 = type { %struct.troika, ptr, %struct.anon.21, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.22 }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.anon.21 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.22 = type { %struct.anon.23 }
%struct.anon.23 = type { i64, ptr }
%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.10, %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.8 }
%struct.anon.8 = 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.9 }
%struct.anon.9 = type { i64, i64, i32 }
%struct.anon.10 = 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 }
%struct.page = type <{ i64, i16, i16, %union.anon.25, i32, [0 x i16] }>
%union.anon.25 = type { i32 }

@globals = external global %struct.libmdbx_globals, align 8
@__func__.mdbx_env_close_ex = external hidden unnamed_addr constant [18 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [39 x i8], align 1

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

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

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

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

declare i32 @osal_fastmutex_destroy(ptr noundef) #2

; Function Attrs: inlinehint nounwind willreturn memory(none) uwtable
declare hidden ptr @lckless_stub(ptr noundef) #4

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @osal_getpid() #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden zeroext i1 @atomic_cas32(ptr noundef, i32 noundef, i32 noundef) #6

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_env_close_ex(ptr noundef %0, i1 noundef zeroext %1) #7 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.stat, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  %12 = zext i1 %1 to i8
  store i8 %12, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #10
  store i32 0, ptr %7, align 4, !tbaa !11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  %15 = xor i1 %14, true
  %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 0)
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %2
  %23 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_env_close_ex, i32 noundef 579)
  store i32 %23, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %299

24:                                               ; preds = %2
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MDBX_env, ptr %25, i32 0, i32 0
  %27 = load volatile i32, ptr %26, align 8, !tbaa !13
  %28 = icmp ne i32 %27, 445224513
  %29 = xor i1 %28, true
  %30 = xor i1 %29, true
  %31 = zext i1 %30 to i32
  %32 = sext i32 %31 to i64
  %33 = call i64 @llvm.expect.i64(i64 %32, i64 0)
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %24
  %36 = call i32 @log_if_error(i32 noundef -30420, ptr noundef @__func__.mdbx_env_close_ex, i32 noundef 582)
  store i32 %36, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %299

37:                                               ; preds = %24
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.MDBX_env, ptr %38, i32 0, i32 20
  %40 = load i32, ptr %39, align 4, !tbaa !14
  %41 = call i32 @osal_getpid()
  %42 = icmp ne i32 %40, %41
  %43 = xor i1 %42, true
  %44 = xor i1 %43, true
  %45 = zext i1 %44 to i32
  %46 = sext i32 %45 to i64
  %47 = call i64 @llvm.expect.i64(i64 %46, i64 0)
  %48 = icmp ne i64 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %37
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.MDBX_env, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !25
  %53 = or i32 %52, -2147483648
  store i32 %53, ptr %51, align 4, !tbaa !25
  br label %54

54:                                               ; preds = %49, %37
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.MDBX_env, ptr %55, i32 0, i32 3
  %57 = getelementptr inbounds %struct.osal_mmap, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %89

60:                                               ; preds = %54
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.MDBX_env, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !25
  %64 = and i32 %63, -2147352576
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %66, label %89

66:                                               ; preds = %60
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.MDBX_env, ptr %67, i32 0, i32 24
  %69 = load ptr, ptr %68, align 8, !tbaa !26
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %89

71:                                               ; preds = %66
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.MDBX_env, ptr %72, i32 0, i32 24
  %74 = load ptr, ptr %73, align 8, !tbaa !26
  %75 = getelementptr inbounds %struct.MDBX_txn, ptr %74, i32 0, i32 3
  %76 = load i64, ptr %75, align 8, !tbaa !27
  %77 = icmp ne i64 %76, 0
  br i1 %77, label %78, label %88

78:                                               ; preds = %71
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.MDBX_env, ptr %79, i32 0, i32 24
  %81 = load ptr, ptr %80, align 8, !tbaa !26
  %82 = getelementptr inbounds %struct.MDBX_txn, ptr %81, i32 0, i32 3
  %83 = load i64, ptr %82, align 8, !tbaa !27
  %84 = call i64 @osal_thread_self()
  %85 = icmp ne i64 %83, %84
  br i1 %85, label %86, label %88

86:                                               ; preds = %78
  %87 = call i32 @log_if_error(i32 noundef -30778, ptr noundef @__func__.mdbx_env_close_ex, i32 noundef 595)
  store i32 %87, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %299

88:                                               ; preds = %78, %71
  br label %90

89:                                               ; preds = %66, %60, %54
  store i8 1, ptr %5, align 1, !tbaa !9
  br label %90

90:                                               ; preds = %89, %88
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.MDBX_env, ptr %91, i32 0, i32 0
  %93 = call zeroext i1 @atomic_cas32(ptr noundef %92, i32 noundef 445224513, i32 noundef 0)
  br i1 %93, label %96, label %94

94:                                               ; preds = %90
  %95 = call i32 @log_if_error(i32 noundef -30420, ptr noundef @__func__.mdbx_env_close_ex, i32 noundef 600)
  store i32 %95, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %299

96:                                               ; preds = %90
  %97 = load i8, ptr %5, align 1, !tbaa !9, !range !31, !noundef !32
  %98 = trunc i8 %97 to i1
  br i1 %98, label %146, label %99

99:                                               ; preds = %96
  call void @llvm.lifetime.start.p0(i64 144, ptr %9) #10
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.MDBX_env, ptr %100, i32 0, i32 3
  %102 = getelementptr inbounds %struct.osal_mmap, ptr %101, i32 0, i32 1
  %103 = load i32, ptr %102, align 8, !tbaa !33
  %104 = call i32 @fstat64(i32 noundef %103, ptr noundef %9) #10
  %105 = icmp ne i32 %104, 0
  %106 = xor i1 %105, true
  %107 = xor i1 %106, true
  %108 = zext i1 %107 to i32
  %109 = sext i32 %108 to i64
  %110 = call i64 @llvm.expect.i64(i64 %109, i64 0)
  %111 = icmp ne i64 %110, 0
  br i1 %111, label %112, label %115

112:                                              ; preds = %99
  %113 = call ptr @__errno_location() #11
  %114 = load i32, ptr %113, align 4, !tbaa !11
  store i32 %114, ptr %7, align 4, !tbaa !11
  br label %145

115:                                              ; preds = %99
  %116 = getelementptr inbounds %struct.stat, ptr %9, i32 0, i32 2
  %117 = load i64, ptr %116, align 8, !tbaa !34
  %118 = icmp ugt i64 %117, 0
  br i1 %118, label %119, label %144

119:                                              ; preds = %115
  %120 = load ptr, ptr %4, align 8, !tbaa !5
  %121 = call i32 @env_sync(ptr noundef %120, i1 noundef zeroext true, i1 noundef zeroext true)
  store i32 %121, ptr %7, align 4, !tbaa !11
  %122 = load i32, ptr %7, align 4, !tbaa !11
  %123 = icmp eq i32 %122, -30778
  br i1 %123, label %139, label %124

124:                                              ; preds = %119
  %125 = load i32, ptr %7, align 4, !tbaa !11
  %126 = icmp eq i32 %125, 11
  br i1 %126, label %139, label %127

127:                                              ; preds = %124
  %128 = load i32, ptr %7, align 4, !tbaa !11
  %129 = icmp eq i32 %128, 13
  br i1 %129, label %139, label %130

130:                                              ; preds = %127
  %131 = load i32, ptr %7, align 4, !tbaa !11
  %132 = icmp eq i32 %131, 16
  br i1 %132, label %139, label %133

133:                                              ; preds = %130
  %134 = load i32, ptr %7, align 4, !tbaa !11
  %135 = icmp eq i32 %134, 11
  br i1 %135, label %139, label %136

136:                                              ; preds = %133
  %137 = load i32, ptr %7, align 4, !tbaa !11
  %138 = icmp eq i32 %137, -1
  br i1 %138, label %139, label %140

139:                                              ; preds = %136, %133, %130, %127, %124, %119
  br label %142

140:                                              ; preds = %136
  %141 = load i32, ptr %7, align 4, !tbaa !11
  br label %142

142:                                              ; preds = %140, %139
  %143 = phi i32 [ 0, %139 ], [ %141, %140 ]
  store i32 %143, ptr %7, align 4, !tbaa !11
  br label %144

144:                                              ; preds = %142, %115
  br label %145

145:                                              ; preds = %144, %112
  call void @llvm.lifetime.end.p0(i64 144, ptr %9) #10
  br label %146

146:                                              ; preds = %145, %96
  %147 = load ptr, ptr %4, align 8, !tbaa !5
  %148 = getelementptr inbounds %struct.MDBX_env, ptr %147, i32 0, i32 24
  %149 = load ptr, ptr %148, align 8, !tbaa !26
  %150 = icmp ne ptr %149, null
  br i1 %150, label %151, label %169

151:                                              ; preds = %146
  br i1 true, label %152, label %160

152:                                              ; preds = %151
  %153 = load ptr, ptr %4, align 8, !tbaa !5
  %154 = getelementptr inbounds %struct.MDBX_env, ptr %153, i32 0, i32 24
  %155 = load ptr, ptr %154, align 8, !tbaa !26
  %156 = getelementptr inbounds %struct.MDBX_txn, ptr %155, i32 0, i32 3
  %157 = load i64, ptr %156, align 8, !tbaa !27
  %158 = call i64 @osal_thread_self()
  %159 = icmp eq i64 %157, %158
  br i1 %159, label %167, label %169

160:                                              ; preds = %151
  %161 = load ptr, ptr %4, align 8, !tbaa !5
  %162 = getelementptr inbounds %struct.MDBX_env, ptr %161, i32 0, i32 24
  %163 = load ptr, ptr %162, align 8, !tbaa !26
  %164 = getelementptr inbounds %struct.MDBX_txn, ptr %163, i32 0, i32 3
  %165 = load i64, ptr %164, align 8, !tbaa !27
  %166 = icmp ne i64 %165, 0
  br i1 %166, label %167, label %169

167:                                              ; preds = %160, %152
  %168 = load ptr, ptr %4, align 8, !tbaa !5
  call void @lck_txn_unlock(ptr noundef %168)
  br label %169

169:                                              ; preds = %167, %160, %152, %146
  br label %170

170:                                              ; preds = %169
  %171 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !37
  %172 = zext i8 %171 to i32
  %173 = and i32 %172, 1
  %174 = icmp ne i32 %173, 0
  %175 = xor i1 %174, true
  %176 = xor i1 %175, true
  %177 = zext i1 %176 to i32
  %178 = sext i32 %177 to i64
  %179 = call i64 @llvm.expect.i64(i64 %178, i64 1)
  %180 = icmp ne i64 %179, 0
  br i1 %180, label %181, label %199

181:                                              ; preds = %170
  br label %182

182:                                              ; preds = %181
  %183 = load ptr, ptr %4, align 8, !tbaa !5
  %184 = getelementptr inbounds %struct.MDBX_env, ptr %183, i32 0, i32 0
  %185 = load volatile i32, ptr %184, align 8, !tbaa !13
  %186 = icmp eq i32 %185, 0
  %187 = xor i1 %186, true
  %188 = xor i1 %187, true
  %189 = xor i1 %188, true
  %190 = zext i1 %189 to i32
  %191 = sext i32 %190 to i64
  %192 = call i64 @llvm.expect.i64(i64 %191, i64 0)
  %193 = icmp ne i64 %192, 0
  br i1 %193, label %194, label %196

194:                                              ; preds = %182
  %195 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %195, ptr noundef @.str.12, ptr noundef @__func__.mdbx_env_close_ex, i32 noundef 627) #12
  unreachable

196:                                              ; preds = %182
  br label %197

197:                                              ; preds = %196
  br label %198

198:                                              ; preds = %197
  br label %199

199:                                              ; preds = %198, %170
  br label %200

200:                                              ; preds = %199
  br label %201

201:                                              ; preds = %200
  %202 = load ptr, ptr %4, align 8, !tbaa !5
  %203 = call i32 @env_close(ptr noundef %202, i1 noundef zeroext false)
  %204 = icmp ne i32 %203, 0
  br i1 %204, label %205, label %206

205:                                              ; preds = %201
  br label %208

206:                                              ; preds = %201
  %207 = load i32, ptr %7, align 4, !tbaa !11
  br label %208

208:                                              ; preds = %206, %205
  %209 = phi i32 [ -30795, %205 ], [ %207, %206 ]
  store i32 %209, ptr %7, align 4, !tbaa !11
  br label %210

210:                                              ; preds = %208
  %211 = load ptr, ptr %4, align 8, !tbaa !5
  %212 = getelementptr inbounds %struct.MDBX_env, ptr %211, i32 0, i32 41
  %213 = call i32 @osal_fastmutex_destroy(ptr noundef %212)
  %214 = icmp eq i32 %213, 0
  %215 = xor i1 %214, true
  %216 = xor i1 %215, true
  %217 = xor i1 %216, true
  %218 = zext i1 %217 to i32
  %219 = sext i32 %218 to i64
  %220 = call i64 @llvm.expect.i64(i64 %219, i64 0)
  %221 = icmp ne i64 %220, 0
  br i1 %221, label %222, label %224

222:                                              ; preds = %210
  %223 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %223, ptr noundef @.str.13, ptr noundef @__func__.mdbx_env_close_ex, i32 noundef 629) #12
  unreachable

224:                                              ; preds = %210
  br label %225

225:                                              ; preds = %224
  br label %226

226:                                              ; preds = %225
  br label %227

227:                                              ; preds = %226
  %228 = load ptr, ptr %4, align 8, !tbaa !5
  %229 = getelementptr inbounds %struct.MDBX_env, ptr %228, i32 0, i32 46
  %230 = call i32 @osal_fastmutex_destroy(ptr noundef %229)
  %231 = icmp eq i32 %230, 0
  %232 = xor i1 %231, true
  %233 = xor i1 %232, true
  %234 = xor i1 %233, true
  %235 = zext i1 %234 to i32
  %236 = sext i32 %235 to i64
  %237 = call i64 @llvm.expect.i64(i64 %236, i64 0)
  %238 = icmp ne i64 %237, 0
  br i1 %238, label %239, label %241

239:                                              ; preds = %227
  %240 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %240, ptr noundef @.str.14, ptr noundef @__func__.mdbx_env_close_ex, i32 noundef 634) #12
  unreachable

241:                                              ; preds = %227
  br label %242

242:                                              ; preds = %241
  br label %243

243:                                              ; preds = %242
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #10
  %244 = load ptr, ptr %4, align 8, !tbaa !5
  %245 = call ptr @lckless_stub(ptr noundef %244) #11
  store ptr %245, ptr %10, align 8, !tbaa !5
  %246 = load ptr, ptr %10, align 8, !tbaa !5
  %247 = getelementptr inbounds %struct.shared_lck, ptr %246, i32 0, i32 11
  %248 = call i32 @lck_ipclock_destroy(ptr noundef %247)
  br label %249

249:                                              ; preds = %280, %243
  %250 = load ptr, ptr %4, align 8, !tbaa !5
  %251 = getelementptr inbounds %struct.MDBX_env, ptr %250, i32 0, i32 44
  %252 = load ptr, ptr %251, align 8, !tbaa !39
  store ptr %252, ptr %6, align 8, !tbaa !5
  %253 = icmp ne ptr %252, null
  br i1 %253, label %254, label %295

254:                                              ; preds = %249
  br label %255

255:                                              ; preds = %254
  br label %256

256:                                              ; preds = %255
  %257 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !40
  %258 = zext i8 %257 to i32
  %259 = icmp sle i32 6, %258
  %260 = xor i1 %259, true
  %261 = xor i1 %260, true
  %262 = zext i1 %261 to i32
  %263 = sext i32 %262 to i64
  %264 = call i64 @llvm.expect.i64(i64 %263, i64 0)
  %265 = icmp ne i64 %264, 0
  br i1 %265, label %266, label %272

266:                                              ; preds = %256
  %267 = load ptr, ptr %6, align 8, !tbaa !5
  %268 = load ptr, ptr %4, align 8, !tbaa !5
  %269 = getelementptr inbounds %struct.MDBX_env, ptr %268, i32 0, i32 2
  %270 = load i32, ptr %269, align 8, !tbaa !41
  %271 = zext i32 %270 to i64
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.mdbx_env_close_ex, i32 noundef 644, ptr noundef @.str.15, ptr noundef %267, i64 noundef %271, i32 noundef 644)
  br label %272

272:                                              ; preds = %266, %256
  br label %273

273:                                              ; preds = %272
  br label %274

274:                                              ; preds = %273
  %275 = load ptr, ptr %6, align 8, !tbaa !5
  %276 = load ptr, ptr %4, align 8, !tbaa !5
  %277 = getelementptr inbounds %struct.MDBX_env, ptr %276, i32 0, i32 2
  %278 = load i32, ptr %277, align 8, !tbaa !41
  br label %279

279:                                              ; preds = %274
  br label %280

280:                                              ; preds = %279
  %281 = load ptr, ptr %6, align 8, !tbaa !5
  %282 = getelementptr inbounds %struct.page, ptr %281, i32 0, i32 5
  %283 = getelementptr inbounds [0 x i16], ptr %282, i64 0, i64 0
  %284 = ptrtoint ptr %283 to i64
  %285 = add nsw i64 %284, 4
  %286 = inttoptr i64 %285 to ptr
  %287 = load ptr, ptr %286, align 8, !tbaa !5
  %288 = load ptr, ptr %4, align 8, !tbaa !5
  %289 = getelementptr inbounds %struct.MDBX_env, ptr %288, i32 0, i32 44
  store ptr %287, ptr %289, align 8, !tbaa !39
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #10
  %290 = load ptr, ptr %6, align 8, !tbaa !5
  %291 = ptrtoint ptr %290 to i64
  %292 = add nsw i64 %291, -8
  %293 = inttoptr i64 %292 to ptr
  store ptr %293, ptr %11, align 8, !tbaa !5
  %294 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %294) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #10
  br label %249, !llvm.loop !42

295:                                              ; preds = %249
  %296 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %296) #10
  %297 = load i32, ptr %7, align 4, !tbaa !11
  %298 = call i32 @log_if_error(i32 noundef %297, ptr noundef @__func__.mdbx_env_close_ex, i32 noundef 653)
  store i32 %298, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #10
  br label %299

299:                                              ; preds = %295, %94, %86, %35, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #10
  %300 = load i32, ptr %3, align 4
  ret i32 %300
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @osal_thread_self() #1

; Function Attrs: nounwind
declare i32 @fstat64(i32 noundef, ptr noundef) #5

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #8

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

declare void @lck_txn_unlock(ptr noundef) #2

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

declare i32 @lck_ipclock_destroy(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint nounwind willreturn memory(none) 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 "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 = { 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 #7 = { cold nounwind optsize uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #8 = { nounwind willreturn memory(none) "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 #9 = { 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 #10 = { nounwind }
attributes #11 = { nounwind willreturn memory(none) }
attributes #12 = { 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 = !{!7, !7, i64 0}
!14 = !{!15, !12, i64 140}
!15 = !{!"MDBX_env", !7, i64 0, !12, i64 4, !12, i64 8, !16, i64 16, !12, i64 56, !12, i64 60, !16, i64 64, !6, i64 104, !18, i64 112, !18, i64 114, !18, i64 116, !18, i64 118, !18, i64 120, !18, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !18, i64 130, !12, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !19, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !12, i64 224, !12, i64 228, !12, i64 232, !6, i64 240, !6, i64 248, !17, i64 256, !20, i64 264, !22, i64 320, !10, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !23, i64 392, !7, i64 400, !12, i64 440, !12, i64 444, !6, i64 448, !24, i64 456, !7, i64 496, !7, i64 536}
!16 = !{!"osal_mmap", !7, i64 0, !12, i64 8, !17, i64 16, !17, i64 24, !17, i64 32}
!17 = !{!"long", !7, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!20 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !17, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !12, i64 28, !12, i64 32, !10, i64 36, !10, i64 37, !10, i64 38, !21, i64 40, !7, i64 48}
!21 = !{!"", !18, i64 0, !18, i64 2, !18, i64 4, !18, i64 6}
!22 = !{!"", !17, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32}
!23 = !{!"", !17, i64 0}
!24 = !{!"osal_ioring", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!25 = !{!15, !12, i64 4}
!26 = !{!15, !6, i64 192}
!27 = !{!28, !17, i64 16}
!28 = !{!"MDBX_txn", !12, i64 0, !12, i64 4, !17, i64 8, !17, i64 16, !6, i64 24, !6, i64 32, !29, i64 40, !17, i64 64, !17, 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", !18, i64 0, !18, i64 2, !12, i64 4, !12, i64 8, !7, i64 12, !7, i64 16}
!30 = !{!"MDBX_canary", !17, i64 0, !17, i64 8, !17, i64 16, !17, i64 24}
!31 = !{i8 0, i8 2}
!32 = !{}
!33 = !{!15, !12, i64 24}
!34 = !{!35, !17, i64 16}
!35 = !{!"stat", !17, i64 0, !17, i64 8, !17, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !17, i64 40, !17, i64 48, !17, i64 56, !17, i64 64, !36, i64 72, !36, i64 88, !36, i64 104, !7, i64 120}
!36 = !{!"timespec", !17, i64 0, !17, i64 8}
!37 = !{!38, !7, i64 25}
!38 = !{!"libmdbx_globals", !7, i64 0, !12, i64 16, !12, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !10, i64 27, !12, i64 28, !7, i64 32, !7, i64 40, !17, i64 80, !6, i64 88}
!39 = !{!15, !6, i64 448}
!40 = !{!38, !7, i64 26}
!41 = !{!15, !12, i64 8}
!42 = distinct !{!42, !43}
!43 = !{!"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 }
%struct.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@__func__.mdbx_env_close_ex = external hidden unnamed_addr constant [18 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [39 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 void @debug_log(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

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

declare i32 @osal_fastmutex_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare hidden ptr @lckless_stub(ptr noundef) local_unnamed_addr #3

; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

declare i32 @env_close(ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @osal_getpid() local_unnamed_addr #0

; Function Attrs: alwaysinline nounwind uwtable
declare hidden zeroext i1 @atomic_cas32(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #5

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

4:                                                ; preds = %2
  %5 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_env_close_ex, i32 noundef 579)
  br label %111

6:                                                ; preds = %2
  %7 = load volatile i32, ptr %0, align 8, !tbaa !6
  %.not59 = icmp eq i32 %7, 445224513
  br i1 %.not59, label %10, label %8, !prof !9

8:                                                ; preds = %6
  %9 = tail call i32 @log_if_error(i32 noundef -30420, ptr noundef nonnull @__func__.mdbx_env_close_ex, i32 noundef 582)
  br label %111

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 140
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = tail call i32 @osal_getpid()
  %.not60 = icmp eq i32 %12, %13
  br i1 %.not60, label %18, label %14, !prof !9

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !24
  %17 = or i32 %16, -2147483648
  store i32 %17, ptr %15, align 4, !tbaa !24
  br label %18

18:                                               ; preds = %14, %10
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !6
  %.not61 = icmp eq ptr %20, null
  br i1 %.not61, label %36, label %21

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %0, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !24
  %24 = and i32 %23, -2147352576
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %36

26:                                               ; preds = %21
  %27 = getelementptr inbounds i8, ptr %0, i64 192
  %28 = load ptr, ptr %27, align 8, !tbaa !25
  %.not62 = icmp eq ptr %28, null
  br i1 %.not62, label %36, label %29

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %28, i64 16
  %31 = load i64, ptr %30, align 8, !tbaa !26
  %.not63 = icmp eq i64 %31, 0
  br i1 %.not63, label %36, label %32

32:                                               ; preds = %29
  %33 = tail call i64 @osal_thread_self()
  %.not64 = icmp eq i64 %31, %33
  br i1 %.not64, label %36, label %34

34:                                               ; preds = %32
  %35 = tail call i32 @log_if_error(i32 noundef -30778, ptr noundef nonnull @__func__.mdbx_env_close_ex, i32 noundef 595)
  br label %111

36:                                               ; preds = %18, %21, %26, %29, %32
  %.053.shrunk = phi i1 [ %1, %32 ], [ %1, %29 ], [ true, %26 ], [ true, %21 ], [ true, %18 ]
  %37 = tail call zeroext i1 @atomic_cas32(ptr noundef nonnull %0, i32 noundef 445224513, i32 noundef 0)
  br i1 %37, label %40, label %38

38:                                               ; preds = %36
  %39 = tail call i32 @log_if_error(i32 noundef -30420, ptr noundef nonnull @__func__.mdbx_env_close_ex, i32 noundef 600)
  br label %111

40:                                               ; preds = %36
  br i1 %.053.shrunk, label %61, label %41

41:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %3) #10
  %42 = getelementptr inbounds i8, ptr %0, i64 24
  %43 = load i32, ptr %42, align 8, !tbaa !30
  %44 = call i32 @fstat64(i32 noundef %43, ptr noundef nonnull %3) #10
  %.not65 = icmp eq i32 %44, 0
  br i1 %.not65, label %48, label %45, !prof !9

45:                                               ; preds = %41
  %46 = tail call ptr @__errno_location() #11
  %47 = load i32, ptr %46, align 4, !tbaa !31
  br label %60

48:                                               ; preds = %41
  %49 = getelementptr inbounds i8, ptr %3, i64 16
  %50 = load i64, ptr %49, align 8, !tbaa !32
  %.not66 = icmp eq i64 %50, 0
  br i1 %.not66, label %60, label %51

51:                                               ; preds = %48
  %52 = tail call i32 @env_sync(ptr noundef nonnull %0, i1 noundef zeroext true, i1 noundef zeroext true) #10
  %53 = insertelement <4 x i32> poison, i32 %52, i64 0
  %54 = shufflevector <4 x i32> %53, <4 x i32> poison, <4 x i32> zeroinitializer
  %55 = icmp eq <4 x i32> %54, <i32 -30778, i32 13, i32 16, i32 11>
  %56 = icmp eq i32 %52, -1
  %57 = bitcast <4 x i1> %55 to i4
  %58 = icmp ne i4 %57, 0
  %op.rdx = or i1 %58, %56
  %59 = select i1 %op.rdx, i32 0, i32 %52
  br label %60

60:                                               ; preds = %48, %51, %45
  %.054 = phi i32 [ %47, %45 ], [ %59, %51 ], [ 0, %48 ]
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %3) #10
  br label %61

61:                                               ; preds = %60, %40
  %.1 = phi i32 [ 0, %40 ], [ %.054, %60 ]
  %62 = getelementptr inbounds i8, ptr %0, i64 192
  %63 = load ptr, ptr %62, align 8, !tbaa !25
  %.not67 = icmp eq ptr %63, null
  br i1 %.not67, label %70, label %64

64:                                               ; preds = %61
  %65 = getelementptr inbounds i8, ptr %63, i64 16
  %66 = load i64, ptr %65, align 8, !tbaa !26
  %67 = tail call i64 @osal_thread_self()
  %68 = icmp eq i64 %66, %67
  br i1 %68, label %69, label %70

69:                                               ; preds = %64
  tail call void @lck_txn_unlock(ptr noundef nonnull %0) #10
  br label %70

70:                                               ; preds = %61, %64, %69
  %71 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !35
  %72 = and i8 %71, 1
  %.not68 = icmp eq i8 %72, 0
  br i1 %.not68, label %76, label %73, !prof !5

73:                                               ; preds = %70
  %74 = load volatile i32, ptr %0, align 8, !tbaa !6
  %.not69 = icmp eq i32 %74, 0
  br i1 %.not69, label %76, label %75, !prof !9

75:                                               ; preds = %73
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.12, ptr noundef nonnull @__func__.mdbx_env_close_ex, i32 noundef 627) #12
  unreachable

76:                                               ; preds = %73, %70
  %77 = tail call i32 @env_close(ptr noundef nonnull %0, i1 noundef zeroext false) #10
  %.not70 = icmp eq i32 %77, 0
  %78 = select i1 %.not70, i32 %.1, i32 -30795
  %79 = getelementptr inbounds i8, ptr %0, i64 400
  %80 = tail call i32 @osal_fastmutex_destroy(ptr noundef nonnull %79) #10
  %.not71 = icmp eq i32 %80, 0
  br i1 %.not71, label %82, label %81, !prof !9

81:                                               ; preds = %76
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.13, ptr noundef nonnull @__func__.mdbx_env_close_ex, i32 noundef 629) #12
  unreachable

82:                                               ; preds = %76
  %83 = getelementptr inbounds i8, ptr %0, i64 496
  %84 = tail call i32 @osal_fastmutex_destroy(ptr noundef nonnull %83) #10
  %.not72 = icmp eq i32 %84, 0
  br i1 %.not72, label %86, label %85, !prof !9

85:                                               ; preds = %82
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.14, ptr noundef nonnull @__func__.mdbx_env_close_ex, i32 noundef 634) #12
  unreachable

86:                                               ; preds = %82
  %87 = tail call ptr @lckless_stub(ptr noundef nonnull %0) #11
  %88 = getelementptr inbounds i8, ptr %87, i64 320
  %89 = tail call i32 @lck_ipclock_destroy(ptr noundef nonnull %88) #10
  %90 = getelementptr inbounds i8, ptr %0, i64 448
  %91 = load ptr, ptr %90, align 8, !tbaa !37
  %.not7374 = icmp eq ptr %91, null
  br i1 %.not7374, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %86
  %92 = getelementptr inbounds i8, ptr %0, i64 8
  br label %93

93:                                               ; preds = %.lr.ph, %100
  %94 = phi ptr [ %91, %.lr.ph ], [ %109, %100 ]
  %95 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !38
  %96 = icmp ugt i8 %95, 5
  br i1 %96, label %97, label %100, !prof !5

97:                                               ; preds = %93
  %98 = load i32, ptr %92, align 8, !tbaa !39
  %99 = zext i32 %98 to i64
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.mdbx_env_close_ex, i32 noundef 644, ptr noundef nonnull @.str.15, ptr noundef nonnull %94, i64 noundef %99, i32 noundef 644) #10
  br label %100

100:                                              ; preds = %97, %93
  %101 = getelementptr inbounds i8, ptr %94, i64 20
  %102 = ptrtoint ptr %101 to i64
  %103 = add nsw i64 %102, 4
  %104 = inttoptr i64 %103 to ptr
  %105 = load ptr, ptr %104, align 8, !tbaa !40
  store ptr %105, ptr %90, align 8, !tbaa !37
  %106 = ptrtoint ptr %94 to i64
  %107 = add nsw i64 %106, -8
  %108 = inttoptr i64 %107 to ptr
  tail call void @free(ptr noundef %108) #10
  %109 = load ptr, ptr %90, align 8, !tbaa !37
  %.not73 = icmp eq ptr %109, null
  br i1 %.not73, label %._crit_edge, label %93, !llvm.loop !41

._crit_edge:                                      ; preds = %100, %86
  tail call void @free(ptr noundef nonnull %0) #10
  %110 = tail call i32 @log_if_error(i32 noundef %78, ptr noundef nonnull @__func__.mdbx_env_close_ex, i32 noundef 653)
  br label %111

111:                                              ; preds = %._crit_edge, %38, %34, %8, %4
  %.0 = phi i32 [ %5, %4 ], [ %9, %8 ], [ %35, %34 ], [ %110, %._crit_edge ], [ %39, %38 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @osal_thread_self() local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fstat64(i32 noundef, ptr nocapture noundef) local_unnamed_addr #7

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #8

declare i32 @env_sync(ptr noundef, i1 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #1

declare void @lck_txn_unlock(ptr noundef) local_unnamed_addr #1

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

declare i32 @lck_ipclock_destroy(ptr noundef) local_unnamed_addr #1

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint mustprogress nofree nosync nounwind willreturn memory(none) 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 = { 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 = { 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 #6 = { cold nounwind optsize uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #7 = { nofree 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 #8 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #9 = { 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 #10 = { nounwind }
attributes #11 = { nounwind willreturn memory(none) }
attributes #12 = { 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 1, i32 2000}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!10 = !{!11, !12, i64 140}
!11 = !{!"MDBX_env", !7, i64 0, !12, i64 4, !12, i64 8, !13, i64 16, !12, i64 56, !12, i64 60, !13, i64 64, !15, i64 104, !16, i64 112, !16, i64 114, !16, i64 116, !16, i64 118, !16, i64 120, !16, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !16, i64 130, !12, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !17, i64 152, !15, i64 184, !15, i64 192, !15, i64 200, !15, i64 208, !15, i64 216, !12, i64 224, !12, i64 228, !12, i64 232, !15, i64 240, !15, i64 248, !14, i64 256, !18, i64 264, !21, i64 320, !19, i64 360, !15, i64 368, !15, i64 376, !15, i64 384, !22, i64 392, !7, i64 400, !12, i64 440, !12, i64 444, !15, i64 448, !23, i64 456, !7, i64 496, !7, i64 536}
!12 = !{!"int", !7, i64 0}
!13 = !{!"osal_mmap", !7, i64 0, !12, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24}
!18 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !14, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !12, i64 28, !12, i64 32, !19, i64 36, !19, i64 37, !19, i64 38, !20, i64 40, !7, i64 48}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!"", !16, i64 0, !16, i64 2, !16, i64 4, !16, i64 6}
!21 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!22 = !{!"", !14, i64 0}
!23 = !{!"osal_ioring", !12, i64 0, !12, i64 4, !12, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!24 = !{!11, !12, i64 4}
!25 = !{!11, !15, i64 192}
!26 = !{!27, !14, i64 16}
!27 = !{!"MDBX_txn", !12, i64 0, !12, i64 4, !14, i64 8, !14, i64 16, !15, i64 24, !15, i64 32, !28, i64 40, !14, i64 64, !14, i64 72, !15, i64 80, !15, i64 88, !15, i64 96, !15, i64 104, !15, i64 112, !15, i64 120, !29, i64 128, !15, i64 160, !7, i64 168}
!28 = !{!"geo", !16, i64 0, !16, i64 2, !12, i64 4, !12, i64 8, !7, i64 12, !7, i64 16}
!29 = !{!"MDBX_canary", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!30 = !{!11, !12, i64 24}
!31 = !{!12, !12, i64 0}
!32 = !{!33, !14, i64 16}
!33 = !{!"stat", !14, i64 0, !14, i64 8, !14, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !34, i64 72, !34, i64 88, !34, i64 104, !7, i64 120}
!34 = !{!"timespec", !14, i64 0, !14, i64 8}
!35 = !{!36, !7, i64 25}
!36 = !{!"libmdbx_globals", !7, i64 0, !12, i64 16, !12, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !19, i64 27, !12, i64 28, !7, i64 32, !7, i64 40, !14, i64 80, !15, i64 88}
!37 = !{!11, !15, i64 448}
!38 = !{!36, !7, i64 26}
!39 = !{!11, !12, i64 8}
!40 = !{!15, !15, i64 0}
!41 = distinct !{!41, !42}
!42 = !{!"llvm.loop.mustprogress"}


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