; 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.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%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.18 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.12, %union.anon.13 }
%union.anon.12 = type { i32 }
%union.anon.13 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.18 = type { %struct.anon.20 }
%struct.anon.20 = type { %struct.troika, ptr, %struct.anon.21, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.22 }
%struct.anon.21 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.22 = type { %struct.anon.23 }
%struct.anon.23 = type { i64, ptr }

@__func__.mdbx_env_info_ex = external hidden unnamed_addr constant [17 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

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

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

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

; Function Attrs: cold nounwind optsize uwtable
declare dso_local i32 @env_info(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) #3

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_env_info_ex(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca %struct.troika, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %4
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %25, label %22

22:                                               ; preds = %19, %4
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br label %25

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

33:                                               ; preds = %25
  %34 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_env_info_ex, i32 noundef 815)
  store i32 %34, ptr %5, align 4
  br label %126

35:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 144, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 240, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store i64 336, ptr %12, align 8, !tbaa !9
  %36 = load i64, ptr %9, align 8, !tbaa !9
  %37 = icmp ne i64 %36, 352
  %38 = xor i1 %37, true
  %39 = xor i1 %38, true
  %40 = zext i1 %39 to i32
  %41 = sext i32 %40 to i64
  %42 = call i64 @llvm.expect.i64(i64 %41, i64 0)
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %55

44:                                               ; preds = %35
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = icmp ne i64 %45, 144
  br i1 %46, label %47, label %55

47:                                               ; preds = %44
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = icmp ne i64 %48, 240
  br i1 %49, label %50, label %55

50:                                               ; preds = %47
  %51 = load i64, ptr %9, align 8, !tbaa !9
  %52 = icmp ne i64 %51, 336
  br i1 %52, label %53, label %55

53:                                               ; preds = %50
  %54 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_env_info_ex, i32 noundef 822)
  store i32 %54, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %125

55:                                               ; preds = %50, %47, %44, %35
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %76

58:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = call i32 @check_txn(ptr noundef %59, i32 noundef 49)
  store i32 %60, ptr %14, align 4, !tbaa !11
  %61 = load i32, ptr %14, align 4, !tbaa !11
  %62 = icmp ne i32 %61, 0
  %63 = xor i1 %62, true
  %64 = xor i1 %63, true
  %65 = zext i1 %64 to i32
  %66 = sext i32 %65 to i64
  %67 = call i64 @llvm.expect.i64(i64 %66, i64 0)
  %68 = icmp ne i64 %67, 0
  br i1 %68, label %69, label %72

69:                                               ; preds = %58
  %70 = load i32, ptr %14, align 4, !tbaa !11
  %71 = call i32 @log_if_error(i32 noundef %70, ptr noundef @__func__.mdbx_env_info_ex, i32 noundef 827)
  store i32 %71, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %73

72:                                               ; preds = %58
  store i32 0, ptr %13, align 4
  br label %73

73:                                               ; preds = %72, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  %74 = load i32, ptr %13, align 4
  switch i32 %74, label %125 [
    i32 0, label %75
  ]

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75, %55
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %114

79:                                               ; preds = %76
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = call i32 @check_env(ptr noundef %80, i1 noundef zeroext false)
  store i32 %81, ptr %15, align 4, !tbaa !11
  %82 = load i32, ptr %15, align 4, !tbaa !11
  %83 = icmp ne i32 %82, 0
  %84 = xor i1 %83, true
  %85 = xor i1 %84, true
  %86 = zext i1 %85 to i32
  %87 = sext i32 %86 to i64
  %88 = call i64 @llvm.expect.i64(i64 %87, i64 0)
  %89 = icmp ne i64 %88, 0
  br i1 %89, label %90, label %93

90:                                               ; preds = %79
  %91 = load i32, ptr %15, align 4, !tbaa !11
  %92 = call i32 @log_if_error(i32 noundef %91, ptr noundef @__func__.mdbx_env_info_ex, i32 noundef 832)
  store i32 %92, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %111

93:                                               ; preds = %79
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = icmp ne ptr %94, null
  br i1 %95, label %96, label %110

96:                                               ; preds = %93
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.MDBX_txn, ptr %97, i32 0, i32 9
  %99 = load ptr, ptr %98, align 8, !tbaa !13
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = icmp ne ptr %99, %100
  %102 = xor i1 %101, true
  %103 = xor i1 %102, true
  %104 = zext i1 %103 to i32
  %105 = sext i32 %104 to i64
  %106 = call i64 @llvm.expect.i64(i64 %105, i64 0)
  %107 = icmp ne i64 %106, 0
  br i1 %107, label %108, label %110

108:                                              ; preds = %96
  %109 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_env_info_ex, i32 noundef 834)
  store i32 %109, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %111

110:                                              ; preds = %96, %93
  store i32 0, ptr %13, align 4
  br label %111

111:                                              ; preds = %110, %108, %90
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  %112 = load i32, ptr %13, align 4
  switch i32 %112, label %125 [
    i32 0, label %113
  ]

113:                                              ; preds = %111
  br label %118

114:                                              ; preds = %76
  %115 = load ptr, ptr %7, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.MDBX_txn, ptr %115, i32 0, i32 9
  %117 = load ptr, ptr %116, align 8, !tbaa !13
  store ptr %117, ptr %6, align 8, !tbaa !5
  br label %118

118:                                              ; preds = %114, %113
  call void @llvm.lifetime.start.p0(i64 32, ptr %16) #5
  %119 = load ptr, ptr %6, align 8, !tbaa !5
  %120 = load ptr, ptr %7, align 8, !tbaa !5
  %121 = load ptr, ptr %8, align 8, !tbaa !5
  %122 = load i64, ptr %9, align 8, !tbaa !9
  %123 = call i32 @env_info(ptr noundef %119, ptr noundef %120, ptr noundef %121, i64 noundef %122, ptr noundef %16) #6
  %124 = call i32 @log_if_error(i32 noundef %123, ptr noundef @__func__.mdbx_env_info_ex, i32 noundef 840)
  store i32 %124, ptr %5, align 4
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 32, ptr %16) #5
  br label %125

125:                                              ; preds = %118, %111, %73, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %126

126:                                              ; preds = %125, %33
  %127 = load i32, ptr %5, align 4
  ret i32 %127
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @check_txn(ptr noundef, i32 noundef) #4

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 = { 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 = { 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 #5 = { nounwind }
attributes #6 = { 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, !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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 80}
!14 = !{!"MDBX_txn", !12, i64 0, !12, i64 4, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !15, 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, !17, i64 128, !6, i64 160, !7, i64 168}
!15 = !{!"geo", !16, i64 0, !16, i64 2, !12, i64 4, !12, i64 8, !7, i64 12, !7, i64 16}
!16 = !{!"short", !7, i64 0}
!17 = !{!"MDBX_canary", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}


; 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.troika = type { i8, i8, i8, i8, i32, [3 x i64] }

@__func__.mdbx_env_info_ex = external hidden unnamed_addr constant [17 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

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

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

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

; Function Attrs: cold nounwind optsize uwtable
declare dso_local i32 @env_info(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_env_info_ex(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.troika, align 8
  %6 = icmp eq ptr %0, null
  %7 = icmp eq ptr %1, null
  %or.cond = and i1 %6, %7
  %8 = icmp eq ptr %2, null
  %spec.select = or i1 %or.cond, %8
  br i1 %spec.select, label %9, label %11, !prof !5

9:                                                ; preds = %4
  %10 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_env_info_ex, i32 noundef 815)
  br label %34

11:                                               ; preds = %4
  switch i64 %3, label %12 [
    i64 352, label %14
    i64 336, label %14
    i64 240, label %14
    i64 144, label %14
  ], !prof !6

12:                                               ; preds = %11
  %13 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_env_info_ex, i32 noundef 822)
  br label %34

14:                                               ; preds = %11, %11, %11, %11
  br i1 %7, label %.thread, label %15

15:                                               ; preds = %14
  %16 = tail call i32 @check_txn(ptr noundef nonnull %1, i32 noundef 49)
  %.not41 = icmp eq i32 %16, 0
  br i1 %.not41, label %.thread, label %17, !prof !7

17:                                               ; preds = %15
  %18 = tail call i32 @log_if_error(i32 noundef %16, ptr noundef nonnull @__func__.mdbx_env_info_ex, i32 noundef 827)
  br label %34

.thread:                                          ; preds = %15, %14
  br i1 %6, label %29, label %19

19:                                               ; preds = %.thread
  %20 = tail call i32 @check_env(ptr noundef nonnull %0, i1 noundef zeroext false)
  %.not43 = icmp eq i32 %20, 0
  br i1 %.not43, label %23, label %21, !prof !7

21:                                               ; preds = %19
  %22 = tail call i32 @log_if_error(i32 noundef %20, ptr noundef nonnull @__func__.mdbx_env_info_ex, i32 noundef 832)
  br label %34

23:                                               ; preds = %19
  br i1 %7, label %.thread46, label %24

24:                                               ; preds = %23
  %25 = getelementptr inbounds i8, ptr %1, i64 80
  %26 = load ptr, ptr %25, align 8, !tbaa !8
  %.not44 = icmp eq ptr %26, %0
  br i1 %.not44, label %.thread46, label %27, !prof !7

27:                                               ; preds = %24
  %28 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_env_info_ex, i32 noundef 834)
  br label %34

29:                                               ; preds = %.thread
  %30 = getelementptr inbounds i8, ptr %1, i64 80
  %31 = load ptr, ptr %30, align 8, !tbaa !8
  br label %.thread46

.thread46:                                        ; preds = %23, %24, %29
  %.031 = phi ptr [ %31, %29 ], [ %0, %24 ], [ %0, %23 ]
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  %32 = call i32 @env_info(ptr noundef %.031, ptr noundef %1, ptr noundef nonnull %2, i64 noundef %3, ptr noundef nonnull %5) #5
  %33 = call i32 @log_if_error(i32 noundef %32, ptr noundef nonnull @__func__.mdbx_env_info_ex, i32 noundef 840)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  br label %34

34:                                               ; preds = %21, %27, %17, %12, %.thread46, %9
  %.4 = phi i32 [ %10, %9 ], [ %13, %12 ], [ %33, %.thread46 ], [ %18, %17 ], [ %22, %21 ], [ %28, %27 ]
  ret i32 %.4
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @check_txn(ptr noundef, i32 noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { 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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!"branch_weights", i32 1, i32 8000, i32 1, i32 1, i32 1}
!7 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!8 = !{!9, !14, i64 80}
!9 = !{!"MDBX_txn", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 16, !14, i64 24, !14, i64 32, !15, i64 40, !13, i64 64, !13, i64 72, !14, i64 80, !14, i64 88, !14, i64 96, !14, i64 104, !14, i64 112, !14, i64 120, !17, i64 128, !14, i64 160, !11, i64 168}
!10 = !{!"int", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C/C++ TBAA"}
!13 = !{!"long", !11, i64 0}
!14 = !{!"any pointer", !11, i64 0}
!15 = !{!"geo", !16, i64 0, !16, i64 2, !10, i64 4, !10, i64 8, !11, i64 12, !11, i64 16}
!16 = !{!"short", !11, i64 0}
!17 = !{!"MDBX_canary", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}


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