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

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12imread2caffe5imageiiPfS0_(ptr dead_on_unwind noalias writable sret(%struct.image) align 8 %0, ptr noundef byval(%struct.image) align 8 %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  store ptr %4, ptr %9, align 8, !tbaa !9
  store ptr %5, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %82, %6
  %17 = load i32, ptr %11, align 4, !tbaa !5
  %18 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 2
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp slt i32 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %85

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %78, %22
  %24 = load i32, ptr %13, align 4, !tbaa !5
  %25 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = icmp slt i32 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %81

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %74, %29
  %31 = load i32, ptr %14, align 4, !tbaa !5
  %32 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !14
  %34 = icmp slt i32 %31, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %30
  store i32 8, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %77

36:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %37 = load i32, ptr %11, align 4, !tbaa !5
  %38 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = mul nsw i32 %37, %39
  %41 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !14
  %43 = mul nsw i32 %40, %42
  %44 = load i32, ptr %13, align 4, !tbaa !5
  %45 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !14
  %47 = mul nsw i32 %44, %46
  %48 = add nsw i32 %43, %47
  %49 = load i32, ptr %14, align 4, !tbaa !5
  %50 = add nsw i32 %48, %49
  store i32 %50, ptr %15, align 4, !tbaa !5
  %51 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = load i32, ptr %15, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds float, ptr %52, i64 %54
  %56 = load float, ptr %55, align 4, !tbaa !16
  %57 = load ptr, ptr %9, align 8, !tbaa !9
  %58 = load i32, ptr %11, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds float, ptr %57, i64 %59
  %61 = load float, ptr %60, align 4, !tbaa !16
  %62 = fsub float %56, %61
  %63 = load ptr, ptr %10, align 8, !tbaa !9
  %64 = load i32, ptr %11, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds float, ptr %63, i64 %65
  %67 = load float, ptr %66, align 4, !tbaa !16
  %68 = fmul float %62, %67
  %69 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 3
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = load i32, ptr %15, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds float, ptr %70, i64 %72
  store float %68, ptr %73, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %74

74:                                               ; preds = %36
  %75 = load i32, ptr %14, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %14, align 4, !tbaa !5
  br label %30, !llvm.loop !18

77:                                               ; preds = %35
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %13, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %13, align 4, !tbaa !5
  br label %23, !llvm.loop !20

81:                                               ; preds = %28
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %11, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %11, align 4, !tbaa !5
  br label %16, !llvm.loop !21

85:                                               ; preds = %21
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %1, i64 24, i1 false), !tbaa.struct !22
  ret void
}

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


; 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z12imread2caffe5imageiiPfS0_(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.image) align 8 %0, ptr nocapture noundef readonly byval(%struct.image) align 8 %1, i32 noundef %2, i32 noundef %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readonly %5) local_unnamed_addr #1 {
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.preheader17.lr.ph, label %._crit_edge

.preheader17.lr.ph:                               ; preds = %6
  %10 = getelementptr inbounds i8, ptr %1, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = icmp sgt i32 %11, 0
  %13 = load i32, ptr %1, align 8
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = load ptr, ptr %14, align 8
  %16 = icmp sgt i32 %13, 0
  %or.cond = select i1 %12, i1 %16, i1 false
  br i1 %or.cond, label %.preheader17.us.us.preheader, label %._crit_edge

.preheader17.us.us.preheader:                     ; preds = %.preheader17.lr.ph
  %17 = zext nneg i32 %11 to i64
  %wide.trip.count37 = zext nneg i32 %8 to i64
  %wide.trip.count = zext nneg i32 %13 to i64
  %18 = mul i32 %11, %13
  %19 = zext i32 %18 to i64
  %20 = shl nuw nsw i64 %wide.trip.count, 2
  %scevgep39 = getelementptr i8, ptr %15, i64 %20
  %min.iters.check = icmp ult i32 %13, 8
  %n.vec = and i64 %wide.trip.count, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  %xtraiter = and i64 %wide.trip.count, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %21 = add nsw i64 %wide.trip.count, -1
  br label %.preheader17.us.us

.preheader17.us.us:                               ; preds = %.preheader17.us.us.preheader, %._crit_edge20.split.us.us.us
  %indvars.iv34 = phi i64 [ 0, %.preheader17.us.us.preheader ], [ %indvars.iv.next35, %._crit_edge20.split.us.us.us ]
  %22 = mul i64 %indvars.iv34, %19
  %23 = shl nuw nsw i64 %indvars.iv34, 2
  %scevgep41 = getelementptr i8, ptr %4, i64 %23
  %24 = add nuw i64 %23, 4
  %scevgep42 = getelementptr i8, ptr %4, i64 %24
  %scevgep43 = getelementptr i8, ptr %5, i64 %23
  %scevgep44 = getelementptr i8, ptr %5, i64 %24
  %25 = mul nuw nsw i64 %indvars.iv34, %17
  %26 = getelementptr inbounds float, ptr %4, i64 %indvars.iv34
  %27 = getelementptr inbounds float, ptr %5, i64 %indvars.iv34
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader17.us.us
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %._crit_edge.us.us.us ], [ 0, %.preheader17.us.us ]
  %28 = add nuw nsw i64 %25, %indvars.iv29
  %29 = trunc nuw i64 %28 to i32
  %30 = mul i32 %13, %29
  %31 = sext i32 %30 to i64
  %invariant.gep = getelementptr float, ptr %15, i64 %31
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader.us.us.us
  %32 = mul i64 %indvars.iv29, %wide.trip.count
  %33 = add i64 %22, %32
  %sext = shl i64 %33, 32
  %34 = ashr exact i64 %sext, 30
  %scevgep40 = getelementptr i8, ptr %scevgep39, i64 %34
  %scevgep = getelementptr i8, ptr %15, i64 %34
  %bound0 = icmp ult ptr %scevgep, %scevgep42
  %bound1 = icmp ult ptr %scevgep41, %scevgep40
  %found.conflict = and i1 %bound0, %bound1
  %bound045 = icmp ult ptr %scevgep, %scevgep44
  %bound146 = icmp ult ptr %scevgep43, %scevgep40
  %found.conflict47 = and i1 %bound045, %bound146
  %conflict.rdx = or i1 %found.conflict, %found.conflict47
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %35 = load float, ptr %26, align 4, !tbaa !12, !alias.scope !14
  %broadcast.splatinsert49 = insertelement <4 x float> poison, float %35, i64 0
  %broadcast.splat50 = shufflevector <4 x float> %broadcast.splatinsert49, <4 x float> poison, <4 x i32> zeroinitializer
  %36 = load float, ptr %27, align 4, !tbaa !12, !alias.scope !17
  %broadcast.splatinsert53 = insertelement <4 x float> poison, float %36, i64 0
  %broadcast.splat54 = shufflevector <4 x float> %broadcast.splatinsert53, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %37 = getelementptr float, ptr %invariant.gep, i64 %index
  %38 = getelementptr i8, ptr %37, i64 16
  %wide.load = load <4 x float>, ptr %37, align 4, !tbaa !12, !alias.scope !19, !noalias !21
  %wide.load48 = load <4 x float>, ptr %38, align 4, !tbaa !12, !alias.scope !19, !noalias !21
  %39 = fsub <4 x float> %wide.load, %broadcast.splat50
  %40 = fsub <4 x float> %wide.load48, %broadcast.splat50
  %41 = fmul <4 x float> %39, %broadcast.splat54
  %42 = fmul <4 x float> %40, %broadcast.splat54
  store <4 x float> %41, ptr %37, align 4, !tbaa !12, !alias.scope !19, !noalias !21
  store <4 x float> %42, ptr %38, align 4, !tbaa !12, !alias.scope !19, !noalias !21
  %index.next = add nuw i64 %index, 8
  %43 = icmp eq i64 %index.next, %n.vec
  br i1 %43, label %middle.block, label %vector.body, !llvm.loop !22

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us.us.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.preheader.us.us.us
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.preheader.us.us.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %gep.prol = getelementptr float, ptr %invariant.gep, i64 %indvars.iv.ph
  %44 = load float, ptr %gep.prol, align 4, !tbaa !12
  %45 = load float, ptr %26, align 4, !tbaa !12
  %46 = fsub float %44, %45
  %47 = load float, ptr %27, align 4, !tbaa !12
  %48 = fmul float %46, %47
  store float %48, ptr %gep.prol, align 4, !tbaa !12
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

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 ]
  %49 = icmp eq i64 %indvars.iv.ph, %21
  br i1 %49, label %._crit_edge.us.us.us, label %scalar.ph.preheader.new

scalar.ph.preheader.new:                          ; preds = %scalar.ph.prol.loopexit
  %invariant.gep55 = getelementptr i8, ptr %invariant.gep, i64 4
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph, %scalar.ph.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.unr, %scalar.ph.preheader.new ], [ %indvars.iv.next.1, %scalar.ph ]
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv
  %50 = load float, ptr %gep, align 4, !tbaa !12
  %51 = load float, ptr %26, align 4, !tbaa !12
  %52 = fsub float %50, %51
  %53 = load float, ptr %27, align 4, !tbaa !12
  %54 = fmul float %52, %53
  store float %54, ptr %gep, align 4, !tbaa !12
  %gep56 = getelementptr float, ptr %invariant.gep55, i64 %indvars.iv
  %55 = load float, ptr %gep56, align 4, !tbaa !12
  %56 = load float, ptr %26, align 4, !tbaa !12
  %57 = fsub float %55, %56
  %58 = load float, ptr %27, align 4, !tbaa !12
  %59 = fmul float %57, %58
  store float %59, ptr %gep56, align 4, !tbaa !12
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %._crit_edge.us.us.us, label %scalar.ph, !llvm.loop !26

._crit_edge.us.us.us:                             ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next30, %17
  br i1 %exitcond33.not, label %._crit_edge20.split.us.us.us, label %.preheader.us.us.us, !llvm.loop !27

._crit_edge20.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge, label %.preheader17.us.us, !llvm.loop !28

._crit_edge:                                      ; preds = %._crit_edge20.split.us.us.us, %.preheader17.lr.ph, %6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 24, i1 false), !tbaa.struct !29
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = !{!15}
!15 = distinct !{!15, !16}
!16 = distinct !{!16, !"LVerDomain"}
!17 = !{!18}
!18 = distinct !{!18, !16}
!19 = !{!20}
!20 = distinct !{!20, !16}
!21 = !{!15, !18}
!22 = distinct !{!22, !23, !24, !25}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!"llvm.loop.isvectorized", i32 1}
!25 = !{!"llvm.loop.unroll.runtime.disable"}
!26 = distinct !{!26, !23, !24}
!27 = distinct !{!27, !23}
!28 = distinct !{!28, !23}
!29 = !{i64 0, i64 4, !30, i64 4, i64 4, !30, i64 8, i64 4, !30, i64 16, i64 8, !31}
!30 = !{!7, !7, i64 0}
!31 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass