; LLVM IR from ggml-org/ggml :: examples/yolo/yolo-image.ll (Z15letterbox_imageRK10yolo_imageii)

; 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.yolo_image = type { i32, i32, i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" = type { ptr, ptr, 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
define dso_local void @_Z15letterbox_imageRK10yolo_imageii(ptr dead_on_unwind noalias writable sret(%struct.yolo_image) align 8 %0, ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %2, i32 noundef %3) #1 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.yolo_image, align 8
  %12 = alloca i1, align 1
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.yolo_image, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !11
  store i32 %17, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.yolo_image, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !17
  store i32 %20, ptr %10, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sitofp i32 %21 to float
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.yolo_image, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = sitofp i32 %25 to float
  %27 = fdiv float %22, %26
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = sitofp i32 %28 to float
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.yolo_image, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !17
  %33 = sitofp i32 %32 to float
  %34 = fdiv float %29, %33
  %35 = fcmp olt float %27, %34
  br i1 %35, label %36, label %47

36:                                               ; preds = %4
  %37 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %37, ptr %9, align 4, !tbaa !9
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.yolo_image, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = mul nsw i32 %40, %41
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.yolo_image, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !11
  %46 = sdiv i32 %42, %45
  store i32 %46, ptr %10, align 4, !tbaa !9
  br label %58

47:                                               ; preds = %4
  %48 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %48, ptr %10, align 4, !tbaa !9
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.yolo_image, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !11
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = mul nsw i32 %51, %52
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.yolo_image, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !17
  %57 = sdiv i32 %53, %56
  store i32 %57, ptr %9, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %47, %36
  call void @llvm.lifetime.start.p0(i64 40, ptr %11) #3
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = load i32, ptr %10, align 4, !tbaa !9
  call void @_ZL12resize_imageRK10yolo_imageii(ptr dead_on_unwind writable sret(%struct.yolo_image) align 8 %11, ptr noundef nonnull align 8 dereferenceable(40) %59, i32 noundef %60, i32 noundef %61)
  store i1 false, ptr %12, align 1
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.yolo_image, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 8, !tbaa !18
  invoke void @_ZN10yolo_imageC2Eiii(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %62, i32 noundef %63, i32 noundef %66)
          to label %67 unwind label %79

67:                                               ; preds = %58
  invoke void @_ZN10yolo_image4fillEf(ptr noundef nonnull align 8 dereferenceable(40) %0, float noundef 5.000000e-01)
          to label %68 unwind label %83

68:                                               ; preds = %67
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = sub nsw i32 %69, %70
  %72 = sdiv i32 %71, 2
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = sub nsw i32 %73, %74
  %76 = sdiv i32 %75, 2
  invoke void @_ZL11embed_imageRK10yolo_imageRS_ii(ptr noundef nonnull align 8 dereferenceable(40) %11, ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %72, i32 noundef %76)
          to label %77 unwind label %83

77:                                               ; preds = %68
  store i1 true, ptr %12, align 1
  %78 = load i1, ptr %12, align 1
  br i1 %78, label %88, label %87

79:                                               ; preds = %58
  %80 = landingpad { ptr, i32 }
          cleanup
  %81 = extractvalue { ptr, i32 } %80, 0
  store ptr %81, ptr %13, align 8
  %82 = extractvalue { ptr, i32 } %80, 1
  store i32 %82, ptr %14, align 4
  br label %89

83:                                               ; preds = %68, %67
  %84 = landingpad { ptr, i32 }
          cleanup
  %85 = extractvalue { ptr, i32 } %84, 0
  store ptr %85, ptr %13, align 8
  %86 = extractvalue { ptr, i32 } %84, 1
  store i32 %86, ptr %14, align 4
  call void @_ZN10yolo_imageD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) #3
  br label %89

87:                                               ; preds = %77
  call void @_ZN10yolo_imageD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) #3
  br label %88

88:                                               ; preds = %87, %77
  call void @_ZN10yolo_imageD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %11) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void

89:                                               ; preds = %83, %79
  call void @_ZN10yolo_imageD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %11) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %90

90:                                               ; preds = %89
  %91 = load ptr, ptr %13, align 8
  %92 = load i32, ptr %14, align 4
  %93 = insertvalue { ptr, i32 } poison, ptr %91, 0
  %94 = insertvalue { ptr, i32 } %93, i32 %92, 1
  resume { ptr, i32 } %94
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL12resize_imageRK10yolo_imageii(ptr dead_on_unwind noalias writable sret(%struct.yolo_image) align 8, ptr noundef nonnull align 8 dereferenceable(40), i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10yolo_imageC2Eiii(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef, i32 noundef, i32 noundef) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10yolo_image4fillEf(ptr noundef nonnull align 8 dereferenceable(40), float noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL11embed_imageRK10yolo_imageRS_ii(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(40), i32 noundef, i32 noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10yolo_imageD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #2 align 2

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 = { inlinehint 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 = !{!"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 0}
!12 = !{!"_ZTS10yolo_image", !10, i64 0, !10, i64 4, !10, i64 8, !13, i64 16}
!13 = !{!"_ZTSSt6vectorIfSaIfEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIfSaIfEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!12, !10, i64 4}
!18 = !{!12, !10, i64 8}


; 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.yolo_image = type { i32, i32, i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" = type { ptr, ptr, 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 uwtable
define dso_local void @_Z15letterbox_imageRK10yolo_imageii(ptr dead_on_unwind noalias writable sret(%struct.yolo_image) align 8 %0, ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %5 = alloca %struct.yolo_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
  %.028 = phi i32 [ %2, %15 ], [ %24, %20 ]
  %.027 = phi i32 [ %19, %15 ], [ %3, %20 ]
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #3
  call void @_ZL12resize_imageRK10yolo_imageii(ptr dead_on_unwind nonnull writable sret(%struct.yolo_image) align 8 %5, ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %.028, i32 noundef %.027)
  %26 = getelementptr inbounds i8, ptr %1, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !9
  invoke void @_ZN10yolo_imageC2Eiii(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %2, i32 noundef %3, i32 noundef %27)
          to label %28 unwind label %34

28:                                               ; preds = %25
  invoke void @_ZN10yolo_image4fillEf(ptr noundef nonnull align 8 dereferenceable(40) %0, float noundef 5.000000e-01)
          to label %29 unwind label %36

29:                                               ; preds = %28
  %30 = sub nsw i32 %2, %.028
  %31 = sdiv i32 %30, 2
  %32 = sub nsw i32 %3, %.027
  %33 = sdiv i32 %32, 2
  invoke void @_ZL11embed_imageRK10yolo_imageRS_ii(ptr noundef nonnull align 8 dereferenceable(40) %5, ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %31, i32 noundef %33)
          to label %38 unwind label %36

34:                                               ; preds = %25
  %35 = landingpad { ptr, i32 }
          cleanup
  br label %39

36:                                               ; preds = %29, %28
  %37 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN10yolo_imageD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) #3
  br label %39

38:                                               ; preds = %29
  call void @_ZN10yolo_imageD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %5) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #3
  ret void

39:                                               ; preds = %36, %34
  %.pn = phi { ptr, i32 } [ %37, %36 ], [ %35, %34 ]
  call void @_ZN10yolo_imageD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %5) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #3
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL12resize_imageRK10yolo_imageii(ptr dead_on_unwind noalias writable sret(%struct.yolo_image) align 8, ptr noundef nonnull align 8 dereferenceable(40), i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10yolo_imageC2Eiii(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef, i32 noundef, i32 noundef) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10yolo_image4fillEf(ptr noundef nonnull align 8 dereferenceable(40), float noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL11embed_imageRK10yolo_imageRS_ii(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(40), i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10yolo_imageD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #2 align 2

attributes #0 = { mustprogress 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 = { inlinehint 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, !6, i64 8}
!10 = !{!"_ZTS10yolo_image", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 16}
!11 = !{!"_ZTSSt6vectorIfSaIfEE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIfSaIfEE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE17_Vector_impl_dataE", !15, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass