; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseImageSaveBmp.ll (ZN4Simd4Base13ImageBmpSaverC2ERKNS_15ImageSaverParamE)

; 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.Simd::Base::ImageBmpSaver" = type { %"class.Simd::ImageSaver", ptr, i64, i64, i64 }
%"class.Simd::ImageSaver" = type { ptr, %"struct.Simd::ImageSaverParam", %"class.Simd::OutputMemoryStream" }
%"struct.Simd::ImageSaverParam" = type { i64, i64, i32, i32, i32, i32 }
%"class.Simd::OutputMemoryStream" = type { i64, ptr, i64, i64, i64, i64, i64 }

@_ZTVN4Simd4Base13ImageBmpSaverE = external dso_local unnamed_addr constant { [5 x ptr] }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base13ImageBmpSaverC2ERKNS_15ImageSaverParamE(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) unnamed_addr #0 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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4Simd10ImageSaverC2ERKNS_15ImageSaverParamE(ptr noundef nonnull align 8 dereferenceable(96) %7, ptr noundef nonnull align 8 dereferenceable(32) %8)
  store ptr getelementptr inbounds inrange(-16, 24) ({ [5 x ptr] }, ptr @_ZTVN4Simd4Base13ImageBmpSaverE, i32 0, i32 0, i32 2), ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 1
  store ptr null, ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %7, i32 0, i32 1
  %11 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !21
  switch i32 %12, label %26 [
    i32 1, label %13
    i32 3, label %16
    i32 4, label %18
    i32 16, label %20
    i32 17, label %23
  ]

13:                                               ; preds = %2
  %14 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 1
  store ptr @_ZN4Simd4Base9GrayToBgrEPKhmmmPhm, ptr %14, align 8, !tbaa !11
  %15 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 2
  store i64 3, ptr %15, align 8, !tbaa !22
  br label %27

16:                                               ; preds = %2
  %17 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 2
  store i64 3, ptr %17, align 8, !tbaa !22
  br label %27

18:                                               ; preds = %2
  %19 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 2
  store i64 4, ptr %19, align 8, !tbaa !22
  br label %27

20:                                               ; preds = %2
  %21 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 1
  store ptr @_ZN4Simd4Base8BgrToRgbEPKhmmmPhm, ptr %21, align 8, !tbaa !11
  %22 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 2
  store i64 3, ptr %22, align 8, !tbaa !22
  br label %27

23:                                               ; preds = %2
  %24 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 1
  store ptr @_ZN4Simd4Base10BgraToRgbaEPKhmmmPhm, ptr %24, align 8, !tbaa !11
  %25 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 2
  store i64 4, ptr %25, align 8, !tbaa !22
  br label %27

26:                                               ; preds = %2
  br label %27

27:                                               ; preds = %26, %23, %20, %18, %16, %13
  %28 = getelementptr inbounds %"class.Simd::ImageSaver", ptr %7, i32 0, i32 1
  %29 = getelementptr inbounds %"struct.Simd::ImageSaverParam", ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !23
  %31 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !22
  %33 = mul i64 %30, %32
  %34 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 3
  store i64 %33, ptr %34, align 8, !tbaa !24
  %35 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 3
  %36 = load i64, ptr %35, align 8, !tbaa !24
  %37 = invoke noundef i64 @_ZN4Simd7AlignHiEmm(i64 noundef %36, i64 noundef 4)
          to label %38 unwind label %43

38:                                               ; preds = %27
  %39 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 3
  %40 = load i64, ptr %39, align 8, !tbaa !24
  %41 = sub i64 %37, %40
  %42 = getelementptr inbounds %"class.Simd::Base::ImageBmpSaver", ptr %7, i32 0, i32 4
  store i64 %41, ptr %42, align 8, !tbaa !25
  ret void

43:                                               ; preds = %27
  %44 = landingpad { ptr, i32 }
          cleanup
  %45 = extractvalue { ptr, i32 } %44, 0
  store ptr %45, ptr %5, align 8
  %46 = extractvalue { ptr, i32 } %44, 1
  store i32 %46, ptr %6, align 4
  call void @_ZN4Simd10ImageSaverD2Ev(ptr noundef nonnull align 8 dereferenceable(96) %7) #4
  br label %47

47:                                               ; preds = %43
  %48 = load ptr, ptr %5, align 8
  %49 = load i32, ptr %6, align 4
  %50 = insertvalue { ptr, i32 } poison, ptr %48, 0
  %51 = insertvalue { ptr, i32 } %50, i32 %49, 1
  resume { ptr, i32 } %51
}

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

declare void @_ZN4Simd4Base9GrayToBgrEPKhmmmPhm(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef) #1

declare void @_ZN4Simd4Base8BgrToRgbEPKhmmmPhm(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef) #1

declare void @_ZN4Simd4Base10BgraToRgbaEPKhmmmPhm(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd7AlignHiEmm(i64 noundef, i64 noundef) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Simd10ImageSaverD2Ev(ptr noundef nonnull align 8 dereferenceable(96)) unnamed_addr #3 align 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 = { "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 = { alwaysinline 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 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, !6, i64 96}
!12 = !{!"_ZTSN4Simd4Base13ImageBmpSaverE", !13, i64 0, !6, i64 96, !15, i64 104, !15, i64 112, !15, i64 120}
!13 = !{!"_ZTSN4Simd10ImageSaverE", !14, i64 8, !20, i64 40}
!14 = !{!"_ZTSN4Simd15ImageSaverParamE", !15, i64 0, !15, i64 8, !16, i64 16, !17, i64 20, !18, i64 24, !19, i64 28}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTS19SimdPixelFormatType", !7, i64 0}
!17 = !{!"_ZTS17SimdImageFileType", !7, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!"_ZTS11SimdYuvType", !7, i64 0}
!20 = !{!"_ZTSN4Simd18OutputMemoryStreamE", !15, i64 0, !6, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !15, i64 48}
!21 = !{!13, !16, i64 24}
!22 = !{!12, !15, i64 104}
!23 = !{!13, !15, i64 8}
!24 = !{!12, !15, i64 112}
!25 = !{!12, !15, i64 120}


; 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"

@_ZTVN4Simd4Base13ImageBmpSaverE = external dso_local unnamed_addr constant { [5 x ptr] }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base13ImageBmpSaverC2ERKNS_15ImageSaverParamE(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN4Simd10ImageSaverC2ERKNS_15ImageSaverParamE(ptr noundef nonnull align 8 dereferenceable(96) %0, ptr noundef nonnull align 8 dereferenceable(32) %1)
  store ptr getelementptr inbounds inrange(-16, 24) (i8, ptr @_ZTVN4Simd4Base13ImageBmpSaverE, i64 16), ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 96
  store ptr null, ptr %3, align 8, !tbaa !8
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i32, ptr %4, align 8, !tbaa !20
  switch i32 %5, label %._crit_edge [
    i32 1, label %6
    i32 3, label %8
    i32 4, label %10
    i32 16, label %12
    i32 17, label %14
  ]

._crit_edge:                                      ; preds = %2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 104
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !21
  br label %16

6:                                                ; preds = %2
  store ptr @_ZN4Simd4Base9GrayToBgrEPKhmmmPhm, ptr %3, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 3, ptr %7, align 8, !tbaa !21
  br label %16

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 3, ptr %9, align 8, !tbaa !21
  br label %16

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 4, ptr %11, align 8, !tbaa !21
  br label %16

12:                                               ; preds = %2
  store ptr @_ZN4Simd4Base8BgrToRgbEPKhmmmPhm, ptr %3, align 8, !tbaa !8
  %13 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 3, ptr %13, align 8, !tbaa !21
  br label %16

14:                                               ; preds = %2
  store ptr @_ZN4Simd4Base10BgraToRgbaEPKhmmmPhm, ptr %3, align 8, !tbaa !8
  %15 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 4, ptr %15, align 8, !tbaa !21
  br label %16

16:                                               ; preds = %._crit_edge, %14, %12, %10, %8, %6
  %17 = phi i64 [ %.pre, %._crit_edge ], [ 4, %14 ], [ 3, %12 ], [ 4, %10 ], [ 3, %8 ], [ 3, %6 ]
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !22
  %20 = mul i64 %17, %19
  %21 = getelementptr inbounds i8, ptr %0, i64 112
  store i64 %20, ptr %21, align 8, !tbaa !23
  %22 = tail call noundef i64 @_ZN4Simd7AlignHiEmm(i64 noundef %20, i64 noundef 4)
  %23 = load i64, ptr %21, align 8, !tbaa !23
  %24 = sub i64 %22, %23
  %25 = getelementptr inbounds i8, ptr %0, i64 120
  store i64 %24, ptr %25, align 8, !tbaa !24
  ret void
}

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

declare void @_ZN4Simd4Base9GrayToBgrEPKhmmmPhm(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef) #1

declare void @_ZN4Simd4Base8BgrToRgbEPKhmmmPhm(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef) #1

declare void @_ZN4Simd4Base10BgraToRgbaEPKhmmmPhm(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd7AlignHiEmm(i64 noundef, i64 noundef) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

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 = { "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 = { alwaysinline 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" }

!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, !19, i64 96}
!9 = !{!"_ZTSN4Simd4Base13ImageBmpSaverE", !10, i64 0, !19, i64 96, !12, i64 104, !12, i64 112, !12, i64 120}
!10 = !{!"_ZTSN4Simd10ImageSaverE", !11, i64 8, !18, i64 40}
!11 = !{!"_ZTSN4Simd15ImageSaverParamE", !12, i64 0, !12, i64 8, !14, i64 16, !15, i64 20, !16, i64 24, !17, i64 28}
!12 = !{!"long", !13, i64 0}
!13 = !{!"omnipotent char", !7, i64 0}
!14 = !{!"_ZTS19SimdPixelFormatType", !13, i64 0}
!15 = !{!"_ZTS17SimdImageFileType", !13, i64 0}
!16 = !{!"int", !13, i64 0}
!17 = !{!"_ZTS11SimdYuvType", !13, i64 0}
!18 = !{!"_ZTSN4Simd18OutputMemoryStreamE", !12, i64 0, !19, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48}
!19 = !{!"any pointer", !13, i64 0}
!20 = !{!10, !14, i64 24}
!21 = !{!9, !12, i64 104}
!22 = !{!10, !12, i64 8}
!23 = !{!9, !12, i64 112}
!24 = !{!9, !12, i64 120}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass