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

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

@_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEhE9lookup_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 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

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

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

14:                                               ; preds = %40, %13
  %15 = load i8, ptr %7, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = load i8, ptr %6, align 1, !tbaa !9
  %18 = zext i8 %17 to i64
  %19 = getelementptr inbounds [4 x i8], ptr @_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEhE9lookup_sz, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = icmp slt i32 %16, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %14
  store i32 2, ptr %8, align 4
  br label %43

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

36:                                               ; preds = %24
  %37 = load i8, ptr %6, align 1, !tbaa !9
  %38 = load i8, ptr %7, align 1, !tbaa !9
  call void @_ZN3Ani4DofT15TetGeomSparsity3PosC2Ehh(ptr noundef nonnull align 1 dereferenceable(2) %3, i8 noundef zeroext %37, i8 noundef zeroext %38)
  store i32 1, ptr %8, align 4
  br label %43

39:                                               ; preds = %24
  br label %40

40:                                               ; preds = %39
  %41 = load i8, ptr %7, align 1, !tbaa !9
  %42 = add i8 %41, 1
  store i8 %42, ptr %7, align 1, !tbaa !9
  br label %14, !llvm.loop !10

43:                                               ; preds = %36, %23
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  %44 = load i32, ptr %8, align 4
  switch i32 %44, label %48 [
    i32 2, label %45
  ]

45:                                               ; preds = %43
  br label %46

46:                                               ; preds = %45, %2
  %47 = call i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4) %9)
  store i16 %47, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %48

48:                                               ; preds = %46, %43
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %49 = load i16, ptr %3, align 1
  ret i16 %49
}

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


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

@_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEhE9lookup_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 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local i16 @_ZNK3Ani4DofT15TetGeomSparsity8beginPosEh(ptr noundef nonnull align 1 dereferenceable(4) %0, i8 noundef zeroext %1) local_unnamed_addr #0 align 2 {
  %3 = alloca %"struct.Ani::DofT::TetGeomSparsity::Pos", align 2
  %4 = tail call noundef zeroext i1 @_ZNK3Ani4DofT15TetGeomSparsity5emptyEh(ptr noundef nonnull align 1 dereferenceable(4) %0, i8 noundef zeroext %1)
  br i1 %4, label %.critedge, label %.preheader

.preheader:                                       ; preds = %2
  %5 = zext i8 %1 to i64
  %6 = getelementptr inbounds [4 x i8], ptr @_ZZNK3Ani4DofT15TetGeomSparsity8beginPosEhE9lookup_sz, i64 0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %.not1214.not = icmp eq i8 %7, 0
  br i1 %.not1214.not, label %.critedge, label %.lr.ph.preheader

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

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

13:                                               ; preds = %.lr.ph
  %14 = trunc nuw i32 %indvars.iv to i8
  call void @_ZN3Ani4DofT15TetGeomSparsity3PosC2Ehh(ptr noundef nonnull align 1 dereferenceable(2) %3, i8 noundef zeroext %1, i8 noundef zeroext %14)
  %.pre = load i16, ptr %3, align 2
  br label %17

15:                                               ; 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 %.critedge, label %.lr.ph, !llvm.loop !8

.critedge:                                        ; preds = %15, %.preheader, %2
  %16 = tail call i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4) %0)
  br label %17

17:                                               ; preds = %13, %.critedge
  %18 = phi i16 [ %.pre, %13 ], [ %16, %.critedge ]
  ret i16 %18
}

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