; LLVM IR from erthink/libmdbx :: src (page-ops)

; 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_txn = type { i32, i32, i64, i64, ptr, ptr, %struct.geo, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, %struct.MDBX_canary, ptr, %union.anon.4 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.2, %union.anon.3 }
%union.anon.2 = type { i32 }
%union.anon.3 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.4 = type { %struct.anon.6 }
%struct.anon.6 = type { %struct.troika, ptr, %struct.anon.7, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.8 }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.anon.7 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.8 = type { %struct.anon.9 }
%struct.anon.9 = type { i64, 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.13, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.14, %struct.anon.18, i8, ptr, ptr, ptr, %struct.anon.19, %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.12, i32, i64, i64, i64 }
%union.anon.12 = type { ptr }
%union.mdbx_atomic_uint32_t = type { i32 }
%struct.anon.13 = type { ptr, ptr, ptr, ptr }
%struct.anon.14 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.15, %union.anon.16 }
%struct.anon.15 = type { i16, i16, i16, i16 }
%union.anon.16 = type { i32 }
%struct.anon.18 = type { i64, i64, i64, i64, i64 }
%struct.anon.19 = type { i64 }
%struct.osal_ioring = type { i32, i32, i32, ptr, ptr, ptr }
%union.mdbx_atomic_uint64_t = type { i64 }
%struct.page = type <{ i64, i16, i16, %union.anon.10, i32, [0 x i16] }>
%union.anon.10 = type { i32 }

@globals = external global %struct.libmdbx_globals, align 8
@.str.28 = external hidden unnamed_addr constant [28 x i8], align 1
@__func__.page_shadow_alloc = external hidden unnamed_addr constant [18 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [39 x i8], align 1

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

; Function Attrs: noreturn
declare void @mdbx_assert_fail(ptr noundef, ptr 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @page_shadow_alloc(ptr noundef %0, i64 noundef %1) #5 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #8
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.MDBX_txn, ptr %12, i32 0, i32 9
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  store ptr %14, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #8
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.MDBX_env, ptr %15, i32 0, i32 44
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  store ptr %17, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #8
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.MDBX_env, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !27
  %21 = zext i32 %20 to i64
  store i64 %21, ptr %8, align 8, !tbaa !9
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = icmp eq i64 %22, 1
  br i1 %23, label %24, label %27

24:                                               ; preds = %2
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br label %27

27:                                               ; preds = %24, %2
  %28 = phi i1 [ false, %2 ], [ %26, %24 ]
  %29 = xor i1 %28, true
  %30 = xor i1 %29, true
  %31 = zext i1 %30 to i32
  %32 = sext i32 %31 to i64
  %33 = call i64 @llvm.expect.i64(i64 %32, i64 1)
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %102

35:                                               ; preds = %27
  br label %36

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

47:                                               ; preds = %36
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.MDBX_env, ptr %49, i32 0, i32 43
  %51 = load i32, ptr %50, align 4, !tbaa !30
  %52 = icmp ugt i32 %51, 0
  %53 = xor i1 %52, true
  %54 = xor i1 %53, true
  %55 = xor i1 %54, true
  %56 = zext i1 %55 to i32
  %57 = sext i32 %56 to i64
  %58 = call i64 @llvm.expect.i64(i64 %57, i64 0)
  %59 = icmp ne i64 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %48
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %61, ptr noundef @.str.28, ptr noundef @__func__.page_shadow_alloc, i32 noundef 284) #9
  unreachable

62:                                               ; preds = %48
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64, %36
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  br label %69

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

79:                                               ; preds = %69
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load i64, ptr %8, align 8, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef @__func__.page_shadow_alloc, i32 noundef 285, ptr noundef @.str.29, ptr noundef %80, i64 noundef %81, i32 noundef 285)
  br label %82

82:                                               ; preds = %79, %69
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load i64, ptr %8, align 8, !tbaa !9
  br label %87

87:                                               ; preds = %84
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.page, ptr %89, i32 0, i32 5
  %91 = getelementptr inbounds [0 x i16], ptr %90, i64 0, i64 0
  %92 = ptrtoint ptr %91 to i64
  %93 = add nsw i64 %92, 4
  %94 = inttoptr i64 %93 to ptr
  %95 = load ptr, ptr %94, align 8, !tbaa !5
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.MDBX_env, ptr %96, i32 0, i32 44
  store ptr %95, ptr %97, align 8, !tbaa !17
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.MDBX_env, ptr %98, i32 0, i32 43
  %100 = load i32, ptr %99, align 4, !tbaa !30
  %101 = sub i32 %100, 1
  store i32 %101, ptr %99, align 4, !tbaa !30
  br label %131

102:                                              ; preds = %27
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = load i64, ptr %5, align 8, !tbaa !9
  %105 = call i64 @pgno2bytes(ptr noundef %103, i64 noundef %104) #10
  store i64 %105, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #8
  %106 = load i64, ptr %8, align 8, !tbaa !9
  %107 = add i64 %106, 8
  %108 = call noalias ptr @malloc(i64 noundef %107) #11
  store ptr %108, ptr %9, align 8, !tbaa !5
  %109 = load ptr, ptr %9, align 8, !tbaa !5
  %110 = icmp ne ptr %109, null
  %111 = xor i1 %110, true
  %112 = xor i1 %111, true
  %113 = xor i1 %112, true
  %114 = zext i1 %113 to i32
  %115 = sext i32 %114 to i64
  %116 = call i64 @llvm.expect.i64(i64 %115, i64 0)
  %117 = icmp ne i64 %116, 0
  br i1 %117, label %118, label %123

118:                                              ; preds = %102
  %119 = load ptr, ptr %4, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.MDBX_txn, ptr %119, i32 0, i32 1
  %121 = load i32, ptr %120, align 4, !tbaa !32
  %122 = or i32 %121, 2
  store i32 %122, ptr %120, align 4, !tbaa !32
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %128

123:                                              ; preds = %102
  %124 = load ptr, ptr %9, align 8, !tbaa !5
  %125 = ptrtoint ptr %124 to i64
  %126 = add nsw i64 %125, 8
  %127 = inttoptr i64 %126 to ptr
  store ptr %127, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %10, align 4
  br label %128

128:                                              ; preds = %123, %118
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  %129 = load i32, ptr %10, align 4
  switch i32 %129, label %166 [
    i32 0, label %130
  ]

130:                                              ; preds = %128
  br label %131

131:                                              ; preds = %130, %88
  %132 = load ptr, ptr %6, align 8, !tbaa !5
  %133 = getelementptr inbounds %struct.MDBX_env, ptr %132, i32 0, i32 1
  %134 = load i32, ptr %133, align 4, !tbaa !33
  %135 = and i32 %134, 16777216
  %136 = icmp eq i32 %135, 0
  br i1 %136, label %137, label %156

137:                                              ; preds = %131
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #8
  store i64 20, ptr %11, align 8, !tbaa !9
  %138 = load i64, ptr %5, align 8, !tbaa !9
  %139 = icmp ugt i64 %138, 1
  br i1 %139, label %140, label %147

140:                                              ; preds = %137
  %141 = load ptr, ptr %6, align 8, !tbaa !5
  %142 = load i64, ptr %5, align 8, !tbaa !9
  %143 = sub i64 %142, 1
  %144 = call i64 @pgno2bytes(ptr noundef %141, i64 noundef %143) #10
  %145 = load i64, ptr %11, align 8, !tbaa !9
  %146 = add i64 %145, %144
  store i64 %146, ptr %11, align 8, !tbaa !9
  br label %147

147:                                              ; preds = %140, %137
  %148 = load ptr, ptr %7, align 8, !tbaa !5
  %149 = ptrtoint ptr %148 to i64
  %150 = load i64, ptr %11, align 8, !tbaa !9
  %151 = add nsw i64 %149, %150
  %152 = inttoptr i64 %151 to ptr
  %153 = load i64, ptr %8, align 8, !tbaa !9
  %154 = load i64, ptr %11, align 8, !tbaa !9
  %155 = sub i64 %153, %154
  call void @llvm.memset.p0.i64(ptr align 1 %152, i8 0, i64 %155, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #8
  br label %156

156:                                              ; preds = %147, %131
  %157 = load ptr, ptr %7, align 8, !tbaa !5
  %158 = getelementptr inbounds %struct.page, ptr %157, i32 0, i32 4
  store i32 0, ptr %158, align 1, !tbaa !34
  %159 = load ptr, ptr %7, align 8, !tbaa !5
  %160 = getelementptr inbounds %struct.page, ptr %159, i32 0, i32 2
  store i16 0, ptr %160, align 1, !tbaa !35
  %161 = load i64, ptr %5, align 8, !tbaa !9
  %162 = trunc i64 %161 to i32
  %163 = load ptr, ptr %7, align 8, !tbaa !5
  %164 = getelementptr inbounds %struct.page, ptr %163, i32 0, i32 3
  store i32 %162, ptr %164, align 1, !tbaa !36
  %165 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %165, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %166

166:                                              ; preds = %156, %128
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #8
  %167 = load ptr, ptr %3, align 8
  ret ptr %167
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #7

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #7 = { nounwind allocsize(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 = { noreturn }
attributes #10 = { nounwind willreturn memory(read) }
attributes #11 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 80}
!12 = !{!"MDBX_txn", !13, i64 0, !13, i64 4, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !10, i64 64, !10, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !16, i64 128, !6, i64 160, !7, i64 168}
!13 = !{!"int", !7, i64 0}
!14 = !{!"geo", !15, i64 0, !15, i64 2, !13, i64 4, !13, i64 8, !7, i64 12, !7, i64 16}
!15 = !{!"short", !7, i64 0}
!16 = !{!"MDBX_canary", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!17 = !{!18, !6, i64 448}
!18 = !{!"MDBX_env", !7, i64 0, !13, i64 4, !13, i64 8, !19, i64 16, !13, i64 56, !13, i64 60, !19, 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, !13, i64 132, !13, i64 136, !13, i64 140, !13, i64 144, !20, 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, !10, i64 256, !21, i64 264, !24, i64 320, !22, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !25, i64 392, !7, i64 400, !13, i64 440, !13, i64 444, !6, i64 448, !26, i64 456, !7, i64 496, !7, i64 536}
!19 = !{!"osal_mmap", !7, i64 0, !13, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!20 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!21 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !10, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !13, i64 28, !13, i64 32, !22, i64 36, !22, i64 37, !22, i64 38, !23, i64 40, !7, i64 48}
!22 = !{!"_Bool", !7, i64 0}
!23 = !{!"", !15, i64 0, !15, i64 2, !15, i64 4, !15, i64 6}
!24 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!25 = !{!"", !10, i64 0}
!26 = !{!"osal_ioring", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!27 = !{!18, !13, i64 8}
!28 = !{!29, !7, i64 25}
!29 = !{!"libmdbx_globals", !7, i64 0, !13, i64 16, !13, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !22, i64 27, !13, i64 28, !7, i64 32, !7, i64 40, !10, i64 80, !6, i64 88}
!30 = !{!18, !13, i64 444}
!31 = !{!29, !7, i64 26}
!32 = !{!12, !13, i64 4}
!33 = !{!18, !13, i64 4}
!34 = !{!13, !13, i64 0}
!35 = !{!15, !15, i64 0}
!36 = !{!7, !7, i64 0}


; 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.28 = external hidden unnamed_addr constant [28 x i8], align 1
@__func__.page_shadow_alloc = external hidden unnamed_addr constant [18 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [39 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @page_shadow_alloc(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #3 {
  %3 = getelementptr inbounds i8, ptr %0, i64 80
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 448
  %6 = load ptr, ptr %5, align 8, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !25
  %9 = zext i32 %8 to i64
  %10 = icmp eq i64 %1, 1
  %11 = icmp ne ptr %6, null
  %12 = select i1 %10, i1 %11, i1 false, !prof !26
  br i1 %12, label %13, label %24, !prof !26

13:                                               ; preds = %2
  %14 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !27
  %15 = and i8 %14, 1
  %.not = icmp eq i8 %15, 0
  br i1 %.not, label %20, label %16, !prof !29

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %4, i64 444
  %18 = load i32, ptr %17, align 4, !tbaa !30
  %.not42 = icmp eq i32 %18, 0
  br i1 %.not42, label %19, label %20, !prof !29

19:                                               ; preds = %16
  tail call void @mdbx_assert_fail(ptr noundef nonnull %4, ptr noundef nonnull @.str.28, ptr noundef nonnull @__func__.page_shadow_alloc, i32 noundef 284) #6
  unreachable

20:                                               ; preds = %16, %13
  %21 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !31
  %22 = icmp ugt i8 %21, 5
  br i1 %22, label %23, label %.thread44, !prof !29

23:                                               ; preds = %20
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 6, ptr noundef nonnull @__func__.page_shadow_alloc, i32 noundef 285, ptr noundef nonnull @.str.29, ptr noundef nonnull %6, i64 noundef %9, i32 noundef 285) #7
  br label %.thread44

24:                                               ; preds = %2
  %25 = tail call i64 @pgno2bytes(ptr noundef nonnull %4, i64 noundef %1) #8
  %26 = add i64 %25, 8
  %27 = tail call noalias ptr @malloc(i64 noundef %26) #9
  %.not.not = icmp eq ptr %27, null
  br i1 %.not.not, label %.thread, label %31, !prof !29

.thread:                                          ; preds = %24
  %28 = getelementptr inbounds i8, ptr %0, i64 4
  %29 = load i32, ptr %28, align 4, !tbaa !32
  %30 = or i32 %29, 2
  store i32 %30, ptr %28, align 4, !tbaa !32
  br label %66

31:                                               ; preds = %24
  %32 = ptrtoint ptr %27 to i64
  %33 = add nsw i64 %32, 8
  %34 = inttoptr i64 %33 to ptr
  %35 = getelementptr inbounds i8, ptr %4, i64 4
  %36 = load i32, ptr %35, align 4, !tbaa !33
  %37 = and i32 %36, 16777216
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %51, label %61

.thread44:                                        ; preds = %20, %23
  %39 = getelementptr inbounds i8, ptr %6, i64 20
  %40 = ptrtoint ptr %39 to i64
  %41 = add nsw i64 %40, 4
  %42 = inttoptr i64 %41 to ptr
  %43 = load ptr, ptr %42, align 8, !tbaa !34
  store ptr %43, ptr %5, align 8, !tbaa !15
  %44 = getelementptr inbounds i8, ptr %4, i64 444
  %45 = load i32, ptr %44, align 4, !tbaa !30
  %46 = add i32 %45, -1
  store i32 %46, ptr %44, align 4, !tbaa !30
  %47 = getelementptr inbounds i8, ptr %4, i64 4
  %48 = load i32, ptr %47, align 4, !tbaa !33
  %49 = and i32 %48, 16777216
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %.thread50, label %61

51:                                               ; preds = %31
  %52 = icmp ugt i64 %1, 1
  br i1 %52, label %53, label %.thread50

53:                                               ; preds = %51
  %54 = add i64 %1, -1
  %55 = tail call i64 @pgno2bytes(ptr noundef nonnull %4, i64 noundef %54) #8
  %56 = add i64 %55, 20
  br label %.thread50

.thread50:                                        ; preds = %.thread44, %53, %51
  %.1394754 = phi ptr [ %34, %53 ], [ %34, %51 ], [ %6, %.thread44 ]
  %.0374953 = phi i64 [ %25, %53 ], [ %25, %51 ], [ %9, %.thread44 ]
  %.0 = phi i64 [ %56, %53 ], [ 20, %51 ], [ 20, %.thread44 ]
  %57 = ptrtoint ptr %.1394754 to i64
  %58 = add nsw i64 %.0, %57
  %59 = inttoptr i64 %58 to ptr
  %60 = sub i64 %.0374953, %.0
  tail call void @llvm.memset.p0.i64(ptr align 1 %59, i8 0, i64 %60, i1 false)
  br label %61

61:                                               ; preds = %.thread44, %.thread50, %31
  %.13948 = phi ptr [ %6, %.thread44 ], [ %.1394754, %.thread50 ], [ %34, %31 ]
  %62 = getelementptr inbounds i8, ptr %.13948, i64 16
  store i32 0, ptr %62, align 1, !tbaa !35
  %63 = getelementptr inbounds i8, ptr %.13948, i64 10
  store i16 0, ptr %63, align 1, !tbaa !36
  %64 = trunc i64 %1 to i32
  %65 = getelementptr inbounds i8, ptr %.13948, i64 12
  store i32 %64, ptr %65, align 1, !tbaa !37
  br label %66

66:                                               ; preds = %.thread, %61
  %.1 = phi ptr [ %.13948, %61 ], [ null, %.thread ]
  ret ptr %.1
}

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #5

attributes #0 = { 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 #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 nounwind willreturn memory(argmem: write) }
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 = { 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind }
attributes #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind allocsize(0) }

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


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