; LLVM IR from OAID/AutoKernel :: autokernel_plugin/tests/common/tengine_operations.ll (Z8subtract5imageS_S_)

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

%struct.image = type { i32, i32, i32, ptr }

; 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 nounwind uwtable
define dso_local void @_Z8subtract5imageS_S_(ptr noundef byval(%struct.image) align 8 %0, ptr noundef byval(%struct.image) align 8 %1, ptr noundef byval(%struct.image) align 8 %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %6 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 2
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 1
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = mul nsw i32 %7, %9
  %11 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %13 = mul nsw i32 %10, %12
  store i32 %13, ptr %4, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !13
  br label %14

14:                                               ; preds = %38, %3
  %15 = load i32, ptr %5, align 4, !tbaa !13
  %16 = load i32, ptr %4, align 4, !tbaa !13
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %41

19:                                               ; preds = %14
  %20 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = load i32, ptr %5, align 4, !tbaa !13
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds float, ptr %21, i64 %23
  %25 = load float, ptr %24, align 4, !tbaa !15
  %26 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load i32, ptr %5, align 4, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds float, ptr %27, i64 %29
  %31 = load float, ptr %30, align 4, !tbaa !15
  %32 = fsub float %25, %31
  %33 = getelementptr inbounds %struct.image, ptr %2, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load i32, ptr %5, align 4, !tbaa !13
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds float, ptr %34, i64 %36
  store float %32, ptr %37, align 4, !tbaa !15
  br label %38

38:                                               ; preds = %19
  %39 = load i32, ptr %5, align 4, !tbaa !13
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %5, align 4, !tbaa !13
  br label %14, !llvm.loop !17

41:                                               ; preds = %18
  %42 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 2
  %43 = load i32, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.image, ptr %2, i32 0, i32 2
  store i32 %43, ptr %44, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = getelementptr inbounds %struct.image, ptr %2, i32 0, i32 1
  store i32 %46, ptr %47, align 4, !tbaa !11
  %48 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !12
  %50 = getelementptr inbounds %struct.image, ptr %2, i32 0, i32 0
  store i32 %49, ptr %50, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !7, i64 8}
!6 = !{!"_ZTS5image", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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

%struct.image = type { i32, i32, i32, ptr }

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z8subtract5imageS_S_(ptr nocapture noundef readonly byval(%struct.image) align 8 %0, ptr nocapture noundef readonly byval(%struct.image) align 8 %1, ptr nocapture noundef readonly byval(%struct.image) align 8 %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = mul nsw i32 %7, %5
  %9 = load i32, ptr %0, align 8, !tbaa !12
  %10 = mul nsw i32 %8, %9
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %2, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %10 to i64
  %min.iters.check = icmp ult i32 %10, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %18 = getelementptr inbounds float, ptr %13, i64 %indvars.iv.prol
  %19 = load float, ptr %18, align 4, !tbaa !14
  %20 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.prol
  %21 = load float, ptr %20, align 4, !tbaa !14
  %22 = fsub float %19, %21
  %23 = getelementptr inbounds float, ptr %17, i64 %indvars.iv.prol
  store float %22, ptr %23, align 4, !tbaa !14
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !16

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %24 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %25 = icmp ugt i64 %24, -4
  br i1 %25, label %._crit_edge, label %scalar.ph

vector.memcheck:                                  ; preds = %.lr.ph
  %26 = ptrtoint ptr %17 to i64
  %27 = ptrtoint ptr %15 to i64
  %28 = ptrtoint ptr %13 to i64
  %29 = sub i64 %26, %28
  %diff.check = icmp ult i64 %29, 32
  %30 = sub i64 %26, %27
  %diff.check8 = icmp ult i64 %30, 32
  %conflict.rdx = or i1 %diff.check, %diff.check8
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %31 = getelementptr inbounds float, ptr %13, i64 %index
  %32 = getelementptr inbounds i8, ptr %31, i64 16
  %wide.load = load <4 x float>, ptr %31, align 4, !tbaa !14
  %wide.load9 = load <4 x float>, ptr %32, align 4, !tbaa !14
  %33 = getelementptr inbounds float, ptr %15, i64 %index
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  %wide.load10 = load <4 x float>, ptr %33, align 4, !tbaa !14
  %wide.load11 = load <4 x float>, ptr %34, align 4, !tbaa !14
  %35 = fsub <4 x float> %wide.load, %wide.load10
  %36 = fsub <4 x float> %wide.load9, %wide.load11
  %37 = getelementptr inbounds float, ptr %17, i64 %index
  %38 = getelementptr inbounds i8, ptr %37, i64 16
  store <4 x float> %35, ptr %37, align 4, !tbaa !14
  store <4 x float> %36, ptr %38, align 4, !tbaa !14
  %index.next = add nuw i64 %index, 8
  %39 = icmp eq i64 %index.next, %n.vec
  br i1 %39, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %3
  ret void

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %40 = getelementptr inbounds float, ptr %13, i64 %indvars.iv
  %41 = load float, ptr %40, align 4, !tbaa !14
  %42 = getelementptr inbounds float, ptr %15, i64 %indvars.iv
  %43 = load float, ptr %42, align 4, !tbaa !14
  %44 = fsub float %41, %43
  %45 = getelementptr inbounds float, ptr %17, i64 %indvars.iv
  store float %44, ptr %45, align 4, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %46 = getelementptr inbounds float, ptr %13, i64 %indvars.iv.next
  %47 = load float, ptr %46, align 4, !tbaa !14
  %48 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.next
  %49 = load float, ptr %48, align 4, !tbaa !14
  %50 = fsub float %47, %49
  %51 = getelementptr inbounds float, ptr %17, i64 %indvars.iv.next
  store float %50, ptr %51, align 4, !tbaa !14
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %52 = getelementptr inbounds float, ptr %13, i64 %indvars.iv.next.1
  %53 = load float, ptr %52, align 4, !tbaa !14
  %54 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.next.1
  %55 = load float, ptr %54, align 4, !tbaa !14
  %56 = fsub float %53, %55
  %57 = getelementptr inbounds float, ptr %17, i64 %indvars.iv.next.1
  store float %56, ptr %57, align 4, !tbaa !14
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %58 = getelementptr inbounds float, ptr %13, i64 %indvars.iv.next.2
  %59 = load float, ptr %58, align 4, !tbaa !14
  %60 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.next.2
  %61 = load float, ptr %60, align 4, !tbaa !14
  %62 = fsub float %59, %61
  %63 = getelementptr inbounds float, ptr %17, i64 %indvars.iv.next.2
  store float %62, ptr %63, align 4, !tbaa !14
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !22
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !7, i64 8}
!6 = !{!"_ZTS5image", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}
!18 = distinct !{!18, !19, !20, !21}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!"llvm.loop.isvectorized", i32 1}
!21 = !{!"llvm.loop.unroll.runtime.disable"}
!22 = distinct !{!22, !19, !20}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass