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

; 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, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.0, %struct.anon.4, i8, ptr, ptr, ptr, %struct.anon.5, %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 = type { ptr, ptr, ptr, ptr }
%struct.anon.0 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.1, %union.anon.2 }
%struct.anon.1 = type { i16, i16, i16, i16 }
%union.anon.2 = type { i32 }
%struct.anon.4 = type { i64, i64, i64, i64, i64 }
%struct.anon.5 = 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 }
%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.19 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.13, %union.anon.14 }
%union.anon.13 = type { i32 }
%union.anon.14 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.19 = type { %struct.anon.21 }
%struct.anon.21 = type { %struct.troika, ptr, %struct.anon.22, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.23 }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.anon.22 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.23 = type { %struct.anon.24 }
%struct.anon.24 = type { i64, ptr }

@__func__.mdbx_txn_lock = external hidden unnamed_addr constant [14 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: inlinehint nounwind uwtable
declare hidden i32 @check_env(ptr noundef, i1 noundef zeroext) #1

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

; 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.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @mdbx_txn_lock(ptr noundef %0, i1 noundef zeroext %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %8 = zext i1 %1 to i8
  store i8 %8, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i32 @check_env(ptr noundef %9, i1 noundef zeroext true)
  store i32 %10, ptr %6, align 4, !tbaa !11
  %11 = load i32, ptr %6, align 4, !tbaa !11
  %12 = icmp ne i32 %11, 0
  %13 = xor i1 %12, true
  %14 = xor i1 %13, true
  %15 = zext i1 %14 to i32
  %16 = sext i32 %15 to i64
  %17 = call i64 @llvm.expect.i64(i64 %16, i64 0)
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %2
  %20 = load i32, ptr %6, align 4, !tbaa !11
  %21 = call i32 @log_if_error(i32 noundef %20, ptr noundef @__func__.mdbx_txn_lock, i32 noundef 139)
  store i32 %21, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

22:                                               ; preds = %2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MDBX_env, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = and i32 %25, 131072
  %27 = icmp ne i32 %26, 0
  %28 = xor i1 %27, true
  %29 = xor i1 %28, true
  %30 = zext i1 %29 to i32
  %31 = sext i32 %30 to i64
  %32 = call i64 @llvm.expect.i64(i64 %31, i64 0)
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %22
  %35 = call i32 @log_if_error(i32 noundef 13, ptr noundef @__func__.mdbx_txn_lock, i32 noundef 142)
  store i32 %35, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

36:                                               ; preds = %22
  %37 = load i8, ptr %5, align 1, !tbaa !9, !range !24, !noundef !25
  %38 = trunc i8 %37 to i1
  br i1 %38, label %39, label %64

39:                                               ; preds = %36
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.MDBX_env, ptr %40, i32 0, i32 24
  %42 = load ptr, ptr %41, align 8, !tbaa !26
  %43 = getelementptr inbounds %struct.MDBX_txn, ptr %42, i32 0, i32 3
  %44 = load i64, ptr %43, align 8, !tbaa !27
  %45 = icmp ne i64 %44, 0
  br i1 %45, label %54, label %46

46:                                               ; preds = %39
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.MDBX_env, ptr %47, i32 0, i32 24
  %49 = load ptr, ptr %48, align 8, !tbaa !26
  %50 = getelementptr inbounds %struct.MDBX_txn, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !31
  %52 = and i32 %51, 1
  %53 = icmp eq i32 %52, 0
  br label %54

54:                                               ; preds = %46, %39
  %55 = phi i1 [ true, %39 ], [ %53, %46 ]
  %56 = xor i1 %55, true
  %57 = xor i1 %56, true
  %58 = zext i1 %57 to i32
  %59 = sext i32 %58 to i64
  %60 = call i64 @llvm.expect.i64(i64 %59, i64 0)
  %61 = icmp ne i64 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %54
  %63 = call i32 @log_if_error(i32 noundef -30778, ptr noundef @__func__.mdbx_txn_lock, i32 noundef 144)
  store i32 %63, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

64:                                               ; preds = %54, %36
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = load i8, ptr %5, align 1, !tbaa !9, !range !24, !noundef !25
  %67 = trunc i8 %66 to i1
  %68 = call i32 @lck_txn_lock(ptr noundef %65, i1 noundef zeroext %67)
  %69 = call i32 @log_if_error(i32 noundef %68, ptr noundef @__func__.mdbx_txn_lock, i32 noundef 146)
  store i32 %69, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

70:                                               ; preds = %64, %62, %34, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

declare i32 @lck_txn_lock(ptr noundef, i1 noundef zeroext) #4

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

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


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

@__func__.mdbx_txn_lock = external hidden unnamed_addr constant [14 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mdbx_txn_lock(ptr noundef %0, i1 noundef zeroext %1) local_unnamed_addr #1 {
  %3 = tail call i32 @check_env(ptr noundef %0, i1 noundef zeroext true)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %6, label %4, !prof !5

4:                                                ; preds = %2
  %5 = tail call i32 @log_if_error(i32 noundef %3, ptr noundef nonnull @__func__.mdbx_txn_lock, i32 noundef 139)
  br label %27

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !6
  %9 = and i32 %8, 131072
  %.not10 = icmp eq i32 %9, 0
  br i1 %.not10, label %12, label %10, !prof !5

10:                                               ; preds = %6
  %11 = tail call i32 @log_if_error(i32 noundef 13, ptr noundef nonnull @__func__.mdbx_txn_lock, i32 noundef 142)
  br label %27

12:                                               ; preds = %6
  br i1 %1, label %13, label %24

13:                                               ; preds = %12
  %14 = getelementptr inbounds i8, ptr %0, i64 192
  %15 = load ptr, ptr %14, align 8, !tbaa !22
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !23
  %.not11 = icmp eq i64 %17, 0
  br i1 %.not11, label %18, label %.critedge, !prof !5

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %15, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !27
  %21 = and i32 %20, 1
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.critedge, label %24, !prof !28

.critedge:                                        ; preds = %13, %18
  %23 = tail call i32 @log_if_error(i32 noundef -30778, ptr noundef nonnull @__func__.mdbx_txn_lock, i32 noundef 144)
  br label %27

24:                                               ; preds = %18, %12
  %25 = tail call i32 @lck_txn_lock(ptr noundef nonnull %0, i1 noundef zeroext %1) #3
  %26 = tail call i32 @log_if_error(i32 noundef %25, ptr noundef nonnull @__func__.mdbx_txn_lock, i32 noundef 146)
  br label %27

27:                                               ; preds = %24, %.critedge, %10, %4
  %.0 = phi i32 [ %5, %4 ], [ %11, %10 ], [ %23, %.critedge ], [ %26, %24 ]
  ret i32 %.0
}

declare i32 @lck_txn_lock(ptr noundef, i1 noundef zeroext) local_unnamed_addr #2

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


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