; LLVM IR from erthink/libmdbx :: src (api-env)

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

%struct.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.meta = type { [2 x i32], %union.anon.11, i16, i8, i8, %struct.geo, %union.anon.14, %struct.MDBX_canary, %union.anon.17, [2 x %union.mdbx_atomic_uint32_t], [2 x i32], %union.bin128, %union.bin128 }
%union.anon.11 = type { i64 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.12, %union.anon.13 }
%union.anon.12 = type { i32 }
%union.anon.13 = type { i32 }
%union.anon.14 = type { %struct.anon.15 }
%struct.anon.15 = type { %struct.tree, %struct.tree }
%struct.tree = type { i16, i16, i32, i32, i32, i32, i32, i64, i64, i64 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.17 = type { i64 }
%union.mdbx_atomic_uint32_t = type { i32 }
%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 }
%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
@__func__.mdbx_env_turn_for_recovery = external hidden unnamed_addr constant [27 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @log_if_error(i32 noundef, ptr noundef, i32 noundef) #1

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

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

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_env_turn_for_recovery(ptr noundef %0, i32 noundef %1) #4 {
  %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 ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca %struct.meta, align 4
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp uge i32 %15, 3
  %17 = xor i1 %16, true
  %18 = xor i1 %17, true
  %19 = zext i1 %18 to i32
  %20 = sext i32 %19 to i64
  %21 = call i64 @llvm.expect.i64(i64 %20, i64 0)
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %2
  %24 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_env_turn_for_recovery, i32 noundef 270)
  store i32 %24, ptr %3, align 4
  br label %159

25:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call i32 @check_env(ptr noundef %26, i1 noundef zeroext true)
  store i32 %27, ptr %6, align 4, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  %30 = xor i1 %29, true
  %31 = xor i1 %30, true
  %32 = zext i1 %31 to i32
  %33 = sext i32 %32 to i64
  %34 = call i64 @llvm.expect.i64(i64 %33, i64 0)
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %25
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = call i32 @log_if_error(i32 noundef %37, ptr noundef @__func__.mdbx_env_turn_for_recovery, i32 noundef 273)
  store i32 %38, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %158

39:                                               ; preds = %25
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.MDBX_env, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = and i32 %42, 4325376
  %44 = icmp ne i32 %43, 4194304
  %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 0)
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %39
  %52 = call i32 @log_if_error(i32 noundef 1, ptr noundef @__func__.mdbx_env_turn_for_recovery, i32 noundef 276)
  store i32 %52, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %158

53:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #8
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = call ptr @pgno2page(ptr noundef %54, i64 noundef %56) #9
  %58 = call ptr @page_meta(ptr noundef %57) #9
  store ptr %58, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #8
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = call i64 @constmeta_txnid(ptr noundef %59) #9
  store i64 %60, ptr %9, align 8, !tbaa !23
  %61 = load i64, ptr %9, align 8, !tbaa !23
  %62 = icmp ult i64 %61, 1
  br i1 %62, label %63, label %64

63:                                               ; preds = %53
  store i64 1, ptr %9, align 8, !tbaa !23
  br label %64

64:                                               ; preds = %63, %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #8
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %119, %64
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = icmp ult i32 %66, 3
  br i1 %67, label %69, label %68

68:                                               ; preds = %65
  store i32 2, ptr %7, align 4
  br label %122

69:                                               ; preds = %65
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = load i32, ptr %5, align 4, !tbaa !9
  %72 = icmp eq i32 %70, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %69
  br label %119

74:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #8
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = zext i32 %76 to i64
  %78 = call ptr @pgno2page(ptr noundef %75, i64 noundef %77) #9
  store ptr %78, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 224, ptr %12) #8
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = call ptr @page_meta(ptr noundef %79) #9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %80, i64 224, i1 false), !tbaa.struct !24
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  %83 = load i32, ptr %10, align 4, !tbaa !9
  %84 = call i32 @meta_validate(ptr noundef %81, ptr noundef %12, ptr noundef %82, i32 noundef %83, ptr noundef null)
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %106

86:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #8
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = load i32, ptr %10, align 4, !tbaa !9
  %89 = zext i32 %88 to i64
  %90 = call i32 @meta_override(ptr noundef %87, i64 noundef %89, i64 noundef 0, ptr noundef null)
  store i32 %90, ptr %13, align 4, !tbaa !9
  %91 = load i32, ptr %13, align 4, !tbaa !9
  %92 = icmp ne i32 %91, 0
  %93 = xor i1 %92, true
  %94 = xor i1 %93, true
  %95 = zext i1 %94 to i32
  %96 = sext i32 %95 to i64
  %97 = call i64 @llvm.expect.i64(i64 %96, i64 0)
  %98 = icmp ne i64 %97, 0
  br i1 %98, label %99, label %102

99:                                               ; preds = %86
  %100 = load i32, ptr %13, align 4, !tbaa !9
  %101 = call i32 @log_if_error(i32 noundef %100, ptr noundef @__func__.mdbx_env_turn_for_recovery, i32 noundef 290)
  store i32 %101, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %103

102:                                              ; preds = %86
  store i32 0, ptr %7, align 4
  br label %103

103:                                              ; preds = %102, %99
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  %104 = load i32, ptr %7, align 4
  switch i32 %104, label %116 [
    i32 0, label %105
  ]

105:                                              ; preds = %103
  br label %115

106:                                              ; preds = %74
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #8
  %107 = call i64 @constmeta_txnid(ptr noundef %12) #9
  store i64 %107, ptr %14, align 8, !tbaa !23
  %108 = load i64, ptr %9, align 8, !tbaa !23
  %109 = load i64, ptr %14, align 8, !tbaa !23
  %110 = icmp ule i64 %108, %109
  br i1 %110, label %111, label %114

111:                                              ; preds = %106
  %112 = load i64, ptr %14, align 8, !tbaa !23
  %113 = call i64 @safe64_txnid_next(i64 noundef %112)
  store i64 %113, ptr %9, align 8, !tbaa !23
  br label %114

114:                                              ; preds = %111, %106
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #8
  br label %115

115:                                              ; preds = %114, %105
  store i32 0, ptr %7, align 4
  br label %116

116:                                              ; preds = %115, %103
  call void @llvm.lifetime.end.p0(i64 224, ptr %12) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #8
  %117 = load i32, ptr %7, align 4
  switch i32 %117, label %122 [
    i32 0, label %118
  ]

118:                                              ; preds = %116
  br label %119

119:                                              ; preds = %118, %73
  %120 = load i32, ptr %10, align 4, !tbaa !9
  %121 = add i32 %120, 1
  store i32 %121, ptr %10, align 4, !tbaa !9
  br label %65, !llvm.loop !27

122:                                              ; preds = %116, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #8
  %123 = load i32, ptr %7, align 4
  switch i32 %123, label %157 [
    i32 2, label %124
  ]

124:                                              ; preds = %122
  %125 = load i64, ptr %9, align 8, !tbaa !23
  %126 = icmp ugt i64 %125, -4294967297
  %127 = xor i1 %126, true
  %128 = xor i1 %127, true
  %129 = zext i1 %128 to i32
  %130 = sext i32 %129 to i64
  %131 = call i64 @llvm.expect.i64(i64 %130, i64 0)
  %132 = icmp ne i64 %131, 0
  br i1 %132, label %133, label %149

133:                                              ; preds = %124
  br label %134

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

144:                                              ; preds = %134
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.mdbx_env_turn_for_recovery, i32 noundef 299, ptr noundef @.str.2, i32 noundef -30788)
  br label %145

145:                                              ; preds = %144, %134
  br label %146

146:                                              ; preds = %145
  br label %147

147:                                              ; preds = %146
  %148 = call i32 @log_if_error(i32 noundef -30788, ptr noundef @__func__.mdbx_env_turn_for_recovery, i32 noundef 300)
  store i32 %148, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %157

149:                                              ; preds = %124
  %150 = load ptr, ptr %4, align 8, !tbaa !5
  %151 = load i32, ptr %5, align 4, !tbaa !9
  %152 = zext i32 %151 to i64
  %153 = load i64, ptr %9, align 8, !tbaa !23
  %154 = load ptr, ptr %8, align 8, !tbaa !5
  %155 = call i32 @meta_override(ptr noundef %150, i64 noundef %152, i64 noundef %153, ptr noundef %154)
  %156 = call i32 @log_if_error(i32 noundef %155, ptr noundef @__func__.mdbx_env_turn_for_recovery, i32 noundef 302)
  store i32 %156, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %157

157:                                              ; preds = %149, %147, %122
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #8
  br label %158

158:                                              ; preds = %157, %51, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  br label %159

159:                                              ; preds = %158, %23
  %160 = load i32, ptr %3, align 4
  ret i32 %160
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_env(ptr noundef, i1 noundef zeroext) #1

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden ptr @page_meta(ptr noundef) #5

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden ptr @pgno2page(ptr noundef, i64 noundef) #5

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden i64 @constmeta_txnid(ptr noundef) #5

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #6

declare i32 @meta_validate(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare i32 @meta_override(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @safe64_txnid_next(i64 noundef) #7

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

!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, !10, i64 4}
!12 = !{!"MDBX_env", !7, i64 0, !10, i64 4, !10, i64 8, !13, i64 16, !10, i64 56, !10, i64 60, !13, i64 64, !6, i64 104, !15, i64 112, !15, i64 114, !15, i64 116, !15, i64 118, !15, i64 120, !15, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !15, i64 130, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !16, 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, !17, i64 264, !20, i64 320, !18, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !21, i64 392, !7, i64 400, !10, i64 440, !10, i64 444, !6, i64 448, !22, i64 456, !7, i64 496, !7, i64 536}
!13 = !{!"osal_mmap", !7, i64 0, !10, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!"", !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, !18, i64 36, !18, i64 37, !18, i64 38, !19, i64 40, !7, i64 48}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!"", !15, i64 0, !15, i64 2, !15, i64 4, !15, i64 6}
!20 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!21 = !{!"", !14, i64 0}
!22 = !{!"osal_ioring", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!23 = !{!14, !14, i64 0}
!24 = !{i64 0, i64 8, !25, i64 8, i64 8, !25, i64 16, i64 2, !26, i64 18, i64 1, !25, i64 19, i64 1, !25, i64 20, i64 2, !26, i64 22, i64 2, !26, i64 24, i64 4, !9, i64 28, i64 4, !9, i64 32, i64 4, !25, i64 36, i64 4, !25, i64 40, i64 96, !25, i64 136, i64 8, !23, i64 144, i64 8, !23, i64 152, i64 8, !23, i64 160, i64 8, !23, i64 168, i64 8, !25, i64 176, i64 8, !25, i64 184, i64 8, !25, i64 192, i64 16, !25, i64 208, i64 16, !25}
!25 = !{!7, !7, i64 0}
!26 = !{!15, !15, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{!30, !7, i64 26}
!30 = !{!"libmdbx_globals", !7, i64 0, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !18, i64 27, !10, i64 28, !7, i64 32, !7, i64 40, !14, i64 80, !6, i64 88}


; 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 }
%struct.meta = type { [2 x i32], %union.anon.11, i16, i8, i8, %struct.geo, %union.anon.14, %struct.MDBX_canary, %union.anon.17, [2 x %union.mdbx_atomic_uint32_t], [2 x i32], %union.bin128, %union.bin128 }
%union.anon.11 = type { i64 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.12, %union.anon.13 }
%union.anon.12 = type { i32 }
%union.anon.13 = type { i32 }
%union.anon.14 = type { %struct.anon.15 }
%struct.anon.15 = type { %struct.tree, %struct.tree }
%struct.tree = type { i16, i16, i32, i32, i32, i32, i32, i64, i64, i64 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.17 = type { i64 }
%union.mdbx_atomic_uint32_t = type { i32 }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@__func__.mdbx_env_turn_for_recovery = external hidden unnamed_addr constant [27 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @log_if_error(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_env_turn_for_recovery(ptr noundef %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.meta, align 4
  %4 = icmp ugt i32 %1, 2
  br i1 %4, label %5, label %7, !prof !5

5:                                                ; preds = %2
  %6 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_env_turn_for_recovery, i32 noundef 270)
  br label %48

7:                                                ; preds = %2
  %8 = tail call i32 @check_env(ptr noundef %0, i1 noundef zeroext true)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %11, label %9, !prof !6

9:                                                ; preds = %7
  %10 = tail call i32 @log_if_error(i32 noundef %8, ptr noundef nonnull @__func__.mdbx_env_turn_for_recovery, i32 noundef 273)
  br label %48

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !7
  %14 = and i32 %13, 4325376
  %.not50 = icmp eq i32 %14, 4194304
  br i1 %.not50, label %17, label %15, !prof !6

15:                                               ; preds = %11
  %16 = tail call i32 @log_if_error(i32 noundef 1, ptr noundef nonnull @__func__.mdbx_env_turn_for_recovery, i32 noundef 276)
  br label %48

17:                                               ; preds = %11
  %18 = zext nneg i32 %1 to i64
  %19 = tail call ptr @pgno2page(ptr noundef nonnull %0, i64 noundef %18) #8
  %20 = tail call ptr @page_meta(ptr noundef %19) #8
  %21 = tail call i64 @constmeta_txnid(ptr noundef %20) #8
  %spec.store.select = tail call i64 @llvm.umax.i64(i64 %21, i64 1)
  br label %22

22:                                               ; preds = %17, %35
  %indvars.iv = phi i64 [ 0, %17 ], [ %indvars.iv.next, %35 ]
  %.03964 = phi i64 [ %spec.store.select, %17 ], [ %.443, %35 ]
  %23 = icmp eq i64 %indvars.iv, %18
  br i1 %23, label %35, label %24

24:                                               ; preds = %22
  %25 = call ptr @pgno2page(ptr noundef %0, i64 noundef %indvars.iv) #8
  call void @llvm.lifetime.start.p0(i64 224, ptr nonnull %3) #9
  %26 = call ptr @page_meta(ptr noundef %25) #8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(224) %3, ptr noundef nonnull align 4 dereferenceable(224) %26, i64 224, i1 false), !tbaa.struct !23
  %27 = trunc nuw nsw i64 %indvars.iv to i32
  %28 = call i32 @meta_validate(ptr noundef %0, ptr noundef nonnull %3, ptr noundef %25, i32 noundef %27, ptr noundef null) #9
  %.not51 = icmp eq i32 %28, 0
  br i1 %.not51, label %31, label %29

29:                                               ; preds = %24
  %30 = call i32 @meta_override(ptr noundef %0, i64 noundef %indvars.iv, i64 noundef 0, ptr noundef null) #9
  %.not53 = icmp eq i32 %30, 0
  br i1 %.not53, label %.thread, label %36, !prof !6

31:                                               ; preds = %24
  %32 = call i64 @constmeta_txnid(ptr noundef nonnull %3) #8
  %.not52 = icmp ugt i64 %.03964, %32
  br i1 %.not52, label %.thread, label %33

33:                                               ; preds = %31
  %34 = call i64 @safe64_txnid_next(i64 noundef %32)
  br label %.thread

.thread:                                          ; preds = %31, %33, %29
  %.342.ph = phi i64 [ %.03964, %29 ], [ %.03964, %31 ], [ %34, %33 ]
  call void @llvm.lifetime.end.p0(i64 224, ptr nonnull %3) #9
  br label %35

35:                                               ; preds = %.thread, %22
  %.443 = phi i64 [ %.03964, %22 ], [ %.342.ph, %.thread ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv.next, 3
  br i1 %exitcond, label %38, label %22, !llvm.loop !28

36:                                               ; preds = %29
  %37 = call i32 @log_if_error(i32 noundef %30, ptr noundef nonnull @__func__.mdbx_env_turn_for_recovery, i32 noundef 290)
  call void @llvm.lifetime.end.p0(i64 224, ptr nonnull %3) #9
  br label %48

38:                                               ; preds = %35
  %39 = icmp ugt i64 %.443, -4294967297
  br i1 %39, label %40, label %45, !prof !5

40:                                               ; preds = %38
  %41 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !30
  %.not54 = icmp eq i8 %41, 0
  br i1 %.not54, label %43, label %42, !prof !6

42:                                               ; preds = %40
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.mdbx_env_turn_for_recovery, i32 noundef 299, ptr noundef nonnull @.str.2, i32 noundef -30788) #9
  br label %43

43:                                               ; preds = %42, %40
  %44 = call i32 @log_if_error(i32 noundef -30788, ptr noundef nonnull @__func__.mdbx_env_turn_for_recovery, i32 noundef 300)
  br label %48

45:                                               ; preds = %38
  %46 = call i32 @meta_override(ptr noundef %0, i64 noundef %18, i64 noundef %.443, ptr noundef %20) #9
  %47 = call i32 @log_if_error(i32 noundef %46, ptr noundef nonnull @__func__.mdbx_env_turn_for_recovery, i32 noundef 302)
  br label %48

48:                                               ; preds = %36, %9, %15, %45, %43, %5
  %.8 = phi i32 [ %6, %5 ], [ %10, %9 ], [ %16, %15 ], [ %44, %43 ], [ %47, %45 ], [ %37, %36 ]
  ret i32 %.8
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_env(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden ptr @page_meta(ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden ptr @pgno2page(ptr noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden i64 @constmeta_txnid(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

declare i32 @meta_validate(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @meta_override(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @safe64_txnid_next(i64 noundef) local_unnamed_addr #6

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

attributes #0 = { 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 #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { alwaysinline 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 #7 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { 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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!7 = !{!8, !11, i64 4}
!8 = !{!"MDBX_env", !9, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !11, i64 56, !11, i64 60, !12, i64 64, !14, i64 104, !15, i64 112, !15, i64 114, !15, i64 116, !15, i64 118, !15, i64 120, !15, i64 122, !9, i64 124, !9, i64 128, !9, i64 129, !15, i64 130, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !16, i64 152, !14, i64 184, !14, i64 192, !14, i64 200, !14, i64 208, !14, i64 216, !11, i64 224, !11, i64 228, !11, i64 232, !14, i64 240, !14, i64 248, !13, i64 256, !17, i64 264, !20, i64 320, !18, i64 360, !14, i64 368, !14, i64 376, !14, i64 384, !21, i64 392, !9, i64 400, !11, i64 440, !11, i64 444, !14, i64 448, !22, i64 456, !9, i64 496, !9, i64 536}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"osal_mmap", !9, i64 0, !11, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!13 = !{!"long", !9, i64 0}
!14 = !{!"any pointer", !9, i64 0}
!15 = !{!"short", !9, i64 0}
!16 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!17 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !13, i64 16, !9, i64 24, !9, i64 25, !9, i64 26, !9, i64 27, !11, i64 28, !11, i64 32, !18, i64 36, !18, i64 37, !18, i64 38, !19, i64 40, !9, i64 48}
!18 = !{!"_Bool", !9, i64 0}
!19 = !{!"", !15, i64 0, !15, i64 2, !15, i64 4, !15, i64 6}
!20 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!21 = !{!"", !13, i64 0}
!22 = !{!"osal_ioring", !11, i64 0, !11, i64 4, !11, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!23 = !{i64 0, i64 8, !24, i64 8, i64 8, !24, i64 16, i64 2, !25, i64 18, i64 1, !24, i64 19, i64 1, !24, i64 20, i64 2, !25, i64 22, i64 2, !25, i64 24, i64 4, !26, i64 28, i64 4, !26, i64 32, i64 4, !24, i64 36, i64 4, !24, i64 40, i64 96, !24, i64 136, i64 8, !27, i64 144, i64 8, !27, i64 152, i64 8, !27, i64 160, i64 8, !27, i64 168, i64 8, !24, i64 176, i64 8, !24, i64 184, i64 8, !24, i64 192, i64 16, !24, i64 208, i64 16, !24}
!24 = !{!9, !9, i64 0}
!25 = !{!15, !15, i64 0}
!26 = !{!11, !11, i64 0}
!27 = !{!13, !13, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = !{!31, !9, i64 26}
!31 = !{!"libmdbx_globals", !9, i64 0, !11, i64 16, !11, i64 20, !9, i64 24, !9, i64 25, !9, i64 26, !18, i64 27, !11, i64 28, !9, i64 32, !9, i64 40, !13, i64 80, !14, i64 88}


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