; 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.osal_mmap = type { %union.anon, i32, i64, i64, i64 }
%union.anon = type { ptr }

@globals = external global %struct.libmdbx_globals, align 8
@.str.40 = external hidden unnamed_addr constant [14 x i8], align 1
@__func__.osal_mmap = external hidden unnamed_addr constant [10 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [39 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
declare dso_local i32 @osal_filesize(i32 noundef, ptr noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local i32 @osal_ftruncate(i32 noundef, i64 noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local i32 @osal_check_fs_local(i32 noundef, i32 noundef) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @osal_mmap(i32 noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i32 noundef %4, ptr noundef %5) #5 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !9
  store i64 %2, ptr %10, align 8, !tbaa !11
  store i64 %3, ptr %11, align 8, !tbaa !11
  store i32 %4, ptr %12, align 4, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %6
  %17 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !13
  %18 = zext i8 %17 to i32
  %19 = and i32 %18, 1
  %20 = icmp ne i32 %19, 0
  %21 = xor i1 %20, true
  %22 = xor i1 %21, true
  %23 = zext i1 %22 to i32
  %24 = sext i32 %23 to i64
  %25 = call i64 @llvm.expect.i64(i64 %24, i64 1)
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %27, label %42

27:                                               ; preds = %16
  br label %28

28:                                               ; preds = %27
  %29 = load i64, ptr %10, align 8, !tbaa !11
  %30 = load i64, ptr %11, align 8, !tbaa !11
  %31 = icmp ule i64 %29, %30
  %32 = xor i1 %31, true
  %33 = xor i1 %32, true
  %34 = xor i1 %33, true
  %35 = zext i1 %34 to i32
  %36 = sext i32 %35 to i64
  %37 = call i64 @llvm.expect.i64(i64 %36, i64 0)
  %38 = icmp ne i64 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %28
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.40, ptr noundef @__func__.osal_mmap, i32 noundef 2028) #7
  unreachable

40:                                               ; preds = %28
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41, %16
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.osal_mmap, ptr %44, i32 0, i32 2
  store i64 0, ptr %45, align 8, !tbaa !16
  %46 = load ptr, ptr %9, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.osal_mmap, ptr %46, i32 0, i32 3
  store i64 0, ptr %47, align 8, !tbaa !18
  %48 = load ptr, ptr %9, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.osal_mmap, ptr %48, i32 0, i32 0
  store ptr null, ptr %49, align 8, !tbaa !19
  %50 = load ptr, ptr %9, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.osal_mmap, ptr %50, i32 0, i32 4
  store i64 0, ptr %51, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #8
  %52 = load ptr, ptr %9, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.osal_mmap, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !21
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = call i32 @osal_check_fs_local(i32 noundef %54, i32 noundef %55)
  store i32 %56, ptr %14, align 4, !tbaa !5
  %57 = load i32, ptr %14, align 4, !tbaa !5
  %58 = icmp ne i32 %57, 0
  %59 = xor i1 %58, true
  %60 = xor i1 %59, true
  %61 = zext i1 %60 to i32
  %62 = sext i32 %61 to i64
  %63 = call i64 @llvm.expect.i64(i64 %62, i64 0)
  %64 = icmp ne i64 %63, 0
  br i1 %64, label %65, label %101

65:                                               ; preds = %43
  %66 = load i32, ptr %14, align 4, !tbaa !5
  switch i32 %66, label %99 [
    i32 -1, label %67
    i32 121, label %83
  ]

67:                                               ; preds = %65
  br label %68

68:                                               ; preds = %67
  %69 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !22
  %70 = zext i8 %69 to i32
  %71 = icmp sle i32 1, %70
  %72 = xor i1 %71, true
  %73 = xor i1 %72, true
  %74 = zext i1 %73 to i32
  %75 = sext i32 %74 to i64
  %76 = call i64 @llvm.expect.i64(i64 %75, i64 0)
  %77 = icmp ne i64 %76, 0
  br i1 %77, label %78, label %80

78:                                               ; preds = %68
  %79 = load ptr, ptr %13, align 8, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.osal_mmap, i32 noundef 2049, ptr noundef @.str.41, ptr noundef %79)
  br label %80

80:                                               ; preds = %78, %68
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81
  store i32 121, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %332

83:                                               ; preds = %65
  br label %84

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

94:                                               ; preds = %84
  %95 = load ptr, ptr %13, align 8, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.osal_mmap, i32 noundef 2053, ptr noundef @.str.42, ptr noundef %95, ptr noundef @.str.43)
  br label %96

96:                                               ; preds = %94, %84
  br label %97

97:                                               ; preds = %96
  br label %98

98:                                               ; preds = %97
  br label %99

99:                                               ; preds = %98, %65
  %100 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %100, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %332

101:                                              ; preds = %43
  %102 = load i64, ptr %11, align 8, !tbaa !11
  %103 = call i32 @check_mmap_limit(i64 noundef %102)
  store i32 %103, ptr %14, align 4, !tbaa !5
  %104 = load i32, ptr %14, align 4, !tbaa !5
  %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 %114

112:                                              ; preds = %101
  %113 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %113, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %332

114:                                              ; preds = %101
  %115 = load i32, ptr %8, align 4, !tbaa !5
  %116 = and i32 %115, 131072
  %117 = icmp eq i32 %116, 0
  br i1 %117, label %118, label %155

118:                                              ; preds = %114
  %119 = load i32, ptr %12, align 4, !tbaa !5
  %120 = and i32 %119, 1
  %121 = icmp ne i32 %120, 0
  br i1 %121, label %122, label %155

122:                                              ; preds = %118
  %123 = load ptr, ptr %9, align 8, !tbaa !9
  %124 = getelementptr inbounds %struct.osal_mmap, ptr %123, i32 0, i32 1
  %125 = load i32, ptr %124, align 8, !tbaa !21
  %126 = load i64, ptr %10, align 8, !tbaa !11
  %127 = call i32 @osal_ftruncate(i32 noundef %125, i64 noundef %126)
  store i32 %127, ptr %14, align 4, !tbaa !5
  br label %128

128:                                              ; preds = %122
  %129 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !22
  %130 = zext i8 %129 to i32
  %131 = icmp sle i32 4, %130
  %132 = xor i1 %131, true
  %133 = xor i1 %132, true
  %134 = zext i1 %133 to i32
  %135 = sext i32 %134 to i64
  %136 = call i64 @llvm.expect.i64(i64 %135, i64 0)
  %137 = icmp ne i64 %136, 0
  br i1 %137, label %138, label %141

138:                                              ; preds = %128
  %139 = load i64, ptr %10, align 8, !tbaa !11
  %140 = load i32, ptr %14, align 4, !tbaa !5
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 4, ptr noundef @__func__.osal_mmap, i32 noundef 2066, ptr noundef @.str.44, i64 noundef %139, i32 noundef %140)
  br label %141

141:                                              ; preds = %138, %128
  br label %142

142:                                              ; preds = %141
  br label %143

143:                                              ; preds = %142
  %144 = load i32, ptr %14, align 4, !tbaa !5
  %145 = icmp ne i32 %144, 0
  br i1 %145, label %146, label %148

146:                                              ; preds = %143
  %147 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %147, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %332

148:                                              ; preds = %143
  %149 = load i64, ptr %10, align 8, !tbaa !11
  %150 = load ptr, ptr %9, align 8, !tbaa !9
  %151 = getelementptr inbounds %struct.osal_mmap, ptr %150, i32 0, i32 4
  store i64 %149, ptr %151, align 8, !tbaa !20
  %152 = load i64, ptr %10, align 8, !tbaa !11
  %153 = load ptr, ptr %9, align 8, !tbaa !9
  %154 = getelementptr inbounds %struct.osal_mmap, ptr %153, i32 0, i32 3
  store i64 %152, ptr %154, align 8, !tbaa !18
  br label %200

155:                                              ; preds = %118, %114
  %156 = load ptr, ptr %9, align 8, !tbaa !9
  %157 = getelementptr inbounds %struct.osal_mmap, ptr %156, i32 0, i32 1
  %158 = load i32, ptr %157, align 8, !tbaa !21
  %159 = load ptr, ptr %9, align 8, !tbaa !9
  %160 = getelementptr inbounds %struct.osal_mmap, ptr %159, i32 0, i32 4
  %161 = call i32 @osal_filesize(i32 noundef %158, ptr noundef %160)
  store i32 %161, ptr %14, align 4, !tbaa !5
  br label %162

162:                                              ; preds = %155
  %163 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !22
  %164 = zext i8 %163 to i32
  %165 = icmp sle i32 4, %164
  %166 = xor i1 %165, true
  %167 = xor i1 %166, true
  %168 = zext i1 %167 to i32
  %169 = sext i32 %168 to i64
  %170 = call i64 @llvm.expect.i64(i64 %169, i64 0)
  %171 = icmp ne i64 %170, 0
  br i1 %171, label %172, label %177

172:                                              ; preds = %162
  %173 = load ptr, ptr %9, align 8, !tbaa !9
  %174 = getelementptr inbounds %struct.osal_mmap, ptr %173, i32 0, i32 4
  %175 = load i64, ptr %174, align 8, !tbaa !20
  %176 = load i32, ptr %14, align 4, !tbaa !5
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 4, ptr noundef @__func__.osal_mmap, i32 noundef 2075, ptr noundef @.str.45, i64 noundef %175, i32 noundef %176)
  br label %177

177:                                              ; preds = %172, %162
  br label %178

178:                                              ; preds = %177
  br label %179

179:                                              ; preds = %178
  %180 = load i32, ptr %14, align 4, !tbaa !5
  %181 = icmp ne i32 %180, 0
  br i1 %181, label %182, label %184

182:                                              ; preds = %179
  %183 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %183, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %332

184:                                              ; preds = %179
  %185 = load ptr, ptr %9, align 8, !tbaa !9
  %186 = getelementptr inbounds %struct.osal_mmap, ptr %185, i32 0, i32 4
  %187 = load i64, ptr %186, align 8, !tbaa !20
  %188 = load i64, ptr %11, align 8, !tbaa !11
  %189 = icmp ugt i64 %187, %188
  br i1 %189, label %190, label %192

190:                                              ; preds = %184
  %191 = load i64, ptr %11, align 8, !tbaa !11
  br label %196

192:                                              ; preds = %184
  %193 = load ptr, ptr %9, align 8, !tbaa !9
  %194 = getelementptr inbounds %struct.osal_mmap, ptr %193, i32 0, i32 4
  %195 = load i64, ptr %194, align 8, !tbaa !20
  br label %196

196:                                              ; preds = %192, %190
  %197 = phi i64 [ %191, %190 ], [ %195, %192 ]
  %198 = load ptr, ptr %9, align 8, !tbaa !9
  %199 = getelementptr inbounds %struct.osal_mmap, ptr %198, i32 0, i32 3
  store i64 %197, ptr %199, align 8, !tbaa !18
  br label %200

200:                                              ; preds = %196, %148
  %201 = load i64, ptr %11, align 8, !tbaa !11
  %202 = load i32, ptr %8, align 4, !tbaa !5
  %203 = and i32 %202, 524288
  %204 = icmp ne i32 %203, 0
  %205 = zext i1 %204 to i64
  %206 = select i1 %204, i32 3, i32 1
  %207 = load i32, ptr %8, align 4, !tbaa !5
  %208 = and i32 %207, 1114112
  %209 = icmp eq i32 %208, 1114112
  %210 = zext i1 %209 to i64
  %211 = select i1 %209, i32 0, i32 0
  %212 = or i32 16385, %211
  %213 = load i32, ptr %12, align 4, !tbaa !5
  %214 = and i32 %213, 2
  %215 = icmp ne i32 %214, 0
  %216 = zext i1 %215 to i64
  %217 = select i1 %215, i32 0, i32 0
  %218 = or i32 %212, %217
  %219 = load ptr, ptr %9, align 8, !tbaa !9
  %220 = getelementptr inbounds %struct.osal_mmap, ptr %219, i32 0, i32 1
  %221 = load i32, ptr %220, align 8, !tbaa !21
  %222 = call ptr @mmap64(ptr noundef null, i64 noundef %201, i32 noundef %206, i32 noundef %218, i32 noundef %221, i64 noundef 0) #8
  %223 = load ptr, ptr %9, align 8, !tbaa !9
  %224 = getelementptr inbounds %struct.osal_mmap, ptr %223, i32 0, i32 0
  store ptr %222, ptr %224, align 8, !tbaa !19
  %225 = load ptr, ptr %9, align 8, !tbaa !9
  %226 = getelementptr inbounds %struct.osal_mmap, ptr %225, i32 0, i32 0
  %227 = load ptr, ptr %226, align 8, !tbaa !19
  %228 = icmp eq ptr %227, inttoptr (i64 -1 to ptr)
  %229 = xor i1 %228, true
  %230 = xor i1 %229, true
  %231 = zext i1 %230 to i32
  %232 = sext i32 %231 to i64
  %233 = call i64 @llvm.expect.i64(i64 %232, i64 0)
  %234 = icmp ne i64 %233, 0
  br i1 %234, label %235, label %274

235:                                              ; preds = %200
  %236 = load ptr, ptr %9, align 8, !tbaa !9
  %237 = getelementptr inbounds %struct.osal_mmap, ptr %236, i32 0, i32 2
  store i64 0, ptr %237, align 8, !tbaa !16
  %238 = load ptr, ptr %9, align 8, !tbaa !9
  %239 = getelementptr inbounds %struct.osal_mmap, ptr %238, i32 0, i32 3
  store i64 0, ptr %239, align 8, !tbaa !18
  %240 = load ptr, ptr %9, align 8, !tbaa !9
  %241 = getelementptr inbounds %struct.osal_mmap, ptr %240, i32 0, i32 0
  store ptr null, ptr %241, align 8, !tbaa !19
  br label %242

242:                                              ; preds = %235
  %243 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !13
  %244 = zext i8 %243 to i32
  %245 = and i32 %244, 1
  %246 = icmp ne i32 %245, 0
  %247 = xor i1 %246, true
  %248 = xor i1 %247, true
  %249 = zext i1 %248 to i32
  %250 = sext i32 %249 to i64
  %251 = call i64 @llvm.expect.i64(i64 %250, i64 1)
  %252 = icmp ne i64 %251, 0
  br i1 %252, label %253, label %269

253:                                              ; preds = %242
  br label %254

254:                                              ; preds = %253
  %255 = call ptr @__errno_location() #9
  %256 = load i32, ptr %255, align 4, !tbaa !5
  %257 = icmp ne i32 %256, 0
  %258 = xor i1 %257, true
  %259 = xor i1 %258, true
  %260 = xor i1 %259, true
  %261 = zext i1 %260 to i32
  %262 = sext i32 %261 to i64
  %263 = call i64 @llvm.expect.i64(i64 %262, i64 0)
  %264 = icmp ne i64 %263, 0
  br i1 %264, label %265, label %266

265:                                              ; preds = %254
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.46, ptr noundef @__func__.osal_mmap, i32 noundef 2159) #7
  unreachable

266:                                              ; preds = %254
  br label %267

267:                                              ; preds = %266
  br label %268

268:                                              ; preds = %267
  br label %269

269:                                              ; preds = %268, %242
  br label %270

270:                                              ; preds = %269
  br label %271

271:                                              ; preds = %270
  %272 = call ptr @__errno_location() #9
  %273 = load i32, ptr %272, align 4, !tbaa !5
  store i32 %273, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %332

274:                                              ; preds = %200
  %275 = load i64, ptr %11, align 8, !tbaa !11
  %276 = load ptr, ptr %9, align 8, !tbaa !9
  %277 = getelementptr inbounds %struct.osal_mmap, ptr %276, i32 0, i32 2
  store i64 %275, ptr %277, align 8, !tbaa !16
  %278 = load ptr, ptr %9, align 8, !tbaa !9
  %279 = getelementptr inbounds %struct.osal_mmap, ptr %278, i32 0, i32 0
  %280 = load ptr, ptr %279, align 8, !tbaa !19
  %281 = load ptr, ptr %9, align 8, !tbaa !9
  %282 = getelementptr inbounds %struct.osal_mmap, ptr %281, i32 0, i32 2
  %283 = load i64, ptr %282, align 8, !tbaa !16
  %284 = call i32 @madvise(ptr noundef %280, i64 noundef %283, i32 noundef 10) #8
  %285 = icmp ne i32 %284, 0
  %286 = xor i1 %285, true
  %287 = xor i1 %286, true
  %288 = zext i1 %287 to i32
  %289 = sext i32 %288 to i64
  %290 = call i64 @llvm.expect.i64(i64 %289, i64 0)
  %291 = icmp ne i64 %290, 0
  br i1 %291, label %292, label %295

292:                                              ; preds = %274
  %293 = call ptr @__errno_location() #9
  %294 = load i32, ptr %293, align 4, !tbaa !5
  store i32 %294, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %332

295:                                              ; preds = %274
  %296 = load ptr, ptr %9, align 8, !tbaa !9
  %297 = getelementptr inbounds %struct.osal_mmap, ptr %296, i32 0, i32 0
  %298 = load ptr, ptr %297, align 8, !tbaa !19
  %299 = load ptr, ptr %9, align 8, !tbaa !9
  %300 = getelementptr inbounds %struct.osal_mmap, ptr %299, i32 0, i32 2
  %301 = load i64, ptr %300, align 8, !tbaa !16
  %302 = call i32 @madvise(ptr noundef %298, i64 noundef %301, i32 noundef 15) #8
  br label %303

303:                                              ; preds = %295
  br label %304

304:                                              ; preds = %303
  %305 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !22
  %306 = zext i8 %305 to i32
  %307 = icmp sle i32 6, %306
  %308 = xor i1 %307, true
  %309 = xor i1 %308, true
  %310 = zext i1 %309 to i32
  %311 = sext i32 %310 to i64
  %312 = call i64 @llvm.expect.i64(i64 %311, i64 0)
  %313 = icmp ne i64 %312, 0
  br i1 %313, label %314, label %321

314:                                              ; preds = %304
  %315 = load ptr, ptr %9, align 8, !tbaa !9
  %316 = getelementptr inbounds %struct.osal_mmap, ptr %315, i32 0, i32 0
  %317 = load ptr, ptr %316, align 8, !tbaa !19
  %318 = load ptr, ptr %9, align 8, !tbaa !9
  %319 = getelementptr inbounds %struct.osal_mmap, ptr %318, i32 0, i32 3
  %320 = load i64, ptr %319, align 8, !tbaa !18
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.osal_mmap, i32 noundef 2175, ptr noundef @.str.47, ptr noundef %317, i64 noundef %320, i32 noundef 2175)
  br label %321

321:                                              ; preds = %314, %304
  br label %322

322:                                              ; preds = %321
  br label %323

323:                                              ; preds = %322
  %324 = load ptr, ptr %9, align 8, !tbaa !9
  %325 = getelementptr inbounds %struct.osal_mmap, ptr %324, i32 0, i32 0
  %326 = load ptr, ptr %325, align 8, !tbaa !19
  %327 = load ptr, ptr %9, align 8, !tbaa !9
  %328 = getelementptr inbounds %struct.osal_mmap, ptr %327, i32 0, i32 3
  %329 = load i64, ptr %328, align 8, !tbaa !18
  br label %330

330:                                              ; preds = %323
  br label %331

331:                                              ; preds = %330
  store i32 0, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %332

332:                                              ; preds = %331, %292, %271, %182, %146, %112, %99, %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #8
  %333 = load i32, ptr %7, align 4
  ret i32 %333
}

; Function Attrs: nounwind uwtable
declare hidden i32 @check_mmap_limit(i64 noundef) #5

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

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

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 = { cold noreturn }
attributes #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(none) }

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !7, i64 25}
!14 = !{!"libmdbx_globals", !7, i64 0, !6, i64 16, !6, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !15, i64 27, !6, i64 28, !7, i64 32, !7, i64 40, !12, i64 80, !10, i64 88}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!17, !12, i64 16}
!17 = !{!"osal_mmap", !7, i64 0, !6, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!18 = !{!17, !12, i64 24}
!19 = !{!7, !7, i64 0}
!20 = !{!17, !12, i64 32}
!21 = !{!17, !6, i64 8}
!22 = !{!14, !7, i64 26}


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

%struct.libmdbx_globals = type { %union.bin128, i32, i32, i8, i8, i8, i8, i32, %union.logger_union, %union.pthread_mutex_t, i64, ptr }
%union.bin128 = type { %struct.anon.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 }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str.40 = external hidden unnamed_addr constant [14 x i8], align 1
@__func__.osal_mmap = external hidden unnamed_addr constant [10 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [39 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 nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @osal_filesize(i32 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @osal_ftruncate(i32 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @osal_check_fs_local(i32 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @osal_mmap(i32 noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i32 noundef %4, ptr noundef %5) local_unnamed_addr #3 {
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %8 = and i8 %7, 1
  %.not = icmp ne i8 %8, 0
  %.not65 = icmp ugt i64 %2, %3
  %or.cond = and i1 %.not65, %.not
  br i1 %or.cond, label %9, label %10, !prof !13

9:                                                ; preds = %6
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.40, ptr noundef nonnull @__func__.osal_mmap, i32 noundef 2028) #7
  unreachable

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %1, i64 16
  %12 = getelementptr inbounds i8, ptr %1, i64 24
  store ptr null, ptr %1, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %1, i64 32
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %11, i8 0, i64 24, i1 false)
  %15 = load i32, ptr %14, align 8, !tbaa !15
  %16 = tail call i32 @osal_check_fs_local(i32 noundef %15, i32 noundef %0)
  switch i32 %16, label %73 [
    i32 0, label %23
    i32 -1, label %17
    i32 121, label %20
  ], !prof !17

17:                                               ; preds = %10
  %18 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !18
  %.not76 = icmp eq i8 %18, 0
  br i1 %.not76, label %73, label %19, !prof !19

19:                                               ; preds = %17
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.osal_mmap, i32 noundef 2049, ptr noundef nonnull @.str.41, ptr noundef %5) #8
  br label %73

20:                                               ; preds = %10
  %21 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !18
  %.not75 = icmp eq i8 %21, 0
  br i1 %.not75, label %73, label %22, !prof !19

22:                                               ; preds = %20
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.osal_mmap, i32 noundef 2053, ptr noundef nonnull @.str.42, ptr noundef %5, ptr noundef nonnull @.str.43) #8
  br label %73

23:                                               ; preds = %10
  %24 = tail call i32 @check_mmap_limit(i64 noundef %3)
  %.not67 = icmp eq i32 %24, 0
  br i1 %.not67, label %25, label %73, !prof !19

25:                                               ; preds = %23
  %26 = and i32 %0, 131072
  %27 = icmp ne i32 %26, 0
  %28 = and i32 %4, 1
  %.not68 = icmp eq i32 %28, 0
  %or.cond77 = or i1 %27, %.not68
  %29 = load i32, ptr %14, align 8, !tbaa !15
  br i1 %or.cond77, label %37, label %30

30:                                               ; preds = %25
  %31 = tail call i32 @osal_ftruncate(i32 noundef %29, i64 noundef %2)
  %32 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !18
  %33 = icmp ugt i8 %32, 3
  br i1 %33, label %34, label %35, !prof !20

34:                                               ; preds = %30
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 4, ptr noundef nonnull @__func__.osal_mmap, i32 noundef 2066, ptr noundef nonnull @.str.44, i64 noundef %2, i32 noundef %31) #8
  br label %35

35:                                               ; preds = %34, %30
  %.not70 = icmp eq i32 %31, 0
  br i1 %.not70, label %36, label %73

36:                                               ; preds = %35
  store i64 %2, ptr %13, align 8, !tbaa !21
  br label %46

37:                                               ; preds = %25
  %38 = tail call i32 @osal_filesize(i32 noundef %29, ptr noundef nonnull %13)
  %39 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !18
  %40 = icmp ugt i8 %39, 3
  br i1 %40, label %41, label %43, !prof !20

41:                                               ; preds = %37
  %42 = load i64, ptr %13, align 8, !tbaa !21
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 4, ptr noundef nonnull @__func__.osal_mmap, i32 noundef 2075, ptr noundef nonnull @.str.45, i64 noundef %42, i32 noundef %38) #8
  br label %43

43:                                               ; preds = %41, %37
  %.not69 = icmp eq i32 %38, 0
  br i1 %.not69, label %44, label %73

44:                                               ; preds = %43
  %45 = load i64, ptr %13, align 8, !tbaa !21
  %. = tail call i64 @llvm.umin.i64(i64 %45, i64 %3)
  br label %46

46:                                               ; preds = %44, %36
  %storemerge = phi i64 [ %., %44 ], [ %2, %36 ]
  store i64 %storemerge, ptr %12, align 8, !tbaa !22
  %47 = and i32 %0, 524288
  %.not71 = icmp eq i32 %47, 0
  %48 = select i1 %.not71, i32 1, i32 3
  %49 = load i32, ptr %14, align 8, !tbaa !15
  %50 = tail call ptr @mmap64(ptr noundef null, i64 noundef %3, i32 noundef %48, i32 noundef 16385, i32 noundef %49, i64 noundef 0) #8
  store ptr %50, ptr %1, align 8, !tbaa !14
  %51 = icmp eq ptr %50, inttoptr (i64 -1 to ptr)
  br i1 %51, label %52, label %59, !prof !20

52:                                               ; preds = %46
  store ptr null, ptr %1, align 8, !tbaa !14
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %11, i8 0, i64 16, i1 false)
  %53 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %54 = and i8 %53, 1
  %.not73 = icmp eq i8 %54, 0
  %.pre = tail call ptr @__errno_location() #9
  br i1 %.not73, label %._crit_edge, label %55, !prof !20

55:                                               ; preds = %52
  %56 = load i32, ptr %.pre, align 4, !tbaa !23
  %.not74 = icmp eq i32 %56, 0
  br i1 %.not74, label %57, label %._crit_edge, !prof !20

57:                                               ; preds = %55
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.46, ptr noundef nonnull @__func__.osal_mmap, i32 noundef 2159) #7
  unreachable

._crit_edge:                                      ; preds = %52, %55
  %58 = load i32, ptr %.pre, align 4, !tbaa !23
  br label %73

59:                                               ; preds = %46
  store i64 %3, ptr %11, align 8, !tbaa !24
  %60 = tail call i32 @madvise(ptr noundef %50, i64 noundef %3, i32 noundef 10) #8
  %.not72 = icmp eq i32 %60, 0
  br i1 %.not72, label %64, label %61, !prof !19

61:                                               ; preds = %59
  %62 = tail call ptr @__errno_location() #9
  %63 = load i32, ptr %62, align 4, !tbaa !23
  br label %73

64:                                               ; preds = %59
  %65 = load ptr, ptr %1, align 8, !tbaa !14
  %66 = load i64, ptr %11, align 8, !tbaa !24
  %67 = tail call i32 @madvise(ptr noundef %65, i64 noundef %66, i32 noundef 15) #8
  %68 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !18
  %69 = icmp ugt i8 %68, 5
  br i1 %69, label %70, label %73, !prof !20

70:                                               ; preds = %64
  %71 = load ptr, ptr %1, align 8, !tbaa !14
  %72 = load i64, ptr %12, align 8, !tbaa !22
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.osal_mmap, i32 noundef 2175, ptr noundef nonnull @.str.47, ptr noundef %71, i64 noundef %72, i32 noundef 2175) #8
  br label %73

73:                                               ; preds = %64, %70, %43, %35, %23, %22, %20, %10, %17, %19, %61, %._crit_edge
  %.0 = phi i32 [ %58, %._crit_edge ], [ %63, %61 ], [ 121, %19 ], [ 121, %17 ], [ %16, %10 ], [ 121, %20 ], [ 121, %22 ], [ %24, %23 ], [ %31, %35 ], [ %38, %43 ], [ 0, %70 ], [ 0, %64 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @check_mmap_limit(i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare ptr @mmap64(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare i32 @madvise(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

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 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 #3 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { cold noreturn }
attributes #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(none) }

!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, !7, i64 25}
!6 = !{!"libmdbx_globals", !7, i64 0, !9, i64 16, !9, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !10, i64 27, !9, i64 28, !7, i64 32, !7, i64 40, !11, i64 80, !12, i64 88}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"branch_weights", i32 2000, i32 4002001}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !9, i64 8}
!16 = !{!"osal_mmap", !7, i64 0, !9, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!17 = !{!"branch_weights", i32 1, i32 6000, i32 1, i32 1}
!18 = !{!6, !7, i64 26}
!19 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!20 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!21 = !{!16, !11, i64 32}
!22 = !{!16, !11, i64 24}
!23 = !{!9, !9, i64 0}
!24 = !{!16, !11, i64 16}


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