; LLVM IR from filipwasil/fillwave :: ext/nv_helpers_gl/nv_dds.ll (ZN6nv_dds8CTextureC2ERKS0_)

; 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.nv_dds::CTexture" = type { %"class.nv_dds::CSurface", %"class.std::deque.0" }
%"class.nv_dds::CSurface" = type { ptr, i32, i32, i32, i32, ptr }
%"class.std::deque.0" = type { %"class.std::_Deque_base.1" }
%"class.std::_Deque_base.1" = type { %"struct.std::_Deque_base<nv_dds::CSurface, std::allocator<nv_dds::CSurface>>::_Deque_impl" }
%"struct.std::_Deque_base<nv_dds::CSurface, std::allocator<nv_dds::CSurface>>::_Deque_impl" = type { %"struct.std::_Deque_base<nv_dds::CSurface, std::allocator<nv_dds::CSurface>>::_Deque_impl_data" }
%"struct.std::_Deque_base<nv_dds::CSurface, std::allocator<nv_dds::CSurface>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator.5", %"struct.std::_Deque_iterator.5" }
%"struct.std::_Deque_iterator.5" = type { ptr, ptr, ptr, ptr }

@_ZTVN6nv_dds8CTextureE = external dso_local unnamed_addr constant { [6 x ptr] }, align 8

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6nv_dds8CTexture15get_num_mipmapsEv(ptr noundef nonnull align 8 dereferenceable(112)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNK6nv_dds8CTexture10get_mipmapEj(ptr noundef nonnull align 8 dereferenceable(112), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(80)) unnamed_addr #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(80)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6nv_dds8CTextureC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr noundef nonnull align 8 dereferenceable(112) %1) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN6nv_dds8CSurfaceC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %8, ptr noundef nonnull align 8 dereferenceable(32) %9)
  store ptr getelementptr inbounds inrange(-16, 32) ({ [6 x ptr] }, ptr @_ZTVN6nv_dds8CTextureE, i32 0, i32 0, i32 2), ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %"class.nv_dds::CTexture", ptr %8, i32 0, i32 1
  invoke void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(80) %10)
          to label %11 unwind label %19

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %34, %11
  %13 = load i32, ptr %7, align 4, !tbaa !11
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = invoke noundef i32 @_ZNK6nv_dds8CTexture15get_num_mipmapsEv(ptr noundef nonnull align 8 dereferenceable(112) %14)
          to label %16 unwind label %23

16:                                               ; preds = %12
  %17 = icmp ult i32 %13, %15
  br i1 %17, label %27, label %18

18:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %37

19:                                               ; preds = %2
  %20 = landingpad { ptr, i32 }
          cleanup
  %21 = extractvalue { ptr, i32 } %20, 0
  store ptr %21, ptr %5, align 8
  %22 = extractvalue { ptr, i32 } %20, 1
  store i32 %22, ptr %6, align 4
  br label %38

23:                                               ; preds = %32, %27, %12
  %24 = landingpad { ptr, i32 }
          cleanup
  %25 = extractvalue { ptr, i32 } %24, 0
  store ptr %25, ptr %5, align 8
  %26 = extractvalue { ptr, i32 } %24, 1
  store i32 %26, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(80) %10) #4
  br label %38

27:                                               ; preds = %16
  %28 = getelementptr inbounds %"class.nv_dds::CTexture", ptr %8, i32 0, i32 1
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !11
  %31 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNK6nv_dds8CTexture10get_mipmapEj(ptr noundef nonnull align 8 dereferenceable(112) %29, i32 noundef %30)
          to label %32 unwind label %23

32:                                               ; preds = %27
  invoke void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EE9push_backERKS1_(ptr noundef nonnull align 8 dereferenceable(80) %28, ptr noundef nonnull align 8 dereferenceable(32) %31)
          to label %33 unwind label %23

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %7, align 4, !tbaa !11
  %36 = add i32 %35, 1
  store i32 %36, ptr %7, align 4, !tbaa !11
  br label %12, !llvm.loop !13

37:                                               ; preds = %18
  ret void

38:                                               ; preds = %23, %19
  call void @_ZN6nv_dds8CSurfaceD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %8) #4
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr %5, align 8
  %41 = load i32, ptr %6, align 4
  %42 = insertvalue { ptr, i32 } poison, ptr %40, 0
  %43 = insertvalue { ptr, i32 } %42, i32 %41, 1
  resume { ptr, i32 } %43
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6nv_dds8CSurfaceC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EE9push_backERKS1_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { 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 = { 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@_ZTVN6nv_dds8CTextureE = external dso_local unnamed_addr constant { [6 x ptr] }, align 8

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6nv_dds8CTexture15get_num_mipmapsEv(ptr noundef nonnull align 8 dereferenceable(112)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNK6nv_dds8CTexture10get_mipmapEj(ptr noundef nonnull align 8 dereferenceable(112), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(80)) unnamed_addr #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6nv_dds8CTextureC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr noundef nonnull align 8 dereferenceable(112) %1) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN6nv_dds8CSurfaceC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1)
  store ptr getelementptr inbounds inrange(-16, 32) (i8, ptr @_ZTVN6nv_dds8CTextureE, i64 16), ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  invoke void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(80) %3)
          to label %.preheader unwind label %5

.preheader:                                       ; preds = %2
  %4 = tail call noundef i32 @_ZNK6nv_dds8CTexture15get_num_mipmapsEv(ptr noundef nonnull align 8 dereferenceable(112) %1)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %10, %.preheader
  ret void

5:                                                ; preds = %2
  %6 = landingpad { ptr, i32 }
          cleanup
  br label %14

7:                                                ; preds = %.lr.ph
  %8 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(80) %3) #3
  br label %14

.lr.ph:                                           ; preds = %.preheader, %10
  %.011 = phi i32 [ %11, %10 ], [ 0, %.preheader ]
  %9 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZNK6nv_dds8CTexture10get_mipmapEj(ptr noundef nonnull align 8 dereferenceable(112) %1, i32 noundef %.011)
  invoke void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EE9push_backERKS1_(ptr noundef nonnull align 8 dereferenceable(80) %3, ptr noundef nonnull align 8 dereferenceable(32) %9)
          to label %10 unwind label %7

10:                                               ; preds = %.lr.ph
  %11 = add nuw i32 %.011, 1
  %12 = tail call noundef i32 @_ZNK6nv_dds8CTexture15get_num_mipmapsEv(ptr noundef nonnull align 8 dereferenceable(112) %1)
  %13 = icmp ult i32 %11, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !8

14:                                               ; preds = %7, %5
  %.pn = phi { ptr, i32 } [ %8, %7 ], [ %6, %5 ]
  tail call void @_ZN6nv_dds8CSurfaceD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) #3
  resume { ptr, i32 } %.pn
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5dequeIN6nv_dds8CSurfaceESaIS1_EE9push_backERKS1_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

attributes #0 = { 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 #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 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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