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

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

@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__._ZN6nv_dds9CDDSImage21upload_textureCubemapEv = external hidden unnamed_addr constant [48 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; 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 i64 @_ZNKSt5dequeIN6nv_dds8CTextureESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt5dequeIN6nv_dds8CTextureESaIS1_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN6nv_dds9CDDSImage16upload_texture2DEjj(ptr noundef nonnull align 8 dereferenceable(104), i32 noundef, i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6nv_dds9CDDSImage21upload_textureCubemapEv(ptr noundef nonnull align 8 dereferenceable(104) %0) #3 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %"class.nv_dds::CDDSImage", ptr %7, i32 0, i32 4
  %9 = load i8, ptr %8, align 8, !tbaa !9, !range !20, !noundef !21
  %10 = trunc i8 %9 to i1
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  br label %14

12:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.18, ptr noundef @.str.1, i32 noundef 896, ptr noundef @__PRETTY_FUNCTION__._ZN6nv_dds9CDDSImage21upload_textureCubemapEv) #4
  unreachable

13:                                               ; No predecessors!
  br label %14

14:                                               ; preds = %13, %11
  %15 = getelementptr inbounds %"class.nv_dds::CDDSImage", ptr %7, i32 0, i32 5
  %16 = call noundef zeroext i1 @_ZNKSt5dequeIN6nv_dds8CTextureESaIS1_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) %15) #5
  %17 = xor i1 %16, true
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  br label %21

19:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.22, ptr noundef @.str.1, i32 noundef 897, ptr noundef @__PRETTY_FUNCTION__._ZN6nv_dds9CDDSImage21upload_textureCubemapEv) #4
  unreachable

20:                                               ; No predecessors!
  br label %21

21:                                               ; preds = %20, %18
  %22 = getelementptr inbounds %"class.nv_dds::CDDSImage", ptr %7, i32 0, i32 3
  %23 = load i32, ptr %22, align 4, !tbaa !22
  %24 = icmp eq i32 %23, 3
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  br label %28

26:                                               ; preds = %21
  call void @__assert_fail(ptr noundef @.str.33, ptr noundef @.str.1, i32 noundef 898, ptr noundef @__PRETTY_FUNCTION__._ZN6nv_dds9CDDSImage21upload_textureCubemapEv) #4
  unreachable

27:                                               ; No predecessors!
  br label %28

28:                                               ; preds = %27, %25
  %29 = getelementptr inbounds %"class.nv_dds::CDDSImage", ptr %7, i32 0, i32 5
  %30 = call noundef i64 @_ZNKSt5dequeIN6nv_dds8CTextureESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80) %29) #5
  %31 = icmp eq i64 %30, 6
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  br label %35

33:                                               ; preds = %28
  call void @__assert_fail(ptr noundef @.str.21, ptr noundef @.str.1, i32 noundef 899, ptr noundef @__PRETTY_FUNCTION__._ZN6nv_dds9CDDSImage21upload_textureCubemapEv) #4
  unreachable

34:                                               ; No predecessors!
  br label %35

35:                                               ; preds = %34, %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !23
  br label %36

36:                                               ; preds = %48, %35
  %37 = load i32, ptr %5, align 4, !tbaa !23
  %38 = icmp ult i32 %37, 6
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  store i32 2, ptr %6, align 4
  br label %51

40:                                               ; preds = %36
  %41 = load i32, ptr %5, align 4, !tbaa !23
  %42 = add i32 34069, %41
  store i32 %42, ptr %4, align 4, !tbaa !23
  %43 = load i32, ptr %5, align 4, !tbaa !23
  %44 = load i32, ptr %4, align 4, !tbaa !23
  %45 = call noundef zeroext i1 @_ZN6nv_dds9CDDSImage16upload_texture2DEjj(ptr noundef nonnull align 8 dereferenceable(104) %7, i32 noundef %43, i32 noundef %44)
  br i1 %45, label %47, label %46

46:                                               ; preds = %40
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %51

47:                                               ; preds = %40
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %5, align 4, !tbaa !23
  %50 = add i32 %49, 1
  store i32 %50, ptr %5, align 4, !tbaa !23
  br label %36, !llvm.loop !24

51:                                               ; preds = %46, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  %52 = load i32, ptr %6, align 4
  switch i32 %52, label %54 [
    i32 2, label %53
  ]

53:                                               ; preds = %51
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %54

54:                                               ; preds = %53, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %55 = load i1, ptr %2, align 1
  ret i1 %55
}

attributes #0 = { noreturn 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 #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 = { 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 #4 = { noreturn nounwind }
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 = !{!10, !13, i64 16}
!10 = !{!"_ZTSN6nv_dds9CDDSImageE", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 12, !13, i64 16, !14, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSN6nv_dds11TextureTypeE", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSSt5dequeIN6nv_dds8CTextureESaIS1_EE", !15, i64 0}
!15 = !{!"_ZTSSt11_Deque_baseIN6nv_dds8CTextureESaIS1_EE", !16, i64 0}
!16 = !{!"_ZTSNSt11_Deque_baseIN6nv_dds8CTextureESaIS1_EE11_Deque_implE", !17, i64 0}
!17 = !{!"_ZTSNSt11_Deque_baseIN6nv_dds8CTextureESaIS1_EE16_Deque_impl_dataE", !6, i64 0, !18, i64 8, !19, i64 16, !19, i64 48}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_ZTSSt15_Deque_iteratorIN6nv_dds8CTextureERS1_PS1_E", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!10, !12, i64 12}
!23 = !{!11, !11, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__._ZN6nv_dds9CDDSImage21upload_textureCubemapEv = external hidden unnamed_addr constant [48 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt5dequeIN6nv_dds8CTextureESaIS1_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN6nv_dds9CDDSImage16upload_texture2DEjj(ptr noundef nonnull align 8 dereferenceable(104), i32 noundef, i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6nv_dds9CDDSImage21upload_textureCubemapEv(ptr noundef nonnull align 8 dereferenceable(104) %0) local_unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i8, ptr %2, align 8, !tbaa !5, !range !19, !noundef !20
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %6, label %5

5:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.1, i32 noundef 896, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6nv_dds9CDDSImage21upload_textureCubemapEv) #3
  unreachable

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = tail call noundef zeroext i1 @_ZNKSt5dequeIN6nv_dds8CTextureESaIS1_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) %7) #4
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.22, ptr noundef nonnull @.str.1, i32 noundef 897, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6nv_dds9CDDSImage21upload_textureCubemapEv) #3
  unreachable

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  %12 = load i32, ptr %11, align 4, !tbaa !21
  %13 = icmp eq i32 %12, 3
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str.33, ptr noundef nonnull @.str.1, i32 noundef 898, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6nv_dds9CDDSImage21upload_textureCubemapEv) #3
  unreachable

15:                                               ; preds = %10
  %16 = tail call noundef i64 @_ZNKSt5dequeIN6nv_dds8CTextureESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80) %7) #4
  %17 = icmp eq i64 %16, 6
  br i1 %17, label %.preheader.preheader, label %19

.preheader.preheader:                             ; preds = %15
  %18 = tail call noundef zeroext i1 @_ZN6nv_dds9CDDSImage16upload_texture2DEjj(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef 0, i32 noundef 34069)
  br i1 %18, label %.preheader.1, label %.critedge

19:                                               ; preds = %15
  tail call void @__assert_fail(ptr noundef nonnull @.str.21, ptr noundef nonnull @.str.1, i32 noundef 899, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6nv_dds9CDDSImage21upload_textureCubemapEv) #3
  unreachable

.preheader.1:                                     ; preds = %.preheader.preheader
  %20 = tail call noundef zeroext i1 @_ZN6nv_dds9CDDSImage16upload_texture2DEjj(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef 1, i32 noundef 34070)
  br i1 %20, label %.preheader.2, label %.critedge

.preheader.2:                                     ; preds = %.preheader.1
  %21 = tail call noundef zeroext i1 @_ZN6nv_dds9CDDSImage16upload_texture2DEjj(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef 2, i32 noundef 34071)
  br i1 %21, label %.preheader.3, label %.critedge

.preheader.3:                                     ; preds = %.preheader.2
  %22 = tail call noundef zeroext i1 @_ZN6nv_dds9CDDSImage16upload_texture2DEjj(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef 3, i32 noundef 34072)
  br i1 %22, label %.preheader.4, label %.critedge

.preheader.4:                                     ; preds = %.preheader.3
  %23 = tail call noundef zeroext i1 @_ZN6nv_dds9CDDSImage16upload_texture2DEjj(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef 4, i32 noundef 34073)
  br i1 %23, label %.preheader.5, label %.critedge

.preheader.5:                                     ; preds = %.preheader.4
  %24 = tail call noundef zeroext i1 @_ZN6nv_dds9CDDSImage16upload_texture2DEjj(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef 5, i32 noundef 34074)
  br label %.critedge

.critedge:                                        ; preds = %.preheader.5, %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  %.lcssa = phi i1 [ false, %.preheader.preheader ], [ false, %.preheader.1 ], [ false, %.preheader.2 ], [ false, %.preheader.3 ], [ false, %.preheader.4 ], [ %24, %.preheader.5 ]
  ret i1 %.lcssa
}

attributes #0 = { noreturn 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 #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 = { 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 = { noreturn nounwind }
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, !11, i64 16}
!6 = !{!"_ZTSN6nv_dds9CDDSImageE", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 12, !11, i64 16, !12, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN6nv_dds11TextureTypeE", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"_ZTSSt5dequeIN6nv_dds8CTextureESaIS1_EE", !13, i64 0}
!13 = !{!"_ZTSSt11_Deque_baseIN6nv_dds8CTextureESaIS1_EE", !14, i64 0}
!14 = !{!"_ZTSNSt11_Deque_baseIN6nv_dds8CTextureESaIS1_EE11_Deque_implE", !15, i64 0}
!15 = !{!"_ZTSNSt11_Deque_baseIN6nv_dds8CTextureESaIS1_EE16_Deque_impl_dataE", !16, i64 0, !17, i64 8, !18, i64 16, !18, i64 48}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"long", !8, i64 0}
!18 = !{!"_ZTSSt15_Deque_iteratorIN6nv_dds8CTextureERS1_PS1_E", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!6, !10, i64 12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass