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

; 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 uwtable
declare dso_local void @_Z14load_image_stbPKci(ptr dead_on_unwind noalias writable sret(%struct.image) align 8, ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11imread2postPKc(ptr dead_on_unwind noalias writable sret(%struct.image) align 8 %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %1, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z14load_image_stbPKci(ptr dead_on_unwind writable sret(%struct.image) align 8 %0, ptr noundef %9, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %65, %2
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp slt i32 %11, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %61, %16
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = icmp slt i32 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %64

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %57, %23
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !14
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = mul nsw i32 %31, %33
  %35 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !14
  %37 = mul nsw i32 %34, %36
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !14
  %41 = mul nsw i32 %38, %40
  %42 = add nsw i32 %37, %41
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = add nsw i32 %42, %43
  store i32 %44, ptr %8, align 4, !tbaa !9
  %45 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 3
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds float, ptr %46, i64 %48
  %50 = load float, ptr %49, align 4, !tbaa !16
  %51 = fmul float %50, 2.550000e+02
  %52 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds float, ptr %53, i64 %55
  store float %51, ptr %56, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %57

57:                                               ; preds = %30
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %7, align 4, !tbaa !9
  br label %24, !llvm.loop !18

60:                                               ; preds = %29
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %6, align 4, !tbaa !9
  br label %17, !llvm.loop !20

64:                                               ; preds = %22
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %4, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %4, align 4, !tbaa !9
  br label %10, !llvm.loop !21

68:                                               ; preds = %15
  ret void
}

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS5image", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !6, 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}


; 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 uwtable
declare dso_local void @_Z14load_image_stbPKci(ptr dead_on_unwind noalias writable sret(%struct.image) align 8, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11imread2postPKc(ptr dead_on_unwind noalias writable sret(%struct.image) align 8 %0, ptr noundef %1) local_unnamed_addr #0 {
  tail call void @_Z14load_image_stbPKci(ptr dead_on_unwind writable sret(%struct.image) align 8 %0, ptr noundef %1, i32 noundef 0)
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader14.lr.ph, label %._crit_edge

.preheader14.lr.ph:                               ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = icmp sgt i32 %7, 0
  %9 = load i32, ptr %0, align 8
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = icmp sgt i32 %9, 0
  %or.cond = select i1 %8, i1 %11, i1 false
  br i1 %or.cond, label %.preheader14.us.us.preheader, label %._crit_edge

.preheader14.us.us.preheader:                     ; preds = %.preheader14.lr.ph
  %12 = zext nneg i32 %7 to i64
  %wide.trip.count34 = zext nneg i32 %4 to i64
  %wide.trip.count = zext nneg i32 %9 to i64
  %min.iters.check = icmp ult i32 %9, 8
  %n.vec = and i64 %wide.trip.count, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br label %.preheader14.us.us

.preheader14.us.us:                               ; preds = %.preheader14.us.us.preheader, %._crit_edge17.split.us.us.us
  %indvars.iv31 = phi i64 [ 0, %.preheader14.us.us.preheader ], [ %indvars.iv.next32, %._crit_edge17.split.us.us.us ]
  %13 = mul nuw nsw i64 %indvars.iv31, %12
  %14 = load ptr, ptr %10, align 8
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader14.us.us
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %._crit_edge.us.us.us ], [ 0, %.preheader14.us.us ]
  %15 = add nuw nsw i64 %13, %indvars.iv26
  %16 = trunc nuw i64 %15 to i32
  %17 = mul i32 %9, %16
  %18 = sext i32 %17 to i64
  %invariant.gep = getelementptr float, ptr %14, i64 %18
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us.us.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us.us.us ]
  %19 = getelementptr float, ptr %invariant.gep, i64 %index
  %20 = getelementptr i8, ptr %19, i64 16
  %wide.load = load <4 x float>, ptr %19, align 4, !tbaa !12
  %wide.load36 = load <4 x float>, ptr %20, align 4, !tbaa !12
  %21 = fmul <4 x float> %wide.load, <float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02>
  %22 = fmul <4 x float> %wide.load36, <float 2.550000e+02, float 2.550000e+02, float 2.550000e+02, float 2.550000e+02>
  store <4 x float> %21, ptr %19, align 4, !tbaa !12
  store <4 x float> %22, ptr %20, align 4, !tbaa !12
  %index.next = add nuw i64 %index, 8
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !14

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, %.preheader.us.us.us
  %indvars.iv.ph = phi i64 [ 0, %.preheader.us.us.us ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv
  %24 = load float, ptr %gep, align 4, !tbaa !12
  %25 = fmul float %24, 2.550000e+02
  store float %25, ptr %gep, align 4, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us.us.us, label %scalar.ph, !llvm.loop !18

._crit_edge.us.us.us:                             ; preds = %scalar.ph, %middle.block
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond30.not = icmp eq i64 %indvars.iv.next27, %12
  br i1 %exitcond30.not, label %._crit_edge17.split.us.us.us, label %.preheader.us.us.us, !llvm.loop !19

._crit_edge17.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next32, %wide.trip.count34
  br i1 %exitcond35.not, label %._crit_edge, label %.preheader14.us.us, !llvm.loop !20

._crit_edge:                                      ; preds = %._crit_edge17.split.us.us.us, %.preheader14.lr.ph, %2
  ret void
}

attributes #0 = { 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" }

!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 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !17, !16}
!19 = distinct !{!19, !15}
!20 = distinct !{!20, !15}


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