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

; 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.6 }
%struct.anon.6 = 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, 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.mdbx_atomic_uint64_t = type { i64 }

@globals = external global %struct.libmdbx_globals, align 8
@osal_openfile.dev_null = external hidden constant [10 x i8], align 1
@__func__.osal_openfile = external hidden unnamed_addr constant [14 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [105 x i8], align 1

; Function Attrs: cold noreturn nounwind optsize uwtable
declare dso_local void @mdbx_assert_fail(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #0

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @osal_openfile(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #5 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i8, align 1
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca %struct.stat, align 8
  %19 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !5
  %20 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 -1, ptr %20, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %21 = load i32, ptr %11, align 4, !tbaa !5
  %22 = icmp ne i32 %21, 0
  %23 = zext i1 %22 to i64
  %24 = select i1 %22, i32 64, i32 0
  store i32 %24, ptr %12, align 4, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %25, label %26 [
    i32 3, label %27
    i32 0, label %30
    i32 1, label %31
    i32 4, label %34
    i32 2, label %35
    i32 5, label %40
  ]

26:                                               ; preds = %5
  store i32 22, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %379

27:                                               ; preds = %5
  %28 = load i32, ptr %12, align 4, !tbaa !5
  %29 = or i32 %28, 2
  store i32 %29, ptr %12, align 4, !tbaa !5
  br label %41

30:                                               ; preds = %5
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %41

31:                                               ; preds = %5
  %32 = load i32, ptr %12, align 4, !tbaa !5
  %33 = or i32 %32, 2
  store i32 %33, ptr %12, align 4, !tbaa !5
  br label %41

34:                                               ; preds = %5
  store i32 193, ptr %12, align 4, !tbaa !5
  br label %41

35:                                               ; preds = %5
  %36 = load i32, ptr %12, align 4, !tbaa !5
  %37 = or i32 %36, 1
  store i32 %37, ptr %12, align 4, !tbaa !5
  %38 = load i32, ptr %12, align 4, !tbaa !5
  %39 = or i32 %38, 4096
  store i32 %39, ptr %12, align 4, !tbaa !5
  br label %41

40:                                               ; preds = %5
  store i32 2, ptr %12, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %40, %35, %34, %31, %30, %27
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #7
  %42 = load ptr, ptr %8, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.MDBX_env, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 1), align 8, !tbaa !23
  %46 = icmp uge i32 %44, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %41
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = icmp eq i32 %48, 4
  br label %50

50:                                               ; preds = %47, %41
  %51 = phi i1 [ false, %41 ], [ %49, %47 ]
  %52 = zext i1 %51 to i8
  store i8 %52, ptr %14, align 1, !tbaa !25
  %53 = load i8, ptr %14, align 1, !tbaa !25, !range !26, !noundef !27
  %54 = trunc i8 %53 to i1
  br i1 %54, label %55, label %58

55:                                               ; preds = %50
  %56 = load i32, ptr %12, align 4, !tbaa !5
  %57 = or i32 %56, 16384
  store i32 %57, ptr %12, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %55, %50
  %59 = load i32, ptr %12, align 4, !tbaa !5
  %60 = or i32 %59, 524288
  store i32 %60, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  store i32 -1, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #7
  store i32 -1, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #7
  store i32 -1, ptr %17, align 4, !tbaa !5
  %61 = call zeroext i1 @is_valid_fd(i32 noundef 0)
  br i1 %61, label %78, label %62

62:                                               ; preds = %58
  br label %63

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

73:                                               ; preds = %63
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef @__func__.osal_openfile, i32 noundef 1300, ptr noundef @.str.15, ptr noundef @.str.16, i32 noundef 0, ptr noundef @osal_openfile.dev_null)
  br label %74

74:                                               ; preds = %73, %63
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  %77 = call i32 (ptr, i32, ...) @open64(ptr noundef @osal_openfile.dev_null, i32 noundef 256)
  store i32 %77, ptr %15, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %76, %58
  %79 = call zeroext i1 @is_valid_fd(i32 noundef 1)
  br i1 %79, label %96, label %80

80:                                               ; preds = %78
  br label %81

81:                                               ; preds = %80
  %82 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !28
  %83 = zext i8 %82 to i32
  %84 = icmp sle i32 2, %83
  %85 = xor i1 %84, true
  %86 = xor i1 %85, true
  %87 = zext i1 %86 to i32
  %88 = sext i32 %87 to i64
  %89 = call i64 @llvm.expect.i64(i64 %88, i64 0)
  %90 = icmp ne i64 %89, 0
  br i1 %90, label %91, label %92

91:                                               ; preds = %81
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef @__func__.osal_openfile, i32 noundef 1304, ptr noundef @.str.15, ptr noundef @.str.17, i32 noundef 1, ptr noundef @osal_openfile.dev_null)
  br label %92

92:                                               ; preds = %91, %81
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93
  %95 = call i32 (ptr, i32, ...) @open64(ptr noundef @osal_openfile.dev_null, i32 noundef 257)
  store i32 %95, ptr %16, align 4, !tbaa !5
  br label %96

96:                                               ; preds = %94, %78
  %97 = call zeroext i1 @is_valid_fd(i32 noundef 2)
  br i1 %97, label %114, label %98

98:                                               ; preds = %96
  br label %99

99:                                               ; preds = %98
  %100 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !28
  %101 = zext i8 %100 to i32
  %102 = icmp sle i32 2, %101
  %103 = xor i1 %102, true
  %104 = xor i1 %103, true
  %105 = zext i1 %104 to i32
  %106 = sext i32 %105 to i64
  %107 = call i64 @llvm.expect.i64(i64 %106, i64 0)
  %108 = icmp ne i64 %107, 0
  br i1 %108, label %109, label %110

109:                                              ; preds = %99
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef @__func__.osal_openfile, i32 noundef 1308, ptr noundef @.str.15, ptr noundef @.str.18, i32 noundef 2, ptr noundef @osal_openfile.dev_null)
  br label %110

110:                                              ; preds = %109, %99
  br label %111

111:                                              ; preds = %110
  br label %112

112:                                              ; preds = %111
  %113 = call i32 (ptr, i32, ...) @open64(ptr noundef @osal_openfile.dev_null, i32 noundef 257)
  store i32 %113, ptr %17, align 4, !tbaa !5
  br label %114

114:                                              ; preds = %112, %96
  %115 = load ptr, ptr %9, align 8, !tbaa !9
  %116 = load i32, ptr %12, align 4, !tbaa !5
  %117 = load i32, ptr %11, align 4, !tbaa !5
  %118 = call i32 (ptr, i32, ...) @open64(ptr noundef %115, i32 noundef %116, i32 noundef %117)
  %119 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 %118, ptr %119, align 4, !tbaa !5
  %120 = load ptr, ptr %10, align 8, !tbaa !9
  %121 = load i32, ptr %120, align 4, !tbaa !5
  %122 = icmp slt i32 %121, 0
  br i1 %122, label %123, label %143

123:                                              ; preds = %114
  %124 = load i32, ptr %12, align 4, !tbaa !5
  %125 = and i32 %124, 16384
  %126 = icmp ne i32 %125, 0
  br i1 %126, label %127, label %143

127:                                              ; preds = %123
  %128 = call ptr @__errno_location() #8
  %129 = load i32, ptr %128, align 4, !tbaa !5
  %130 = icmp eq i32 %129, 22
  br i1 %130, label %135, label %131

131:                                              ; preds = %127
  %132 = call ptr @__errno_location() #8
  %133 = load i32, ptr %132, align 4, !tbaa !5
  %134 = icmp eq i32 %133, 97
  br i1 %134, label %135, label %143

135:                                              ; preds = %131, %127
  %136 = load i32, ptr %12, align 4, !tbaa !5
  %137 = and i32 %136, -16513
  store i32 %137, ptr %12, align 4, !tbaa !5
  %138 = load ptr, ptr %9, align 8, !tbaa !9
  %139 = load i32, ptr %12, align 4, !tbaa !5
  %140 = load i32, ptr %11, align 4, !tbaa !5
  %141 = call i32 (ptr, i32, ...) @open64(ptr noundef %138, i32 noundef %139, i32 noundef %140)
  %142 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 %141, ptr %142, align 4, !tbaa !5
  br label %143

143:                                              ; preds = %135, %131, %123, %114
  %144 = load ptr, ptr %10, align 8, !tbaa !9
  %145 = load i32, ptr %144, align 4, !tbaa !5
  %146 = icmp slt i32 %145, 0
  br i1 %146, label %147, label %165

147:                                              ; preds = %143
  %148 = call ptr @__errno_location() #8
  %149 = load i32, ptr %148, align 4, !tbaa !5
  %150 = icmp eq i32 %149, 13
  br i1 %150, label %151, label %165

151:                                              ; preds = %147
  %152 = load i32, ptr %7, align 4, !tbaa !5
  %153 = icmp eq i32 %152, 3
  br i1 %153, label %154, label %165

154:                                              ; preds = %151
  call void @llvm.lifetime.start.p0(i64 144, ptr %18) #7
  %155 = load ptr, ptr %9, align 8, !tbaa !9
  %156 = call i32 @stat64(ptr noundef %155, ptr noundef %18) #7
  %157 = icmp eq i32 %156, 0
  br i1 %157, label %162, label %158

158:                                              ; preds = %154
  %159 = call ptr @__errno_location() #8
  %160 = load i32, ptr %159, align 4, !tbaa !5
  %161 = icmp ne i32 %160, 2
  br i1 %161, label %162, label %164

162:                                              ; preds = %158, %154
  %163 = call ptr @__errno_location() #8
  store i32 13, ptr %163, align 4, !tbaa !5
  br label %164

164:                                              ; preds = %162, %158
  call void @llvm.lifetime.end.p0(i64 144, ptr %18) #7
  br label %165

165:                                              ; preds = %164, %151, %147, %143
  %166 = load ptr, ptr %10, align 8, !tbaa !9
  %167 = load i32, ptr %166, align 4, !tbaa !5
  %168 = icmp eq i32 %167, 0
  br i1 %168, label %169, label %217

169:                                              ; preds = %165
  br label %170

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

180:                                              ; preds = %170
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef @__func__.osal_openfile, i32 noundef 1332, ptr noundef @.str.19, ptr noundef @.str.16, i32 noundef 0)
  br label %181

181:                                              ; preds = %180, %170
  br label %182

182:                                              ; preds = %181
  br label %183

183:                                              ; preds = %182
  br label %184

184:                                              ; preds = %183
  %185 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !29
  %186 = zext i8 %185 to i32
  %187 = and i32 %186, 1
  %188 = icmp ne i32 %187, 0
  %189 = xor i1 %188, true
  %190 = xor i1 %189, true
  %191 = zext i1 %190 to i32
  %192 = sext i32 %191 to i64
  %193 = call i64 @llvm.expect.i64(i64 %192, i64 1)
  %194 = icmp ne i64 %193, 0
  br i1 %194, label %195, label %210

195:                                              ; preds = %184
  br label %196

196:                                              ; preds = %195
  %197 = load i32, ptr %15, align 4, !tbaa !5
  %198 = icmp eq i32 %197, -1
  %199 = xor i1 %198, true
  %200 = xor i1 %199, true
  %201 = xor i1 %200, true
  %202 = zext i1 %201 to i32
  %203 = sext i32 %202 to i64
  %204 = call i64 @llvm.expect.i64(i64 %203, i64 0)
  %205 = icmp ne i64 %204, 0
  br i1 %205, label %206, label %207

206:                                              ; preds = %196
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.20, ptr noundef @__func__.osal_openfile, i32 noundef 1333) #9
  unreachable

207:                                              ; preds = %196
  br label %208

208:                                              ; preds = %207
  br label %209

209:                                              ; preds = %208
  br label %210

210:                                              ; preds = %209, %184
  br label %211

211:                                              ; preds = %210
  br label %212

212:                                              ; preds = %211
  %213 = load ptr, ptr %10, align 8, !tbaa !9
  %214 = load i32, ptr %213, align 4, !tbaa !5
  store i32 %214, ptr %15, align 4, !tbaa !5
  %215 = call i32 @dup(i32 noundef %214) #7
  %216 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 %215, ptr %216, align 4, !tbaa !5
  br label %217

217:                                              ; preds = %212, %165
  %218 = load ptr, ptr %10, align 8, !tbaa !9
  %219 = load i32, ptr %218, align 4, !tbaa !5
  %220 = icmp eq i32 %219, 1
  br i1 %220, label %221, label %269

221:                                              ; preds = %217
  br label %222

222:                                              ; preds = %221
  %223 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !28
  %224 = zext i8 %223 to i32
  %225 = icmp sle i32 2, %224
  %226 = xor i1 %225, true
  %227 = xor i1 %226, true
  %228 = zext i1 %227 to i32
  %229 = sext i32 %228 to i64
  %230 = call i64 @llvm.expect.i64(i64 %229, i64 0)
  %231 = icmp ne i64 %230, 0
  br i1 %231, label %232, label %233

232:                                              ; preds = %222
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef @__func__.osal_openfile, i32 noundef 1337, ptr noundef @.str.19, ptr noundef @.str.17, i32 noundef 1)
  br label %233

233:                                              ; preds = %232, %222
  br label %234

234:                                              ; preds = %233
  br label %235

235:                                              ; preds = %234
  br label %236

236:                                              ; preds = %235
  %237 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !29
  %238 = zext i8 %237 to i32
  %239 = and i32 %238, 1
  %240 = icmp ne i32 %239, 0
  %241 = xor i1 %240, true
  %242 = xor i1 %241, true
  %243 = zext i1 %242 to i32
  %244 = sext i32 %243 to i64
  %245 = call i64 @llvm.expect.i64(i64 %244, i64 1)
  %246 = icmp ne i64 %245, 0
  br i1 %246, label %247, label %262

247:                                              ; preds = %236
  br label %248

248:                                              ; preds = %247
  %249 = load i32, ptr %16, align 4, !tbaa !5
  %250 = icmp eq i32 %249, -1
  %251 = xor i1 %250, true
  %252 = xor i1 %251, true
  %253 = xor i1 %252, true
  %254 = zext i1 %253 to i32
  %255 = sext i32 %254 to i64
  %256 = call i64 @llvm.expect.i64(i64 %255, i64 0)
  %257 = icmp ne i64 %256, 0
  br i1 %257, label %258, label %259

258:                                              ; preds = %248
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.21, ptr noundef @__func__.osal_openfile, i32 noundef 1338) #9
  unreachable

259:                                              ; preds = %248
  br label %260

260:                                              ; preds = %259
  br label %261

261:                                              ; preds = %260
  br label %262

262:                                              ; preds = %261, %236
  br label %263

263:                                              ; preds = %262
  br label %264

264:                                              ; preds = %263
  %265 = load ptr, ptr %10, align 8, !tbaa !9
  %266 = load i32, ptr %265, align 4, !tbaa !5
  store i32 %266, ptr %16, align 4, !tbaa !5
  %267 = call i32 @dup(i32 noundef %266) #7
  %268 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 %267, ptr %268, align 4, !tbaa !5
  br label %269

269:                                              ; preds = %264, %217
  %270 = load ptr, ptr %10, align 8, !tbaa !9
  %271 = load i32, ptr %270, align 4, !tbaa !5
  %272 = icmp eq i32 %271, 2
  br i1 %272, label %273, label %321

273:                                              ; preds = %269
  br label %274

274:                                              ; preds = %273
  %275 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !28
  %276 = zext i8 %275 to i32
  %277 = icmp sle i32 2, %276
  %278 = xor i1 %277, true
  %279 = xor i1 %278, true
  %280 = zext i1 %279 to i32
  %281 = sext i32 %280 to i64
  %282 = call i64 @llvm.expect.i64(i64 %281, i64 0)
  %283 = icmp ne i64 %282, 0
  br i1 %283, label %284, label %285

284:                                              ; preds = %274
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef @__func__.osal_openfile, i32 noundef 1342, ptr noundef @.str.19, ptr noundef @.str.18, i32 noundef 2)
  br label %285

285:                                              ; preds = %284, %274
  br label %286

286:                                              ; preds = %285
  br label %287

287:                                              ; preds = %286
  br label %288

288:                                              ; preds = %287
  %289 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !29
  %290 = zext i8 %289 to i32
  %291 = and i32 %290, 1
  %292 = icmp ne i32 %291, 0
  %293 = xor i1 %292, true
  %294 = xor i1 %293, true
  %295 = zext i1 %294 to i32
  %296 = sext i32 %295 to i64
  %297 = call i64 @llvm.expect.i64(i64 %296, i64 1)
  %298 = icmp ne i64 %297, 0
  br i1 %298, label %299, label %314

299:                                              ; preds = %288
  br label %300

300:                                              ; preds = %299
  %301 = load i32, ptr %17, align 4, !tbaa !5
  %302 = icmp eq i32 %301, -1
  %303 = xor i1 %302, true
  %304 = xor i1 %303, true
  %305 = xor i1 %304, true
  %306 = zext i1 %305 to i32
  %307 = sext i32 %306 to i64
  %308 = call i64 @llvm.expect.i64(i64 %307, i64 0)
  %309 = icmp ne i64 %308, 0
  br i1 %309, label %310, label %311

310:                                              ; preds = %300
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.22, ptr noundef @__func__.osal_openfile, i32 noundef 1343) #9
  unreachable

311:                                              ; preds = %300
  br label %312

312:                                              ; preds = %311
  br label %313

313:                                              ; preds = %312
  br label %314

314:                                              ; preds = %313, %288
  br label %315

315:                                              ; preds = %314
  br label %316

316:                                              ; preds = %315
  %317 = load ptr, ptr %10, align 8, !tbaa !9
  %318 = load i32, ptr %317, align 4, !tbaa !5
  store i32 %318, ptr %17, align 4, !tbaa !5
  %319 = call i32 @dup(i32 noundef %318) #7
  %320 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 %319, ptr %320, align 4, !tbaa !5
  br label %321

321:                                              ; preds = %316, %269
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #7
  %322 = call ptr @__errno_location() #8
  %323 = load i32, ptr %322, align 4, !tbaa !5
  store i32 %323, ptr %19, align 4, !tbaa !5
  %324 = load i32, ptr %15, align 4, !tbaa !5
  %325 = icmp ne i32 %324, -1
  br i1 %325, label %326, label %329

326:                                              ; preds = %321
  %327 = load i32, ptr %15, align 4, !tbaa !5
  %328 = call i32 @close(i32 noundef %327)
  br label %329

329:                                              ; preds = %326, %321
  %330 = load i32, ptr %16, align 4, !tbaa !5
  %331 = icmp ne i32 %330, -1
  br i1 %331, label %332, label %335

332:                                              ; preds = %329
  %333 = load i32, ptr %16, align 4, !tbaa !5
  %334 = call i32 @close(i32 noundef %333)
  br label %335

335:                                              ; preds = %332, %329
  %336 = load i32, ptr %17, align 4, !tbaa !5
  %337 = icmp ne i32 %336, -1
  br i1 %337, label %338, label %341

338:                                              ; preds = %335
  %339 = load i32, ptr %17, align 4, !tbaa !5
  %340 = call i32 @close(i32 noundef %339)
  br label %341

341:                                              ; preds = %338, %335
  %342 = load ptr, ptr %10, align 8, !tbaa !9
  %343 = load i32, ptr %342, align 4, !tbaa !5
  %344 = icmp sge i32 %343, 0
  br i1 %344, label %345, label %367

345:                                              ; preds = %341
  %346 = load ptr, ptr %10, align 8, !tbaa !9
  %347 = load i32, ptr %346, align 4, !tbaa !5
  %348 = icmp sle i32 %347, 2
  br i1 %348, label %349, label %367

349:                                              ; preds = %345
  br label %350

350:                                              ; preds = %349
  %351 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !28
  %352 = zext i8 %351 to i32
  %353 = icmp sle i32 1, %352
  %354 = xor i1 %353, true
  %355 = xor i1 %354, true
  %356 = zext i1 %355 to i32
  %357 = sext i32 %356 to i64
  %358 = call i64 @llvm.expect.i64(i64 %357, i64 0)
  %359 = icmp ne i64 %358, 0
  br i1 %359, label %360, label %361

360:                                              ; preds = %350
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.osal_openfile, i32 noundef 1356, ptr noundef @.str.23, i32 noundef 0, i32 noundef 2)
  br label %361

361:                                              ; preds = %360, %350
  br label %362

362:                                              ; preds = %361
  br label %363

363:                                              ; preds = %362
  %364 = load ptr, ptr %10, align 8, !tbaa !9
  %365 = load i32, ptr %364, align 4, !tbaa !5
  %366 = call i32 @close(i32 noundef %365)
  store i32 9, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %378

367:                                              ; preds = %345, %341
  %368 = load ptr, ptr %10, align 8, !tbaa !9
  %369 = load i32, ptr %368, align 4, !tbaa !5
  %370 = icmp slt i32 %369, 0
  br i1 %370, label %371, label %373

371:                                              ; preds = %367
  %372 = load i32, ptr %19, align 4, !tbaa !5
  store i32 %372, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %378

373:                                              ; preds = %367
  %374 = load i8, ptr %14, align 1, !tbaa !25, !range !26, !noundef !27
  %375 = trunc i8 %374 to i1
  br i1 %375, label %376, label %377

376:                                              ; preds = %373
  br label %377

377:                                              ; preds = %376, %373
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %378

378:                                              ; preds = %377, %371, %363
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #7
  br label %379

379:                                              ; preds = %378, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  %380 = load i32, ptr %6, align 4
  ret i32 %380
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @is_valid_fd(i32 noundef) #5

declare i32 @open64(ptr noundef, i32 noundef, ...) #1

; Function Attrs: nounwind
declare i32 @stat64(ptr noundef, ptr noundef) #6

; Function Attrs: nounwind
declare i32 @dup(i32 noundef) #6

declare i32 @close(i32 noundef) #1

attributes #0 = { cold noreturn 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 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #4 = { 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 #5 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { nounwind "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 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { cold 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"MDBX_env", !7, i64 0, !6, i64 4, !6, i64 8, !13, i64 16, !6, i64 56, !6, i64 60, !13, i64 64, !10, 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, !6, i64 132, !6, i64 136, !6, i64 140, !6, i64 144, !16, i64 152, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !6, i64 224, !6, i64 228, !6, i64 232, !10, i64 240, !10, i64 248, !14, i64 256, !17, i64 264, !20, i64 320, !18, i64 360, !10, i64 368, !10, i64 376, !10, i64 384, !21, i64 392, !7, i64 400, !6, i64 440, !6, i64 444, !10, i64 448, !22, i64 456, !7, i64 496, !7, i64 536}
!13 = !{!"osal_mmap", !7, i64 0, !6, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!17 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !14, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !6, i64 28, !6, 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", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!23 = !{!24, !6, i64 16}
!24 = !{!"libmdbx_globals", !7, i64 0, !6, i64 16, !6, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !18, i64 27, !6, i64 28, !7, i64 32, !7, i64 40, !14, i64 80, !10, i64 88}
!25 = !{!18, !18, i64 0}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!24, !7, i64 26}
!29 = !{!24, !7, i64 25}


; 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.6 }
%struct.anon.6 = 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
@osal_openfile.dev_null = external hidden constant [10 x i8], align 1
@__func__.osal_openfile = external hidden unnamed_addr constant [14 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [105 x i8], align 1

; Function Attrs: cold noreturn nounwind optsize uwtable
declare dso_local void @mdbx_assert_fail(ptr noundef, ptr 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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @osal_openfile(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef %3, i32 noundef %4) local_unnamed_addr #4 {
  %6 = alloca %struct.stat, align 8
  store i32 -1, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  %7 = select i1 %.not, i32 0, i32 64
  switch i32 %0, label %131 [
    i32 3, label %8
    i32 0, label %16
    i32 1, label %10
    i32 4, label %12
    i32 2, label %13
    i32 5, label %15
  ]

8:                                                ; preds = %5
  %9 = or disjoint i32 %7, 2
  br label %16

10:                                               ; preds = %5
  %11 = or disjoint i32 %7, 2
  br label %16

12:                                               ; preds = %5
  br label %16

13:                                               ; preds = %5
  %14 = or disjoint i32 %7, 4097
  br label %16

15:                                               ; preds = %5
  br label %16

16:                                               ; preds = %5, %15, %13, %12, %10, %8
  %.057 = phi i32 [ 2, %15 ], [ %14, %13 ], [ 193, %12 ], [ %11, %10 ], [ %9, %8 ], [ %0, %5 ]
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @globals, i64 16), align 8, !tbaa !22
  %20 = icmp uge i32 %18, %19
  %21 = icmp eq i32 %0, 4
  %22 = and i1 %21, %20
  %23 = or i32 %.057, 16384
  %spec.select = select i1 %22, i32 %23, i32 %.057
  %24 = or i32 %spec.select, 524288
  %25 = tail call zeroext i1 @is_valid_fd(i32 noundef 0)
  br i1 %25, label %32, label %26

26:                                               ; preds = %16
  %27 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !24
  %28 = icmp ugt i8 %27, 1
  br i1 %28, label %29, label %30, !prof !25

29:                                               ; preds = %26
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef nonnull @__func__.osal_openfile, i32 noundef 1300, ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.16, i32 noundef 0, ptr noundef nonnull @osal_openfile.dev_null) #8
  br label %30

30:                                               ; preds = %29, %26
  %31 = tail call i32 (ptr, i32, ...) @open64(ptr noundef nonnull @osal_openfile.dev_null, i32 noundef 256) #8
  br label %32

32:                                               ; preds = %30, %16
  %.055 = phi i32 [ -1, %16 ], [ %31, %30 ]
  %33 = tail call zeroext i1 @is_valid_fd(i32 noundef 1)
  br i1 %33, label %40, label %34

34:                                               ; preds = %32
  %35 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !24
  %36 = icmp ugt i8 %35, 1
  br i1 %36, label %37, label %38, !prof !25

37:                                               ; preds = %34
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef nonnull @__func__.osal_openfile, i32 noundef 1304, ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.17, i32 noundef 1, ptr noundef nonnull @osal_openfile.dev_null) #8
  br label %38

38:                                               ; preds = %37, %34
  %39 = tail call i32 (ptr, i32, ...) @open64(ptr noundef nonnull @osal_openfile.dev_null, i32 noundef 257) #8
  br label %40

40:                                               ; preds = %38, %32
  %.053 = phi i32 [ -1, %32 ], [ %39, %38 ]
  %41 = tail call zeroext i1 @is_valid_fd(i32 noundef 2)
  br i1 %41, label %48, label %42

42:                                               ; preds = %40
  %43 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !24
  %44 = icmp ugt i8 %43, 1
  br i1 %44, label %45, label %46, !prof !25

45:                                               ; preds = %42
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef nonnull @__func__.osal_openfile, i32 noundef 1308, ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.18, i32 noundef 2, ptr noundef nonnull @osal_openfile.dev_null) #8
  br label %46

46:                                               ; preds = %45, %42
  %47 = tail call i32 (ptr, i32, ...) @open64(ptr noundef nonnull @osal_openfile.dev_null, i32 noundef 257) #8
  br label %48

48:                                               ; preds = %46, %40
  %.051 = phi i32 [ -1, %40 ], [ %47, %46 ]
  %49 = tail call i32 (ptr, i32, ...) @open64(ptr noundef %2, i32 noundef %24, i32 noundef %4) #8
  store i32 %49, ptr %3, align 4, !tbaa !5
  %50 = icmp sgt i32 %49, -1
  %51 = and i32 %spec.select, 16384
  %.not61 = icmp eq i32 %51, 0
  %or.cond73 = select i1 %50, i1 true, i1 %.not61
  br i1 %or.cond73, label %thread-pre-split, label %52

52:                                               ; preds = %48
  %53 = tail call ptr @__errno_location() #9
  %54 = load i32, ptr %53, align 4, !tbaa !5
  switch i32 %54, label %thread-pre-split.thread [
    i32 22, label %55
    i32 97, label %55
  ]

55:                                               ; preds = %52, %52
  %56 = and i32 %24, -16513
  %57 = tail call i32 (ptr, i32, ...) @open64(ptr noundef %2, i32 noundef %56, i32 noundef %4) #8
  store i32 %57, ptr %3, align 4, !tbaa !5
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %55, %48
  %58 = phi i32 [ %57, %55 ], [ %49, %48 ]
  %59 = icmp slt i32 %58, 0
  br i1 %59, label %thread-pre-split.thread, label %71

thread-pre-split.thread:                          ; preds = %52, %thread-pre-split
  %60 = tail call ptr @__errno_location() #9
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = icmp eq i32 %61, 13
  %63 = icmp eq i32 %0, 3
  %or.cond = and i1 %63, %62
  br i1 %or.cond, label %64, label %thread-pre-split78.thread

64:                                               ; preds = %thread-pre-split.thread
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %6) #8
  %65 = call i32 @stat64(ptr noundef %2, ptr noundef nonnull %6) #8
  %66 = icmp eq i32 %65, 0
  br i1 %66, label %69, label %67

67:                                               ; preds = %64
  %68 = load i32, ptr %60, align 4, !tbaa !5
  %.not62 = icmp eq i32 %68, 2
  br i1 %.not62, label %70, label %69

69:                                               ; preds = %67, %64
  store i32 13, ptr %60, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %69, %67
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %6) #8
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %70, %thread-pre-split
  %72 = phi i32 [ %.pre, %70 ], [ %58, %thread-pre-split ]
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %85

74:                                               ; preds = %71
  %75 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !24
  %76 = icmp ugt i8 %75, 1
  br i1 %76, label %77, label %78, !prof !25

77:                                               ; preds = %74
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef nonnull @__func__.osal_openfile, i32 noundef 1332, ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.16, i32 noundef 0) #8
  br label %78

78:                                               ; preds = %74, %77
  %79 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !26
  %80 = and i8 %79, 1
  %.not63 = icmp eq i8 %80, 0
  %.not64 = icmp eq i32 %.055, -1
  %or.cond74 = or i1 %.not64, %.not63
  br i1 %or.cond74, label %82, label %81, !prof !27

81:                                               ; preds = %78
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.20, ptr noundef nonnull @__func__.osal_openfile, i32 noundef 1333) #10
  unreachable

82:                                               ; preds = %78
  %83 = load i32, ptr %3, align 4, !tbaa !5
  %84 = tail call i32 @dup(i32 noundef %83) #8
  store i32 %84, ptr %3, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %82, %71
  %.pr79 = phi i32 [ %84, %82 ], [ %72, %71 ]
  %.156 = phi i32 [ %83, %82 ], [ %.055, %71 ]
  %86 = icmp eq i32 %.pr79, 1
  br i1 %86, label %87, label %thread-pre-split78

87:                                               ; preds = %85
  %88 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !24
  %89 = icmp ugt i8 %88, 1
  br i1 %89, label %90, label %91, !prof !25

90:                                               ; preds = %87
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef nonnull @__func__.osal_openfile, i32 noundef 1337, ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.17, i32 noundef 1) #8
  br label %91

91:                                               ; preds = %87, %90
  %92 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !26
  %93 = and i8 %92, 1
  %.not65 = icmp eq i8 %93, 0
  %.not66 = icmp eq i32 %.053, -1
  %or.cond75 = or i1 %.not66, %.not65
  br i1 %or.cond75, label %95, label %94, !prof !27

94:                                               ; preds = %91
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.21, ptr noundef nonnull @__func__.osal_openfile, i32 noundef 1338) #10
  unreachable

95:                                               ; preds = %91
  %96 = load i32, ptr %3, align 4, !tbaa !5
  %97 = tail call i32 @dup(i32 noundef %96) #8
  store i32 %97, ptr %3, align 4, !tbaa !5
  br label %thread-pre-split78

thread-pre-split78:                               ; preds = %85, %95
  %98 = phi i32 [ %97, %95 ], [ %.pr79, %85 ]
  %.154 = phi i32 [ %96, %95 ], [ %.053, %85 ]
  %99 = icmp eq i32 %98, 2
  br i1 %99, label %100, label %thread-pre-split78.thread

100:                                              ; preds = %thread-pre-split78
  %101 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !24
  %102 = icmp ugt i8 %101, 1
  br i1 %102, label %103, label %104, !prof !25

103:                                              ; preds = %100
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef nonnull @__func__.osal_openfile, i32 noundef 1342, ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.18, i32 noundef 2) #8
  br label %104

104:                                              ; preds = %100, %103
  %105 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !26
  %106 = and i8 %105, 1
  %.not67 = icmp eq i8 %106, 0
  %.not68 = icmp eq i32 %.051, -1
  %or.cond76 = or i1 %.not68, %.not67
  br i1 %or.cond76, label %108, label %107, !prof !27

107:                                              ; preds = %104
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.22, ptr noundef nonnull @__func__.osal_openfile, i32 noundef 1343) #10
  unreachable

108:                                              ; preds = %104
  %109 = load i32, ptr %3, align 4, !tbaa !5
  %110 = tail call i32 @dup(i32 noundef %109) #8
  store i32 %110, ptr %3, align 4, !tbaa !5
  br label %thread-pre-split78.thread

thread-pre-split78.thread:                        ; preds = %thread-pre-split.thread, %108, %thread-pre-split78
  %.15490 = phi i32 [ %.154, %108 ], [ %.154, %thread-pre-split78 ], [ %.053, %thread-pre-split.thread ]
  %.1568589 = phi i32 [ %.156, %108 ], [ %.156, %thread-pre-split78 ], [ %.055, %thread-pre-split.thread ]
  %.152 = phi i32 [ %109, %108 ], [ %.051, %thread-pre-split78 ], [ %.051, %thread-pre-split.thread ]
  %111 = tail call ptr @__errno_location() #9
  %112 = load i32, ptr %111, align 4, !tbaa !5
  %.not69 = icmp eq i32 %.1568589, -1
  br i1 %.not69, label %115, label %113

113:                                              ; preds = %thread-pre-split78.thread
  %114 = tail call i32 @close(i32 noundef %.1568589) #8
  br label %115

115:                                              ; preds = %113, %thread-pre-split78.thread
  %.not70 = icmp eq i32 %.15490, -1
  br i1 %.not70, label %118, label %116

116:                                              ; preds = %115
  %117 = tail call i32 @close(i32 noundef %.15490) #8
  br label %118

118:                                              ; preds = %116, %115
  %.not71 = icmp eq i32 %.152, -1
  br i1 %.not71, label %121, label %119

119:                                              ; preds = %118
  %120 = tail call i32 @close(i32 noundef %.152) #8
  br label %121

121:                                              ; preds = %119, %118
  %122 = load i32, ptr %3, align 4, !tbaa !5
  %or.cond77 = icmp ult i32 %122, 3
  br i1 %or.cond77, label %123, label %129

123:                                              ; preds = %121
  %124 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !24
  %.not72 = icmp eq i8 %124, 0
  br i1 %.not72, label %126, label %125, !prof !28

125:                                              ; preds = %123
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.osal_openfile, i32 noundef 1356, ptr noundef nonnull @.str.23, i32 noundef 0, i32 noundef 2) #8
  %.pre80 = load i32, ptr %3, align 4, !tbaa !5
  br label %126

126:                                              ; preds = %125, %123
  %127 = phi i32 [ %.pre80, %125 ], [ %122, %123 ]
  %128 = tail call i32 @close(i32 noundef %127) #8
  br label %131

129:                                              ; preds = %121
  %130 = icmp slt i32 %122, 0
  %. = select i1 %130, i32 %112, i32 0
  br label %131

131:                                              ; preds = %126, %129, %5
  %.1 = phi i32 [ 22, %5 ], [ 9, %126 ], [ %., %129 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @is_valid_fd(i32 noundef) local_unnamed_addr #4

; Function Attrs: nofree
declare noundef i32 @open64(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @stat64(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #6

; Function Attrs: nounwind
declare i32 @dup(i32 noundef) local_unnamed_addr #7

declare i32 @close(i32 noundef) local_unnamed_addr #1

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


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