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

; 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::CSurface" = type { ptr, i32, i32, i32, i32, ptr }

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

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

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

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6nv_dds8CSurfaceC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) unnamed_addr #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  store ptr getelementptr inbounds inrange(-16, 32) ({ [6 x ptr] }, ptr @_ZTVN6nv_dds8CSurfaceE, i32 0, i32 0, i32 2), ptr %5, align 8, !tbaa !9
  %6 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 1
  store i32 0, ptr %6, align 8, !tbaa !11
  %7 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 2
  store i32 0, ptr %7, align 4, !tbaa !14
  %8 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 3
  store i32 0, ptr %8, align 8, !tbaa !15
  %9 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 4
  store i32 0, ptr %9, align 4, !tbaa !16
  %10 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 5
  store ptr null, ptr %10, align 8, !tbaa !17
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call noundef i32 @_ZNK6nv_dds8CSurface8get_sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %11)
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %39

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call noundef i32 @_ZNK6nv_dds8CSurface8get_sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %15)
  %17 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 4
  store i32 %16, ptr %17, align 4, !tbaa !16
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call noundef i32 @_ZNK6nv_dds8CSurface9get_widthEv(ptr noundef nonnull align 8 dereferenceable(32) %18)
  %20 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 1
  store i32 %19, ptr %20, align 8, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call noundef i32 @_ZNK6nv_dds8CSurface10get_heightEv(ptr noundef nonnull align 8 dereferenceable(32) %21)
  %23 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 2
  store i32 %22, ptr %23, align 4, !tbaa !14
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call noundef i32 @_ZNK6nv_dds8CSurface9get_depthEv(ptr noundef nonnull align 8 dereferenceable(32) %24)
  %26 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 3
  store i32 %25, ptr %26, align 8, !tbaa !15
  %27 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 4
  %28 = load i32, ptr %27, align 4, !tbaa !16
  %29 = zext i32 %28 to i64
  %30 = call noalias noundef nonnull ptr @_Znam(i64 noundef %29) #5
  %31 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 5
  store ptr %30, ptr %31, align 8, !tbaa !17
  %32 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 5
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = call noundef ptr @_ZNK6nv_dds8CSurfacecvPhEv(ptr noundef nonnull align 8 dereferenceable(32) %34)
  %36 = getelementptr inbounds %"class.nv_dds::CSurface", ptr %5, i32 0, i32 4
  %37 = load i32, ptr %36, align 4, !tbaa !16
  %38 = zext i32 %37 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %33, ptr align 1 %35, i64 %38, i1 false)
  br label %39

39:                                               ; preds = %14, %2
  ret void
}

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 = { nobuiltin allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { builtin allocsize(0) }

!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, !13, i64 8}
!12 = !{!"_ZTSN6nv_dds8CSurfaceE", !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !6, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 12}
!15 = !{!12, !13, i64 16}
!16 = !{!12, !13, i64 20}
!17 = !{!12, !6, i64 24}


; 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_dds8CSurfaceE = external dso_local unnamed_addr constant { [6 x ptr] }, align 8

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

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

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6nv_dds8CSurfaceC2ERKS0_(ptr nocapture noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) unnamed_addr #4 align 2 {
  store ptr getelementptr inbounds inrange(-16, 32) (i8, ptr @_ZTVN6nv_dds8CSurfaceE, i64 16), ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, i8 0, i64 24, i1 false)
  %4 = tail call noundef i32 @_ZNK6nv_dds8CSurface8get_sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %20, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = getelementptr inbounds i8, ptr %0, i64 20
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = getelementptr inbounds i8, ptr %0, i64 12
  %10 = tail call noundef i32 @_ZNK6nv_dds8CSurface8get_sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  store i32 %10, ptr %7, align 4, !tbaa !8
  %11 = tail call noundef i32 @_ZNK6nv_dds8CSurface9get_widthEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  store i32 %11, ptr %3, align 8, !tbaa !13
  %12 = tail call noundef i32 @_ZNK6nv_dds8CSurface10get_heightEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  store i32 %12, ptr %9, align 4, !tbaa !14
  %13 = tail call noundef i32 @_ZNK6nv_dds8CSurface9get_depthEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  store i32 %13, ptr %8, align 8, !tbaa !15
  %14 = load i32, ptr %7, align 4, !tbaa !8
  %15 = zext i32 %14 to i64
  %16 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %15) #6
  store ptr %16, ptr %6, align 8, !tbaa !16
  %17 = tail call noundef ptr @_ZNK6nv_dds8CSurfacecvPhEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %18 = load i32, ptr %7, align 4, !tbaa !8
  %19 = zext i32 %18 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %16, ptr align 1 %17, i64 %19, i1 false)
  br label %20

20:                                               ; preds = %5, %2
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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 = { nobuiltin allocsize(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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { builtin allocsize(0) }

!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 = !{!9, !10, i64 20}
!9 = !{!"_ZTSN6nv_dds8CSurfaceE", !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !12, i64 24}
!10 = !{!"int", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"any pointer", !11, i64 0}
!13 = !{!9, !10, i64 8}
!14 = !{!9, !10, i64 12}
!15 = !{!9, !10, i64 16}
!16 = !{!9, !12, i64 24}


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