; LLVM IR from erthink/libmdbx :: src (lck-posix)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.libmdbx_globals = type { %union.bin128, i32, i32, i8, i8, i8, i8, i32, %union.logger_union, %union.pthread_mutex_t, i64, ptr }
%union.bin128 = type { %struct.anon }
%struct.anon = type { i64, i64 }
%union.logger_union = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct.MDBX_env = type { %union.mdbx_atomic_uint32_t, i32, i32, %struct.osal_mmap, i32, i32, %struct.osal_mmap, ptr, i16, i16, i16, i16, i16, i16, %union.mdbx_atomic_uint32_t, i8, i8, i16, i32, i32, i32, i32, %struct.anon.1, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.2, %struct.anon.6, i8, ptr, ptr, ptr, %struct.anon.7, %union.pthread_mutex_t, i32, i32, ptr, %struct.osal_ioring, %union.pthread_mutex_t, [71 x %union.mdbx_atomic_uint64_t] }
%struct.osal_mmap = type { %union.anon, i32, i64, i64, i64 }
%union.anon = type { ptr }
%union.mdbx_atomic_uint32_t = type { i32 }
%struct.anon.1 = type { ptr, ptr, ptr, ptr }
%struct.anon.2 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.3, %union.anon.4 }
%struct.anon.3 = type { i16, i16, i16, i16 }
%union.anon.4 = type { i32 }
%struct.anon.6 = type { i64, i64, i64, i64, i64 }
%struct.anon.7 = type { i64 }
%struct.osal_ioring = type { i32, i32, i32, ptr, ptr, ptr }
%union.mdbx_atomic_uint64_t = type { i64 }

@op_setlk = external hidden global i32, align 4
@op_setlkw = external hidden global i32, align 4
@globals = external global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [4 x i8], align 1
@__func__.lck_upgrade = external hidden unnamed_addr constant [12 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @lck_op(i32 noundef, i32 noundef, i32 noundef, i64 noundef, i64 noundef) #1

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @lck_upgrade(ptr noundef %0, i1 noundef zeroext %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %8 = zext i1 %1 to i8
  store i8 %8, ptr %5, align 1, !tbaa !9
  br label %9

9:                                                ; preds = %2
  %10 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %11 = zext i8 %10 to i32
  %12 = and i32 %11, 1
  %13 = icmp ne i32 %12, 0
  %14 = xor i1 %13, true
  %15 = xor i1 %14, true
  %16 = zext i1 %15 to i32
  %17 = sext i32 %16 to i64
  %18 = call i64 @llvm.expect.i64(i64 %17, i64 1)
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %20, label %37

20:                                               ; preds = %9
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.MDBX_env, ptr %22, i32 0, i32 6
  %24 = getelementptr inbounds %struct.osal_mmap, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !15
  %26 = icmp ne i32 %25, -1
  %27 = xor i1 %26, true
  %28 = xor i1 %27, true
  %29 = xor i1 %28, true
  %30 = zext i1 %29 to i32
  %31 = sext i32 %30 to i64
  %32 = call i64 @llvm.expect.i64(i64 %31, i64 0)
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %21
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str, ptr noundef @__func__.lck_upgrade, i32 noundef 406) #6
  unreachable

35:                                               ; preds = %21
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36, %9
  br label %38

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

50:                                               ; preds = %38
  store i32 -30795, ptr %3, align 4
  br label %210

51:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %52 = load i8, ptr %5, align 1, !tbaa !9, !range !26, !noundef !27
  %53 = trunc i8 %52 to i1
  br i1 %53, label %54, label %56

54:                                               ; preds = %51
  %55 = load i32, ptr @op_setlk, align 4, !tbaa !28
  br label %58

56:                                               ; preds = %51
  %57 = load i32, ptr @op_setlkw, align 4, !tbaa !28
  br label %58

58:                                               ; preds = %56, %54
  %59 = phi i32 [ %55, %54 ], [ %57, %56 ]
  store i32 %59, ptr %6, align 4, !tbaa !28
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MDBX_env, ptr %60, i32 0, i32 6
  %62 = getelementptr inbounds %struct.osal_mmap, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 8, !tbaa !15
  %64 = load i32, ptr %6, align 4, !tbaa !28
  %65 = call i32 @lck_op(i32 noundef %63, i32 noundef %64, i32 noundef 1, i64 noundef 0, i64 noundef 1)
  store i32 %65, ptr %7, align 4, !tbaa !28
  %66 = load i32, ptr %7, align 4, !tbaa !28
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %149

68:                                               ; preds = %58
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.MDBX_env, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 4, !tbaa !29
  %72 = and i32 %71, 4194304
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %149

74:                                               ; preds = %68
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.MDBX_env, ptr %75, i32 0, i32 20
  %77 = load i32, ptr %76, align 4, !tbaa !25
  %78 = icmp ugt i32 %77, 1
  br i1 %78, label %79, label %91

79:                                               ; preds = %74
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.MDBX_env, ptr %80, i32 0, i32 3
  %82 = getelementptr inbounds %struct.osal_mmap, ptr %81, i32 0, i32 1
  %83 = load i32, ptr %82, align 8, !tbaa !30
  %84 = load i32, ptr %6, align 4, !tbaa !28
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.MDBX_env, ptr %85, i32 0, i32 20
  %87 = load i32, ptr %86, align 4, !tbaa !25
  %88 = sub i32 %87, 1
  %89 = zext i32 %88 to i64
  %90 = call i32 @lck_op(i32 noundef %83, i32 noundef %84, i32 noundef 1, i64 noundef 0, i64 noundef %89)
  br label %92

91:                                               ; preds = %74
  br label %92

92:                                               ; preds = %91, %79
  %93 = phi i32 [ %90, %79 ], [ 0, %91 ]
  store i32 %93, ptr %7, align 4, !tbaa !28
  %94 = load i32, ptr %7, align 4, !tbaa !28
  %95 = icmp eq i32 %94, 0
  br i1 %95, label %96, label %136

96:                                               ; preds = %92
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.MDBX_env, ptr %97, i32 0, i32 3
  %99 = getelementptr inbounds %struct.osal_mmap, ptr %98, i32 0, i32 1
  %100 = load i32, ptr %99, align 8, !tbaa !30
  %101 = load i32, ptr %6, align 4, !tbaa !28
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.MDBX_env, ptr %102, i32 0, i32 20
  %104 = load i32, ptr %103, align 4, !tbaa !25
  %105 = add i32 %104, 1
  %106 = zext i32 %105 to i64
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.MDBX_env, ptr %107, i32 0, i32 20
  %109 = load i32, ptr %108, align 4, !tbaa !25
  %110 = zext i32 %109 to i64
  %111 = sub i64 9223372036853727232, %110
  %112 = sub i64 %111, 1
  %113 = call i32 @lck_op(i32 noundef %100, i32 noundef %101, i32 noundef 1, i64 noundef %106, i64 noundef %112)
  store i32 %113, ptr %7, align 4, !tbaa !28
  %114 = load i32, ptr %7, align 4, !tbaa !28
  %115 = icmp ne i32 %114, 0
  br i1 %115, label %116, label %135

116:                                              ; preds = %96
  %117 = load ptr, ptr %4, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.MDBX_env, ptr %117, i32 0, i32 20
  %119 = load i32, ptr %118, align 4, !tbaa !25
  %120 = icmp ugt i32 %119, 1
  br i1 %120, label %121, label %135

121:                                              ; preds = %116
  %122 = load ptr, ptr %4, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct.MDBX_env, ptr %122, i32 0, i32 3
  %124 = getelementptr inbounds %struct.osal_mmap, ptr %123, i32 0, i32 1
  %125 = load i32, ptr %124, align 8, !tbaa !30
  %126 = load i32, ptr @op_setlk, align 4, !tbaa !28
  %127 = load ptr, ptr %4, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.MDBX_env, ptr %127, i32 0, i32 20
  %129 = load i32, ptr %128, align 4, !tbaa !25
  %130 = sub i32 %129, 1
  %131 = zext i32 %130 to i64
  %132 = call i32 @lck_op(i32 noundef %125, i32 noundef %126, i32 noundef 2, i64 noundef 0, i64 noundef %131)
  %133 = icmp ne i32 %132, 0
  br i1 %133, label %134, label %135

134:                                              ; preds = %121
  store i32 -30795, ptr %7, align 4, !tbaa !28
  br label %135

135:                                              ; preds = %134, %121, %116, %96
  br label %136

136:                                              ; preds = %135, %92
  %137 = load i32, ptr %7, align 4, !tbaa !28
  %138 = icmp ne i32 %137, 0
  br i1 %138, label %139, label %148

139:                                              ; preds = %136
  %140 = load ptr, ptr %4, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.MDBX_env, ptr %140, i32 0, i32 6
  %142 = getelementptr inbounds %struct.osal_mmap, ptr %141, i32 0, i32 1
  %143 = load i32, ptr %142, align 8, !tbaa !15
  %144 = load i32, ptr @op_setlk, align 4, !tbaa !28
  %145 = call i32 @lck_op(i32 noundef %143, i32 noundef %144, i32 noundef 0, i64 noundef 0, i64 noundef 1)
  %146 = icmp ne i32 %145, 0
  br i1 %146, label %147, label %148

147:                                              ; preds = %139
  store i32 -30795, ptr %7, align 4, !tbaa !28
  br label %148

148:                                              ; preds = %147, %139, %136
  br label %149

149:                                              ; preds = %148, %68, %58
  %150 = load i32, ptr %7, align 4, !tbaa !28
  %151 = icmp ne i32 %150, 0
  %152 = xor i1 %151, true
  %153 = xor i1 %152, true
  %154 = zext i1 %153 to i32
  %155 = sext i32 %154 to i64
  %156 = call i64 @llvm.expect.i64(i64 %155, i64 0)
  %157 = icmp ne i64 %156, 0
  br i1 %157, label %158, label %208

158:                                              ; preds = %149
  br label %159

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

169:                                              ; preds = %159
  %170 = load i32, ptr %7, align 4, !tbaa !28
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.lck_upgrade, i32 noundef 423, ptr noundef @.str.4, ptr noundef @.str.14, i32 noundef %170)
  br label %171

171:                                              ; preds = %169, %159
  br label %172

172:                                              ; preds = %171
  br label %173

173:                                              ; preds = %172
  br label %174

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

185:                                              ; preds = %174
  br label %186

186:                                              ; preds = %185
  %187 = load i32, ptr %7, align 4, !tbaa !28
  %188 = icmp ne i32 %187, -1
  br i1 %188, label %189, label %192

189:                                              ; preds = %186
  %190 = load i32, ptr %7, align 4, !tbaa !28
  %191 = icmp ne i32 %190, 0
  br label %192

192:                                              ; preds = %189, %186
  %193 = phi i1 [ false, %186 ], [ %191, %189 ]
  %194 = xor i1 %193, true
  %195 = xor i1 %194, true
  %196 = xor i1 %195, true
  %197 = zext i1 %196 to i32
  %198 = sext i32 %197 to i64
  %199 = call i64 @llvm.expect.i64(i64 %198, i64 0)
  %200 = icmp ne i64 %199, 0
  br i1 %200, label %201, label %202

201:                                              ; preds = %192
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.7, ptr noundef @__func__.lck_upgrade, i32 noundef 424) #6
  unreachable

202:                                              ; preds = %192
  br label %203

203:                                              ; preds = %202
  br label %204

204:                                              ; preds = %203
  br label %205

205:                                              ; preds = %204, %174
  br label %206

206:                                              ; preds = %205
  br label %207

207:                                              ; preds = %206
  br label %208

208:                                              ; preds = %207, %149
  %209 = load i32, ptr %7, align 4, !tbaa !28
  store i32 %209, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %210

210:                                              ; preds = %208, %50
  %211 = load i32, ptr %3, align 4
  ret i32 %211
}

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

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !7, i64 25}
!12 = !{!"libmdbx_globals", !7, i64 0, !13, i64 16, !13, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !10, i64 27, !13, i64 28, !7, i64 32, !7, i64 40, !14, i64 80, !6, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !13, i64 72}
!16 = !{!"MDBX_env", !7, i64 0, !13, i64 4, !13, i64 8, !17, i64 16, !13, i64 56, !13, i64 60, !17, i64 64, !6, i64 104, !18, i64 112, !18, i64 114, !18, i64 116, !18, i64 118, !18, i64 120, !18, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !18, i64 130, !13, i64 132, !13, i64 136, !13, i64 140, !13, i64 144, !19, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !13, i64 224, !13, i64 228, !13, i64 232, !6, i64 240, !6, i64 248, !14, i64 256, !20, i64 264, !22, i64 320, !10, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !23, i64 392, !7, i64 400, !13, i64 440, !13, i64 444, !6, i64 448, !24, i64 456, !7, i64 496, !7, i64 536}
!17 = !{!"osal_mmap", !7, i64 0, !13, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!18 = !{!"short", !7, i64 0}
!19 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!20 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !14, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !13, i64 28, !13, i64 32, !10, i64 36, !10, i64 37, !10, i64 38, !21, i64 40, !7, i64 48}
!21 = !{!"", !18, i64 0, !18, i64 2, !18, i64 4, !18, i64 6}
!22 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!23 = !{!"", !14, i64 0}
!24 = !{!"osal_ioring", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!25 = !{!16, !13, i64 140}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!13, !13, i64 0}
!29 = !{!16, !13, i64 4}
!30 = !{!16, !13, i64 24}
!31 = !{!12, !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 }
%struct.anon = type { i64, i64 }
%union.logger_union = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@op_setlk = external hidden local_unnamed_addr global i32, align 4
@op_setlkw = external hidden local_unnamed_addr global i32, align 4
@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [4 x i8], align 1
@__func__.lck_upgrade = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden i32 @lck_op(i32 noundef, i32 noundef, i32 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @lck_upgrade(ptr nocapture noundef readonly %0, i1 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %4 = and i8 %3, 1
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %9, label %5, !prof !13

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = load i32, ptr %6, align 8, !tbaa !14
  %.not35 = icmp eq i32 %7, -1
  br i1 %.not35, label %8, label %9, !prof !13

8:                                                ; preds = %5
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str, ptr noundef nonnull @__func__.lck_upgrade, i32 noundef 406) #4
  unreachable

9:                                                ; preds = %2, %5
  %10 = tail call i32 @osal_getpid()
  %11 = getelementptr inbounds i8, ptr %0, i64 140
  %12 = load i32, ptr %11, align 4, !tbaa !24
  %.not36 = icmp eq i32 %10, %12
  br i1 %.not36, label %13, label %.thread50, !prof !25

13:                                               ; preds = %9
  %14 = load i32, ptr @op_setlk, align 4
  %15 = load i32, ptr @op_setlkw, align 4
  %16 = select i1 %1, i32 %14, i32 %15
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = tail call i32 @lck_op(i32 noundef %18, i32 noundef %16, i32 noundef 1, i64 noundef 0, i64 noundef 1)
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %57

21:                                               ; preds = %13
  %22 = getelementptr inbounds i8, ptr %0, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !26
  %24 = and i32 %23, 4194304
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %.thread50

26:                                               ; preds = %21
  %27 = load i32, ptr %11, align 4, !tbaa !24
  %28 = icmp ugt i32 %27, 1
  br i1 %28, label %29, label %.thread

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  %31 = load i32, ptr %30, align 8, !tbaa !27
  %32 = add i32 %27, -1
  %33 = zext i32 %32 to i64
  %34 = tail call i32 @lck_op(i32 noundef %31, i32 noundef %16, i32 noundef 1, i64 noundef 0, i64 noundef %33)
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %..thread_crit_edge, label %53

..thread_crit_edge:                               ; preds = %29
  %.pre = load i32, ptr %11, align 4, !tbaa !24
  br label %.thread

.thread:                                          ; preds = %..thread_crit_edge, %26
  %36 = phi i32 [ %.pre, %..thread_crit_edge ], [ %27, %26 ]
  %37 = getelementptr inbounds i8, ptr %0, i64 24
  %38 = load i32, ptr %37, align 8, !tbaa !27
  %39 = add i32 %36, 1
  %40 = zext i32 %39 to i64
  %41 = zext i32 %36 to i64
  %42 = sub nuw nsw i64 9223372036853727231, %41
  %43 = tail call i32 @lck_op(i32 noundef %38, i32 noundef %16, i32 noundef 1, i64 noundef %40, i64 noundef %42)
  %.not37 = icmp eq i32 %43, 0
  br i1 %.not37, label %.thread50, label %44

44:                                               ; preds = %.thread
  %45 = load i32, ptr %11, align 4, !tbaa !24
  %46 = icmp ugt i32 %45, 1
  br i1 %46, label %47, label %53

47:                                               ; preds = %44
  %48 = load i32, ptr %37, align 8, !tbaa !27
  %49 = load i32, ptr @op_setlk, align 4, !tbaa !28
  %50 = add i32 %45, -1
  %51 = zext i32 %50 to i64
  %52 = tail call i32 @lck_op(i32 noundef %48, i32 noundef %49, i32 noundef 2, i64 noundef 0, i64 noundef %51)
  %.not38 = icmp eq i32 %52, 0
  %spec.select = select i1 %.not38, i32 %43, i32 -30795
  br label %53

53:                                               ; preds = %44, %29, %47
  %.0.ph = phi i32 [ %spec.select, %47 ], [ %34, %29 ], [ %43, %44 ]
  %54 = load i32, ptr %17, align 8, !tbaa !14
  %55 = load i32, ptr @op_setlk, align 4, !tbaa !28
  %56 = tail call i32 @lck_op(i32 noundef %54, i32 noundef %55, i32 noundef 0, i64 noundef 0, i64 noundef 1)
  %.not40 = icmp eq i32 %56, 0
  %spec.select45 = select i1 %.not40, i32 %.0.ph, i32 -30795
  br label %57

57:                                               ; preds = %13, %53
  %.1 = phi i32 [ %19, %13 ], [ %spec.select45, %53 ]
  %58 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !29
  %.not42 = icmp eq i8 %58, 0
  br i1 %.not42, label %60, label %59, !prof !25

59:                                               ; preds = %57
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.lck_upgrade, i32 noundef 423, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.14, i32 noundef %.1) #5
  br label %60

60:                                               ; preds = %57, %59
  %61 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %62 = and i8 %61, 1
  %.not43 = icmp ne i8 %62, 0
  %.not44 = icmp eq i32 %.1, -1
  %or.cond = and i1 %.not44, %.not43
  br i1 %or.cond, label %63, label %.thread50, !prof !30

63:                                               ; preds = %60
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.7, ptr noundef nonnull @__func__.lck_upgrade, i32 noundef 424) #4
  unreachable

.thread50:                                        ; preds = %.thread, %21, %60, %9
  %.027 = phi i32 [ -30795, %9 ], [ %.1, %60 ], [ 0, %21 ], [ 0, %.thread ]
  ret i32 %.027
}

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { noreturn "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { noreturn nounwind }
attributes #5 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !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", !"expected", i32 1, i32 2000}
!14 = !{!15, !9, i64 72}
!15 = !{!"MDBX_env", !7, i64 0, !9, i64 4, !9, i64 8, !16, i64 16, !9, i64 56, !9, i64 60, !16, i64 64, !12, i64 104, !17, i64 112, !17, i64 114, !17, i64 116, !17, i64 118, !17, i64 120, !17, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !17, i64 130, !9, i64 132, !9, i64 136, !9, i64 140, !9, i64 144, !18, i64 152, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !12, i64 216, !9, i64 224, !9, i64 228, !9, i64 232, !12, i64 240, !12, i64 248, !11, i64 256, !19, i64 264, !21, i64 320, !10, i64 360, !12, i64 368, !12, i64 376, !12, i64 384, !22, i64 392, !7, i64 400, !9, i64 440, !9, i64 444, !12, i64 448, !23, i64 456, !7, i64 496, !7, i64 536}
!16 = !{!"osal_mmap", !7, i64 0, !9, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!19 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !11, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !9, i64 28, !9, i64 32, !10, i64 36, !10, i64 37, !10, i64 38, !20, i64 40, !7, i64 48}
!20 = !{!"", !17, i64 0, !17, i64 2, !17, i64 4, !17, i64 6}
!21 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!22 = !{!"", !11, i64 0}
!23 = !{!"osal_ioring", !9, i64 0, !9, i64 4, !9, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!24 = !{!15, !9, i64 140}
!25 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!26 = !{!15, !9, i64 4}
!27 = !{!15, !9, i64 24}
!28 = !{!9, !9, i64 0}
!29 = !{!6, !7, i64 26}
!30 = !{!"branch_weights", i32 2000, i32 4002001}


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