; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseImageLoadPng.ll (ZN4Simd4Base14ImagePngLoader11ReadPaletteERKNS1_5ChunkE)

; 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::ImagePngLoader" = type { %"class.Simd::ImageLoader", [7 x ptr], ptr, ptr, i8, i8, i8, i32, i32, i32, i32, [3 x i16], i8, i8, i8, i8, [3 x i8], %"struct.Simd::Array", %"struct.Simd::Array", %"struct.Simd::Array", %"class.std::vector" }
%"class.Simd::ImageLoader" = type { ptr, %"struct.Simd::ImageLoaderParam", %"class.Simd::InputMemoryStream", %"struct.Simd::View" }
%"struct.Simd::ImageLoaderParam" = type { ptr, i64, i32, i32 }
%"class.Simd::InputMemoryStream" = type { ptr, i64, i64, i64, i64 }
%"struct.Simd::View" = type <{ i64, i64, i64, i32, [4 x i8], ptr, i8, [7 x i8] }>
%"struct.Simd::Array" = type { ptr, i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Simd::Base::ImagePngLoader::Chunk, std::allocator<Simd::Base::ImagePngLoader::Chunk>>::_Vector_impl" }
%"struct.std::_Vector_base<Simd::Base::ImagePngLoader::Chunk, std::allocator<Simd::Base::ImagePngLoader::Chunk>>::_Vector_impl" = type { %"struct.std::_Vector_base<Simd::Base::ImagePngLoader::Chunk, std::allocator<Simd::Base::ImagePngLoader::Chunk>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Simd::Base::ImagePngLoader::Chunk, std::allocator<Simd::Base::ImagePngLoader::Chunk>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.Simd::Base::ImagePngLoader::Chunk" = type { i32, i32, i32 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN4Simd17InputMemoryStream4SkipEm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4Simd4Base14ImagePngLoader11ReadPaletteERKNS1_5ChunkE(ptr noundef nonnull align 8 dereferenceable(304) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) #2 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"class.Simd::Base::ImagePngLoader", ptr %8, i32 0, i32 4
  %10 = load i8, ptr %9, align 8, !tbaa !9, !range !26, !noundef !27
  %11 = trunc i8 %10 to i1
  br i1 %11, label %17, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.Simd::Base::ImagePngLoader::Chunk", ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 4, !tbaa !28
  %16 = icmp ugt i32 %15, 768
  br i1 %16, label %17, label %18

17:                                               ; preds = %12, %2
  store i1 false, ptr %3, align 1
  br label %61

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.Simd::Base::ImagePngLoader::Chunk", ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 4, !tbaa !28
  %22 = udiv i32 %21, 3
  %23 = zext i32 %22 to i64
  store i64 %23, ptr %6, align 8, !tbaa !30
  %24 = load i64, ptr %6, align 8, !tbaa !30
  %25 = mul i64 %24, 3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.Simd::Base::ImagePngLoader::Chunk", ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !28
  %29 = zext i32 %28 to i64
  %30 = icmp ne i64 %25, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %18
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %60

32:                                               ; preds = %18
  %33 = getelementptr inbounds %"class.Simd::ImageLoader", ptr %8, i32 0, i32 2
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.Simd::Base::ImagePngLoader::Chunk", ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !28
  %37 = zext i32 %36 to i64
  %38 = call noundef zeroext i1 @_ZNK4Simd17InputMemoryStream7CanReadEm(ptr noundef nonnull align 8 dereferenceable(40) %33, i64 noundef %37)
  br i1 %38, label %39, label %59

39:                                               ; preds = %32
  %40 = getelementptr inbounds %"class.Simd::Base::ImagePngLoader", ptr %8, i32 0, i32 17
  %41 = load i64, ptr %6, align 8, !tbaa !30
  %42 = mul i64 %41, 4
  call void @_ZN4Simd5ArrayIhE6ResizeEmbm(ptr noundef nonnull align 8 dereferenceable(16) %40, i64 noundef %42, i1 noundef zeroext false, i64 noundef 8)
  %43 = getelementptr inbounds %"class.Simd::ImageLoader", ptr %8, i32 0, i32 2
  %44 = call noundef ptr @_ZNK4Simd17InputMemoryStream7CurrentEv(ptr noundef nonnull align 8 dereferenceable(40) %43)
  %45 = load i64, ptr %6, align 8, !tbaa !30
  %46 = load i64, ptr %6, align 8, !tbaa !30
  %47 = getelementptr inbounds %"class.Simd::Base::ImagePngLoader", ptr %8, i32 0, i32 17
  %48 = getelementptr inbounds %"struct.Simd::Array", ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !31
  %50 = getelementptr inbounds %"class.Simd::Base::ImagePngLoader", ptr %8, i32 0, i32 17
  %51 = getelementptr inbounds %"struct.Simd::Array", ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !32
  call void @_ZN4Simd4Base9BgrToBgraEPKhmmmPhmh(ptr noundef %44, i64 noundef %45, i64 noundef 1, i64 noundef %46, ptr noundef %49, i64 noundef %52, i8 noundef zeroext -1)
  %53 = getelementptr inbounds %"class.Simd::ImageLoader", ptr %8, i32 0, i32 2
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.Simd::Base::ImagePngLoader::Chunk", ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 4, !tbaa !28
  %57 = zext i32 %56 to i64
  %58 = call noundef zeroext i1 @_ZN4Simd17InputMemoryStream4SkipEm(ptr noundef nonnull align 8 dereferenceable(40) %53, i64 noundef %57)
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %60

59:                                               ; preds = %32
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %60

60:                                               ; preds = %59, %39, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %61

61:                                               ; preds = %60, %17
  %62 = load i1, ptr %3, align 1
  ret i1 %62
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4Simd17InputMemoryStream7CanReadEm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef) #1 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd5ArrayIhE6ResizeEmbm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i1 noundef zeroext, i64 noundef) #3 align 2

declare void @_ZN4Simd4Base9BgrToBgraEPKhmmmPhmh(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef, i8 noundef zeroext) #4

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4Simd17InputMemoryStream7CurrentEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { alwaysinline 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 = { "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 = { 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, !19, i64 192}
!10 = !{!"_ZTSN4Simd4Base14ImagePngLoaderE", !11, i64 0, !7, i64 120, !6, i64 176, !6, i64 184, !19, i64 192, !19, i64 193, !19, i64 194, !20, i64 196, !20, i64 200, !20, i64 204, !20, i64 208, !7, i64 212, !7, i64 218, !7, i64 219, !7, i64 220, !7, i64 221, !7, i64 222, !21, i64 232, !21, i64 248, !21, i64 264, !22, i64 280}
!11 = !{!"_ZTSN4Simd11ImageLoaderE", !12, i64 8, !16, i64 32, !17, i64 72}
!12 = !{!"_ZTSN4Simd16ImageLoaderParamE", !6, i64 0, !13, i64 8, !14, i64 16, !15, i64 20}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTS17SimdImageFileType", !7, i64 0}
!15 = !{!"_ZTS19SimdPixelFormatType", !7, i64 0}
!16 = !{!"_ZTSN4Simd17InputMemoryStreamE", !6, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!17 = !{!"_ZTSN4Simd4ViewINS_9AllocatorEEE", !13, i64 0, !13, i64 8, !13, i64 16, !18, i64 24, !6, i64 32, !19, i64 40}
!18 = !{!"_ZTSN4Simd4ViewINS_9AllocatorEE6FormatE", !7, i64 0}
!19 = !{!"bool", !7, i64 0}
!20 = !{!"int", !7, i64 0}
!21 = !{!"_ZTSN4Simd5ArrayIhEE", !6, i64 0, !13, i64 8}
!22 = !{!"_ZTSSt6vectorIN4Simd4Base14ImagePngLoader5ChunkESaIS3_EE", !23, i64 0}
!23 = !{!"_ZTSSt12_Vector_baseIN4Simd4Base14ImagePngLoader5ChunkESaIS3_EE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIN4Simd4Base14ImagePngLoader5ChunkESaIS3_EE12_Vector_implE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseIN4Simd4Base14ImagePngLoader5ChunkESaIS3_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!29, !20, i64 0}
!29 = !{!"_ZTSN4Simd4Base14ImagePngLoader5ChunkE", !20, i64 0, !20, i64 4, !20, i64 8}
!30 = !{!13, !13, i64 0}
!31 = !{!10, !6, i64 232}
!32 = !{!10, !13, i64 240}


; 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: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN4Simd17InputMemoryStream4SkipEm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4Simd4Base14ImagePngLoader11ReadPaletteERKNS1_5ChunkE(ptr noundef nonnull align 8 dereferenceable(304) %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(12) %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 192
  %4 = load i8, ptr %3, align 8, !tbaa !5, !range !25, !noundef !26
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %27, label %6

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 4, !tbaa !27
  %8 = icmp ugt i32 %7, 768
  br i1 %8, label %27, label %9

9:                                                ; preds = %6
  %.lhs.trunc = trunc nuw i32 %7 to i16
  %10 = udiv i16 %.lhs.trunc, 3
  %11 = zext nneg i16 %10 to i64
  %12 = mul nuw nsw i64 %11, 3
  %13 = zext nneg i32 %7 to i64
  %.not = icmp eq i64 %12, %13
  br i1 %.not, label %14, label %27

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = tail call noundef zeroext i1 @_ZNK4Simd17InputMemoryStream7CanReadEm(ptr noundef nonnull align 8 dereferenceable(40) %15, i64 noundef %12)
  br i1 %16, label %17, label %27

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %0, i64 232
  %19 = shl nuw nsw i64 %11, 2
  tail call void @_ZN4Simd5ArrayIhE6ResizeEmbm(ptr noundef nonnull align 8 dereferenceable(16) %18, i64 noundef %19, i1 noundef zeroext false, i64 noundef 8)
  %20 = tail call noundef ptr @_ZNK4Simd17InputMemoryStream7CurrentEv(ptr noundef nonnull align 8 dereferenceable(40) %15)
  %21 = load ptr, ptr %18, align 8, !tbaa !29
  %22 = getelementptr inbounds i8, ptr %0, i64 240
  %23 = load i64, ptr %22, align 8, !tbaa !30
  tail call void @_ZN4Simd4Base9BgrToBgraEPKhmmmPhmh(ptr noundef %20, i64 noundef %11, i64 noundef 1, i64 noundef %11, ptr noundef %21, i64 noundef %23, i8 noundef zeroext -1)
  %24 = load i32, ptr %1, align 4, !tbaa !27
  %25 = zext i32 %24 to i64
  %26 = tail call noundef zeroext i1 @_ZN4Simd17InputMemoryStream4SkipEm(ptr noundef nonnull align 8 dereferenceable(40) %15, i64 noundef %25)
  br label %27

27:                                               ; preds = %17, %9, %14, %2, %6
  %.1 = phi i1 [ false, %6 ], [ false, %2 ], [ true, %17 ], [ false, %9 ], [ false, %14 ]
  ret i1 %.1
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4Simd17InputMemoryStream7CanReadEm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd5ArrayIhE6ResizeEmbm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i1 noundef zeroext, i64 noundef) local_unnamed_addr #2 align 2

declare void @_ZN4Simd4Base9BgrToBgraEPKhmmmPhmh(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #3

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4Simd17InputMemoryStream7CurrentEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { 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 #2 = { alwaysinline 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 = { "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, !18, i64 192}
!6 = !{!"_ZTSN4Simd4Base14ImagePngLoaderE", !7, i64 0, !10, i64 120, !9, i64 176, !9, i64 184, !18, i64 192, !18, i64 193, !18, i64 194, !19, i64 196, !19, i64 200, !19, i64 204, !19, i64 208, !10, i64 212, !10, i64 218, !10, i64 219, !10, i64 220, !10, i64 221, !10, i64 222, !20, i64 232, !20, i64 248, !20, i64 264, !21, i64 280}
!7 = !{!"_ZTSN4Simd11ImageLoaderE", !8, i64 8, !15, i64 32, !16, i64 72}
!8 = !{!"_ZTSN4Simd16ImageLoaderParamE", !9, i64 0, !12, i64 8, !13, i64 16, !14, i64 20}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"_ZTS17SimdImageFileType", !10, i64 0}
!14 = !{!"_ZTS19SimdPixelFormatType", !10, i64 0}
!15 = !{!"_ZTSN4Simd17InputMemoryStreamE", !9, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!16 = !{!"_ZTSN4Simd4ViewINS_9AllocatorEEE", !12, i64 0, !12, i64 8, !12, i64 16, !17, i64 24, !9, i64 32, !18, i64 40}
!17 = !{!"_ZTSN4Simd4ViewINS_9AllocatorEE6FormatE", !10, i64 0}
!18 = !{!"bool", !10, i64 0}
!19 = !{!"int", !10, i64 0}
!20 = !{!"_ZTSN4Simd5ArrayIhEE", !9, i64 0, !12, i64 8}
!21 = !{!"_ZTSSt6vectorIN4Simd4Base14ImagePngLoader5ChunkESaIS3_EE", !22, i64 0}
!22 = !{!"_ZTSSt12_Vector_baseIN4Simd4Base14ImagePngLoader5ChunkESaIS3_EE", !23, i64 0}
!23 = !{!"_ZTSNSt12_Vector_baseIN4Simd4Base14ImagePngLoader5ChunkESaIS3_EE12_Vector_implE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIN4Simd4Base14ImagePngLoader5ChunkESaIS3_EE17_Vector_impl_dataE", !9, i64 0, !9, i64 8, !9, i64 16}
!25 = !{i8 0, i8 2}
!26 = !{}
!27 = !{!28, !19, i64 0}
!28 = !{!"_ZTSN4Simd4Base14ImagePngLoader5ChunkE", !19, i64 0, !19, i64 4, !19, i64 8}
!29 = !{!6, !9, i64 232}
!30 = !{!6, !12, i64 240}


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