; LLVM IR from awawa-dev/HyperHDR :: sources/image/ImageData.ll (ZNK9ImageDataI8ColorRgbE5toRgbERS1_)

; 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.ImageData = type { i32, i32, %"class.std::unique_ptr", 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.1" }
%"struct.std::_Head_base.1" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK9ImageDataI8ColorRgbE5toRgbERS1_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #0 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
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = call noundef i32 @_ZNK9ImageDataI8ColorRgbE5widthEv(ptr noundef nonnull align 8 dereferenceable(24) %6)
  %8 = getelementptr inbounds %class.ImageData, ptr %5, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp ne i32 %7, %9
  br i1 %10, label %17, label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call noundef i32 @_ZNK9ImageDataI8ColorRgbE6heightEv(ptr noundef nonnull align 8 dereferenceable(24) %12)
  %14 = getelementptr inbounds %class.ImageData, ptr %5, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !18
  %16 = icmp ne i32 %13, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %11, %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.ImageData, ptr %5, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %class.ImageData, ptr %5, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !18
  call void @_ZN9ImageDataI8ColorRgbE6resizeEjj(ptr noundef nonnull align 8 dereferenceable(24) %18, i32 noundef %20, i32 noundef %22)
  br label %23

23:                                               ; preds = %17, %11
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call noundef ptr @_ZN9ImageDataI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(24) %24)
  %26 = getelementptr inbounds %class.ImageData, ptr %5, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !19
  %28 = getelementptr inbounds %class.ImageData, ptr %5, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds %class.ImageData, ptr %5, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !18
  %33 = zext i32 %32 to i64
  %34 = mul i64 %30, %33
  %35 = mul i64 %34, 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr align 1 %27, i64 %35, i1 false)
  ret void
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN9ImageDataI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 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) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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, !11, i64 0}
!10 = !{!"_ZTS9ImageDataI8ColorRgbE", !11, i64 0, !11, i64 4, !12, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSSt10unique_ptrI12MemoryBufferIhESt14default_deleteIS1_EE", !13, i64 0}
!13 = !{!"_ZTSSt15__uniq_ptr_dataI12MemoryBufferIhESt14default_deleteIS1_ELb1ELb1EE", !14, i64 0}
!14 = !{!"_ZTSSt15__uniq_ptr_implI12MemoryBufferIhESt14default_deleteIS1_EE", !15, i64 0}
!15 = !{!"_ZTSSt5tupleIJP12MemoryBufferIhESt14default_deleteIS1_EEE", !16, i64 0}
!16 = !{!"_ZTSSt11_Tuple_implILm0EJP12MemoryBufferIhESt14default_deleteIS1_EEE", !17, i64 0}
!17 = !{!"_ZTSSt10_Head_baseILm0EP12MemoryBufferIhELb0EE", !6, i64 0}
!18 = !{!10, !11, i64 4}
!19 = !{!10, !6, i64 16}


; 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 void @_ZNK9ImageDataI8ColorRgbE5toRgbERS1_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i32 @_ZNK9ImageDataI8ColorRgbE5widthEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %3, %4
  br i1 %.not, label %5, label %._crit_edge6

._crit_edge6:                                     ; preds = %2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 4
  %.pre7 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !17
  br label %9

5:                                                ; preds = %2
  %6 = tail call noundef i32 @_ZNK9ImageDataI8ColorRgbE6heightEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !17
  %.not5 = icmp eq i32 %6, %8
  br i1 %.not5, label %12, label %._crit_edge

._crit_edge:                                      ; preds = %5
  %.pre = load i32, ptr %0, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %._crit_edge6, %._crit_edge
  %10 = phi i32 [ %8, %._crit_edge ], [ %.pre7, %._crit_edge6 ]
  %11 = phi i32 [ %.pre, %._crit_edge ], [ %4, %._crit_edge6 ]
  tail call void @_ZN9ImageDataI8ColorRgbE6resizeEjj(ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %11, i32 noundef %10)
  br label %12

12:                                               ; preds = %9, %5
  %13 = tail call noundef ptr @_ZN9ImageDataI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !18
  %16 = load i32, ptr %0, align 8, !tbaa !5
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !17
  %20 = zext i32 %19 to i64
  %21 = mul nuw nsw i64 %17, 3
  %22 = mul i64 %21, %20
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %13, ptr align 1 %15, i64 %22, i1 false)
  ret void
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN9ImageDataI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 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) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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, !7, i64 0}
!6 = !{!"_ZTS9ImageDataI8ColorRgbE", !7, i64 0, !7, i64 4, !10, i64 8, !16, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt10unique_ptrI12MemoryBufferIhESt14default_deleteIS1_EE", !11, i64 0}
!11 = !{!"_ZTSSt15__uniq_ptr_dataI12MemoryBufferIhESt14default_deleteIS1_ELb1ELb1EE", !12, i64 0}
!12 = !{!"_ZTSSt15__uniq_ptr_implI12MemoryBufferIhESt14default_deleteIS1_EE", !13, i64 0}
!13 = !{!"_ZTSSt5tupleIJP12MemoryBufferIhESt14default_deleteIS1_EEE", !14, i64 0}
!14 = !{!"_ZTSSt11_Tuple_implILm0EJP12MemoryBufferIhESt14default_deleteIS1_EEE", !15, i64 0}
!15 = !{!"_ZTSSt10_Head_baseILm0EP12MemoryBufferIhELb0EE", !16, i64 0}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!6, !7, i64 4}
!18 = !{!6, !16, i64 16}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass