; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseStatistic.ll (ZN4Simd4Base9SquareSumEPKhmmmPm)

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

@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base9SquareSumEPKhmmmPm = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base9SquareSumEPKhmmmPm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %15 = load i64, ptr %8, align 8, !tbaa !9
  %16 = icmp ult i64 %15, 65536
  br i1 %16, label %17, label %18

17:                                               ; preds = %5
  br label %20

18:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 126, ptr noundef @__PRETTY_FUNCTION__._ZN4Simd4Base9SquareSumEPKhmmmPm) #4
  unreachable

19:                                               ; No predecessors!
  br label %20

20:                                               ; preds = %19, %17
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  store i64 0, ptr %21, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %54, %20
  %23 = load i64, ptr %11, align 8, !tbaa !9
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %57

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %42, %27
  %29 = load i64, ptr %14, align 8, !tbaa !9
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %45

33:                                               ; preds = %28
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %14, align 8, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %34, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = zext i8 %37 to i32
  %39 = call noundef i32 @_ZN4Simd4Base6SquareEi(i32 noundef %38)
  %40 = load i32, ptr %13, align 4, !tbaa !11
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %13, align 4, !tbaa !11
  br label %42

42:                                               ; preds = %33
  %43 = load i64, ptr %14, align 8, !tbaa !9
  %44 = add i64 %43, 1
  store i64 %44, ptr %14, align 8, !tbaa !9
  br label %28, !llvm.loop !14

45:                                               ; preds = %32
  %46 = load i32, ptr %13, align 4, !tbaa !11
  %47 = sext i32 %46 to i64
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = add i64 %49, %47
  store i64 %50, ptr %48, align 8, !tbaa !9
  %51 = load i64, ptr %7, align 8, !tbaa !9
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 %51
  store ptr %53, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %54

54:                                               ; preds = %45
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %11, align 8, !tbaa !9
  br label %22, !llvm.loop !16

57:                                               ; preds = %26
  ret void
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base6SquareEi(i32 noundef) #3

attributes #0 = { noreturn nounwind "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 = { 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 = { alwaysinline 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 #4 = { noreturn nounwind }
attributes #5 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base9SquareSumEPKhmmmPm = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base9SquareSumEPKhmmmPm(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef %4) local_unnamed_addr #1 {
  %6 = icmp ult i64 %2, 65536
  br i1 %6, label %8, label %7

7:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 126, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Simd4Base9SquareSumEPKhmmmPm) #3
  unreachable

8:                                                ; preds = %5
  store i64 0, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  %.not23 = icmp eq i64 %2, 0
  %or.cond = or i1 %.not, %.not23
  br i1 %or.cond, label %._crit_edge22, label %.preheader.us

.preheader.us:                                    ; preds = %8, %._crit_edge.us
  %.01521.us = phi i64 [ %20, %._crit_edge.us ], [ 0, %8 ]
  %.01620.us = phi ptr [ %19, %._crit_edge.us ], [ %0, %8 ]
  br label %9

9:                                                ; preds = %.preheader.us, %9
  %.019.us = phi i64 [ 0, %.preheader.us ], [ %15, %9 ]
  %.01418.us = phi i32 [ 0, %.preheader.us ], [ %14, %9 ]
  %10 = getelementptr inbounds i8, ptr %.01620.us, i64 %.019.us
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = tail call noundef i32 @_ZN4Simd4Base6SquareEi(i32 noundef %12)
  %14 = add nsw i32 %13, %.01418.us
  %15 = add nuw i64 %.019.us, 1
  %exitcond.not = icmp eq i64 %15, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %9, !llvm.loop !10

._crit_edge.us:                                   ; preds = %9
  %16 = sext i32 %14 to i64
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = add i64 %17, %16
  store i64 %18, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.01620.us, i64 %1
  %20 = add nuw i64 %.01521.us, 1
  %exitcond24.not = icmp eq i64 %20, %3
  br i1 %exitcond24.not, label %._crit_edge22, label %.preheader.us, !llvm.loop !12

._crit_edge22:                                    ; preds = %._crit_edge.us, %8
  ret void
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base6SquareEi(i32 noundef) local_unnamed_addr #2

attributes #0 = { noreturn nounwind "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 = { 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 = { alwaysinline 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 #3 = { noreturn 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 = !{!"long", !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}


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