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

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

@mdbx_liberr2str.tbl = external hidden constant [22 x ptr], align 16
@.str.26 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [134 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [92 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [122 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [103 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [131 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [72 x i8], align 1

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

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

; Function Attrs: cold nounwind optsize willreturn memory(read) uwtable
define dso_local ptr @mdbx_liberr2str(i32 noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp sge i32 %5, -30799
  br i1 %6, label %7, label %17

7:                                                ; preds = %1
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp sle i32 %8, -30778
  br i1 %9, label %10, label %17

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sub nsw i32 %11, -30799
  store i32 %12, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [22 x ptr], ptr @mdbx_liberr2str.tbl, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %32

17:                                               ; preds = %7, %1
  %18 = load i32, ptr %3, align 4, !tbaa !5
  switch i32 %18, label %31 [
    i32 0, label %19
    i32 -30421, label %20
    i32 -30420, label %21
    i32 -30419, label %22
    i32 -30418, label %23
    i32 -30417, label %24
    i32 -30416, label %25
    i32 -30415, label %26
    i32 -30413, label %27
    i32 -30412, label %28
    i32 -30411, label %29
    i32 -30410, label %30
  ]

19:                                               ; preds = %17
  store ptr @.str.26, ptr %2, align 8
  br label %32

20:                                               ; preds = %17
  store ptr @.str.27, ptr %2, align 8
  br label %32

21:                                               ; preds = %17
  store ptr @.str.28, ptr %2, align 8
  br label %32

22:                                               ; preds = %17
  store ptr @.str.29, ptr %2, align 8
  br label %32

23:                                               ; preds = %17
  store ptr @.str.30, ptr %2, align 8
  br label %32

24:                                               ; preds = %17
  store ptr @.str.31, ptr %2, align 8
  br label %32

25:                                               ; preds = %17
  store ptr @.str.32, ptr %2, align 8
  br label %32

26:                                               ; preds = %17
  store ptr @.str.33, ptr %2, align 8
  br label %32

27:                                               ; preds = %17
  store ptr @.str.34, ptr %2, align 8
  br label %32

28:                                               ; preds = %17
  store ptr @.str.35, ptr %2, align 8
  br label %32

29:                                               ; preds = %17
  store ptr @.str.36, ptr %2, align 8
  br label %32

30:                                               ; preds = %17
  store ptr @.str.37, ptr %2, align 8
  br label %32

31:                                               ; preds = %17
  store ptr null, ptr %2, align 8
  br label %32

32:                                               ; preds = %31, %30, %29, %28, %27, %26, %25, %24, %23, %22, %21, %20, %19, %10
  %33 = load ptr, ptr %2, align 8
  ret ptr %33
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@mdbx_liberr2str.tbl = external hidden local_unnamed_addr constant [22 x ptr], align 16
@.str.26 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [134 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [92 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [122 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [103 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [131 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [72 x i8], align 1

; Function Attrs: cold mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none) uwtable
define dso_local ptr @mdbx_liberr2str(i32 noundef %0) local_unnamed_addr #0 {
  %2 = add i32 %0, 30799
  %or.cond = icmp ult i32 %2, 22
  br i1 %or.cond, label %3, label %7

3:                                                ; preds = %1
  %4 = zext nneg i32 %2 to i64
  %5 = getelementptr inbounds [22 x ptr], ptr @mdbx_liberr2str.tbl, i64 0, i64 %4
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  br label %20

7:                                                ; preds = %1
  switch i32 %0, label %19 [
    i32 0, label %20
    i32 -30421, label %8
    i32 -30420, label %9
    i32 -30419, label %10
    i32 -30418, label %11
    i32 -30417, label %12
    i32 -30416, label %13
    i32 -30415, label %14
    i32 -30413, label %15
    i32 -30412, label %16
    i32 -30411, label %17
    i32 -30410, label %18
  ]

8:                                                ; preds = %7
  br label %20

9:                                                ; preds = %7
  br label %20

10:                                               ; preds = %7
  br label %20

11:                                               ; preds = %7
  br label %20

12:                                               ; preds = %7
  br label %20

13:                                               ; preds = %7
  br label %20

14:                                               ; preds = %7
  br label %20

15:                                               ; preds = %7
  br label %20

16:                                               ; preds = %7
  br label %20

17:                                               ; preds = %7
  br label %20

18:                                               ; preds = %7
  br label %20

19:                                               ; preds = %7
  br label %20

20:                                               ; preds = %7, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %3
  %.0 = phi ptr [ %6, %3 ], [ null, %19 ], [ @.str.37, %18 ], [ @.str.36, %17 ], [ @.str.35, %16 ], [ @.str.34, %15 ], [ @.str.33, %14 ], [ @.str.32, %13 ], [ @.str.31, %12 ], [ @.str.30, %11 ], [ @.str.29, %10 ], [ @.str.28, %9 ], [ @.str.27, %8 ], [ @.str.26, %7 ]
  ret ptr %.0
}

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


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