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

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

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

; 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 uwtable
define dso_local void @_Z9letterbox5imageii(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) #4 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.image, align 8
  %10 = alloca %struct.image, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.image, align 8
  %13 = alloca %struct.image, align 8
  %14 = alloca %struct.image, align 8
  store i32 %2, ptr %5, align 4, !tbaa !5
  store i32 %3, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %15 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  store i32 %16, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %17 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !12
  store i32 %18, ptr %8, align 4, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sitofp i32 %19 to float
  %21 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !9
  %23 = sitofp i32 %22 to float
  %24 = fdiv float %20, %23
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = sitofp i32 %25 to float
  %27 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !12
  %29 = sitofp i32 %28 to float
  %30 = fdiv float %26, %29
  %31 = fcmp olt float %24, %30
  br i1 %31, label %32, label %41

32:                                               ; preds = %4
  %33 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %33, ptr %7, align 4, !tbaa !5
  %34 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = mul nsw i32 %35, %36
  %38 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !9
  %40 = sdiv i32 %37, %39
  store i32 %40, ptr %8, align 4, !tbaa !5
  br label %50

41:                                               ; preds = %4
  %42 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %42, ptr %8, align 4, !tbaa !5
  %43 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = mul nsw i32 %44, %45
  %47 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !12
  %49 = sdiv i32 %46, %48
  store i32 %49, ptr %7, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %41, %32
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %1, i64 24, i1 false), !tbaa.struct !13
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z12resize_image5imageii(ptr dead_on_unwind writable sret(%struct.image) align 8 %9, ptr noundef byval(%struct.image) align 8 %10, i32 noundef %51, i32 noundef %52)
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 0
  store i32 %53, ptr %54, align 8, !tbaa !9
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 1
  store i32 %55, ptr %56, align 4, !tbaa !12
  %57 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 2
  %58 = load i32, ptr %57, align 8, !tbaa !15
  %59 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 2
  store i32 %58, ptr %59, align 8, !tbaa !15
  %60 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 2
  %61 = load i32, ptr %60, align 8, !tbaa !15
  %62 = sext i32 %61 to i64
  %63 = mul i64 4, %62
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = mul i64 %63, %65
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = mul i64 %66, %68
  %70 = call noalias ptr @malloc(i64 noundef %69) #6
  %71 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 3
  store ptr %70, ptr %71, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %90, %50
  %73 = load i32, ptr %11, align 4, !tbaa !5
  %74 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 2
  %75 = load i32, ptr %74, align 8, !tbaa !15
  %76 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 1
  %77 = load i32, ptr %76, align 4, !tbaa !12
  %78 = mul nsw i32 %75, %77
  %79 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 0
  %80 = load i32, ptr %79, align 8, !tbaa !9
  %81 = mul nsw i32 %78, %80
  %82 = icmp slt i32 %73, %81
  br i1 %82, label %84, label %83

83:                                               ; preds = %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %93

84:                                               ; preds = %72
  %85 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 3
  %86 = load ptr, ptr %85, align 8, !tbaa !16
  %87 = load i32, ptr %11, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds float, ptr %86, i64 %88
  store float 5.000000e-01, ptr %89, align 4, !tbaa !17
  br label %90

90:                                               ; preds = %84
  %91 = load i32, ptr %11, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %11, align 4, !tbaa !5
  br label %72, !llvm.loop !19

93:                                               ; preds = %83
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %9, i64 24, i1 false), !tbaa.struct !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %13, ptr align 8 %0, i64 24, i1 false), !tbaa.struct !13
  %94 = load i32, ptr %5, align 4, !tbaa !5
  %95 = load i32, ptr %7, align 4, !tbaa !5
  %96 = sub nsw i32 %94, %95
  %97 = sdiv i32 %96, 2
  %98 = load i32, ptr %6, align 4, !tbaa !5
  %99 = load i32, ptr %8, align 4, !tbaa !5
  %100 = sub nsw i32 %98, %99
  %101 = sdiv i32 %100, 2
  call void @_Z9add_image5imageS_ii(ptr noundef byval(%struct.image) align 8 %12, ptr noundef byval(%struct.image) align 8 %13, i32 noundef %97, i32 noundef %101)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %14, ptr align 8 %9, i64 24, i1 false), !tbaa.struct !13
  call void @_Z10free_image5image(ptr noundef byval(%struct.image) align 8 %14)
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!10, !6, i64 4}
!13 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 16, i64 8, !14}
!14 = !{!11, !11, i64 0}
!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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9letterbox5imageii(ptr dead_on_unwind noalias nocapture writable sret(%struct.image) align 8 %0, ptr nocapture noundef readonly byval(%struct.image) align 8 %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #3 {
  %5 = alloca %struct.image, align 8
  %6 = insertelement <2 x i32> poison, i32 %2, i64 0
  %7 = insertelement <2 x i32> %6, i32 %3, i64 1
  %8 = sitofp <2 x i32> %7 to <2 x float>
  %9 = load <2 x i32>, ptr %1, align 8, !tbaa !5
  %10 = sitofp <2 x i32> %9 to <2 x float>
  %11 = fdiv <2 x float> %8, %10
  %12 = extractelement <2 x float> %11, i64 0
  %13 = extractelement <2 x float> %11, i64 1
  %14 = fcmp olt float %12, %13
  br i1 %14, label %15, label %20

15:                                               ; preds = %4
  %16 = extractelement <2 x i32> %9, i64 1
  %17 = mul nsw i32 %16, %2
  %18 = extractelement <2 x i32> %9, i64 0
  %19 = sdiv i32 %17, %18
  br label %25

20:                                               ; preds = %4
  %21 = extractelement <2 x i32> %9, i64 0
  %22 = mul nsw i32 %21, %3
  %23 = extractelement <2 x i32> %9, i64 1
  %24 = sdiv i32 %22, %23
  br label %25

25:                                               ; preds = %20, %15
  %.020 = phi i32 [ %2, %15 ], [ %24, %20 ]
  %.019 = phi i32 [ %19, %15 ], [ %3, %20 ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  call void @_Z12resize_image5imageii(ptr dead_on_unwind nonnull writable sret(%struct.image) align 8 %5, ptr noundef nonnull byval(%struct.image) align 8 %1, i32 noundef %.020, i32 noundef %.019)
  store i32 %2, ptr %0, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %3, ptr %26, align 4, !tbaa !12
  %27 = getelementptr inbounds i8, ptr %1, i64 8
  %28 = load i32, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %28, ptr %29, align 8, !tbaa !13
  %30 = sext i32 %28 to i64
  %31 = sext i32 %3 to i64
  %32 = sext i32 %2 to i64
  %33 = shl nsw i64 %32, 2
  %34 = mul i64 %33, %31
  %35 = mul i64 %34, %30
  %36 = call noalias ptr @malloc(i64 noundef %35) #5
  %37 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %36, ptr %37, align 8, !tbaa !14
  %38 = mul i32 %3, %2
  %39 = mul i32 %38, %28
  %40 = icmp sgt i32 %39, 0
  br i1 %40, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %25
  %wide.trip.count = zext nneg i32 %39 to i64
  %min.iters.check = icmp ult i32 %39, 8
  br i1 %min.iters.check, label %.lr.ph.preheader23, label %vector.ph

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

vector.ph:                                        ; preds = %.lr.ph.preheader
  %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 ]
  %41 = getelementptr inbounds float, ptr %36, i64 %index
  %42 = getelementptr inbounds i8, ptr %41, i64 16
  store <4 x float> <float 5.000000e-01, float 5.000000e-01, float 5.000000e-01, float 5.000000e-01>, ptr %41, align 4, !tbaa !15
  store <4 x float> <float 5.000000e-01, float 5.000000e-01, float 5.000000e-01, float 5.000000e-01>, ptr %42, align 4, !tbaa !15
  %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 !17

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

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %25
  %44 = sub nsw i32 %2, %.020
  %45 = sdiv i32 %44, 2
  %46 = sub nsw i32 %3, %.019
  %47 = sdiv i32 %46, 2
  call void @_Z9add_image5imageS_ii(ptr noundef nonnull byval(%struct.image) align 8 %5, ptr noundef nonnull byval(%struct.image) align 8 %0, i32 noundef %45, i32 noundef %47)
  call void @_Z10free_image5image(ptr noundef nonnull byval(%struct.image) align 8 %5)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader23, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader23 ]
  %48 = getelementptr inbounds float, ptr %36, i64 %indvars.iv
  store float 5.000000e-01, ptr %48, align 4, !tbaa !15
  %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 %.lr.ph, !llvm.loop !21
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 = { 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

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


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