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

; 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] }

@_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEvE9lookup_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 uwtable
define dso_local i16 @_ZNK3Ani4DofT15TetGeomSparsity8beginPosEv(ptr noundef nonnull align 1 dereferenceable(4) %0) #2 align 2 {
  %2 = alloca %"struct.Ani::DofT::TetGeomSparsity::Pos", align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  store i8 0, ptr %4, align 1, !tbaa !9
  br label %8

8:                                                ; preds = %50, %1
  %9 = load i8, ptr %4, align 1, !tbaa !9
  %10 = zext i8 %9 to i32
  %11 = icmp slt i32 %10, 4
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  store i32 2, ptr %5, align 4
  br label %53

13:                                               ; preds = %8
  %14 = load i8, ptr %4, align 1, !tbaa !9
  %15 = call noundef zeroext i1 @_ZNK3Ani4DofT15TetGeomSparsity5emptyEh(ptr noundef nonnull align 1 dereferenceable(4) %7, i8 noundef zeroext %14)
  br i1 %15, label %49, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  store i8 0, ptr %6, align 1, !tbaa !9
  br label %17

17:                                               ; preds = %43, %16
  %18 = load i8, ptr %6, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = load i8, ptr %4, align 1, !tbaa !9
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds [4 x i8], ptr @_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEvE9lookup_sz, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = zext i8 %23 to i32
  %25 = icmp slt i32 %19, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %17
  store i32 5, ptr %5, align 4
  br label %46

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

39:                                               ; preds = %27
  %40 = load i8, ptr %4, align 1, !tbaa !9
  %41 = load i8, ptr %6, align 1, !tbaa !9
  call void @_ZN3Ani4DofT15TetGeomSparsity3PosC2Ehh(ptr noundef nonnull align 1 dereferenceable(2) %2, i8 noundef zeroext %40, i8 noundef zeroext %41)
  store i32 1, ptr %5, align 4
  br label %46

42:                                               ; preds = %27
  br label %43

43:                                               ; preds = %42
  %44 = load i8, ptr %6, align 1, !tbaa !9
  %45 = add i8 %44, 1
  store i8 %45, ptr %6, align 1, !tbaa !9
  br label %17, !llvm.loop !10

46:                                               ; preds = %39, %26
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %47 = load i32, ptr %5, align 4
  switch i32 %47, label %53 [
    i32 5, label %48
  ]

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48, %13
  br label %50

50:                                               ; preds = %49
  %51 = load i8, ptr %4, align 1, !tbaa !9
  %52 = add i8 %51, 1
  store i8 %52, ptr %4, align 1, !tbaa !9
  br label %8, !llvm.loop !12

53:                                               ; preds = %46, %12
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  %54 = load i32, ptr %5, align 4
  switch i32 %54, label %59 [
    i32 2, label %55
    i32 1, label %57
  ]

55:                                               ; preds = %53
  %56 = call i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4) %7)
  store i16 %56, ptr %2, align 1
  br label %57

57:                                               ; preds = %55, %53
  %58 = load i16, ptr %2, align 1
  ret i16 %58

59:                                               ; preds = %53
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3Ani4DofT15TetGeomSparsity5emptyEh(ptr noundef nonnull align 1 dereferenceable(4), i8 noundef zeroext) #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

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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEvE9lookup_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
define dso_local i16 @_ZNK3Ani4DofT15TetGeomSparsity8beginPosEv(ptr noundef nonnull align 1 dereferenceable(4) %0) local_unnamed_addr #0 align 2 {
  %2 = alloca %"struct.Ani::DofT::TetGeomSparsity::Pos", align 2
  %3 = tail call noundef zeroext i1 @_ZNK3Ani4DofT15TetGeomSparsity5emptyEh(ptr noundef nonnull align 1 dereferenceable(4) %0, i8 noundef zeroext 0)
  br i1 %3, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %4 = load i8, ptr @_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEvE9lookup_sz, align 1, !tbaa !5
  %.not1523.not = icmp eq i8 %4, 0
  br i1 %.not1523.not, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext i8 %4 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %10
  %indvars.iv = phi i32 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %10 ]
  %5 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm4EEixEm(ptr noundef nonnull align 1 dereferenceable(4) %0, i64 noundef 0) #1
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = zext i8 %6 to i32
  %8 = shl nuw i32 1, %indvars.iv
  %9 = and i32 %8, %7
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %.loopexit34

10:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
  %exitcond.not = icmp eq i32 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !8

.loopexit:                                        ; preds = %10, %.preheader, %1
  %11 = tail call noundef zeroext i1 @_ZNK3Ani4DofT15TetGeomSparsity5emptyEh(ptr noundef nonnull align 1 dereferenceable(4) %0, i8 noundef zeroext 1)
  br i1 %11, label %.loopexit.1, label %.preheader.1

.preheader.1:                                     ; preds = %.loopexit
  %12 = load i8, ptr getelementptr inbounds (i8, ptr @_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEvE9lookup_sz, i64 1), align 1, !tbaa !5
  %.not1523.not.1 = icmp eq i8 %12, 0
  br i1 %.not1523.not.1, label %.loopexit.1, label %.lr.ph.preheader.1

.lr.ph.preheader.1:                               ; preds = %.preheader.1
  %wide.trip.count.1 = zext i8 %12 to i32
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %18, %.lr.ph.preheader.1
  %indvars.iv.1 = phi i32 [ 0, %.lr.ph.preheader.1 ], [ %indvars.iv.next.1, %18 ]
  %13 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm4EEixEm(ptr noundef nonnull align 1 dereferenceable(4) %0, i64 noundef 1) #1
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = shl nuw i32 1, %indvars.iv.1
  %17 = and i32 %16, %15
  %.not.1 = icmp eq i32 %17, 0
  br i1 %.not.1, label %18, label %.loopexit34

18:                                               ; preds = %.lr.ph.1
  %indvars.iv.next.1 = add nuw nsw i32 %indvars.iv.1, 1
  %exitcond.1.not = icmp eq i32 %indvars.iv.next.1, %wide.trip.count.1
  br i1 %exitcond.1.not, label %.loopexit.1, label %.lr.ph.1, !llvm.loop !8

.loopexit.1:                                      ; preds = %18, %.preheader.1, %.loopexit
  %19 = tail call noundef zeroext i1 @_ZNK3Ani4DofT15TetGeomSparsity5emptyEh(ptr noundef nonnull align 1 dereferenceable(4) %0, i8 noundef zeroext 2)
  br i1 %19, label %.loopexit.2, label %.preheader.2

.preheader.2:                                     ; preds = %.loopexit.1
  %20 = load i8, ptr getelementptr inbounds (i8, ptr @_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEvE9lookup_sz, i64 2), align 1, !tbaa !5
  %.not1523.not.2 = icmp eq i8 %20, 0
  br i1 %.not1523.not.2, label %.loopexit.2, label %.lr.ph.preheader.2

.lr.ph.preheader.2:                               ; preds = %.preheader.2
  %wide.trip.count.2 = zext i8 %20 to i32
  br label %.lr.ph.2

.lr.ph.2:                                         ; preds = %26, %.lr.ph.preheader.2
  %indvars.iv.2 = phi i32 [ 0, %.lr.ph.preheader.2 ], [ %indvars.iv.next.2, %26 ]
  %21 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm4EEixEm(ptr noundef nonnull align 1 dereferenceable(4) %0, i64 noundef 2) #1
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = zext i8 %22 to i32
  %24 = shl nuw i32 1, %indvars.iv.2
  %25 = and i32 %24, %23
  %.not.2 = icmp eq i32 %25, 0
  br i1 %.not.2, label %26, label %.loopexit34

26:                                               ; preds = %.lr.ph.2
  %indvars.iv.next.2 = add nuw nsw i32 %indvars.iv.2, 1
  %exitcond.2.not = icmp eq i32 %indvars.iv.next.2, %wide.trip.count.2
  br i1 %exitcond.2.not, label %.loopexit.2, label %.lr.ph.2, !llvm.loop !8

.loopexit.2:                                      ; preds = %26, %.preheader.2, %.loopexit.1
  %27 = tail call noundef zeroext i1 @_ZNK3Ani4DofT15TetGeomSparsity5emptyEh(ptr noundef nonnull align 1 dereferenceable(4) %0, i8 noundef zeroext 3)
  br i1 %27, label %.loopexit.3, label %.preheader.3

.preheader.3:                                     ; preds = %.loopexit.2
  %28 = load i8, ptr getelementptr inbounds (i8, ptr @_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEvE9lookup_sz, i64 3), align 1, !tbaa !5
  %.not1523.not.3 = icmp eq i8 %28, 0
  br i1 %.not1523.not.3, label %.loopexit.3, label %.lr.ph.preheader.3

.lr.ph.preheader.3:                               ; preds = %.preheader.3
  %wide.trip.count.3 = zext i8 %28 to i32
  br label %.lr.ph.3

.lr.ph.3:                                         ; preds = %34, %.lr.ph.preheader.3
  %indvars.iv.3 = phi i32 [ 0, %.lr.ph.preheader.3 ], [ %indvars.iv.next.3, %34 ]
  %29 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm4EEixEm(ptr noundef nonnull align 1 dereferenceable(4) %0, i64 noundef 3) #1
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = zext i8 %30 to i32
  %32 = shl nuw i32 1, %indvars.iv.3
  %33 = and i32 %32, %31
  %.not.3 = icmp eq i32 %33, 0
  br i1 %.not.3, label %34, label %.loopexit34

34:                                               ; preds = %.lr.ph.3
  %indvars.iv.next.3 = add nuw nsw i32 %indvars.iv.3, 1
  %exitcond.3.not = icmp eq i32 %indvars.iv.next.3, %wide.trip.count.3
  br i1 %exitcond.3.not, label %.loopexit.3, label %.lr.ph.3, !llvm.loop !8

.loopexit.3:                                      ; preds = %34, %.preheader.3, %.loopexit.2
  %35 = tail call i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4) %0)
  br label %37

.loopexit34:                                      ; preds = %.lr.ph, %.lr.ph.1, %.lr.ph.2, %.lr.ph.3
  %.01325.lcssa.wide = phi i8 [ 3, %.lr.ph.3 ], [ 2, %.lr.ph.2 ], [ 1, %.lr.ph.1 ], [ 0, %.lr.ph ]
  %.024.lcssa.wide = phi i32 [ %indvars.iv.3, %.lr.ph.3 ], [ %indvars.iv.2, %.lr.ph.2 ], [ %indvars.iv.1, %.lr.ph.1 ], [ %indvars.iv, %.lr.ph ]
  %36 = trunc nuw i32 %.024.lcssa.wide to i8
  call void @_ZN3Ani4DofT15TetGeomSparsity3PosC2Ehh(ptr noundef nonnull align 1 dereferenceable(2) %2, i8 noundef zeroext %.01325.lcssa.wide, i8 noundef zeroext %36)
  %.pre = load i16, ptr %2, align 2
  br label %37

37:                                               ; preds = %.loopexit34, %.loopexit.3
  %38 = phi i16 [ %.pre, %.loopexit34 ], [ %35, %.loopexit.3 ]
  ret i16 %38
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3Ani4DofT15TetGeomSparsity5emptyEh(ptr noundef nonnull align 1 dereferenceable(4), i8 noundef zeroext) 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

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


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