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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z10copy_image5image(ptr dead_on_unwind noalias writable sret(%struct.image) align 8, ptr noundef byval(%struct.image) align 8) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z9add_image5imageS_ii(ptr noundef byval(%struct.image) align 8, ptr noundef byval(%struct.image) align 8, i32 noundef, i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z17combination_image5imageS_ii(ptr noundef byval(%struct.image) align 8, ptr noundef byval(%struct.image) align 8, i32 noundef, i32 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14addText_images5imageS_i(ptr dead_on_unwind noalias writable sret(%struct.image) align 8 %0, ptr noundef byval(%struct.image) align 8 %1, ptr noundef byval(%struct.image) align 8 %2, i32 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.image, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.image, align 8
  %9 = alloca %struct.image, align 8
  %10 = alloca %struct.image, align 8
  %11 = alloca %struct.image, align 8
  store i32 %3, ptr %5, align 4, !tbaa !5
  %12 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %2, i64 24, i1 false), !tbaa.struct !12
  call void @_Z10copy_image5image(ptr dead_on_unwind writable sret(%struct.image) align 8 %0, ptr noundef byval(%struct.image) align 8 %6)
  br label %76

16:                                               ; preds = %4
  %17 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.image, ptr %2, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = add nsw i32 %18, %20
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = add nsw i32 %21, %22
  %24 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = getelementptr inbounds %struct.image, ptr %2, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = icmp sgt i32 %25, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %16
  %30 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !14
  br label %35

32:                                               ; preds = %16
  %33 = getelementptr inbounds %struct.image, ptr %2, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !14
  br label %35

35:                                               ; preds = %32, %29
  %36 = phi i32 [ %31, %29 ], [ %34, %32 ]
  %37 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 2
  %38 = load i32, ptr %37, align 8, !tbaa !15
  %39 = getelementptr inbounds %struct.image, ptr %2, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !15
  %41 = icmp sgt i32 %38, %40
  br i1 %41, label %42, label %45

42:                                               ; preds = %35
  %43 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !15
  br label %48

45:                                               ; preds = %35
  %46 = getelementptr inbounds %struct.image, ptr %2, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !15
  br label %48

48:                                               ; preds = %45, %42
  %49 = phi i32 [ %44, %42 ], [ %47, %45 ]
  call void @_Z10make_imageiii(ptr dead_on_unwind writable sret(%struct.image) align 8 %0, i32 noundef %23, i32 noundef %36, i32 noundef %49)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %68, %48
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !14
  %56 = mul nsw i32 %53, %55
  %57 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 2
  %58 = load i32, ptr %57, align 8, !tbaa !15
  %59 = mul nsw i32 %56, %58
  %60 = icmp slt i32 %51, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %71

62:                                               ; preds = %50
  %63 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !16
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds float, ptr %64, i64 %66
  store float 1.000000e+00, ptr %67, align 4, !tbaa !17
  br label %68

68:                                               ; preds = %62
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %7, align 4, !tbaa !5
  br label %50, !llvm.loop !19

71:                                               ; preds = %61
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %1, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %0, i64 24, i1 false), !tbaa.struct !12
  call void @_Z9add_image5imageS_ii(ptr noundef byval(%struct.image) align 8 %8, ptr noundef byval(%struct.image) align 8 %9, i32 noundef 0, i32 noundef 0)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %2, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %0, i64 24, i1 false), !tbaa.struct !12
  %72 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %73 = load i32, ptr %72, align 8, !tbaa !9
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = add nsw i32 %73, %74
  call void @_Z17combination_image5imageS_ii(ptr noundef byval(%struct.image) align 8 %10, ptr noundef byval(%struct.image) align 8 %11, i32 noundef %75, i32 noundef 0)
  br label %76

76:                                               ; preds = %71, %15
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS5image", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 16, i64 8, !13}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 4}
!15 = !{!10, !6, i64 8}
!16 = !{!10, !11, i64 16}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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 uwtable
declare dso_local void @_Z10make_imageiii(ptr dead_on_unwind noalias writable sret(%struct.image) align 8, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z10copy_image5image(ptr dead_on_unwind noalias writable sret(%struct.image) align 8, ptr noundef byval(%struct.image) align 8) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z9add_image5imageS_ii(ptr noundef byval(%struct.image) align 8, ptr noundef byval(%struct.image) align 8, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z17combination_image5imageS_ii(ptr noundef byval(%struct.image) align 8, ptr noundef byval(%struct.image) align 8, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14addText_images5imageS_i(ptr dead_on_unwind noalias writable sret(%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, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i32, ptr %1, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %4
  tail call void @_Z10copy_image5image(ptr dead_on_unwind writable sret(%struct.image) align 8 %0, ptr noundef nonnull byval(%struct.image) align 8 %2)
  br label %36

8:                                                ; preds = %4
  %9 = load i32, ptr %2, align 8, !tbaa !5
  %10 = add i32 %5, %3
  %11 = add i32 %10, %9
  %12 = getelementptr inbounds i8, ptr %1, i64 4
  %13 = load i32, ptr %12, align 4
  %14 = getelementptr inbounds i8, ptr %2, i64 4
  %15 = load i32, ptr %14, align 4
  %16 = tail call i32 @llvm.smax.i32(i32 %13, i32 %15)
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load i32, ptr %17, align 8
  %19 = getelementptr inbounds i8, ptr %2, i64 8
  %20 = load i32, ptr %19, align 8
  %21 = tail call i32 @llvm.smax.i32(i32 %18, i32 %20)
  tail call void @_Z10make_imageiii(ptr dead_on_unwind writable sret(%struct.image) align 8 %0, i32 noundef %11, i32 noundef %16, i32 noundef %21)
  %22 = load i32, ptr %0, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %0, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = mul nsw i32 %24, %22
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !12
  %28 = mul nsw i32 %25, %27
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %8
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %28 to i64
  %min.iters.check = icmp ult i32 %28, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %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 ]
  %32 = getelementptr inbounds float, ptr %31, i64 %index
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  store <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, ptr %32, align 4, !tbaa !14
  store <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, ptr %33, align 4, !tbaa !14
  %index.next = add nuw i64 %index, 8
  %34 = icmp eq i64 %index.next, %n.vec
  br i1 %34, label %middle.block, label %vector.body, !llvm.loop !16

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, %middle.block, %8
  tail call void @_Z9add_image5imageS_ii(ptr noundef nonnull byval(%struct.image) align 8 %1, ptr noundef nonnull byval(%struct.image) align 8 %0, i32 noundef 0, i32 noundef 0)
  tail call void @_Z17combination_image5imageS_ii(ptr noundef nonnull byval(%struct.image) align 8 %2, ptr noundef nonnull byval(%struct.image) align 8 %0, i32 noundef %10, i32 noundef 0)
  br label %36

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %35 = getelementptr inbounds float, ptr %31, i64 %indvars.iv
  store float 1.000000e+00, ptr %35, align 4, !tbaa !14
  %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, label %scalar.ph, !llvm.loop !20

36:                                               ; preds = %._crit_edge, %7
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

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" }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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