; LLVM IR from Razakhel/RaZ :: src/RaZ/Render/Texture.ll (ZNK3Raz9Texture2D12recoverImageEv)

; 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.Raz::Image" = type { i32, i32, i32, i32, i8, %"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.12" }
%"struct.std::_Head_base.12" = type { ptr }
%"class.Raz::Texture2D" = type { %"class.Raz::Texture", i32, i32 }
%"class.Raz::Texture" = type { ptr, %"class.Raz::OwnerValue", i32, i32, i32 }
%"class.Raz::OwnerValue" = type { i32 }

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3Raz7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(24)) #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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i32 @_ZN3Raz12_GLOBAL__N_113recoverFormatENS_17TextureColorspaceE(i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3Raz9Texture2D12recoverImageEv(ptr dead_on_unwind noalias writable sret(%"class.Raz::Image") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i1, align 1
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  store i1 false, ptr %5, align 1
  %10 = getelementptr inbounds %"class.Raz::Texture2D", ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %"class.Raz::Texture2D", ptr %9, i32 0, i32 2
  %13 = load i32, ptr %12, align 4, !tbaa !17
  %14 = getelementptr inbounds %"class.Raz::Texture", ptr %9, i32 0, i32 3
  %15 = load i32, ptr %14, align 8, !tbaa !18
  %16 = getelementptr inbounds %"class.Raz::Texture", ptr %9, i32 0, i32 4
  %17 = load i32, ptr %16, align 4, !tbaa !19
  %18 = icmp eq i32 %17, 0
  %19 = zext i1 %18 to i64
  %20 = select i1 %18, i32 0, i32 1
  call void @_ZN3Raz5ImageC1EjjNS_15ImageColorspaceENS_13ImageDataTypeE(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %11, i32 noundef %13, i32 noundef %15, i32 noundef %20)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %21 = getelementptr inbounds %"class.Raz::Texture", ptr %9, i32 0, i32 4
  %22 = load i32, ptr %21, align 4, !tbaa !19
  %23 = icmp eq i32 %22, 0
  %24 = zext i1 %23 to i64
  %25 = select i1 %23, i32 5121, i32 5126
  store i32 %25, ptr %6, align 4, !tbaa !20
  invoke void @_ZNK3Raz7Texture4bindEv(ptr noundef nonnull align 8 dereferenceable(24) %9)
          to label %26 unwind label %36

26:                                               ; preds = %2
  %27 = getelementptr inbounds %"class.Raz::Texture", ptr %9, i32 0, i32 3
  %28 = load i32, ptr %27, align 8, !tbaa !18
  %29 = invoke noundef i32 @_ZN3Raz12_GLOBAL__N_113recoverFormatENS_17TextureColorspaceE(i32 noundef %28)
          to label %30 unwind label %36

30:                                               ; preds = %26
  %31 = load i32, ptr %6, align 4, !tbaa !20
  %32 = call noundef ptr @_ZN3Raz5Image10getDataPtrEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #6
  invoke void @_ZN3Raz8Renderer18recoverTextureDataENS_11TextureTypeEjNS_13TextureFormatENS_13PixelDataTypeEPv(i32 noundef 3553, i32 noundef 0, i32 noundef %29, i32 noundef %31, ptr noundef %32)
          to label %33 unwind label %36

33:                                               ; preds = %30
  invoke void @_ZNK3Raz7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(24) %9)
          to label %34 unwind label %36

34:                                               ; preds = %33
  store i1 true, ptr %5, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %35 = load i1, ptr %5, align 1
  br i1 %35, label %41, label %40

36:                                               ; preds = %33, %30, %26, %2
  %37 = landingpad { ptr, i32 }
          cleanup
  %38 = extractvalue { ptr, i32 } %37, 0
  store ptr %38, ptr %7, align 8
  %39 = extractvalue { ptr, i32 } %37, 1
  store i32 %39, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @_ZN3Raz5ImageD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) #6
  br label %42

40:                                               ; preds = %34
  call void @_ZN3Raz5ImageD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) #6
  br label %41

41:                                               ; preds = %40, %34
  ret void

42:                                               ; preds = %36
  %43 = load ptr, ptr %7, align 8
  %44 = load i32, ptr %8, align 4
  %45 = insertvalue { ptr, i32 } poison, ptr %43, 0
  %46 = insertvalue { ptr, i32 } %45, i32 %44, 1
  resume { ptr, i32 } %46
}

declare void @_ZN3Raz5ImageC1EjjNS_15ImageColorspaceENS_13ImageDataTypeE(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, i32 noundef, i32 noundef) unnamed_addr #3

declare void @_ZN3Raz8Renderer18recoverTextureDataENS_11TextureTypeEjNS_13TextureFormatENS_13PixelDataTypeEPv(i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3Raz5Image10getDataPtrEv(ptr noundef nonnull align 8 dereferenceable(32)) #4 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3Raz5ImageD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #5 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { "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 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 #5 = { 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 #6 = { 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, !13, i64 24}
!10 = !{!"_ZTSN3Raz9Texture2DE", !11, i64 0, !13, i64 24, !13, i64 28}
!11 = !{!"_ZTSN3Raz7TextureE", !12, i64 8, !14, i64 12, !15, i64 16, !16, i64 20}
!12 = !{!"_ZTSN3Raz10OwnerValueIjLj0EEE", !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSN3Raz11TextureTypeE", !7, i64 0}
!15 = !{!"_ZTSN3Raz17TextureColorspaceE", !7, i64 0}
!16 = !{!"_ZTSN3Raz15TextureDataTypeE", !7, i64 0}
!17 = !{!10, !13, i64 28}
!18 = !{!11, !15, i64 16}
!19 = !{!11, !16, i64 20}
!20 = !{!21, !21, i64 0}
!21 = !{!"_ZTSN3Raz13PixelDataTypeE", !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"

%"class.Raz::Image" = type { i32, i32, i32, i32, i8, %"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.12" }
%"struct.std::_Head_base.12" = type { ptr }

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

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i32 @_ZN3Raz12_GLOBAL__N_113recoverFormatENS_17TextureColorspaceE(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3Raz9Texture2D12recoverImageEv(ptr dead_on_unwind noalias nonnull writable sret(%"class.Raz::Image") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 24
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 28
  %6 = load i32, ptr %5, align 4, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %1, i64 20
  %10 = load i32, ptr %9, align 4, !tbaa !17
  %11 = icmp ne i32 %10, 0
  %12 = zext i1 %11 to i32
  tail call void @_ZN3Raz5ImageC1EjjNS_15ImageColorspaceENS_13ImageDataTypeE(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %4, i32 noundef %6, i32 noundef %8, i32 noundef %12)
  %13 = load i32, ptr %9, align 4, !tbaa !17
  %14 = icmp eq i32 %13, 0
  %15 = select i1 %14, i32 5121, i32 5126
  invoke void @_ZNK3Raz7Texture4bindEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
          to label %16 unwind label %22

16:                                               ; preds = %2
  %17 = load i32, ptr %7, align 8, !tbaa !16
  %18 = invoke noundef i32 @_ZN3Raz12_GLOBAL__N_113recoverFormatENS_17TextureColorspaceE(i32 noundef %17)
          to label %19 unwind label %22

19:                                               ; preds = %16
  %20 = tail call noundef ptr @_ZN3Raz5Image10getDataPtrEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #5
  invoke void @_ZN3Raz8Renderer18recoverTextureDataENS_11TextureTypeEjNS_13TextureFormatENS_13PixelDataTypeEPv(i32 noundef 3553, i32 noundef 0, i32 noundef %18, i32 noundef %15, ptr noundef %20)
          to label %21 unwind label %22

21:                                               ; preds = %19
  invoke void @_ZNK3Raz7Texture6unbindEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
          to label %24 unwind label %22

22:                                               ; preds = %21, %19, %16, %2
  %23 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN3Raz5ImageD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) #5
  resume { ptr, i32 } %23

24:                                               ; preds = %21
  ret void
}

declare void @_ZN3Raz5ImageC1EjjNS_15ImageColorspaceENS_13ImageDataTypeE(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, i32 noundef, i32 noundef) unnamed_addr #2

declare void @_ZN3Raz8Renderer18recoverTextureDataENS_11TextureTypeEjNS_13TextureFormatENS_13PixelDataTypeEPv(i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3Raz5Image10getDataPtrEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3Raz5ImageD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #4 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 = { inlinehint 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 = { "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 = { 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 #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, !9, i64 24}
!6 = !{!"_ZTSN3Raz9Texture2DE", !7, i64 0, !9, i64 24, !9, i64 28}
!7 = !{!"_ZTSN3Raz7TextureE", !8, i64 8, !12, i64 12, !13, i64 16, !14, i64 20}
!8 = !{!"_ZTSN3Raz10OwnerValueIjLj0EEE", !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSN3Raz11TextureTypeE", !10, i64 0}
!13 = !{!"_ZTSN3Raz17TextureColorspaceE", !10, i64 0}
!14 = !{!"_ZTSN3Raz15TextureDataTypeE", !10, i64 0}
!15 = !{!6, !9, i64 28}
!16 = !{!7, !13, i64 16}
!17 = !{!7, !14, i64 20}


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