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

; 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 @_ZN4Simd4Base14ContourAnchorsEPKtmmmmsPhm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i16 noundef signext %5, ptr noundef %6, i64 noundef %7) #1 {
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i16, align 2
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca i64, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !9
  store i64 %2, ptr %11, align 8, !tbaa !9
  store i64 %3, ptr %12, align 8, !tbaa !9
  store i64 %4, ptr %13, align 8, !tbaa !9
  store i16 %5, ptr %14, align 2, !tbaa !11
  store ptr %6, ptr %15, align 8, !tbaa !5
  store i64 %7, ptr %16, align 8, !tbaa !9
  %20 = load ptr, ptr %15, align 8, !tbaa !5
  %21 = load i64, ptr %11, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %20, i8 0, i64 %21, i1 false)
  %22 = load ptr, ptr %15, align 8, !tbaa !5
  %23 = load i64, ptr %16, align 8, !tbaa !9
  %24 = load i64, ptr %12, align 8, !tbaa !9
  %25 = sub i64 %24, 1
  %26 = mul i64 %23, %25
  %27 = getelementptr inbounds i8, ptr %22, i64 %26
  %28 = load i64, ptr %11, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %27, i8 0, i64 %28, i1 false)
  %29 = load i64, ptr %16, align 8, !tbaa !9
  %30 = load ptr, ptr %15, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 %29
  store ptr %31, ptr %15, align 8, !tbaa !5
  %32 = load i64, ptr %10, align 8, !tbaa !9
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds i16, ptr %33, i64 %32
  store ptr %34, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  store i64 1, ptr %17, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %78, %8
  %36 = load i64, ptr %17, align 8, !tbaa !9
  %37 = load i64, ptr %12, align 8, !tbaa !9
  %38 = sub i64 %37, 1
  %39 = icmp ult i64 %36, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %35
  store i32 2, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  br label %82

41:                                               ; preds = %35
  %42 = load ptr, ptr %15, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 0
  store i8 0, ptr %43, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  store i64 1, ptr %19, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %60, %41
  %45 = load i64, ptr %19, align 8, !tbaa !9
  %46 = load i64, ptr %11, align 8, !tbaa !9
  %47 = sub i64 %46, 1
  %48 = icmp ult i64 %45, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %44
  store i32 5, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  br label %63

50:                                               ; preds = %44
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load i64, ptr %19, align 8, !tbaa !9
  %53 = getelementptr inbounds i16, ptr %51, i64 %52
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = load i16, ptr %14, align 2, !tbaa !11
  %56 = call noundef zeroext i8 @_ZN4Simd4Base6AnchorEPKtls(ptr noundef %53, i64 noundef %54, i16 noundef signext %55)
  %57 = load ptr, ptr %15, align 8, !tbaa !5
  %58 = load i64, ptr %19, align 8, !tbaa !9
  %59 = getelementptr inbounds i8, ptr %57, i64 %58
  store i8 %56, ptr %59, align 1, !tbaa !13
  br label %60

60:                                               ; preds = %50
  %61 = load i64, ptr %19, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr %19, align 8, !tbaa !9
  br label %44, !llvm.loop !14

63:                                               ; preds = %49
  %64 = load ptr, ptr %15, align 8, !tbaa !5
  %65 = load i64, ptr %11, align 8, !tbaa !9
  %66 = sub i64 %65, 1
  %67 = getelementptr inbounds i8, ptr %64, i64 %66
  store i8 0, ptr %67, align 1, !tbaa !13
  %68 = load i64, ptr %13, align 8, !tbaa !9
  %69 = load i64, ptr %16, align 8, !tbaa !9
  %70 = mul i64 %68, %69
  %71 = load ptr, ptr %15, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 %70
  store ptr %72, ptr %15, align 8, !tbaa !5
  %73 = load i64, ptr %13, align 8, !tbaa !9
  %74 = load i64, ptr %10, align 8, !tbaa !9
  %75 = mul i64 %73, %74
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds i16, ptr %76, i64 %75
  store ptr %77, ptr %9, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %63
  %79 = load i64, ptr %13, align 8, !tbaa !9
  %80 = load i64, ptr %17, align 8, !tbaa !9
  %81 = add i64 %80, %79
  store i64 %81, ptr %17, align 8, !tbaa !9
  br label %35, !llvm.loop !16

82:                                               ; preds = %40
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN4Simd4Base6AnchorEPKtls(ptr noundef, i64 noundef, i16 noundef signext) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 = !{!"short", !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 @_ZN4Simd4Base14ContourAnchorsEPKtmmmmsPhm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i16 noundef signext %5, ptr nocapture noundef writeonly %6, i64 noundef %7) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr align 1 %6, i8 0, i64 %2, i1 false)
  %9 = add i64 %3, -1
  %10 = mul i64 %9, %7
  %11 = getelementptr inbounds i8, ptr %6, i64 %10
  tail call void @llvm.memset.p0.i64(ptr align 1 %11, i8 0, i64 %2, i1 false)
  %12 = icmp ugt i64 %9, 1
  br i1 %12, label %.lr.ph40, label %._crit_edge41

.lr.ph40:                                         ; preds = %8
  %13 = getelementptr inbounds i8, ptr %6, i64 %7
  %14 = add i64 %2, -1
  %15 = icmp ugt i64 %14, 1
  %16 = mul i64 %7, %4
  %17 = mul i64 %4, %1
  br i1 %15, label %.lr.ph.us.preheader, label %.lr.ph40.split

.lr.ph.us.preheader:                              ; preds = %.lr.ph40
  %18 = getelementptr inbounds i16, ptr %0, i64 %1
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.03138.us = phi i64 [ %27, %._crit_edge.us ], [ 1, %.lr.ph.us.preheader ]
  %.03237.us = phi ptr [ %26, %._crit_edge.us ], [ %18, %.lr.ph.us.preheader ]
  %.03336.us = phi ptr [ %25, %._crit_edge.us ], [ %13, %.lr.ph.us.preheader ]
  store i8 0, ptr %.03336.us, align 1, !tbaa !5
  br label %19

19:                                               ; preds = %.lr.ph.us, %19
  %.035.us = phi i64 [ 1, %.lr.ph.us ], [ %23, %19 ]
  %20 = getelementptr inbounds i16, ptr %.03237.us, i64 %.035.us
  %21 = tail call noundef zeroext i8 @_ZN4Simd4Base6AnchorEPKtls(ptr noundef nonnull %20, i64 noundef %1, i16 noundef signext %5)
  %22 = getelementptr inbounds i8, ptr %.03336.us, i64 %.035.us
  store i8 %21, ptr %22, align 1, !tbaa !5
  %23 = add nuw i64 %.035.us, 1
  %exitcond.not = icmp eq i64 %23, %14
  br i1 %exitcond.not, label %._crit_edge.us, label %19, !llvm.loop !8

._crit_edge.us:                                   ; preds = %19
  %24 = getelementptr inbounds i8, ptr %.03336.us, i64 %14
  store i8 0, ptr %24, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.03336.us, i64 %16
  %26 = getelementptr inbounds i16, ptr %.03237.us, i64 %17
  %27 = add i64 %.03138.us, %4
  %28 = icmp ult i64 %27, %9
  br i1 %28, label %.lr.ph.us, label %._crit_edge41, !llvm.loop !10

._crit_edge41:                                    ; preds = %.lr.ph40.split, %._crit_edge.us, %8
  ret void

.lr.ph40.split:                                   ; preds = %.lr.ph40, %.lr.ph40.split
  %.03138 = phi i64 [ %31, %.lr.ph40.split ], [ 1, %.lr.ph40 ]
  %.03336 = phi ptr [ %30, %.lr.ph40.split ], [ %13, %.lr.ph40 ]
  store i8 0, ptr %.03336, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.03336, i64 %14
  store i8 0, ptr %29, align 1, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %.03336, i64 %16
  %31 = add i64 %.03138, %4
  %32 = icmp ult i64 %31, %9
  br i1 %32, label %.lr.ph40.split, label %._crit_edge41, !llvm.loop !10
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN4Simd4Base6AnchorEPKtls(ptr noundef, i64 noundef, i16 noundef signext) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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