; LLVM IR from INMOST-DEV/INMOST-FEM :: anifem++/fem/tetdofmap.ll (ZNK3Ani4DofT15TetGeomSparsity12nextPosOnDimENS1_3PosE)

; 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.Ani::DofT::TetGeomSparsity::Pos" = type { i8, i8 }
%"struct.Ani::DofT::TetGeomSparsity" = type { %"struct.std::array" }
%"struct.std::array" = type { [4 x i8] }

@_ZZNK3Ani4DofT15TetGeomSparsity12nextPosOnDimENS1_3PosEE9lookup_sz = external hidden constant [4 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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm4EEixEm(ptr noundef nonnull align 1 dereferenceable(4), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3Ani4DofT15TetGeomSparsity3PosC2Ehh(ptr noundef nonnull align 1 dereferenceable(2), i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3Ani4DofT15TetGeomSparsity3Pos7isValidEv(ptr noundef nonnull align 1 dereferenceable(2)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local i16 @_ZNK3Ani4DofT15TetGeomSparsity12nextPosOnDimENS1_3PosE(ptr noundef nonnull align 1 dereferenceable(4) %0, i16 %1) #2 align 2 {
  %3 = alloca %"struct.Ani::DofT::TetGeomSparsity::Pos", align 1
  %4 = alloca %"struct.Ani::DofT::TetGeomSparsity::Pos", align 1
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store i16 %1, ptr %4, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8
  %9 = call noundef zeroext i1 @_ZN3Ani4DofT15TetGeomSparsity3Pos7isValidEv(ptr noundef nonnull align 1 dereferenceable(2) %4)
  br i1 %9, label %12, label %10

10:                                               ; preds = %2
  %11 = call i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4) %8)
  store i16 %11, ptr %3, align 1
  br label %54

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %13 = getelementptr inbounds %"struct.Ani::DofT::TetGeomSparsity::Pos", ptr %4, i32 0, i32 1
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = zext i8 %14 to i32
  %16 = add nsw i32 %15, 1
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr %6, align 1, !tbaa !11
  br label %18

18:                                               ; preds = %47, %12
  %19 = load i8, ptr %6, align 1, !tbaa !11
  %20 = zext i8 %19 to i32
  %21 = getelementptr inbounds %"struct.Ani::DofT::TetGeomSparsity::Pos", ptr %4, i32 0, i32 0
  %22 = load i8, ptr %21, align 1, !tbaa !12
  %23 = zext i8 %22 to i64
  %24 = getelementptr inbounds [4 x i8], ptr @_ZZNK3Ani4DofT15TetGeomSparsity12nextPosOnDimENS1_3PosEE9lookup_sz, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = icmp slt i32 %20, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %18
  store i32 2, ptr %7, align 4
  br label %50

29:                                               ; preds = %18
  %30 = getelementptr inbounds %"struct.Ani::DofT::TetGeomSparsity", ptr %8, i32 0, i32 0
  %31 = getelementptr inbounds %"struct.Ani::DofT::TetGeomSparsity::Pos", ptr %4, i32 0, i32 0
  %32 = load i8, ptr %31, align 1, !tbaa !12
  %33 = zext i8 %32 to i64
  %34 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm4EEixEm(ptr noundef nonnull align 1 dereferenceable(4) %30, i64 noundef %33) #3
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = load i8, ptr %6, align 1, !tbaa !11
  %38 = zext i8 %37 to i32
  %39 = shl i32 1, %38
  %40 = and i32 %36, %39
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %46

42:                                               ; preds = %29
  %43 = getelementptr inbounds %"struct.Ani::DofT::TetGeomSparsity::Pos", ptr %4, i32 0, i32 0
  %44 = load i8, ptr %43, align 1, !tbaa !12
  %45 = load i8, ptr %6, align 1, !tbaa !11
  call void @_ZN3Ani4DofT15TetGeomSparsity3PosC2Ehh(ptr noundef nonnull align 1 dereferenceable(2) %3, i8 noundef zeroext %44, i8 noundef zeroext %45)
  store i32 1, ptr %7, align 4
  br label %50

46:                                               ; preds = %29
  br label %47

47:                                               ; preds = %46
  %48 = load i8, ptr %6, align 1, !tbaa !11
  %49 = add i8 %48, 1
  store i8 %49, ptr %6, align 1, !tbaa !11
  br label %18, !llvm.loop !13

50:                                               ; preds = %42, %28
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %51 = load i32, ptr %7, align 4
  switch i32 %51, label %56 [
    i32 2, label %52
    i32 1, label %54
  ]

52:                                               ; preds = %50
  %53 = call i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4) %8)
  store i16 %53, ptr %3, align 1
  br label %54

54:                                               ; preds = %52, %50, %10
  %55 = load i16, ptr %3, align 1
  ret i16 %55

56:                                               ; preds = %50
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !7, i64 1}
!10 = !{!"_ZTSN3Ani4DofT15TetGeomSparsity3PosE", !7, i64 0, !7, i64 1}
!11 = !{!7, !7, i64 0}
!12 = !{!10, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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.Ani::DofT::TetGeomSparsity::Pos" = type { i8, i8 }

@_ZZNK3Ani4DofT15TetGeomSparsity12nextPosOnDimENS1_3PosEE9lookup_sz = external hidden local_unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm4EEixEm(ptr noundef nonnull align 1 dereferenceable(4), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3Ani4DofT15TetGeomSparsity3PosC2Ehh(ptr noundef nonnull align 1 dereferenceable(2), i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3Ani4DofT15TetGeomSparsity3Pos7isValidEv(ptr noundef nonnull align 1 dereferenceable(2)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local i16 @_ZNK3Ani4DofT15TetGeomSparsity12nextPosOnDimENS1_3PosE(ptr noundef nonnull align 1 dereferenceable(4) %0, i16 %1) local_unnamed_addr #0 align 2 {
  %3 = alloca %"struct.Ani::DofT::TetGeomSparsity::Pos", align 2
  %4 = alloca %"struct.Ani::DofT::TetGeomSparsity::Pos", align 2
  store i16 %1, ptr %4, align 2
  %5 = call noundef zeroext i1 @_ZN3Ani4DofT15TetGeomSparsity3Pos7isValidEv(ptr noundef nonnull align 1 dereferenceable(2) %4)
  br i1 %5, label %8, label %6

6:                                                ; preds = %2
  %7 = call i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4) %0)
  br label %28

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %4, i64 1
  %10 = load i8, ptr %9, align 1, !tbaa !5
  br label %11

11:                                               ; preds = %17, %8
  %.05.in = phi i8 [ %10, %8 ], [ %.05, %17 ]
  %.05 = add i8 %.05.in, 1
  %12 = load i8, ptr %4, align 2, !tbaa !9
  %13 = zext i8 %12 to i64
  %14 = getelementptr inbounds [4 x i8], ptr @_ZZNK3Ani4DofT15TetGeomSparsity12nextPosOnDimENS1_3PosEE9lookup_sz, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !10
  %16 = icmp ult i8 %.05, %15
  br i1 %16, label %17, label %26

17:                                               ; preds = %11
  %18 = zext nneg i8 %.05 to i32
  %19 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm4EEixEm(ptr noundef nonnull align 1 dereferenceable(4) %0, i64 noundef %13) #1
  %20 = load i8, ptr %19, align 1, !tbaa !10
  %21 = zext i8 %20 to i32
  %22 = shl nuw i32 1, %18
  %23 = and i32 %22, %21
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %11, label %24, !llvm.loop !11

24:                                               ; preds = %17
  %25 = load i8, ptr %4, align 2, !tbaa !9
  call void @_ZN3Ani4DofT15TetGeomSparsity3PosC2Ehh(ptr noundef nonnull align 1 dereferenceable(2) %3, i8 noundef zeroext %25, i8 noundef zeroext %.05)
  %.pre = load i16, ptr %3, align 2
  br label %28

26:                                               ; preds = %11
  %27 = call i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4) %0)
  br label %28

28:                                               ; preds = %24, %26, %6
  %29 = phi i16 [ %.pre, %24 ], [ %27, %26 ], [ %7, %6 ]
  ret i16 %29
}

attributes #0 = { mustprogress 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 }

!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, !7, i64 1}
!6 = !{!"_ZTSN3Ani4DofT15TetGeomSparsity3PosE", !7, i64 0, !7, i64 1}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!6, !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass