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

; 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 }

@globals = external global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@__func__.lck_setup = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [67 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @lck_setup(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !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 %38

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 3
  %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 %36

34:                                               ; preds = %21
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %35, ptr noundef @.str, ptr noundef @__func__.lck_setup, i32 noundef 131) #5
  unreachable

36:                                               ; preds = %21
  br label %37

37:                                               ; preds = %36
  br label %38

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

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  %41 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %42 = zext i8 %41 to i32
  %43 = and i32 %42, 1
  %44 = icmp ne i32 %43, 0
  %45 = xor i1 %44, true
  %46 = xor i1 %45, true
  %47 = zext i1 %46 to i32
  %48 = sext i32 %47 to i64
  %49 = call i64 @llvm.expect.i64(i64 %48, i64 1)
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %51, label %69

51:                                               ; preds = %40
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.MDBX_env, ptr %53, i32 0, i32 6
  %55 = getelementptr inbounds %struct.osal_mmap, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 8, !tbaa !25
  %57 = icmp eq i32 %56, -1
  %58 = xor i1 %57, true
  %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 %67

65:                                               ; preds = %52
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %66, ptr noundef @.str.1, ptr noundef @__func__.lck_setup, i32 noundef 132) #5
  unreachable

67:                                               ; preds = %52
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68, %40
  br label %70

70:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.MDBX_env, ptr %72, i32 0, i32 22
  %74 = getelementptr inbounds %struct.anon.1, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !26
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.MDBX_env, ptr %76, i32 0, i32 6
  %78 = getelementptr inbounds %struct.osal_mmap, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %5, align 4, !tbaa !9
  %80 = call i32 @osal_openfile(i32 noundef 3, ptr noundef %71, ptr noundef %75, ptr noundef %78, i32 noundef %79)
  store i32 %80, ptr %6, align 4, !tbaa !9
  %81 = load i32, ptr %6, align 4, !tbaa !9
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %182

83:                                               ; preds = %70
  %84 = load i32, ptr %6, align 4, !tbaa !9
  switch i32 %84, label %132 [
    i32 13, label %85
    i32 1, label %85
    i32 2, label %93
    i32 30, label %93
  ]

85:                                               ; preds = %83, %83
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.MDBX_env, ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 4, !tbaa !27
  %89 = and i32 %88, 4325376
  %90 = icmp eq i32 %89, 4325376
  br i1 %90, label %91, label %92

91:                                               ; preds = %85
  br label %156

92:                                               ; preds = %85
  br label %93

93:                                               ; preds = %92, %83, %83
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.MDBX_env, ptr %94, i32 0, i32 1
  %96 = load i32, ptr %95, align 4, !tbaa !27
  %97 = and i32 %96, 131072
  %98 = icmp ne i32 %97, 0
  br i1 %98, label %99, label %131

99:                                               ; preds = %93
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.MDBX_env, ptr %100, i32 0, i32 3
  %102 = getelementptr inbounds %struct.osal_mmap, ptr %101, i32 0, i32 1
  %103 = load i32, ptr %102, align 8, !tbaa !15
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.MDBX_env, ptr %104, i32 0, i32 22
  %106 = getelementptr inbounds %struct.anon.1, ptr %105, i32 0, i32 0
  %107 = load ptr, ptr %106, align 8, !tbaa !26
  %108 = load i32, ptr %6, align 4, !tbaa !9
  %109 = call i32 @osal_check_fs_rdonly(i32 noundef %103, ptr noundef %107, i32 noundef %108)
  store i32 %109, ptr %7, align 4, !tbaa !9
  %110 = load i32, ptr %7, align 4, !tbaa !9
  %111 = icmp eq i32 %110, 0
  br i1 %111, label %121, label %112

112:                                              ; preds = %99
  %113 = load i32, ptr %7, align 4, !tbaa !9
  %114 = icmp eq i32 %113, 38
  br i1 %114, label %115, label %122

115:                                              ; preds = %112
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.MDBX_env, ptr %116, i32 0, i32 1
  %118 = load i32, ptr %117, align 4, !tbaa !27
  %119 = and i32 %118, 4194304
  %120 = icmp ne i32 %119, 0
  br i1 %120, label %121, label %122

121:                                              ; preds = %115, %99
  store i32 10, ptr %8, align 4
  br label %128

122:                                              ; preds = %115, %112
  %123 = load i32, ptr %7, align 4, !tbaa !9
  %124 = icmp ne i32 %123, 38
  br i1 %124, label %125, label %127

125:                                              ; preds = %122
  %126 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %126, ptr %6, align 4, !tbaa !9
  br label %127

127:                                              ; preds = %125, %122
  store i32 0, ptr %8, align 4
  br label %128

128:                                              ; preds = %127, %121
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  %129 = load i32, ptr %8, align 4
  switch i32 %129, label %188 [
    i32 0, label %130
    i32 10, label %156
  ]

130:                                              ; preds = %128
  br label %131

131:                                              ; preds = %130, %93
  br label %132

132:                                              ; preds = %131, %83
  br label %133

133:                                              ; preds = %132
  %134 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !28
  %135 = zext i8 %134 to i32
  %136 = icmp sle i32 1, %135
  %137 = xor i1 %136, true
  %138 = xor i1 %137, true
  %139 = zext i1 %138 to i32
  %140 = sext i32 %139 to i64
  %141 = call i64 @llvm.expect.i64(i64 %140, i64 0)
  %142 = icmp ne i64 %141, 0
  br i1 %142, label %143, label %152

143:                                              ; preds = %133
  %144 = load ptr, ptr %4, align 8, !tbaa !5
  %145 = getelementptr inbounds %struct.MDBX_env, ptr %144, i32 0, i32 22
  %146 = getelementptr inbounds %struct.anon.1, ptr %145, i32 0, i32 0
  %147 = load ptr, ptr %146, align 8, !tbaa !26
  %148 = load ptr, ptr %4, align 8, !tbaa !5
  %149 = getelementptr inbounds %struct.MDBX_env, ptr %148, i32 0, i32 1
  %150 = load i32, ptr %149, align 4, !tbaa !27
  %151 = load i32, ptr %6, align 4, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.lck_setup, i32 noundef 156, ptr noundef @.str.2, ptr noundef %147, i32 noundef %150, i32 noundef %151)
  br label %152

152:                                              ; preds = %143, %133
  br label %153

153:                                              ; preds = %152
  br label %154

154:                                              ; preds = %153
  %155 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %155, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %186

156:                                              ; preds = %128, %91
  %157 = load ptr, ptr %4, align 8, !tbaa !5
  %158 = getelementptr inbounds %struct.MDBX_env, ptr %157, i32 0, i32 6
  %159 = getelementptr inbounds %struct.osal_mmap, ptr %158, i32 0, i32 1
  store i32 -1, ptr %159, align 8, !tbaa !25
  br label %160

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

170:                                              ; preds = %160
  %171 = load ptr, ptr %4, align 8, !tbaa !5
  %172 = getelementptr inbounds %struct.MDBX_env, ptr %171, i32 0, i32 22
  %173 = getelementptr inbounds %struct.anon.1, ptr %172, i32 0, i32 1
  %174 = load ptr, ptr %173, align 8, !tbaa !29
  %175 = load ptr, ptr %4, align 8, !tbaa !5
  %176 = getelementptr inbounds %struct.MDBX_env, ptr %175, i32 0, i32 1
  %177 = load i32, ptr %176, align 4, !tbaa !27
  %178 = load i32, ptr %6, align 4, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 3, ptr noundef @__func__.lck_setup, i32 noundef 163, ptr noundef @.str.3, ptr noundef %174, i32 noundef %177, i32 noundef %178)
  br label %179

179:                                              ; preds = %170, %160
  br label %180

180:                                              ; preds = %179
  br label %181

181:                                              ; preds = %180
  br label %182

182:                                              ; preds = %181, %70
  call void @rthc_lock()
  %183 = load ptr, ptr %4, align 8, !tbaa !5
  %184 = call i32 @lck_setup_locked(ptr noundef %183) #7
  store i32 %184, ptr %6, align 4, !tbaa !9
  call void @rthc_unlock()
  %185 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %185, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %186

186:                                              ; preds = %182, %154
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %187 = load i32, ptr %3, align 4
  ret i32 %187

188:                                              ; preds = %128
  unreachable
}

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

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

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

declare i32 @osal_openfile(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #4

declare i32 @osal_check_fs_rdonly(i32 noundef, ptr noundef, i32 noundef) #4

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

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

declare void @rthc_lock() #4

; Function Attrs: cold nounwind optsize uwtable
declare hidden i32 @lck_setup_locked(ptr noundef) #0

declare void @rthc_unlock() #4

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

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 25}
!12 = !{!"libmdbx_globals", !7, i64 0, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !13, i64 27, !10, i64 28, !7, i64 32, !7, i64 40, !14, i64 80, !6, i64 88}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !10, i64 24}
!16 = !{!"MDBX_env", !7, i64 0, !10, i64 4, !10, i64 8, !17, i64 16, !10, i64 56, !10, 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, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !19, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !10, i64 224, !10, i64 228, !10, i64 232, !6, i64 240, !6, i64 248, !14, i64 256, !20, i64 264, !22, i64 320, !13, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !23, i64 392, !7, i64 400, !10, i64 440, !10, i64 444, !6, i64 448, !24, i64 456, !7, i64 496, !7, i64 536}
!17 = !{!"osal_mmap", !7, i64 0, !10, 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 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !14, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !10, i64 28, !10, i64 32, !13, i64 36, !13, i64 37, !13, 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", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!25 = !{!16, !10, i64 72}
!26 = !{!16, !6, i64 152}
!27 = !{!16, !10, i64 4}
!28 = !{!12, !7, i64 26}
!29 = !{!16, !6, i64 160}


; 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 }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [25 x i8], align 1
@__func__.lck_setup = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [67 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @lck_setup(ptr noundef %0, i32 noundef %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 %.thread, label %5, !prof !13

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %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 nonnull %0, ptr noundef nonnull @.str, ptr noundef nonnull @__func__.lck_setup, i32 noundef 131) #3
  unreachable

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  %11 = load i32, ptr %10, align 8, !tbaa !24
  %.not37 = icmp eq i32 %11, -1
  br i1 %.not37, label %.thread, label %12, !prof !25

12:                                               ; preds = %9
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.lck_setup, i32 noundef 132) #3
  unreachable

.thread:                                          ; preds = %2, %9
  %13 = getelementptr inbounds i8, ptr %0, i64 152
  %14 = load ptr, ptr %13, align 8, !tbaa !26
  %15 = getelementptr inbounds i8, ptr %0, i64 72
  %16 = tail call i32 @osal_openfile(i32 noundef 3, ptr noundef %0, ptr noundef %14, ptr noundef nonnull %15, i32 noundef %1) #4
  switch i32 %16, label %.thread43 [
    i32 0, label %47
    i32 13, label %17
    i32 1, label %17
    i32 2, label %22
    i32 30, label %22
  ]

17:                                               ; preds = %.thread, %.thread
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !27
  %20 = and i32 %19, 4325376
  %21 = icmp eq i32 %20, 4325376
  br i1 %21, label %39, label %22

22:                                               ; preds = %.thread, %.thread, %17
  %23 = getelementptr inbounds i8, ptr %0, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !27
  %25 = and i32 %24, 131072
  %.not39 = icmp eq i32 %25, 0
  br i1 %.not39, label %.thread43, label %26

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = load ptr, ptr %13, align 8, !tbaa !26
  %30 = tail call i32 @osal_check_fs_rdonly(i32 noundef %28, ptr noundef %29, i32 noundef %16) #4
  switch i32 %30, label %.thread43 [
    i32 0, label %39
    i32 38, label %31
  ]

31:                                               ; preds = %26
  %32 = load i32, ptr %23, align 4, !tbaa !27
  %33 = and i32 %32, 4194304
  %.not40 = icmp eq i32 %33, 0
  br i1 %.not40, label %.thread43, label %39

.thread43:                                        ; preds = %26, %31, %.thread, %22
  %.2 = phi i32 [ %16, %22 ], [ %16, %.thread ], [ %16, %31 ], [ %30, %26 ]
  %34 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !28
  %.not42 = icmp eq i8 %34, 0
  br i1 %.not42, label %49, label %35, !prof !25

35:                                               ; preds = %.thread43
  %36 = load ptr, ptr %13, align 8, !tbaa !26
  %37 = getelementptr inbounds i8, ptr %0, i64 4
  %38 = load i32, ptr %37, align 4, !tbaa !27
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.lck_setup, i32 noundef 156, ptr noundef nonnull @.str.2, ptr noundef %36, i32 noundef %38, i32 noundef %.2) #4
  br label %49

39:                                               ; preds = %31, %26, %17
  store i32 -1, ptr %15, align 8, !tbaa !24
  %40 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !28
  %41 = icmp ugt i8 %40, 2
  br i1 %41, label %42, label %47, !prof !13

42:                                               ; preds = %39
  %43 = getelementptr inbounds i8, ptr %0, i64 160
  %44 = load ptr, ptr %43, align 8, !tbaa !29
  %45 = getelementptr inbounds i8, ptr %0, i64 4
  %46 = load i32, ptr %45, align 4, !tbaa !27
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 3, ptr noundef nonnull @__func__.lck_setup, i32 noundef 163, ptr noundef nonnull @.str.3, ptr noundef %44, i32 noundef %46, i32 noundef %16) #4
  br label %47

47:                                               ; preds = %.thread, %39, %42
  tail call void @rthc_lock() #4
  %48 = tail call i32 @lck_setup_locked(ptr noundef nonnull %0) #5
  tail call void @rthc_unlock() #4
  br label %49

49:                                               ; preds = %.thread43, %35, %47
  %.031 = phi i32 [ %48, %47 ], [ %.2, %35 ], [ %.2, %.thread43 ]
  ret i32 %.031
}

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

declare i32 @osal_openfile(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @osal_check_fs_rdonly(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

declare void @rthc_lock() local_unnamed_addr #2

; Function Attrs: cold nounwind optsize uwtable
declare hidden i32 @lck_setup_locked(ptr noundef) local_unnamed_addr #0

declare void @rthc_unlock() local_unnamed_addr #2

attributes #0 = { cold nounwind optsize uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { 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 = { "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 = { noreturn nounwind }
attributes #4 = { nounwind }
attributes #5 = { cold }

!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 24}
!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 72}
!25 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!26 = !{!15, !12, i64 152}
!27 = !{!15, !9, i64 4}
!28 = !{!6, !7, i64 26}
!29 = !{!15, !12, i64 160}


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