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

; 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__._ZN4Simd4Base13SobelDxAbsSumEPKhmmmPm = 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: mustprogress uwtable
define dso_local void @_ZN4Simd4Base13SobelDxAbsSumEPKhmmmPm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #1 {
  %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 85, ptr noundef @__PRETTY_FUNCTION__._ZN4Simd4Base13SobelDxAbsSumEPKhmmmPm) #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 %12, align 8, !tbaa !5
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = call noundef i32 @_ZN4Simd4Base7SobelDxILb1EEEiPKhS3_S3_mm(ptr noundef %55, ptr noundef %56, ptr noundef %57, i64 noundef 0, i64 noundef 1)
  %59 = sext i32 %58 to i64
  %60 = load i64, ptr %16, align 8, !tbaa !9
  %61 = add i64 %60, %59
  store i64 %61, 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 %62

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

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

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

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

83:                                               ; preds = %67
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  %86 = load ptr, ptr %13, align 8, !tbaa !5
  %87 = load i64, ptr %8, align 8, !tbaa !9
  %88 = sub i64 %87, 2
  %89 = load i64, ptr %8, align 8, !tbaa !9
  %90 = sub i64 %89, 1
  %91 = call noundef i32 @_ZN4Simd4Base7SobelDxILb1EEEiPKhS3_S3_mm(ptr noundef %84, ptr noundef %85, ptr 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 = %83
  %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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base7SobelDxILb1EEEiPKhS3_S3_mm(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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__._ZN4Simd4Base13SobelDxAbsSumEPKhmmmPm = 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 @_ZN4Simd4Base13SobelDxAbsSumEPKhmmmPm(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 85, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Simd4Base13SobelDxAbsSumEPKhmmmPm) #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_edge50, label %.lr.ph49

.lr.ph49:                                         ; 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.ph49.split.preheader

.lr.ph49.split.preheader:                         ; preds = %.lr.ph49
  %13 = icmp eq i64 %9, 0
  %.039.idx.peel = select i1 %13, i64 0, i64 %1
  %.039.peel = getelementptr inbounds i8, ptr %0, i64 %.039.idx.peel
  %14 = tail call noundef i32 @_ZN4Simd4Base7SobelDxILb1EEEiPKhS3_S3_mm(ptr noundef %0, ptr noundef %0, ptr noundef %.039.peel, i64 noundef 0, i64 noundef 1)
  %15 = sext i32 %14 to i64
  %16 = tail call noundef i32 @_ZN4Simd4Base7SobelDxILb1EEEiPKhS3_S3_mm(ptr noundef %0, ptr noundef %0, ptr noundef %.039.peel, i64 noundef %12, 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_edge50, label %.lr.ph49.split

.lr.ph.us:                                        ; preds = %.lr.ph49, %._crit_edge.us
  %.03847.us = phi i64 [ %40, %._crit_edge.us ], [ 0, %.lr.ph49 ]
  %21 = add i64 %.03847.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 %.03847.us, 0
  %spec.select.us = select i1 %25, ptr %24, ptr %23
  %26 = icmp eq i64 %.03847.us, %9
  %.039.idx.us = select i1 %26, i64 0, i64 %1
  %.039.us = getelementptr inbounds i8, ptr %24, i64 %.039.idx.us
  %27 = tail call noundef i32 @_ZN4Simd4Base7SobelDxILb1EEEiPKhS3_S3_mm(ptr noundef %spec.select.us, ptr noundef %24, ptr noundef %.039.us, i64 noundef 0, i64 noundef 1)
  %28 = sext i32 %27 to i64
  br label %29

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

._crit_edge.us:                                   ; preds = %29
  %35 = tail call noundef i32 @_ZN4Simd4Base7SobelDxILb1EEEiPKhS3_S3_mm(ptr noundef %spec.select.us, ptr noundef %24, ptr noundef %.039.us, i64 noundef %12, 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 %.03847.us, 1
  %exitcond54.not = icmp eq i64 %40, %3
  br i1 %exitcond54.not, label %._crit_edge50, label %.lr.ph.us, !llvm.loop !11

._crit_edge50:                                    ; preds = %.lr.ph49.split, %._crit_edge.us, %.lr.ph49.split.preheader, %8
  ret void

.lr.ph49.split:                                   ; preds = %.lr.ph49.split.preheader, %.lr.ph49.split
  %.03847 = phi i64 [ %53, %.lr.ph49.split ], [ 1, %.lr.ph49.split.preheader ]
  %41 = add i64 %.03847, -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 %.03847, %9
  %.039.idx = select i1 %45, i64 0, i64 %1
  %.039 = getelementptr inbounds i8, ptr %44, i64 %.039.idx
  %46 = tail call noundef i32 @_ZN4Simd4Base7SobelDxILb1EEEiPKhS3_S3_mm(ptr noundef %43, ptr noundef %44, ptr noundef %.039, i64 noundef 0, i64 noundef 1)
  %47 = sext i32 %46 to i64
  %48 = tail call noundef i32 @_ZN4Simd4Base7SobelDxILb1EEEiPKhS3_S3_mm(ptr noundef %43, ptr noundef %44, ptr noundef %.039, i64 noundef %12, 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 %.03847, 1
  %exitcond.not = icmp eq i64 %53, %3
  br i1 %exitcond.not, label %._crit_edge50, label %.lr.ph49.split, !llvm.loop !12
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base7SobelDxILb1EEEiPKhS3_S3_mm(ptr noundef, ptr noundef, ptr 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