; LLVM IR from awawa-dev/HyperHDR :: sources/hyperimage/HyperImage.ll (ZNK10HyperImage11renderImageEv)

; 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.Image = type <{ %"class.std::shared_ptr", i32, [4 x i8] }>
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%class.HyperImage = type { %class.Image, %struct.ColorRgb, [5 x i8] }
%struct.ColorRgb = type { i8, i8, i8 }

; 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) #0

declare void @_ZN5ImageI8ColorRgbEC1Ejj(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef, i32 noundef) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK10HyperImage5widthEv(ptr noundef nonnull align 8 dereferenceable(27)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK10HyperImage6heightEv(ptr noundef nonnull align 8 dereferenceable(27)) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK10HyperImage11renderImageEv(ptr dead_on_unwind noalias writable sret(%class.Image) align 8 %0, ptr noundef nonnull align 8 dereferenceable(27) %1) #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  store i1 false, ptr %5, align 1
  %9 = call noundef i32 @_ZNK10HyperImage5widthEv(ptr noundef nonnull align 8 dereferenceable(27) %8)
  %10 = call noundef i32 @_ZNK10HyperImage6heightEv(ptr noundef nonnull align 8 dereferenceable(27) %8)
  call void @_ZN5ImageI8ColorRgbEC1Ejj(ptr noundef nonnull align 8 dereferenceable(20) %0, i32 noundef %9, i32 noundef %10)
  %11 = invoke noundef ptr @_ZN5ImageI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(20) %0)
          to label %12 unwind label %25

12:                                               ; preds = %2
  %13 = getelementptr inbounds %class.HyperImage, ptr %8, i32 0, i32 0
  %14 = invoke noundef ptr @_ZNK5ImageI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(20) %13)
          to label %15 unwind label %25

15:                                               ; preds = %12
  %16 = invoke noundef i32 @_ZNK10HyperImage5widthEv(ptr noundef nonnull align 8 dereferenceable(27) %8)
          to label %17 unwind label %25

17:                                               ; preds = %15
  %18 = sext i32 %16 to i64
  %19 = mul nsw i64 3, %18
  %20 = invoke noundef i32 @_ZNK10HyperImage6heightEv(ptr noundef nonnull align 8 dereferenceable(27) %8)
          to label %21 unwind label %25

21:                                               ; preds = %17
  %22 = sext i32 %20 to i64
  %23 = mul nsw i64 %19, %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %11, ptr align 1 %14, i64 %23, i1 false)
  store i1 true, ptr %5, align 1
  %24 = load i1, ptr %5, align 1
  br i1 %24, label %30, label %29

25:                                               ; preds = %17, %15, %12, %2
  %26 = landingpad { ptr, i32 }
          cleanup
  %27 = extractvalue { ptr, i32 } %26, 0
  store ptr %27, ptr %6, align 8
  %28 = extractvalue { ptr, i32 } %26, 1
  store i32 %28, ptr %7, align 4
  call void @_ZN5ImageI8ColorRgbED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %0) #4
  br label %31

29:                                               ; preds = %21
  call void @_ZN5ImageI8ColorRgbED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %0) #4
  br label %30

30:                                               ; preds = %29, %21
  ret void

31:                                               ; preds = %25
  %32 = load ptr, ptr %6, align 8
  %33 = load i32, ptr %7, align 4
  %34 = insertvalue { ptr, i32 } poison, ptr %32, 0
  %35 = insertvalue { ptr, i32 } %34, i32 %33, 1
  resume { ptr, i32 } %35
}

declare noundef ptr @_ZN5ImageI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(20)) #1

declare noundef ptr @_ZNK5ImageI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(20)) #1

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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 = { 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"}


; 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.Image = type <{ %"class.std::shared_ptr", i32, [4 x i8] }>
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

; 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) #0

declare void @_ZN5ImageI8ColorRgbEC1Ejj(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef, i32 noundef) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK10HyperImage5widthEv(ptr noundef nonnull align 8 dereferenceable(27)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK10HyperImage6heightEv(ptr noundef nonnull align 8 dereferenceable(27)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK10HyperImage11renderImageEv(ptr dead_on_unwind noalias writable sret(%class.Image) align 8 %0, ptr noundef nonnull align 8 dereferenceable(27) %1) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = tail call noundef i32 @_ZNK10HyperImage5widthEv(ptr noundef nonnull align 8 dereferenceable(27) %1)
  %4 = tail call noundef i32 @_ZNK10HyperImage6heightEv(ptr noundef nonnull align 8 dereferenceable(27) %1)
  tail call void @_ZN5ImageI8ColorRgbEC1Ejj(ptr noundef nonnull align 8 dereferenceable(20) %0, i32 noundef %3, i32 noundef %4)
  %5 = invoke noundef ptr @_ZN5ImageI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(20) %0)
          to label %6 unwind label %17

6:                                                ; preds = %2
  %7 = invoke noundef ptr @_ZNK5ImageI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(20) %1)
          to label %8 unwind label %17

8:                                                ; preds = %6
  %9 = invoke noundef i32 @_ZNK10HyperImage5widthEv(ptr noundef nonnull align 8 dereferenceable(27) %1)
          to label %10 unwind label %17

10:                                               ; preds = %8
  %11 = invoke noundef i32 @_ZNK10HyperImage6heightEv(ptr noundef nonnull align 8 dereferenceable(27) %1)
          to label %12 unwind label %17

12:                                               ; preds = %10
  %13 = sext i32 %9 to i64
  %14 = mul nsw i64 %13, 3
  %15 = sext i32 %11 to i64
  %16 = mul nsw i64 %14, %15
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %5, ptr align 1 %7, i64 %16, i1 false)
  ret void

17:                                               ; preds = %10, %8, %6, %2
  %18 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN5ImageI8ColorRgbED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %0) #4
  resume { ptr, i32 } %18
}

declare noundef ptr @_ZN5ImageI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #1

declare noundef ptr @_ZNK5ImageI8ColorRgbE6rawMemEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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 = { 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)"}


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