; LLVM IR from vectozavr/3dzavr :: engine/components/props/Texture.ll (ZN7Texture10downSampleEv)

; 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"

%class.Image = type { i16, i16, ptr, i8, %class.FilePath }
%class.FilePath = type { %"class.std::filesystem::__cxx11::path" }
%"class.std::filesystem::__cxx11::path" = type { %"class.std::__cxx11::basic_string", %"struct.std::filesystem::__cxx11::path::_List" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"struct.std::filesystem::__cxx11::path::_List" = type { %"class.std::unique_ptr" }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.4" }
%"struct.std::_Head_base.4" = type { ptr }
%class.Texture = type <{ %"class.std::vector", %class.FilePath, i8, [7 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Image, std::allocator<Image>>::_Vector_impl" }
%"struct.std::_Vector_base<Image, std::allocator<Image>>::_Vector_impl" = type { %"struct.std::_Vector_base<Image, std::allocator<Image>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Image, std::allocator<Image>>::_Vector_impl_data" = type { ptr, ptr, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Texture10downSampleEv(ptr noundef nonnull align 8 dereferenceable(65) %0) #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca %class.Image, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  br label %7

7:                                                ; preds = %23, %1
  %8 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 0
  %9 = call noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %8) #5
  %10 = call noundef zeroext i16 @_ZNK5Image5widthEv(ptr noundef nonnull align 8 dereferenceable(64) %9)
  %11 = zext i16 %10 to i32
  %12 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 0
  %13 = call noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #5
  %14 = call noundef zeroext i16 @_ZNK5Image6heightEv(ptr noundef nonnull align 8 dereferenceable(64) %13)
  %15 = zext i16 %14 to i32
  %16 = mul nsw i32 %11, %15
  %17 = icmp ne i32 %16, 1
  br i1 %17, label %18, label %28

18:                                               ; preds = %7
  %19 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 0
  call void @llvm.lifetime.start.p0(i64 64, ptr %3) #5
  %20 = getelementptr inbounds %class.Texture, ptr %6, i32 0, i32 0
  %21 = call noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %20) #5
  call void @_ZNK5Image11downSampledEv(ptr dead_on_unwind writable sret(%class.Image) align 8 %3, ptr noundef nonnull align 8 dereferenceable(64) %21)
  %22 = invoke noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE12emplace_backIJS0_EEERS0_DpOT_(ptr noundef nonnull align 8 dereferenceable(24) %19, ptr noundef nonnull align 8 dereferenceable(64) %3)
          to label %23 unwind label %24

23:                                               ; preds = %18
  call void @_ZN5ImageD1Ev(ptr noundef nonnull align 8 dereferenceable(64) %3) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %3) #5
  br label %7, !llvm.loop !9

24:                                               ; preds = %18
  %25 = landingpad { ptr, i32 }
          cleanup
  %26 = extractvalue { ptr, i32 } %25, 0
  store ptr %26, ptr %4, align 8
  %27 = extractvalue { ptr, i32 } %25, 1
  store i32 %27, ptr %5, align 4
  call void @_ZN5ImageD1Ev(ptr noundef nonnull align 8 dereferenceable(64) %3) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %3) #5
  br label %29

28:                                               ; preds = %7
  ret void

29:                                               ; preds = %24
  %30 = load ptr, ptr %4, align 8
  %31 = load i32, ptr %5, align 4
  %32 = insertvalue { ptr, i32 } poison, ptr %30, 0
  %33 = insertvalue { ptr, i32 } %32, i32 %31, 1
  resume { ptr, i32 } %33
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE12emplace_backIJS0_EEERS0_DpOT_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(64)) #0 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNK5Image5widthEv(ptr noundef nonnull align 8 dereferenceable(64)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNK5Image6heightEv(ptr noundef nonnull align 8 dereferenceable(64)) #2 align 2

declare void @_ZNK5Image11downSampledEv(ptr dead_on_unwind writable sret(%class.Image) align 8, ptr noundef nonnull align 8 dereferenceable(64)) #3

; Function Attrs: nounwind
declare void @_ZN5ImageD1Ev(ptr noundef nonnull align 8 dereferenceable(64)) unnamed_addr #4

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 = { nocallback nofree nosync 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 = { "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 "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 }

!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 = distinct !{!9, !10}
!10 = !{!"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"

%class.Image = type { i16, i16, ptr, i8, %class.FilePath }
%class.FilePath = type { %"class.std::filesystem::__cxx11::path" }
%"class.std::filesystem::__cxx11::path" = type { %"class.std::__cxx11::basic_string", %"struct.std::filesystem::__cxx11::path::_List" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"struct.std::filesystem::__cxx11::path::_List" = type { %"class.std::unique_ptr" }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.4" }
%"struct.std::_Head_base.4" = type { ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7Texture10downSampleEv(ptr noundef nonnull align 8 dereferenceable(65) %0) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %class.Image, align 8
  %3 = tail call noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #5
  %4 = tail call noundef zeroext i16 @_ZNK5Image5widthEv(ptr noundef nonnull align 8 dereferenceable(64) %3)
  %5 = zext i16 %4 to i32
  %6 = tail call noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #5
  %7 = tail call noundef zeroext i16 @_ZNK5Image6heightEv(ptr noundef nonnull align 8 dereferenceable(64) %6)
  %8 = zext i16 %7 to i32
  %9 = mul nuw nsw i32 %8, %5
  %.not2 = icmp eq i32 %9, 1
  br i1 %.not2, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %12
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #5
  %10 = call noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #5
  call void @_ZNK5Image11downSampledEv(ptr dead_on_unwind nonnull writable sret(%class.Image) align 8 %2, ptr noundef nonnull align 8 dereferenceable(64) %10)
  %11 = invoke noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE12emplace_backIJS0_EEERS0_DpOT_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(64) %2)
          to label %12 unwind label %20

12:                                               ; preds = %.lr.ph
  call void @_ZN5ImageD1Ev(ptr noundef nonnull align 8 dereferenceable(64) %2) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #5
  %13 = call noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #5
  %14 = call noundef zeroext i16 @_ZNK5Image5widthEv(ptr noundef nonnull align 8 dereferenceable(64) %13)
  %15 = zext i16 %14 to i32
  %16 = call noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #5
  %17 = call noundef zeroext i16 @_ZNK5Image6heightEv(ptr noundef nonnull align 8 dereferenceable(64) %16)
  %18 = zext i16 %17 to i32
  %19 = mul nuw nsw i32 %18, %15
  %.not = icmp eq i32 %19, 1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

20:                                               ; preds = %.lr.ph
  %21 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN5ImageD1Ev(ptr noundef nonnull align 8 dereferenceable(64) %2) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #5
  resume { ptr, i32 } %21

._crit_edge:                                      ; preds = %12, %1
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE12emplace_backIJS0_EEERS0_DpOT_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(64) ptr @_ZNSt6vectorI5ImageSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNK5Image5widthEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNK5Image6heightEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #2 align 2

declare void @_ZNK5Image11downSampledEv(ptr dead_on_unwind writable sret(%class.Image) align 8, ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #3

; Function Attrs: nounwind
declare void @_ZN5ImageD1Ev(ptr noundef nonnull align 8 dereferenceable(64)) unnamed_addr #4

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 nocallback nofree nosync 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 = { "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 "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 }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass