; LLVM IR from erthink/libmdbx :: src (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.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, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.0, %struct.anon.4, i8, ptr, ptr, ptr, %struct.anon.5, %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 = type { ptr, ptr, ptr, ptr }
%struct.anon.0 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.1, %union.anon.2 }
%struct.anon.1 = type { i16, i16, i16, i16 }
%union.anon.2 = type { i32 }
%struct.anon.4 = type { i64, i64, i64, i64, i64 }
%struct.anon.5 = 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.defer_free_item = type { ptr, i64 }
%struct.kvx = type { %struct.clc2, %struct.iovec }
%struct.clc2 = type { %struct.clc, %struct.clc }
%struct.clc = type { ptr, i64, i64 }
%struct.iovec = type { ptr, i64 }

; 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(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @env_close(ptr noundef %0, i1 noundef zeroext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = zext i1 %1 to i8
  store i8 %10, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.MDBX_env, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %13, ptr %5, align 4, !tbaa !23
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MDBX_env, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = and i32 %16, 1342177279
  store i32 %17, ptr %15, align 4, !tbaa !11
  %18 = load i32, ptr %5, align 4, !tbaa !23
  %19 = and i32 %18, 268435456
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %27

21:                                               ; preds = %2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.MDBX_env, ptr %22, i32 0, i32 21
  %24 = load i32, ptr %23, align 8, !tbaa !24
  call void @thread_key_delete(i32 noundef %24)
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MDBX_env, ptr %25, i32 0, i32 21
  store i32 0, ptr %26, align 8, !tbaa !24
  br label %27

27:                                               ; preds = %21, %2
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.MDBX_env, ptr %28, i32 0, i32 7
  %30 = load ptr, ptr %29, align 8, !tbaa !25
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %34

32:                                               ; preds = %27
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  call void @munlock_all(ptr noundef %33)
  br label %34

34:                                               ; preds = %32, %27
  call void @rthc_lock()
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = call i32 @rthc_remove(ptr noundef %35)
  store i32 %36, ptr %6, align 4, !tbaa !23
  call void @rthc_unlock()
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MDBX_env, ptr %37, i32 0, i32 37
  %39 = load ptr, ptr %38, align 8, !tbaa !26
  store ptr %39, ptr %8, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %49, %34
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %51

44:                                               ; preds = %40
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.defer_free_item, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !27
  store ptr %47, ptr %7, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %48) #5
  br label %49

49:                                               ; preds = %44
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %50, ptr %8, align 8, !tbaa !5
  br label %40, !llvm.loop !29

51:                                               ; preds = %43
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.MDBX_env, ptr %52, i32 0, i32 37
  store ptr null, ptr %53, align 8, !tbaa !26
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.MDBX_env, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !11
  %57 = and i32 %56, 131072
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %62

59:                                               ; preds = %51
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MDBX_env, ptr %60, i32 0, i32 45
  call void @osal_ioring_destroy(ptr noundef %61)
  br label %62

62:                                               ; preds = %59, %51
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.MDBX_env, ptr %63, i32 0, i32 7
  store ptr null, ptr %64, align 8, !tbaa !25
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.MDBX_env, ptr %65, i32 0, i32 6
  %67 = getelementptr inbounds %struct.osal_mmap, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !31
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %74

70:                                               ; preds = %62
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.MDBX_env, ptr %71, i32 0, i32 6
  %73 = call i32 @osal_munmap(ptr noundef %72)
  br label %74

74:                                               ; preds = %70, %62
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.MDBX_env, ptr %75, i32 0, i32 3
  %77 = getelementptr inbounds %struct.osal_mmap, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !31
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %84

80:                                               ; preds = %74
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.MDBX_env, ptr %81, i32 0, i32 3
  %83 = call i32 @osal_munmap(ptr noundef %82)
  br label %84

84:                                               ; preds = %80, %74
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.MDBX_env, ptr %85, i32 0, i32 4
  %87 = load i32, ptr %86, align 8, !tbaa !32
  %88 = icmp ne i32 %87, -1
  br i1 %88, label %89, label %96

89:                                               ; preds = %84
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.MDBX_env, ptr %90, i32 0, i32 4
  %92 = load i32, ptr %91, align 8, !tbaa !32
  %93 = call i32 @osal_closefile(i32 noundef %92)
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.MDBX_env, ptr %94, i32 0, i32 4
  store i32 -1, ptr %95, align 8, !tbaa !32
  br label %96

96:                                               ; preds = %89, %84
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.MDBX_env, ptr %97, i32 0, i32 3
  %99 = getelementptr inbounds %struct.osal_mmap, ptr %98, i32 0, i32 1
  %100 = load i32, ptr %99, align 8, !tbaa !33
  %101 = icmp ne i32 %100, -1
  br i1 %101, label %102, label %111

102:                                              ; preds = %96
  %103 = load ptr, ptr %3, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.MDBX_env, ptr %103, i32 0, i32 3
  %105 = getelementptr inbounds %struct.osal_mmap, ptr %104, i32 0, i32 1
  %106 = load i32, ptr %105, align 8, !tbaa !33
  %107 = call i32 @osal_closefile(i32 noundef %106)
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.MDBX_env, ptr %108, i32 0, i32 3
  %110 = getelementptr inbounds %struct.osal_mmap, ptr %109, i32 0, i32 1
  store i32 -1, ptr %110, align 8, !tbaa !33
  br label %111

111:                                              ; preds = %102, %96
  %112 = load ptr, ptr %3, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.MDBX_env, ptr %112, i32 0, i32 6
  %114 = getelementptr inbounds %struct.osal_mmap, ptr %113, i32 0, i32 1
  %115 = load i32, ptr %114, align 8, !tbaa !34
  %116 = icmp ne i32 %115, -1
  br i1 %116, label %117, label %126

117:                                              ; preds = %111
  %118 = load ptr, ptr %3, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.MDBX_env, ptr %118, i32 0, i32 6
  %120 = getelementptr inbounds %struct.osal_mmap, ptr %119, i32 0, i32 1
  %121 = load i32, ptr %120, align 8, !tbaa !34
  %122 = call i32 @osal_closefile(i32 noundef %121)
  %123 = load ptr, ptr %3, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.MDBX_env, ptr %123, i32 0, i32 6
  %125 = getelementptr inbounds %struct.osal_mmap, ptr %124, i32 0, i32 1
  store i32 -1, ptr %125, align 8, !tbaa !34
  br label %126

126:                                              ; preds = %117, %111
  %127 = load i8, ptr %4, align 1, !tbaa !9, !range !35, !noundef !36
  %128 = trunc i8 %127 to i1
  br i1 %128, label %233, label %129

129:                                              ; preds = %126
  %130 = load ptr, ptr %3, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.MDBX_env, ptr %130, i32 0, i32 25
  %132 = load ptr, ptr %131, align 8, !tbaa !37
  %133 = icmp ne ptr %132, null
  br i1 %133, label %134, label %174

134:                                              ; preds = %129
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 2, ptr %9, align 8, !tbaa !38
  br label %135

135:                                              ; preds = %163, %134
  %136 = load i64, ptr %9, align 8, !tbaa !38
  %137 = load ptr, ptr %3, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.MDBX_env, ptr %137, i32 0, i32 42
  %139 = load i32, ptr %138, align 8, !tbaa !39
  %140 = zext i32 %139 to i64
  %141 = icmp ult i64 %136, %140
  br i1 %141, label %143, label %142

142:                                              ; preds = %135
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %166

143:                                              ; preds = %135
  %144 = load ptr, ptr %3, align 8, !tbaa !5
  %145 = getelementptr inbounds %struct.MDBX_env, ptr %144, i32 0, i32 25
  %146 = load ptr, ptr %145, align 8, !tbaa !37
  %147 = load i64, ptr %9, align 8, !tbaa !38
  %148 = getelementptr inbounds %struct.kvx, ptr %146, i64 %147
  %149 = getelementptr inbounds %struct.kvx, ptr %148, i32 0, i32 1
  %150 = getelementptr inbounds %struct.iovec, ptr %149, i32 0, i32 1
  %151 = load i64, ptr %150, align 8, !tbaa !40
  %152 = icmp ne i64 %151, 0
  br i1 %152, label %153, label %162

153:                                              ; preds = %143
  %154 = load ptr, ptr %3, align 8, !tbaa !5
  %155 = getelementptr inbounds %struct.MDBX_env, ptr %154, i32 0, i32 25
  %156 = load ptr, ptr %155, align 8, !tbaa !37
  %157 = load i64, ptr %9, align 8, !tbaa !38
  %158 = getelementptr inbounds %struct.kvx, ptr %156, i64 %157
  %159 = getelementptr inbounds %struct.kvx, ptr %158, i32 0, i32 1
  %160 = getelementptr inbounds %struct.iovec, ptr %159, i32 0, i32 0
  %161 = load ptr, ptr %160, align 8, !tbaa !45
  call void @free(ptr noundef %161) #5
  br label %162

162:                                              ; preds = %153, %143
  br label %163

163:                                              ; preds = %162
  %164 = load i64, ptr %9, align 8, !tbaa !38
  %165 = add i64 %164, 1
  store i64 %165, ptr %9, align 8, !tbaa !38
  br label %135, !llvm.loop !46

166:                                              ; preds = %142
  %167 = load ptr, ptr %3, align 8, !tbaa !5
  %168 = getelementptr inbounds %struct.MDBX_env, ptr %167, i32 0, i32 25
  %169 = load ptr, ptr %168, align 8, !tbaa !37
  call void @free(ptr noundef %169) #5
  %170 = load ptr, ptr %3, align 8, !tbaa !5
  %171 = getelementptr inbounds %struct.MDBX_env, ptr %170, i32 0, i32 42
  store i32 2, ptr %171, align 8, !tbaa !39
  %172 = load ptr, ptr %3, align 8, !tbaa !5
  %173 = getelementptr inbounds %struct.MDBX_env, ptr %172, i32 0, i32 25
  store ptr null, ptr %173, align 8, !tbaa !37
  br label %174

174:                                              ; preds = %166, %129
  %175 = load ptr, ptr %3, align 8, !tbaa !5
  %176 = getelementptr inbounds %struct.MDBX_env, ptr %175, i32 0, i32 23
  %177 = load ptr, ptr %176, align 8, !tbaa !47
  %178 = icmp ne ptr %177, null
  br i1 %178, label %179, label %185

179:                                              ; preds = %174
  %180 = load ptr, ptr %3, align 8, !tbaa !5
  %181 = getelementptr inbounds %struct.MDBX_env, ptr %180, i32 0, i32 23
  %182 = load ptr, ptr %181, align 8, !tbaa !47
  call void @osal_memalign_free(ptr noundef %182)
  %183 = load ptr, ptr %3, align 8, !tbaa !5
  %184 = getelementptr inbounds %struct.MDBX_env, ptr %183, i32 0, i32 23
  store ptr null, ptr %184, align 8, !tbaa !47
  br label %185

185:                                              ; preds = %179, %174
  %186 = load ptr, ptr %3, align 8, !tbaa !5
  %187 = getelementptr inbounds %struct.MDBX_env, ptr %186, i32 0, i32 27
  %188 = load ptr, ptr %187, align 8, !tbaa !48
  %189 = icmp ne ptr %188, null
  br i1 %189, label %190, label %196

190:                                              ; preds = %185
  %191 = load ptr, ptr %3, align 8, !tbaa !5
  %192 = getelementptr inbounds %struct.MDBX_env, ptr %191, i32 0, i32 27
  %193 = load ptr, ptr %192, align 8, !tbaa !48
  call void @free(ptr noundef %193) #5
  %194 = load ptr, ptr %3, align 8, !tbaa !5
  %195 = getelementptr inbounds %struct.MDBX_env, ptr %194, i32 0, i32 27
  store ptr null, ptr %195, align 8, !tbaa !48
  br label %196

196:                                              ; preds = %190, %185
  %197 = load ptr, ptr %3, align 8, !tbaa !5
  %198 = getelementptr inbounds %struct.MDBX_env, ptr %197, i32 0, i32 26
  %199 = load ptr, ptr %198, align 8, !tbaa !49
  %200 = icmp ne ptr %199, null
  br i1 %200, label %201, label %207

201:                                              ; preds = %196
  %202 = load ptr, ptr %3, align 8, !tbaa !5
  %203 = getelementptr inbounds %struct.MDBX_env, ptr %202, i32 0, i32 26
  %204 = load ptr, ptr %203, align 8, !tbaa !49
  call void @free(ptr noundef %204) #5
  %205 = load ptr, ptr %3, align 8, !tbaa !5
  %206 = getelementptr inbounds %struct.MDBX_env, ptr %205, i32 0, i32 26
  store ptr null, ptr %206, align 8, !tbaa !49
  br label %207

207:                                              ; preds = %201, %196
  %208 = load ptr, ptr %3, align 8, !tbaa !5
  %209 = getelementptr inbounds %struct.MDBX_env, ptr %208, i32 0, i32 22
  %210 = getelementptr inbounds %struct.anon, ptr %209, i32 0, i32 3
  %211 = load ptr, ptr %210, align 8, !tbaa !50
  %212 = icmp ne ptr %211, null
  br i1 %212, label %213, label %221

213:                                              ; preds = %207
  %214 = load ptr, ptr %3, align 8, !tbaa !5
  %215 = getelementptr inbounds %struct.MDBX_env, ptr %214, i32 0, i32 22
  %216 = getelementptr inbounds %struct.anon, ptr %215, i32 0, i32 3
  %217 = load ptr, ptr %216, align 8, !tbaa !50
  call void @free(ptr noundef %217) #5
  %218 = load ptr, ptr %3, align 8, !tbaa !5
  %219 = getelementptr inbounds %struct.MDBX_env, ptr %218, i32 0, i32 22
  %220 = getelementptr inbounds %struct.anon, ptr %219, i32 0, i32 3
  store ptr null, ptr %220, align 8, !tbaa !50
  br label %221

221:                                              ; preds = %213, %207
  %222 = load ptr, ptr %3, align 8, !tbaa !5
  %223 = getelementptr inbounds %struct.MDBX_env, ptr %222, i32 0, i32 24
  %224 = load ptr, ptr %223, align 8, !tbaa !51
  %225 = icmp ne ptr %224, null
  br i1 %225, label %226, label %232

226:                                              ; preds = %221
  %227 = load ptr, ptr %3, align 8, !tbaa !5
  %228 = getelementptr inbounds %struct.MDBX_env, ptr %227, i32 0, i32 24
  %229 = load ptr, ptr %228, align 8, !tbaa !51
  call void @txn_basal_destroy(ptr noundef %229)
  %230 = load ptr, ptr %3, align 8, !tbaa !5
  %231 = getelementptr inbounds %struct.MDBX_env, ptr %230, i32 0, i32 24
  store ptr null, ptr %231, align 8, !tbaa !51
  br label %232

232:                                              ; preds = %226, %221
  br label %233

233:                                              ; preds = %232, %126
  %234 = load ptr, ptr %3, align 8, !tbaa !5
  %235 = getelementptr inbounds %struct.MDBX_env, ptr %234, i32 0, i32 16
  store i8 -1, ptr %235, align 1, !tbaa !52
  %236 = load i32, ptr %6, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %236
}

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

declare void @munlock_all(ptr noundef) #3

declare void @rthc_lock() #3

declare i32 @rthc_remove(ptr noundef) #3

declare void @rthc_unlock() #3

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

declare void @osal_ioring_destroy(ptr noundef) #3

declare i32 @osal_munmap(ptr noundef) #3

declare i32 @osal_closefile(i32 noundef) #3

declare void @osal_memalign_free(ptr noundef) #3

declare void @txn_basal_destroy(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { "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 "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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !13, i64 4}
!12 = !{!"MDBX_env", !7, i64 0, !13, i64 4, !13, i64 8, !14, i64 16, !13, i64 56, !13, i64 60, !14, i64 64, !6, 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, !13, i64 132, !13, i64 136, !13, i64 140, !13, i64 144, !17, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !13, i64 224, !13, i64 228, !13, i64 232, !6, i64 240, !6, i64 248, !15, i64 256, !18, i64 264, !20, i64 320, !10, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !21, i64 392, !7, i64 400, !13, i64 440, !13, i64 444, !6, i64 448, !22, i64 456, !7, i64 496, !7, i64 536}
!13 = !{!"int", !7, i64 0}
!14 = !{!"osal_mmap", !7, i64 0, !13, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!18 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !15, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !13, i64 28, !13, i64 32, !10, i64 36, !10, i64 37, !10, i64 38, !19, i64 40, !7, i64 48}
!19 = !{!"", !16, i64 0, !16, i64 2, !16, i64 4, !16, i64 6}
!20 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!21 = !{!"", !15, i64 0}
!22 = !{!"osal_ioring", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!23 = !{!13, !13, i64 0}
!24 = !{!12, !13, i64 144}
!25 = !{!12, !6, i64 104}
!26 = !{!12, !6, i64 368}
!27 = !{!28, !6, i64 0}
!28 = !{!"defer_free_item", !6, i64 0, !15, i64 8}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}
!31 = !{!7, !7, i64 0}
!32 = !{!12, !13, i64 56}
!33 = !{!12, !13, i64 24}
!34 = !{!12, !13, i64 72}
!35 = !{i8 0, i8 2}
!36 = !{}
!37 = !{!12, !6, i64 200}
!38 = !{!15, !15, i64 0}
!39 = !{!12, !13, i64 440}
!40 = !{!41, !15, i64 56}
!41 = !{!"kvx", !42, i64 0, !44, i64 48}
!42 = !{!"clc2", !43, i64 0, !43, i64 24}
!43 = !{!"clc", !6, i64 0, !15, i64 8, !15, i64 16}
!44 = !{!"iovec", !6, i64 0, !15, i64 8}
!45 = !{!41, !6, i64 48}
!46 = distinct !{!46, !30}
!47 = !{!12, !6, i64 184}
!48 = !{!12, !6, i64 216}
!49 = !{!12, !6, i64 208}
!50 = !{!12, !6, i64 176}
!51 = !{!12, !6, i64 192}
!52 = !{!12, !7, i64 129}


; 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.kvx = type { %struct.clc2, %struct.iovec }
%struct.clc2 = type { %struct.clc, %struct.clc }
%struct.clc = type { ptr, i64, i64 }
%struct.iovec = type { ptr, i64 }

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @env_close(ptr noundef %0, i1 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = and i32 %4, 1342177279
  store i32 %5, ptr %3, align 4, !tbaa !5
  %6 = and i32 %4, 268435456
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %10, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 144
  %9 = load i32, ptr %8, align 8, !tbaa !21
  tail call void @thread_key_delete(i32 noundef %9)
  store i32 0, ptr %8, align 8, !tbaa !21
  br label %10

10:                                               ; preds = %7, %2
  %11 = getelementptr inbounds i8, ptr %0, i64 104
  %12 = load ptr, ptr %11, align 8, !tbaa !22
  %.not67 = icmp eq ptr %12, null
  br i1 %.not67, label %14, label %13

13:                                               ; preds = %10
  tail call void @munlock_all(ptr noundef nonnull %0) #4
  br label %14

14:                                               ; preds = %13, %10
  tail call void @rthc_lock() #4
  %15 = tail call i32 @rthc_remove(ptr noundef nonnull %0) #4
  tail call void @rthc_unlock() #4
  %16 = getelementptr inbounds i8, ptr %0, i64 368
  %17 = load ptr, ptr %16, align 8, !tbaa !23
  %.not6881 = icmp eq ptr %17, null
  br i1 %.not6881, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %14
  store ptr null, ptr %16, align 8, !tbaa !23
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = and i32 %18, 131072
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %22, label %24

.lr.ph:                                           ; preds = %14, %.lr.ph
  %.05882 = phi ptr [ %21, %.lr.ph ], [ %17, %14 ]
  %21 = load ptr, ptr %.05882, align 8, !tbaa !24
  tail call void @free(ptr noundef nonnull %.05882) #4
  %.not68 = icmp eq ptr %21, null
  br i1 %.not68, label %._crit_edge, label %.lr.ph, !llvm.loop !26

22:                                               ; preds = %._crit_edge
  %23 = getelementptr inbounds i8, ptr %0, i64 456
  tail call void @osal_ioring_destroy(ptr noundef nonnull %23) #4
  br label %24

24:                                               ; preds = %22, %._crit_edge
  store ptr null, ptr %11, align 8, !tbaa !22
  %25 = getelementptr inbounds i8, ptr %0, i64 64
  %26 = load ptr, ptr %25, align 8, !tbaa !28
  %.not69 = icmp eq ptr %26, null
  br i1 %.not69, label %29, label %27

27:                                               ; preds = %24
  %28 = tail call i32 @osal_munmap(ptr noundef nonnull %25) #4
  br label %29

29:                                               ; preds = %27, %24
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  %31 = load ptr, ptr %30, align 8, !tbaa !28
  %.not70 = icmp eq ptr %31, null
  br i1 %.not70, label %34, label %32

32:                                               ; preds = %29
  %33 = tail call i32 @osal_munmap(ptr noundef nonnull %30) #4
  br label %34

34:                                               ; preds = %32, %29
  %35 = getelementptr inbounds i8, ptr %0, i64 56
  %36 = load i32, ptr %35, align 8, !tbaa !29
  %.not71 = icmp eq i32 %36, -1
  br i1 %.not71, label %39, label %37

37:                                               ; preds = %34
  %38 = tail call i32 @osal_closefile(i32 noundef %36) #4
  store i32 -1, ptr %35, align 8, !tbaa !29
  br label %39

39:                                               ; preds = %37, %34
  %40 = getelementptr inbounds i8, ptr %0, i64 24
  %41 = load i32, ptr %40, align 8, !tbaa !30
  %.not72 = icmp eq i32 %41, -1
  br i1 %.not72, label %44, label %42

42:                                               ; preds = %39
  %43 = tail call i32 @osal_closefile(i32 noundef %41) #4
  store i32 -1, ptr %40, align 8, !tbaa !30
  br label %44

44:                                               ; preds = %42, %39
  %45 = getelementptr inbounds i8, ptr %0, i64 72
  %46 = load i32, ptr %45, align 8, !tbaa !31
  %.not73 = icmp eq i32 %46, -1
  br i1 %.not73, label %49, label %47

47:                                               ; preds = %44
  %48 = tail call i32 @osal_closefile(i32 noundef %46) #4
  store i32 -1, ptr %45, align 8, !tbaa !31
  br label %49

49:                                               ; preds = %47, %44
  br i1 %1, label %89, label %50

50:                                               ; preds = %49
  %51 = getelementptr inbounds i8, ptr %0, i64 200
  %52 = load ptr, ptr %51, align 8, !tbaa !32
  %.not74 = icmp eq ptr %52, null
  br i1 %.not74, label %69, label %.preheader

.preheader:                                       ; preds = %50
  %53 = getelementptr inbounds i8, ptr %0, i64 440
  %54 = load i32, ptr %53, align 8, !tbaa !33
  %55 = icmp ugt i32 %54, 2
  br i1 %55, label %.lr.ph84, label %._crit_edge85

._crit_edge85.loopexit:                           ; preds = %64
  %.pre86 = load ptr, ptr %51, align 8, !tbaa !32
  br label %._crit_edge85

._crit_edge85:                                    ; preds = %._crit_edge85.loopexit, %.preheader
  %56 = phi ptr [ %.pre86, %._crit_edge85.loopexit ], [ %52, %.preheader ]
  tail call void @free(ptr noundef %56) #4
  store i32 2, ptr %53, align 8, !tbaa !33
  store ptr null, ptr %51, align 8, !tbaa !32
  br label %69

.lr.ph84:                                         ; preds = %.preheader, %64
  %57 = phi i32 [ %65, %64 ], [ %54, %.preheader ]
  %.083 = phi i64 [ %66, %64 ], [ 2, %.preheader ]
  %58 = load ptr, ptr %51, align 8, !tbaa !32
  %59 = getelementptr inbounds %struct.kvx, ptr %58, i64 %.083, i32 1
  %60 = getelementptr inbounds i8, ptr %59, i64 8
  %61 = load i64, ptr %60, align 8, !tbaa !34
  %.not80 = icmp eq i64 %61, 0
  br i1 %.not80, label %64, label %62

62:                                               ; preds = %.lr.ph84
  %63 = load ptr, ptr %59, align 8, !tbaa !39
  tail call void @free(ptr noundef %63) #4
  %.pre = load i32, ptr %53, align 8, !tbaa !33
  br label %64

64:                                               ; preds = %.lr.ph84, %62
  %65 = phi i32 [ %57, %.lr.ph84 ], [ %.pre, %62 ]
  %66 = add nuw nsw i64 %.083, 1
  %67 = zext i32 %65 to i64
  %68 = icmp ult i64 %66, %67
  br i1 %68, label %.lr.ph84, label %._crit_edge85.loopexit, !llvm.loop !40

69:                                               ; preds = %._crit_edge85, %50
  %70 = getelementptr inbounds i8, ptr %0, i64 184
  %71 = load ptr, ptr %70, align 8, !tbaa !41
  %.not75 = icmp eq ptr %71, null
  br i1 %.not75, label %73, label %72

72:                                               ; preds = %69
  tail call void @osal_memalign_free(ptr noundef nonnull %71) #4
  store ptr null, ptr %70, align 8, !tbaa !41
  br label %73

73:                                               ; preds = %72, %69
  %74 = getelementptr inbounds i8, ptr %0, i64 216
  %75 = load ptr, ptr %74, align 8, !tbaa !42
  %.not76 = icmp eq ptr %75, null
  br i1 %.not76, label %77, label %76

76:                                               ; preds = %73
  tail call void @free(ptr noundef nonnull %75) #4
  store ptr null, ptr %74, align 8, !tbaa !42
  br label %77

77:                                               ; preds = %76, %73
  %78 = getelementptr inbounds i8, ptr %0, i64 208
  %79 = load ptr, ptr %78, align 8, !tbaa !43
  %.not77 = icmp eq ptr %79, null
  br i1 %.not77, label %81, label %80

80:                                               ; preds = %77
  tail call void @free(ptr noundef nonnull %79) #4
  store ptr null, ptr %78, align 8, !tbaa !43
  br label %81

81:                                               ; preds = %80, %77
  %82 = getelementptr inbounds i8, ptr %0, i64 176
  %83 = load ptr, ptr %82, align 8, !tbaa !44
  %.not78 = icmp eq ptr %83, null
  br i1 %.not78, label %85, label %84

84:                                               ; preds = %81
  tail call void @free(ptr noundef nonnull %83) #4
  store ptr null, ptr %82, align 8, !tbaa !44
  br label %85

85:                                               ; preds = %84, %81
  %86 = getelementptr inbounds i8, ptr %0, i64 192
  %87 = load ptr, ptr %86, align 8, !tbaa !45
  %.not79 = icmp eq ptr %87, null
  br i1 %.not79, label %89, label %88

88:                                               ; preds = %85
  tail call void @txn_basal_destroy(ptr noundef nonnull %87) #4
  store ptr null, ptr %86, align 8, !tbaa !45
  br label %89

89:                                               ; preds = %85, %88, %49
  %90 = getelementptr inbounds i8, ptr %0, i64 129
  store i8 -1, ptr %90, align 1, !tbaa !46
  ret i32 %15
}

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

declare void @munlock_all(ptr noundef) local_unnamed_addr #2

declare void @rthc_lock() local_unnamed_addr #2

declare i32 @rthc_remove(ptr noundef) local_unnamed_addr #2

declare void @rthc_unlock() local_unnamed_addr #2

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

declare void @osal_ioring_destroy(ptr noundef) local_unnamed_addr #2

declare i32 @osal_munmap(ptr noundef) local_unnamed_addr #2

declare i32 @osal_closefile(i32 noundef) local_unnamed_addr #2

declare void @osal_memalign_free(ptr noundef) local_unnamed_addr #2

declare void @txn_basal_destroy(ptr noundef) local_unnamed_addr #2

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


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