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

; 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__._ZN4Simd4Base14ValueSquareSumEPKhmmmPmS3_ = external hidden unnamed_addr constant [97 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: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base6SquareEi(i32 noundef) #2

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

21:                                               ; preds = %6
  br label %24

22:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 141, ptr noundef @__PRETTY_FUNCTION__._ZN4Simd4Base14ValueSquareSumEPKhmmmPmS3_) #4
  unreachable

23:                                               ; No predecessors!
  br label %24

24:                                               ; preds = %23, %21
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %25, align 8, !tbaa !9
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  store i64 0, ptr %26, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %68, %24
  %28 = load i64, ptr %13, align 8, !tbaa !9
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = icmp ult i64 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %71

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  store i32 0, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  store i32 0, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %51, %32
  %34 = load i64, ptr %17, align 8, !tbaa !9
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = icmp ult i64 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  br label %54

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i64, ptr %17, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = zext i8 %42 to i32
  store i32 %43, ptr %18, align 4, !tbaa !11
  %44 = load i32, ptr %18, align 4, !tbaa !11
  %45 = load i32, ptr %15, align 4, !tbaa !11
  %46 = add nsw i32 %45, %44
  store i32 %46, ptr %15, align 4, !tbaa !11
  %47 = load i32, ptr %18, align 4, !tbaa !11
  %48 = call noundef i32 @_ZN4Simd4Base6SquareEi(i32 noundef %47)
  %49 = load i32, ptr %16, align 4, !tbaa !11
  %50 = add nsw i32 %49, %48
  store i32 %50, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  br label %51

51:                                               ; preds = %38
  %52 = load i64, ptr %17, align 8, !tbaa !9
  %53 = add i64 %52, 1
  store i64 %53, ptr %17, align 8, !tbaa !9
  br label %33, !llvm.loop !14

54:                                               ; preds = %37
  %55 = load i32, ptr %15, align 4, !tbaa !11
  %56 = sext i32 %55 to i64
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = add i64 %58, %56
  store i64 %59, ptr %57, align 8, !tbaa !9
  %60 = load i32, ptr %16, align 4, !tbaa !11
  %61 = sext i32 %60 to i64
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = load i64, ptr %62, align 8, !tbaa !9
  %64 = add i64 %63, %61
  store i64 %64, ptr %62, align 8, !tbaa !9
  %65 = load i64, ptr %8, align 8, !tbaa !9
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 %65
  store ptr %67, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %68

68:                                               ; preds = %54
  %69 = load i64, ptr %13, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %13, align 8, !tbaa !9
  br label %27, !llvm.loop !16

71:                                               ; preds = %31
  ret void
}

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 = { 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 = { 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 #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__._ZN4Simd4Base14ValueSquareSumEPKhmmmPmS3_ = external hidden unnamed_addr constant [97 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: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base6SquareEi(i32 noundef) local_unnamed_addr #1

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

8:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 141, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Simd4Base14ValueSquareSumEPKhmmmPmS3_) #3
  unreachable

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

.preheader.us:                                    ; preds = %9, %._crit_edge.us
  %.030.us = phi ptr [ %24, %._crit_edge.us ], [ %0, %9 ]
  %.02329.us = phi i64 [ %25, %._crit_edge.us ], [ 0, %9 ]
  br label %10

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

._crit_edge.us:                                   ; preds = %10
  %18 = zext nneg i32 %14 to i64
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = add i64 %19, %18
  store i64 %20, ptr %4, align 8, !tbaa !5
  %21 = sext i32 %16 to i64
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = add i64 %22, %21
  store i64 %23, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.030.us, i64 %1
  %25 = add nuw i64 %.02329.us, 1
  %exitcond35.not = icmp eq i64 %25, %3
  br i1 %exitcond35.not, label %._crit_edge31, label %.preheader.us, !llvm.loop !12

._crit_edge31:                                    ; preds = %._crit_edge.us, %9
  ret void
}

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 = { 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 #2 = { 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: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass