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

; 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.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.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 }
%union.mdbx_atomic_uint64_t = type { i64 }

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

; Function Attrs: cold nounwind optsize willreturn memory(read) uwtable
define dso_local ptr @mdbx_env_get_hsr(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  br i1 %4, label %5, label %10

5:                                                ; preds = %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.MDBX_env, ptr %6, i32 0, i32 0
  %8 = load volatile i32, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i32 %8, 445224513
  br label %10

10:                                               ; preds = %5, %1
  %11 = phi i1 [ false, %1 ], [ %9, %5 ]
  %12 = xor i1 %11, true
  %13 = xor i1 %12, true
  %14 = zext i1 %13 to i32
  %15 = sext i32 %14 to i64
  %16 = call i64 @llvm.expect.i64(i64 %15, i64 1)
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %10
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.MDBX_env, ptr %19, i32 0, i32 32
  %21 = load ptr, ptr %20, align 8, !tbaa !10
  br label %23

22:                                               ; preds = %10
  br label %23

23:                                               ; preds = %22, %18
  %24 = phi ptr [ %21, %18 ], [ null, %22 ]
  ret ptr %24
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #1 = { cold nounwind optsize 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" }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 248}
!11 = !{!"MDBX_env", !7, i64 0, !12, i64 4, !12, i64 8, !13, i64 16, !12, i64 56, !12, 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, !12, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !16, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !12, i64 224, !12, i64 228, !12, 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, !12, i64 440, !12, i64 444, !6, i64 448, !22, i64 456, !7, i64 496, !7, i64 536}
!12 = !{!"int", !7, i64 0}
!13 = !{!"osal_mmap", !7, i64 0, !12, 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 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !14, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !12, i64 28, !12, 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", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}


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

; Function Attrs: cold mustprogress nofree norecurse nounwind optsize willreturn memory(argmem: read, inaccessiblemem: read) uwtable
define dso_local ptr @mdbx_env_get_hsr(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.critedge, label %2, !prof !5

2:                                                ; preds = %1
  %3 = load volatile i32, ptr %0, align 8, !tbaa !6
  %4 = icmp eq i32 %3, 445224513
  br i1 %4, label %5, label %.critedge, !prof !9

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 248
  %7 = load ptr, ptr %6, align 8, !tbaa !10
  br label %.critedge

.critedge:                                        ; preds = %1, %2, %5
  %8 = phi ptr [ %7, %5 ], [ null, %2 ], [ null, %1 ]
  ret ptr %8
}

attributes #0 = { cold mustprogress nofree norecurse nounwind optsize willreturn memory(argmem: read, inaccessiblemem: 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" }

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


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