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

; 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_cursor = type { i32, %union.anon, i8, i8, ptr, ptr, ptr, ptr, ptr, [32 x ptr], [32 x i16], ptr, ptr }
%union.anon = type { i16 }
%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.2 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.0, %union.anon.1 }
%union.anon.0 = type { i32 }
%union.anon.1 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.2 = type { %struct.anon.4 }
%struct.anon.4 = type { %struct.troika, ptr, %struct.anon.5, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.6 }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.anon.5 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.6 = type { %struct.anon.7 }
%struct.anon.7 = type { i64, ptr }
%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.9, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.10, %struct.anon.14, i8, ptr, ptr, ptr, %struct.anon.15, %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.8, i32, i64, i64, i64 }
%union.anon.8 = type { ptr }
%union.mdbx_atomic_uint32_t = type { i32 }
%struct.anon.9 = type { ptr, ptr, ptr, ptr }
%struct.anon.10 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.11, %union.anon.12 }
%struct.anon.11 = type { i16, i16, i16, i16 }
%union.anon.12 = type { i32 }
%struct.anon.14 = type { i64, i64, i64, i64, i64 }
%struct.anon.15 = 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(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #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 willreturn memory(read) uwtable
define dso_local ptr @mdbx_cursor_txn(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %13

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.MDBX_cursor, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp ne i32 %11, 2114311601
  br label %13

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

21:                                               ; preds = %13
  store ptr null, ptr %2, align 8
  br label %65

22:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MDBX_cursor, ptr %23, i32 0, i32 5
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  store ptr %25, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %39

28:                                               ; preds = %22
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MDBX_txn, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !13
  %32 = icmp ne i32 %31, 332741169
  br i1 %32, label %39, label %33

33:                                               ; preds = %28
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MDBX_txn, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !19
  %37 = and i32 %36, 1
  %38 = icmp ne i32 %37, 0
  br label %39

39:                                               ; preds = %33, %28, %22
  %40 = phi i1 [ true, %28 ], [ true, %22 ], [ %38, %33 ]
  %41 = xor i1 %40, true
  %42 = xor i1 %41, true
  %43 = zext i1 %42 to i32
  %44 = sext i32 %43 to i64
  %45 = call i64 @llvm.expect.i64(i64 %44, i64 0)
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %39
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %64

48:                                               ; preds = %39
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.MDBX_txn, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !19
  %52 = and i32 %51, 16
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %60

54:                                               ; preds = %48
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.MDBX_txn, ptr %55, i32 0, i32 9
  %57 = load ptr, ptr %56, align 8, !tbaa !20
  %58 = getelementptr inbounds %struct.MDBX_env, ptr %57, i32 0, i32 39
  %59 = load ptr, ptr %58, align 8, !tbaa !21
  br label %62

60:                                               ; preds = %48
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %60, %54
  %63 = phi ptr [ %59, %54 ], [ %61, %60 ]
  store ptr %63, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %64

64:                                               ; preds = %62, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %65

65:                                               ; preds = %64, %21
  %66 = load ptr, ptr %2, align 8
  ret ptr %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { nounwind 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 #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 = !{!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 0}
!10 = !{!"MDBX_cursor", !11, i64 0, !7, i64 4, !7, i64 6, !7, i64 7, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !7, i64 48, !7, i64 304, !6, i64 368, !6, i64 376}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !11, i64 0}
!14 = !{!"MDBX_txn", !11, i64 0, !11, i64 4, !15, i64 8, !15, i64 16, !6, i64 24, !6, i64 32, !16, i64 40, !15, i64 64, !15, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !18, i64 128, !6, i64 160, !7, i64 168}
!15 = !{!"long", !7, i64 0}
!16 = !{!"geo", !17, i64 0, !17, i64 2, !11, i64 4, !11, i64 8, !7, i64 12, !7, i64 16}
!17 = !{!"short", !7, i64 0}
!18 = !{!"MDBX_canary", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24}
!19 = !{!14, !11, i64 4}
!20 = !{!14, !6, i64 80}
!21 = !{!22, !6, i64 384}
!22 = !{!"MDBX_env", !7, i64 0, !11, i64 4, !11, i64 8, !23, i64 16, !11, i64 56, !11, i64 60, !23, 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, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !24, 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, !15, i64 256, !25, i64 264, !28, i64 320, !26, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !29, i64 392, !7, i64 400, !11, i64 440, !11, i64 444, !6, i64 448, !30, i64 456, !7, i64 496, !7, i64 536}
!23 = !{!"osal_mmap", !7, i64 0, !11, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!24 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!25 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !15, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !11, i64 28, !11, i64 32, !26, i64 36, !26, i64 37, !26, i64 38, !27, i64 40, !7, i64 48}
!26 = !{!"_Bool", !7, i64 0}
!27 = !{!"", !17, i64 0, !17, i64 2, !17, i64 4, !17, i64 6}
!28 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32}
!29 = !{!"", !15, i64 0}
!30 = !{!"osal_ioring", !11, i64 0, !11, i64 4, !11, 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: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @mdbx_cursor_txn(ptr noundef readonly %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 i32, ptr %0, align 8, !tbaa !6
  %.not17 = icmp eq i32 %3, 2114311601
  br i1 %.not17, label %4, label %.critedge, !prof !12

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !13
  %.not12 = icmp eq ptr %6, null
  br i1 %.not12, label %.critedge, label %7, !prof !5

7:                                                ; preds = %4
  %8 = load i32, ptr %6, align 8, !tbaa !14
  %.not13 = icmp eq i32 %8, 332741169
  br i1 %.not13, label %9, label %.critedge, !prof !12

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %6, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !20
  %12 = and i32 %11, 1
  %.not18 = icmp eq i32 %12, 0
  br i1 %.not18, label %13, label %.critedge, !prof !12

13:                                               ; preds = %9
  %14 = and i32 %11, 16
  %.not14 = icmp eq i32 %14, 0
  br i1 %.not14, label %.critedge, label %15

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %6, i64 80
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %17, i64 384
  %19 = load ptr, ptr %18, align 8, !tbaa !22
  br label %.critedge

.critedge:                                        ; preds = %7, %4, %1, %9, %13, %15, %2
  %.1 = phi ptr [ null, %2 ], [ null, %9 ], [ %19, %15 ], [ %6, %13 ], [ null, %1 ], [ null, %4 ], [ null, %7 ]
  ret ptr %.1
}

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


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