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

; 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: cold nounwind optsize uwtable
declare dso_local i32 @default_dp_limit(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @env_max_pgno(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @default_dp_initial(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @env_options_adjust_dp_limit(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.MDBX_env, ptr %4, i32 0, i32 34
  %6 = getelementptr inbounds %struct.anon.2, ptr %5, i32 0, i32 15
  %7 = load i8, ptr %6, align 8
  %8 = and i8 %7, 1
  %9 = zext i8 %8 to i32
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %17, label %11

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call i32 @default_dp_limit(ptr noundef %12) #3
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MDBX_env, ptr %14, i32 0, i32 34
  %16 = getelementptr inbounds %struct.anon.2, ptr %15, i32 0, i32 2
  store i32 %13, ptr %16, align 8, !tbaa !9
  br label %44

17:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = call i32 @env_max_pgno(ptr noundef %18)
  store i32 %19, ptr %3, align 4, !tbaa !22
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.MDBX_env, ptr %20, i32 0, i32 34
  %22 = getelementptr inbounds %struct.anon.2, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = load i32, ptr %3, align 4, !tbaa !22
  %25 = sub i32 %24, 3
  %26 = icmp ugt i32 %23, %25
  br i1 %26, label %27, label %33

27:                                               ; preds = %17
  %28 = load i32, ptr %3, align 4, !tbaa !22
  %29 = sub i32 %28, 3
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.MDBX_env, ptr %30, i32 0, i32 34
  %32 = getelementptr inbounds %struct.anon.2, ptr %31, i32 0, i32 2
  store i32 %29, ptr %32, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %27, %17
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MDBX_env, ptr %34, i32 0, i32 34
  %36 = getelementptr inbounds %struct.anon.2, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = icmp ult i32 %37, 128
  br i1 %38, label %39, label %43

39:                                               ; preds = %33
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.MDBX_env, ptr %40, i32 0, i32 34
  %42 = getelementptr inbounds %struct.anon.2, ptr %41, i32 0, i32 2
  store i32 128, ptr %42, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %39, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %44

44:                                               ; preds = %43, %11
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MDBX_env, ptr %45, i32 0, i32 34
  %47 = getelementptr inbounds %struct.anon.2, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %47, align 4, !tbaa !23
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.MDBX_env, ptr %49, i32 0, i32 34
  %51 = getelementptr inbounds %struct.anon.2, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !9
  %53 = icmp ugt i32 %48, %52
  br i1 %53, label %54, label %70

54:                                               ; preds = %44
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.MDBX_env, ptr %55, i32 0, i32 34
  %57 = getelementptr inbounds %struct.anon.2, ptr %56, i32 0, i32 3
  %58 = load i32, ptr %57, align 4, !tbaa !23
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = call i32 @default_dp_initial(ptr noundef %59)
  %61 = icmp ugt i32 %58, %60
  br i1 %61, label %62, label %70

62:                                               ; preds = %54
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.MDBX_env, ptr %63, i32 0, i32 34
  %65 = getelementptr inbounds %struct.anon.2, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 8, !tbaa !9
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.MDBX_env, ptr %67, i32 0, i32 34
  %69 = getelementptr inbounds %struct.anon.2, ptr %68, i32 0, i32 3
  store i32 %66, ptr %69, align 4, !tbaa !23
  br label %70

70:                                               ; preds = %62, %54, %44
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.MDBX_env, ptr %71, i32 0, i32 34
  %73 = getelementptr inbounds %struct.anon.2, ptr %72, i32 0, i32 13
  store i8 0, ptr %73, align 2, !tbaa !24
  ret void
}

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

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

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


; 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 nounwind optsize uwtable
declare dso_local i32 @default_dp_limit(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @env_max_pgno(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @default_dp_initial(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @env_options_adjust_dp_limit(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 312
  %3 = load i8, ptr %2, align 8
  %4 = and i8 %3, 1
  %.not = icmp eq i8 %4, 0
  %5 = getelementptr inbounds i8, ptr %0, i64 272
  br i1 %.not, label %6, label %condstore.split

6:                                                ; preds = %1
  %7 = tail call i32 @default_dp_limit(ptr noundef nonnull %0) #3
  br label %.sink.split

condstore.split:                                  ; preds = %1
  %8 = tail call i32 @env_max_pgno(ptr noundef nonnull %0)
  %9 = load i32, ptr %5, align 8, !tbaa !5
  %10 = add i32 %8, -3
  %.not17 = icmp ugt i32 %9, %10
  %11 = tail call i32 @llvm.umin.i32(i32 %9, i32 %10)
  %12 = icmp ult i32 %11, 128
  %13 = or i1 %.not17, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %condstore.split
  %simplifycfg.merge = tail call i32 @llvm.umax.i32(i32 %11, i32 128)
  br label %.sink.split

.sink.split:                                      ; preds = %6, %14
  %simplifycfg.merge.sink = phi i32 [ %simplifycfg.merge, %14 ], [ %7, %6 ]
  store i32 %simplifycfg.merge.sink, ptr %5, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %.sink.split, %condstore.split
  %16 = phi i32 [ %9, %condstore.split ], [ %simplifycfg.merge.sink, %.sink.split ]
  %17 = getelementptr inbounds i8, ptr %0, i64 276
  %18 = load i32, ptr %17, align 4, !tbaa !21
  %19 = getelementptr inbounds i8, ptr %0, i64 272
  %20 = icmp ugt i32 %18, %16
  br i1 %20, label %21, label %26

21:                                               ; preds = %15
  %22 = tail call i32 @default_dp_initial(ptr noundef nonnull %0)
  %23 = icmp ugt i32 %18, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %21
  %25 = load i32, ptr %19, align 8, !tbaa !5
  store i32 %25, ptr %17, align 4, !tbaa !21
  br label %26

26:                                               ; preds = %24, %21, %15
  %27 = getelementptr inbounds i8, ptr %0, i64 302
  store i8 0, ptr %27, align 2, !tbaa !22
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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, !9, i64 272}
!6 = !{!"MDBX_env", !7, i64 0, !9, i64 4, !9, i64 8, !10, i64 16, !9, i64 56, !9, i64 60, !10, i64 64, !12, i64 104, !13, i64 112, !13, i64 114, !13, i64 116, !13, i64 118, !13, i64 120, !13, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !13, i64 130, !9, i64 132, !9, i64 136, !9, i64 140, !9, i64 144, !14, 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, !15, i64 264, !18, i64 320, !16, i64 360, !12, i64 368, !12, i64 376, !12, i64 384, !19, i64 392, !7, i64 400, !9, i64 440, !9, i64 444, !12, i64 448, !20, i64 456, !7, i64 496, !7, i64 536}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"osal_mmap", !7, i64 0, !9, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!15 = !{!"", !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, !16, i64 36, !16, i64 37, !16, i64 38, !17, i64 40, !7, i64 48}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6}
!18 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!19 = !{!"", !11, i64 0}
!20 = !{!"osal_ioring", !9, i64 0, !9, i64 4, !9, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!21 = !{!6, !9, i64 276}
!22 = !{!6, !16, i64 302}


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