; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseSobel.ll (ZN4Simd4Base13SobelDyAbsSumEPKhmmmPm)

; 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 [75 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base13SobelDyAbsSumEPKhmmmPm = external hidden unnamed_addr constant [84 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 @_ZN4Simd4Base13SobelDyAbsSumEPKhmmmPm(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 ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  %17 = 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
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = icmp ugt i64 %18, 1
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  br label %23

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

22:                                               ; No predecessors!
  br label %23

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

25:                                               ; preds = %99, %23
  %26 = load i64, ptr %14, align 8, !tbaa !9
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 2, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %102

30:                                               ; preds = %25
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = load i64, ptr %14, align 8, !tbaa !9
  %34 = sub i64 %33, 1
  %35 = mul i64 %32, %34
  %36 = getelementptr inbounds i8, ptr %31, i64 %35
  store ptr %36, ptr %11, align 8, !tbaa !5
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  store ptr %39, ptr %12, align 8, !tbaa !5
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  store ptr %42, ptr %13, align 8, !tbaa !5
  %43 = load i64, ptr %14, align 8, !tbaa !9
  %44 = icmp eq i64 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %30
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %46, ptr %11, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %45, %30
  %48 = load i64, ptr %14, align 8, !tbaa !9
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = sub i64 %49, 1
  %51 = icmp eq i64 %48, %50
  br i1 %51, label %52, label %54

52:                                               ; preds = %47
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %53, ptr %13, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %52, %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  store i64 0, ptr %16, align 8, !tbaa !9
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = call noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef %55, ptr noundef %56, i64 noundef 0, i64 noundef 0, i64 noundef 1)
  %58 = sext i32 %57 to i64
  %59 = load i64, ptr %16, align 8, !tbaa !9
  %60 = add i64 %59, %58
  store i64 %60, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  store i64 1, ptr %17, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %79, %54
  %62 = load i64, ptr %17, align 8, !tbaa !9
  %63 = load i64, ptr %8, align 8, !tbaa !9
  %64 = sub i64 %63, 1
  %65 = icmp ult i64 %62, %64
  br i1 %65, label %67, label %66

66:                                               ; preds = %61
  store i32 5, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  br label %82

67:                                               ; preds = %61
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = load i64, ptr %17, align 8, !tbaa !9
  %71 = sub i64 %70, 1
  %72 = load i64, ptr %17, align 8, !tbaa !9
  %73 = load i64, ptr %17, align 8, !tbaa !9
  %74 = add i64 %73, 1
  %75 = call noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef %68, ptr noundef %69, i64 noundef %71, i64 noundef %72, i64 noundef %74)
  %76 = sext i32 %75 to i64
  %77 = load i64, ptr %16, align 8, !tbaa !9
  %78 = add i64 %77, %76
  store i64 %78, ptr %16, align 8, !tbaa !9
  br label %79

79:                                               ; preds = %67
  %80 = load i64, ptr %17, align 8, !tbaa !9
  %81 = add i64 %80, 1
  store i64 %81, ptr %17, align 8, !tbaa !9
  br label %61, !llvm.loop !11

82:                                               ; preds = %66
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  %85 = load i64, ptr %8, align 8, !tbaa !9
  %86 = sub i64 %85, 2
  %87 = load i64, ptr %8, align 8, !tbaa !9
  %88 = sub i64 %87, 1
  %89 = load i64, ptr %8, align 8, !tbaa !9
  %90 = sub i64 %89, 1
  %91 = call noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef %83, ptr noundef %84, i64 noundef %86, i64 noundef %88, i64 noundef %90)
  %92 = sext i32 %91 to i64
  %93 = load i64, ptr %16, align 8, !tbaa !9
  %94 = add i64 %93, %92
  store i64 %94, ptr %16, align 8, !tbaa !9
  %95 = load i64, ptr %16, align 8, !tbaa !9
  %96 = load ptr, ptr %10, align 8, !tbaa !5
  %97 = load i64, ptr %96, align 8, !tbaa !9
  %98 = add i64 %97, %95
  store i64 %98, ptr %96, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %99

99:                                               ; preds = %82
  %100 = load i64, ptr %14, align 8, !tbaa !9
  %101 = add i64 %100, 1
  store i64 %101, ptr %14, align 8, !tbaa !9
  br label %25, !llvm.loop !13

102:                                              ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret void
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 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 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 [75 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base13SobelDyAbsSumEPKhmmmPm = external hidden unnamed_addr constant [84 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 uwtable
define dso_local void @_ZN4Simd4Base13SobelDyAbsSumEPKhmmmPm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef %4) local_unnamed_addr #1 {
  %6 = icmp ugt i64 %2, 1
  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 172, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Simd4Base13SobelDyAbsSumEPKhmmmPm) #3
  unreachable

8:                                                ; preds = %5
  store i64 0, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge49, label %.lr.ph48

.lr.ph48:                                         ; preds = %8
  %9 = add i64 %3, -1
  %10 = add i64 %2, -1
  %11 = icmp ugt i64 %10, 1
  %12 = add i64 %2, -2
  br i1 %11, label %.lr.ph.us, label %.lr.ph48.split.preheader

.lr.ph48.split.preheader:                         ; preds = %.lr.ph48
  %13 = icmp eq i64 %9, 0
  %.038.idx.peel = select i1 %13, i64 0, i64 %1
  %.038.peel = getelementptr inbounds i8, ptr %0, i64 %.038.idx.peel
  %14 = tail call noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef %0, ptr noundef %.038.peel, i64 noundef 0, i64 noundef 0, i64 noundef 1)
  %15 = sext i32 %14 to i64
  %16 = tail call noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef %0, ptr noundef %.038.peel, i64 noundef %12, i64 noundef %10, i64 noundef %10)
  %17 = sext i32 %16 to i64
  %18 = add nsw i64 %17, %15
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = add i64 %18, %19
  store i64 %20, ptr %4, align 8, !tbaa !5
  %exitcond.peel.not = icmp eq i64 %3, 1
  br i1 %exitcond.peel.not, label %._crit_edge49, label %.lr.ph48.split

.lr.ph.us:                                        ; preds = %.lr.ph48, %._crit_edge.us
  %.03746.us = phi i64 [ %40, %._crit_edge.us ], [ 0, %.lr.ph48 ]
  %21 = add i64 %.03746.us, -1
  %22 = mul i64 %21, %1
  %23 = getelementptr inbounds i8, ptr %0, i64 %22
  %24 = getelementptr inbounds i8, ptr %23, i64 %1
  %25 = icmp eq i64 %.03746.us, 0
  %spec.select.us = select i1 %25, ptr %24, ptr %23
  %26 = icmp eq i64 %.03746.us, %9
  %.038.idx.us = select i1 %26, i64 0, i64 %1
  %.038.us = getelementptr inbounds i8, ptr %24, i64 %.038.idx.us
  %27 = tail call noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef %spec.select.us, ptr noundef %.038.us, i64 noundef 0, i64 noundef 0, i64 noundef 1)
  %28 = sext i32 %27 to i64
  br label %29

29:                                               ; preds = %.lr.ph.us, %29
  %.044.us = phi i64 [ 1, %.lr.ph.us ], [ %31, %29 ]
  %.03643.us = phi i64 [ %28, %.lr.ph.us ], [ %34, %29 ]
  %30 = add i64 %.044.us, -1
  %31 = add nuw i64 %.044.us, 1
  %32 = tail call noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef %spec.select.us, ptr noundef %.038.us, i64 noundef %30, i64 noundef %.044.us, i64 noundef %31)
  %33 = sext i32 %32 to i64
  %34 = add i64 %.03643.us, %33
  %exitcond52.not = icmp eq i64 %31, %10
  br i1 %exitcond52.not, label %._crit_edge.us, label %29, !llvm.loop !9

._crit_edge.us:                                   ; preds = %29
  %35 = tail call noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef %spec.select.us, ptr noundef %.038.us, i64 noundef %12, i64 noundef %10, i64 noundef %10)
  %36 = sext i32 %35 to i64
  %37 = add i64 %34, %36
  %38 = load i64, ptr %4, align 8, !tbaa !5
  %39 = add i64 %37, %38
  store i64 %39, ptr %4, align 8, !tbaa !5
  %40 = add nuw i64 %.03746.us, 1
  %exitcond53.not = icmp eq i64 %40, %3
  br i1 %exitcond53.not, label %._crit_edge49, label %.lr.ph.us, !llvm.loop !11

._crit_edge49:                                    ; preds = %.lr.ph48.split, %._crit_edge.us, %.lr.ph48.split.preheader, %8
  ret void

.lr.ph48.split:                                   ; preds = %.lr.ph48.split.preheader, %.lr.ph48.split
  %.03746 = phi i64 [ %53, %.lr.ph48.split ], [ 1, %.lr.ph48.split.preheader ]
  %41 = add i64 %.03746, -1
  %42 = mul i64 %41, %1
  %43 = getelementptr inbounds i8, ptr %0, i64 %42
  %44 = getelementptr inbounds i8, ptr %43, i64 %1
  %45 = icmp eq i64 %.03746, %9
  %.038.idx = select i1 %45, i64 0, i64 %1
  %.038 = getelementptr inbounds i8, ptr %44, i64 %.038.idx
  %46 = tail call noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef %43, ptr noundef %.038, i64 noundef 0, i64 noundef 0, i64 noundef 1)
  %47 = sext i32 %46 to i64
  %48 = tail call noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef %43, ptr noundef %.038, i64 noundef %12, i64 noundef %10, i64 noundef %10)
  %49 = sext i32 %48 to i64
  %50 = add nsw i64 %49, %47
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = add i64 %50, %51
  store i64 %52, ptr %4, align 8, !tbaa !5
  %53 = add nuw i64 %.03746, 1
  %exitcond.not = icmp eq i64 %53, %3
  br i1 %exitcond.not, label %._crit_edge49, label %.lr.ph48.split, !llvm.loop !12
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base7SobelDyILb1EEEiPKhS3_mmm(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 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 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 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10, !13}
!13 = !{!"llvm.loop.peeled.count", i32 1}


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