; LLVM IR from INMOST-DEV/INMOST-FEM :: anifem++/fem/tetdofmap.ll (ZNK3Ani4DofT15TetGeomSparsity7nextPosENS1_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] }

@_ZZNK3Ani4DofT15TetGeomSparsity7nextPosENS1_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 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 @_ZNK3Ani4DofT15TetGeomSparsity7nextPosENS1_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
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  store i16 %1, ptr %4, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  %11 = call noundef zeroext i1 @_ZN3Ani4DofT15TetGeomSparsity3Pos7isValidEv(ptr noundef nonnull align 1 dereferenceable(2) %4)
  br i1 %11, label %14, label %12

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

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

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

30:                                               ; preds = %20
  store i32 2, ptr %7, align 4
  br label %52

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

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

48:                                               ; preds = %31
  br label %49

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

52:                                               ; preds = %44, %30
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %53 = load i32, ptr %7, align 4
  switch i32 %53, label %111 [
    i32 2, label %54
    i32 1, label %109
  ]

54:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %55 = getelementptr inbounds %"struct.Ani::DofT::TetGeomSparsity::Pos", ptr %4, i32 0, i32 0
  %56 = load i8, ptr %55, align 1, !tbaa !12
  %57 = zext i8 %56 to i32
  %58 = add nsw i32 %57, 1
  %59 = trunc i32 %58 to i8
  store i8 %59, ptr %8, align 1, !tbaa !11
  br label %60

60:                                               ; preds = %102, %54
  %61 = load i8, ptr %8, align 1, !tbaa !11
  %62 = zext i8 %61 to i32
  %63 = icmp slt i32 %62, 4
  br i1 %63, label %65, label %64

64:                                               ; preds = %60
  store i32 5, ptr %7, align 4
  br label %105

65:                                               ; preds = %60
  %66 = load i8, ptr %8, align 1, !tbaa !11
  %67 = call noundef zeroext i1 @_ZNK3Ani4DofT15TetGeomSparsity5emptyEh(ptr noundef nonnull align 1 dereferenceable(4) %10, i8 noundef zeroext %66)
  br i1 %67, label %101, label %68

68:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  store i8 0, ptr %9, align 1, !tbaa !11
  br label %69

69:                                               ; preds = %95, %68
  %70 = load i8, ptr %9, align 1, !tbaa !11
  %71 = zext i8 %70 to i32
  %72 = load i8, ptr %8, align 1, !tbaa !11
  %73 = zext i8 %72 to i64
  %74 = getelementptr inbounds [4 x i8], ptr @_ZZNK3Ani4DofT15TetGeomSparsity7nextPosENS1_3PosEE9lookup_sz, i64 0, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !11
  %76 = zext i8 %75 to i32
  %77 = icmp slt i32 %71, %76
  br i1 %77, label %79, label %78

78:                                               ; preds = %69
  store i32 8, ptr %7, align 4
  br label %98

79:                                               ; preds = %69
  %80 = getelementptr inbounds %"struct.Ani::DofT::TetGeomSparsity", ptr %10, i32 0, i32 0
  %81 = load i8, ptr %8, align 1, !tbaa !11
  %82 = zext i8 %81 to i64
  %83 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm4EEixEm(ptr noundef nonnull align 1 dereferenceable(4) %80, i64 noundef %82) #3
  %84 = load i8, ptr %83, align 1, !tbaa !11
  %85 = zext i8 %84 to i32
  %86 = load i8, ptr %9, align 1, !tbaa !11
  %87 = zext i8 %86 to i32
  %88 = shl i32 1, %87
  %89 = and i32 %85, %88
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %91, label %94

91:                                               ; preds = %79
  %92 = load i8, ptr %8, align 1, !tbaa !11
  %93 = load i8, ptr %9, align 1, !tbaa !11
  call void @_ZN3Ani4DofT15TetGeomSparsity3PosC2Ehh(ptr noundef nonnull align 1 dereferenceable(2) %3, i8 noundef zeroext %92, i8 noundef zeroext %93)
  store i32 1, ptr %7, align 4
  br label %98

94:                                               ; preds = %79
  br label %95

95:                                               ; preds = %94
  %96 = load i8, ptr %9, align 1, !tbaa !11
  %97 = add i8 %96, 1
  store i8 %97, ptr %9, align 1, !tbaa !11
  br label %69, !llvm.loop !15

98:                                               ; preds = %91, %78
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  %99 = load i32, ptr %7, align 4
  switch i32 %99, label %105 [
    i32 8, label %100
  ]

100:                                              ; preds = %98
  br label %101

101:                                              ; preds = %100, %65
  br label %102

102:                                              ; preds = %101
  %103 = load i8, ptr %8, align 1, !tbaa !11
  %104 = add i8 %103, 1
  store i8 %104, ptr %8, align 1, !tbaa !11
  br label %60, !llvm.loop !16

105:                                              ; preds = %98, %64
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  %106 = load i32, ptr %7, align 4
  switch i32 %106, label %111 [
    i32 5, label %107
    i32 1, label %109
  ]

107:                                              ; preds = %105
  %108 = call i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4) %10)
  store i16 %108, ptr %3, align 1
  br label %109

109:                                              ; preds = %107, %105, %52, %12
  %110 = load i16, ptr %3, align 1
  ret i16 %110

111:                                              ; preds = %105, %52
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3Ani4DofT15TetGeomSparsity3Pos7isValidEv(ptr noundef nonnull align 1 dereferenceable(2)) #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 = !{!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"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@_ZZNK3Ani4DofT15TetGeomSparsity7nextPosENS1_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 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 @_ZNK3Ani4DofT15TetGeomSparsity7nextPosENS1_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)
  store i16 %7, ptr %3, align 2
  br label %43

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
  %.019.in = phi i8 [ %10, %8 ], [ %.019, %17 ]
  %.019 = add i8 %.019.in, 1
  %12 = load i8, ptr %4, align 2, !tbaa !9
  %13 = zext i8 %12 to i64
  %14 = getelementptr inbounds [4 x i8], ptr @_ZZNK3Ani4DofT15TetGeomSparsity7nextPosENS1_3PosEE9lookup_sz, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !10
  %16 = icmp ult i8 %.019, %15
  br i1 %16, label %17, label %26

17:                                               ; preds = %11
  %18 = zext nneg i8 %.019 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 %.019)
  br label %43

26:                                               ; preds = %11
  %.01740 = add i8 %12, 1
  %27 = icmp ult i8 %.01740, 4
  br i1 %27, label %.lr.ph42.preheader, label %._crit_edge

.lr.ph42.preheader:                               ; preds = %26
  %28 = zext nneg i8 %.01740 to i64
  br label %.lr.ph42

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %.loopexit
  %indvars.iv47 = phi i64 [ %28, %.lr.ph42.preheader ], [ %indvars.iv.next48, %.loopexit ]
  %29 = trunc nuw nsw i64 %indvars.iv47 to i8
  %30 = call noundef zeroext i1 @_ZNK3Ani4DofT15TetGeomSparsity5emptyEh(ptr noundef nonnull align 1 dereferenceable(4) %0, i8 noundef zeroext %29)
  br i1 %30, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.lr.ph42
  %31 = getelementptr inbounds [4 x i8], ptr @_ZZNK3Ani4DofT15TetGeomSparsity7nextPosENS1_3PosEE9lookup_sz, i64 0, i64 %indvars.iv47
  %32 = load i8, ptr %31, align 1, !tbaa !10
  %.not2338.not = icmp eq i8 %32, 0
  br i1 %.not2338.not, label %.loopexit, label %.lr.ph.preheader

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %38
  %indvars.iv = phi i32 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %38 ]
  %33 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt5arrayIhLm4EEixEm(ptr noundef nonnull align 1 dereferenceable(4) %0, i64 noundef %indvars.iv47) #1
  %34 = load i8, ptr %33, align 1, !tbaa !10
  %35 = zext i8 %34 to i32
  %36 = shl nuw i32 1, %indvars.iv
  %37 = and i32 %36, %35
  %.not22 = icmp eq i32 %37, 0
  br i1 %.not22, label %38, label %40

38:                                               ; 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 !13

.loopexit:                                        ; preds = %38, %.preheader, %.lr.ph42
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %39 = and i64 %indvars.iv.next48, 255
  %exitcond50.not = icmp eq i64 %39, 4
  br i1 %exitcond50.not, label %._crit_edge, label %.lr.ph42, !llvm.loop !14

40:                                               ; preds = %.lr.ph
  %41 = trunc nuw i32 %indvars.iv to i8
  call void @_ZN3Ani4DofT15TetGeomSparsity3PosC2Ehh(ptr noundef nonnull align 1 dereferenceable(2) %3, i8 noundef zeroext %29, i8 noundef zeroext %41)
  br label %43

._crit_edge:                                      ; preds = %.loopexit, %26
  %42 = call i16 @_ZNK3Ani4DofT15TetGeomSparsity6endPosEv(ptr noundef nonnull align 1 dereferenceable(4) %0)
  store i16 %42, ptr %3, align 2
  br label %43

43:                                               ; preds = %40, %24, %._crit_edge, %6
  %44 = load i16, ptr %3, align 2
  ret i16 %44
}

; 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

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"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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