; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseTexture.ll (ZN4Simd4Base23TextureGetDifferenceSumEPKhmmmS2_mS2_mPl)

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

; 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 uwtable
define dso_local void @_ZN4Simd4Base23TextureGetDifferenceSumEPKhmmmS2_mS2_mPl(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8) #1 {
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i64, align 8
  store ptr %0, ptr %10, align 8, !tbaa !5
  store i64 %1, ptr %11, align 8, !tbaa !9
  store i64 %2, ptr %12, align 8, !tbaa !9
  store i64 %3, ptr %13, align 8, !tbaa !9
  store ptr %4, ptr %14, align 8, !tbaa !5
  store i64 %5, ptr %15, align 8, !tbaa !9
  store ptr %6, ptr %16, align 8, !tbaa !5
  store i64 %7, ptr %17, align 8, !tbaa !9
  store ptr %8, ptr %18, align 8, !tbaa !5
  %23 = load ptr, ptr %18, align 8, !tbaa !5
  store i64 0, ptr %23, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  store i64 0, ptr %19, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %73, %9
  %25 = load i64, ptr %19, align 8, !tbaa !9
  %26 = load i64, ptr %13, align 8, !tbaa !9
  %27 = icmp ult i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 2, ptr %20, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  br label %76

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  store i32 0, ptr %21, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #3
  store i64 0, ptr %22, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %55, %29
  %31 = load i64, ptr %22, align 8, !tbaa !9
  %32 = load i64, ptr %12, align 8, !tbaa !9
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 5, ptr %20, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  br label %58

35:                                               ; preds = %30
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load i64, ptr %22, align 8, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %36, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = zext i8 %39 to i32
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  %42 = load i64, ptr %22, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %41, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !13
  %45 = zext i8 %44 to i32
  %46 = load ptr, ptr %16, align 8, !tbaa !5
  %47 = load i64, ptr %22, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !13
  %50 = zext i8 %49 to i32
  %51 = call noundef i32 @_ZN4Simd4Base7AverageEii(i32 noundef %45, i32 noundef %50)
  %52 = sub nsw i32 %40, %51
  %53 = load i32, ptr %21, align 4, !tbaa !11
  %54 = add nsw i32 %53, %52
  store i32 %54, ptr %21, align 4, !tbaa !11
  br label %55

55:                                               ; preds = %35
  %56 = load i64, ptr %22, align 8, !tbaa !9
  %57 = add i64 %56, 1
  store i64 %57, ptr %22, align 8, !tbaa !9
  br label %30, !llvm.loop !14

58:                                               ; preds = %34
  %59 = load i32, ptr %21, align 4, !tbaa !11
  %60 = sext i32 %59 to i64
  %61 = load ptr, ptr %18, align 8, !tbaa !5
  %62 = load i64, ptr %61, align 8, !tbaa !9
  %63 = add nsw i64 %62, %60
  store i64 %63, ptr %61, align 8, !tbaa !9
  %64 = load i64, ptr %11, align 8, !tbaa !9
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i64 %64
  store ptr %66, ptr %10, align 8, !tbaa !5
  %67 = load i64, ptr %15, align 8, !tbaa !9
  %68 = load ptr, ptr %14, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 %67
  store ptr %69, ptr %14, align 8, !tbaa !5
  %70 = load i64, ptr %17, align 8, !tbaa !9
  %71 = load ptr, ptr %16, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 %70
  store ptr %72, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  br label %73

73:                                               ; preds = %58
  %74 = load i64, ptr %19, align 8, !tbaa !9
  %75 = add i64 %74, 1
  store i64 %75, ptr %19, align 8, !tbaa !9
  br label %24, !llvm.loop !16

76:                                               ; preds = %28
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base23TextureGetDifferenceSumEPKhmmmS2_mS2_mPl(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef readonly %4, i64 noundef %5, ptr nocapture noundef readonly %6, i64 noundef %7, ptr nocapture noundef %8) local_unnamed_addr #0 {
  store i64 0, ptr %8, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  %.not33 = icmp eq i64 %2, 0
  %or.cond = or i1 %.not, %.not33
  br i1 %or.cond, label %._crit_edge32, label %.preheader.us

.preheader.us:                                    ; preds = %9, %._crit_edge.us
  %.02231.us = phi i64 [ %30, %._crit_edge.us ], [ 0, %9 ]
  %.02330.us = phi ptr [ %27, %._crit_edge.us ], [ %0, %9 ]
  %.02429.us = phi ptr [ %28, %._crit_edge.us ], [ %4, %9 ]
  %.02528.us = phi ptr [ %29, %._crit_edge.us ], [ %6, %9 ]
  br label %10

10:                                               ; preds = %.preheader.us, %10
  %.027.us = phi i64 [ 0, %.preheader.us ], [ %23, %10 ]
  %.02126.us = phi i32 [ 0, %.preheader.us ], [ %22, %10 ]
  %11 = getelementptr inbounds i8, ptr %.02330.us, i64 %.027.us
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = getelementptr inbounds i8, ptr %.02429.us, i64 %.027.us
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = getelementptr inbounds i8, ptr %.02528.us, i64 %.027.us
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = tail call noundef i32 @_ZN4Simd4Base7AverageEii(i32 noundef %16, i32 noundef %19)
  %21 = add i32 %.02126.us, %13
  %22 = sub i32 %21, %20
  %23 = add nuw i64 %.027.us, 1
  %exitcond.not = icmp eq i64 %23, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %10, !llvm.loop !10

._crit_edge.us:                                   ; preds = %10
  %24 = sext i32 %22 to i64
  %25 = load i64, ptr %8, align 8, !tbaa !5
  %26 = add nsw i64 %25, %24
  store i64 %26, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.02330.us, i64 %1
  %28 = getelementptr inbounds i8, ptr %.02429.us, i64 %5
  %29 = getelementptr inbounds i8, ptr %.02528.us, i64 %7
  %30 = add nuw i64 %.02231.us, 1
  %exitcond34.not = icmp eq i64 %30, %3
  br i1 %exitcond34.not, label %._crit_edge32, label %.preheader.us, !llvm.loop !12

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base7AverageEii(i32 noundef, i32 noundef) local_unnamed_addr #1

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

!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: CorrelatedValuePropagationPass,DSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass