; LLVM IR from erthink/libmdbx :: src (meta)

; 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.meta_snap = type { i64, i64 }

@troika_fsm_map = external hidden constant [216 x i8], align 16

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i64 } @meta_snap(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: inlinehint nounwind willreturn memory(read) uwtable
declare hidden ptr @page_meta(ptr noundef) #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden ptr @pgno2page(ptr noundef, i64 noundef) #2

; Function Attrs: 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 void @meta_troika_unpack(ptr noundef, i8 noundef zeroext) #0

; Function Attrs: hot nounwind uwtable
define dso_local void @meta_tap(ptr dead_on_unwind noalias writable sret(%struct.troika) align 8 %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.meta_snap, align 8
  %5 = alloca %struct.meta_snap, align 8
  %6 = alloca %struct.meta_snap, align 8
  %7 = alloca %struct.meta_snap, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call ptr @pgno2page(ptr noundef %8, i64 noundef 0) #6
  %10 = call ptr @page_meta(ptr noundef %9) #6
  %11 = call { i64, i64 } @meta_snap(ptr noundef %10)
  %12 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  %13 = extractvalue { i64, i64 } %11, 0
  store i64 %13, ptr %12, align 8
  %14 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  %15 = extractvalue { i64, i64 } %11, 1
  store i64 %15, ptr %14, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %5, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #5
  %16 = getelementptr inbounds %struct.meta_snap, ptr %4, i32 0, i32 0
  %17 = load i64, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 5
  %19 = getelementptr inbounds [3 x i64], ptr %18, i64 0, i64 0
  store i64 %17, ptr %19, align 8, !tbaa !10
  %20 = getelementptr inbounds %struct.meta_snap, ptr %4, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !14
  %22 = trunc i64 %21 to i8
  %23 = zext i8 %22 to i32
  %24 = shl i32 %23, 0
  %25 = trunc i32 %24 to i8
  %26 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 0
  store i8 %25, ptr %26, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call ptr @pgno2page(ptr noundef %27, i64 noundef 1) #6
  %29 = call ptr @page_meta(ptr noundef %28) #6
  %30 = call { i64, i64 } @meta_snap(ptr noundef %29)
  %31 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  %32 = extractvalue { i64, i64 } %30, 0
  store i64 %32, ptr %31, align 8
  %33 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  %34 = extractvalue { i64, i64 } %30, 1
  store i64 %34, ptr %33, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  %35 = getelementptr inbounds %struct.meta_snap, ptr %4, i32 0, i32 0
  %36 = load i64, ptr %35, align 8, !tbaa !12
  %37 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 5
  %38 = getelementptr inbounds [3 x i64], ptr %37, i64 0, i64 1
  store i64 %36, ptr %38, align 8, !tbaa !10
  %39 = getelementptr inbounds %struct.meta_snap, ptr %4, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !14
  %41 = trunc i64 %40 to i8
  %42 = zext i8 %41 to i32
  %43 = shl i32 %42, 1
  %44 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 0
  %45 = load i8, ptr %44, align 8, !tbaa !15
  %46 = zext i8 %45 to i32
  %47 = add nsw i32 %46, %43
  %48 = trunc i32 %47 to i8
  store i8 %48, ptr %44, align 8, !tbaa !15
  %49 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 5
  %50 = getelementptr inbounds [3 x i64], ptr %49, i64 0, i64 0
  %51 = load i64, ptr %50, align 8, !tbaa !10
  %52 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 5
  %53 = getelementptr inbounds [3 x i64], ptr %52, i64 0, i64 1
  %54 = load i64, ptr %53, align 8, !tbaa !10
  %55 = call zeroext i8 @meta_cmp2int(i64 noundef %51, i64 noundef %54, i8 noundef zeroext 8)
  %56 = zext i8 %55 to i32
  %57 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 0
  %58 = load i8, ptr %57, align 8, !tbaa !15
  %59 = zext i8 %58 to i32
  %60 = add nsw i32 %59, %56
  %61 = trunc i32 %60 to i8
  store i8 %61, ptr %57, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = call ptr @pgno2page(ptr noundef %62, i64 noundef 2) #6
  %64 = call ptr @page_meta(ptr noundef %63) #6
  %65 = call { i64, i64 } @meta_snap(ptr noundef %64)
  %66 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %67 = extractvalue { i64, i64 } %65, 0
  store i64 %67, ptr %66, align 8
  %68 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %69 = extractvalue { i64, i64 } %65, 1
  store i64 %69, ptr %68, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  %70 = getelementptr inbounds %struct.meta_snap, ptr %4, i32 0, i32 0
  %71 = load i64, ptr %70, align 8, !tbaa !12
  %72 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 5
  %73 = getelementptr inbounds [3 x i64], ptr %72, i64 0, i64 2
  store i64 %71, ptr %73, align 8, !tbaa !10
  %74 = getelementptr inbounds %struct.meta_snap, ptr %4, i32 0, i32 1
  %75 = load i64, ptr %74, align 8, !tbaa !14
  %76 = trunc i64 %75 to i8
  %77 = zext i8 %76 to i32
  %78 = shl i32 %77, 2
  %79 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 0
  %80 = load i8, ptr %79, align 8, !tbaa !15
  %81 = zext i8 %80 to i32
  %82 = add nsw i32 %81, %78
  %83 = trunc i32 %82 to i8
  store i8 %83, ptr %79, align 8, !tbaa !15
  %84 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 5
  %85 = getelementptr inbounds [3 x i64], ptr %84, i64 0, i64 0
  %86 = load i64, ptr %85, align 8, !tbaa !10
  %87 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 5
  %88 = getelementptr inbounds [3 x i64], ptr %87, i64 0, i64 2
  %89 = load i64, ptr %88, align 8, !tbaa !10
  %90 = call zeroext i8 @meta_cmp2int(i64 noundef %86, i64 noundef %89, i8 noundef zeroext 24)
  %91 = zext i8 %90 to i32
  %92 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 0
  %93 = load i8, ptr %92, align 8, !tbaa !15
  %94 = zext i8 %93 to i32
  %95 = add nsw i32 %94, %91
  %96 = trunc i32 %95 to i8
  store i8 %96, ptr %92, align 8, !tbaa !15
  %97 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 5
  %98 = getelementptr inbounds [3 x i64], ptr %97, i64 0, i64 1
  %99 = load i64, ptr %98, align 8, !tbaa !10
  %100 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 5
  %101 = getelementptr inbounds [3 x i64], ptr %100, i64 0, i64 2
  %102 = load i64, ptr %101, align 8, !tbaa !10
  %103 = call zeroext i8 @meta_cmp2int(i64 noundef %99, i64 noundef %102, i8 noundef zeroext 72)
  %104 = zext i8 %103 to i32
  %105 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 0
  %106 = load i8, ptr %105, align 8, !tbaa !15
  %107 = zext i8 %106 to i32
  %108 = add nsw i32 %107, %104
  %109 = trunc i32 %108 to i8
  store i8 %109, ptr %105, align 8, !tbaa !15
  %110 = getelementptr inbounds %struct.troika, ptr %0, i32 0, i32 0
  %111 = load i8, ptr %110, align 8, !tbaa !15
  %112 = zext i8 %111 to i64
  %113 = getelementptr inbounds [216 x i8], ptr @troika_fsm_map, i64 0, i64 %112
  %114 = load i8, ptr %113, align 1, !tbaa !18
  call void @meta_troika_unpack(ptr noundef %0, i8 noundef zeroext %114)
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @meta_cmp2int(i64 noundef, i64 noundef, i8 noundef zeroext) #0

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { hot 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{i64 0, i64 8, !10, i64 8, i64 8, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"meta_snap", !11, i64 0, !11, i64 8}
!14 = !{!13, !11, i64 8}
!15 = !{!16, !7, i64 0}
!16 = !{!"troika", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !17, i64 4, !7, i64 8}
!17 = !{!"int", !7, i64 0}
!18 = !{!7, !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"

%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }

@troika_fsm_map = external hidden local_unnamed_addr constant [216 x i8], align 16

; Function Attrs: inlinehint nounwind uwtable
declare hidden { i64, i64 } @meta_snap(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden ptr @page_meta(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden ptr @pgno2page(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @meta_troika_unpack(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: hot nounwind uwtable
define dso_local void @meta_tap(ptr dead_on_unwind noalias writable sret(%struct.troika) align 8 %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = tail call ptr @pgno2page(ptr noundef %1, i64 noundef 0) #3
  %4 = tail call ptr @page_meta(ptr noundef %3) #3
  %5 = tail call { i64, i64 } @meta_snap(ptr noundef %4)
  %6 = extractvalue { i64, i64 } %5, 0
  %7 = extractvalue { i64, i64 } %5, 1
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %6, ptr %8, align 8, !tbaa !5
  %9 = trunc i64 %7 to i8
  %10 = tail call ptr @pgno2page(ptr noundef %1, i64 noundef 1) #3
  %11 = tail call ptr @page_meta(ptr noundef %10) #3
  %12 = tail call { i64, i64 } @meta_snap(ptr noundef %11)
  %13 = extractvalue { i64, i64 } %12, 0
  %14 = extractvalue { i64, i64 } %12, 1
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %13, ptr %15, align 8, !tbaa !5
  %16 = trunc i64 %14 to i8
  %17 = shl i8 %16, 1
  %18 = add i8 %17, %9
  %19 = tail call zeroext i8 @meta_cmp2int(i64 noundef %6, i64 noundef %13, i8 noundef zeroext 8)
  %20 = add i8 %18, %19
  %21 = tail call ptr @pgno2page(ptr noundef %1, i64 noundef 2) #3
  %22 = tail call ptr @page_meta(ptr noundef %21) #3
  %23 = tail call { i64, i64 } @meta_snap(ptr noundef %22)
  %24 = extractvalue { i64, i64 } %23, 0
  %25 = extractvalue { i64, i64 } %23, 1
  %26 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %24, ptr %26, align 8, !tbaa !5
  %27 = trunc i64 %25 to i8
  %28 = shl i8 %27, 2
  %29 = add i8 %28, %20
  %30 = tail call zeroext i8 @meta_cmp2int(i64 noundef %6, i64 noundef %24, i8 noundef zeroext 24)
  %31 = add i8 %29, %30
  %32 = tail call zeroext i8 @meta_cmp2int(i64 noundef %13, i64 noundef %24, i8 noundef zeroext 72)
  %33 = add i8 %31, %32
  store i8 %33, ptr %0, align 8, !tbaa !9
  %34 = zext i8 %33 to i64
  %35 = getelementptr inbounds [216 x i8], ptr @troika_fsm_map, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !12
  tail call void @meta_troika_unpack(ptr noundef nonnull %0, i8 noundef zeroext %36)
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @meta_cmp2int(i64 noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #0

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 = { inlinehint mustprogress nofree 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 #2 = { hot 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 = { nounwind willreturn memory(read) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"troika", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !11, i64 4, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass