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

; 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.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 }
%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 }

; 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 noundef nonnull align 8 dereferenceable(64) ptr @_ZNK7Texture10get_sampleEd(ptr noundef nonnull align 8 dereferenceable(65) %0, double noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i64, align 8
  %6 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = getelementptr inbounds %class.Texture, ptr %7, i32 0, i32 0
  %9 = call noundef i64 @_ZNKSt6vectorI5ImageSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %8) #4
  %10 = sub i64 %9, 1
  %11 = shl i64 1, %10
  store i64 %11, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #4
  %12 = load double, ptr %4, align 8, !tbaa !9
  %13 = fcmp olt double %12, 2.000000e+00
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i16 0, ptr %6, align 2, !tbaa !13
  br label %34

15:                                               ; preds = %2
  %16 = load double, ptr %4, align 8, !tbaa !9
  %17 = load i64, ptr %5, align 8, !tbaa !11
  %18 = uitofp i64 %17 to double
  %19 = fcmp olt double %16, %18
  br i1 %19, label %20, label %28

20:                                               ; preds = %15
  %21 = load double, ptr %4, align 8, !tbaa !9
  %22 = fptoui double %21 to i64
  %23 = call noundef i32 @_Z8log2_u64m(i64 noundef %22)
  %24 = trunc i32 %23 to i16
  %25 = zext i16 %24 to i32
  %26 = sub nsw i32 %25, 1
  %27 = trunc i32 %26 to i16
  store i16 %27, ptr %6, align 2, !tbaa !13
  br label %33

28:                                               ; preds = %15
  %29 = getelementptr inbounds %class.Texture, ptr %7, i32 0, i32 0
  %30 = call noundef i64 @_ZNKSt6vectorI5ImageSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %29) #4
  %31 = sub i64 %30, 1
  %32 = trunc i64 %31 to i16
  store i16 %32, ptr %6, align 2, !tbaa !13
  br label %33

33:                                               ; preds = %28, %20
  br label %34

34:                                               ; preds = %33, %14
  %35 = getelementptr inbounds %class.Texture, ptr %7, i32 0, i32 0
  %36 = load i16, ptr %6, align 2, !tbaa !13
  %37 = zext i16 %36 to i64
  %38 = call noundef nonnull align 8 dereferenceable(64) ptr @_ZNKSt6vectorI5ImageSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %35, i64 noundef %37) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %38
}

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

declare noundef i32 @_Z8log2_u64m(i64 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(64) ptr @_ZNKSt6vectorI5ImageSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #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 = { 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 }

!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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(64) ptr @_ZNK7Texture10get_sampleEd(ptr noundef nonnull align 8 dereferenceable(65) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i64 @_ZNKSt6vectorI5ImageSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  %4 = fcmp olt double %1, 2.000000e+00
  br i1 %4, label %18, label %5

5:                                                ; preds = %2
  %6 = add i64 %3, -1
  %7 = shl nuw i64 1, %6
  %8 = uitofp i64 %7 to double
  %9 = fcmp ogt double %8, %1
  br i1 %9, label %10, label %15

10:                                               ; preds = %5
  %11 = fptoui double %1 to i64
  %12 = tail call noundef i32 @_Z8log2_u64m(i64 noundef %11)
  %13 = zext i32 %12 to i64
  %14 = add nuw nsw i64 %13, 65535
  br label %18

15:                                               ; preds = %5
  %16 = tail call noundef i64 @_ZNKSt6vectorI5ImageSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  %17 = add i64 %16, 65535
  br label %18

18:                                               ; preds = %2, %10, %15
  %.0 = phi i64 [ %14, %10 ], [ %17, %15 ], [ 0, %2 ]
  %19 = and i64 %.0, 65535
  %20 = tail call noundef nonnull align 8 dereferenceable(64) ptr @_ZNKSt6vectorI5ImageSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %19) #3
  ret ptr %20
}

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

declare noundef i32 @_Z8log2_u64m(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(64) ptr @_ZNKSt6vectorI5ImageSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 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 = { "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)"}


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