; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseImageLoadJpeg.ll (ZN4Simd4Base11JpegContextC2EPNS_17InputMemoryStreamE)

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

%"struct.Simd::Base::JpegContext" = type { ptr, i32, i32, i32, i32, [4 x %"struct.Simd::Base::JpegHuffman"], [4 x %"struct.Simd::Base::JpegHuffman"], [4 x [64 x i16]], i32, i32, i32, i32, i32, i32, [4 x %"struct.Simd::Base::JpegImgComp"], i32, i32, i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [4 x i32], i32, i32, %"struct.Simd::Array", ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%"struct.Simd::Base::JpegHuffman" = type { [512 x i8], [256 x i16], [256 x i8], [257 x i8], [18 x i32], [17 x i32], [512 x i16] }
%"struct.Simd::Base::JpegImgComp" = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %"struct.Simd::Array", %"struct.Simd::Array", ptr, %"struct.Simd::Array.0", ptr, i32, i32 }
%"struct.Simd::Array.0" = type { ptr, i64 }
%"struct.Simd::Array" = type { ptr, i64 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base11JpegContextC2EPNS_17InputMemoryStreamE(ptr noundef nonnull align 8 dereferenceable(22832) %0, ptr noundef %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 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %9, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %7, i32 0, i32 3
  store i32 0, ptr %10, align 8, !tbaa !14
  %11 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %7, i32 0, i32 5
  %12 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %7, i32 0, i32 6
  %13 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %7, i32 0, i32 14
  %14 = getelementptr inbounds [4 x %"struct.Simd::Base::JpegImgComp"], ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %"struct.Simd::Base::JpegImgComp", ptr %14, i64 4
  br label %16

16:                                               ; preds = %18, %2
  %17 = phi ptr [ %14, %2 ], [ %19, %18 ]
  invoke void @_ZN4Simd4Base11JpegImgCompC2Ev(ptr noundef nonnull align 8 dereferenceable(120) %17)
          to label %18 unwind label %24

18:                                               ; preds = %16
  %19 = getelementptr inbounds %"struct.Simd::Base::JpegImgComp", ptr %17, i64 1
  %20 = icmp eq ptr %19, %15
  br i1 %20, label %21, label %16

21:                                               ; preds = %18
  %22 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %7, i32 0, i32 32
  invoke void @_ZN4Simd5ArrayIhEC2Embm(ptr noundef nonnull align 8 dereferenceable(16) %22, i64 noundef 0, i1 noundef zeroext false, i64 noundef 8)
          to label %23 unwind label %34

23:                                               ; preds = %21
  ret void

24:                                               ; preds = %16
  %25 = landingpad { ptr, i32 }
          cleanup
  %26 = extractvalue { ptr, i32 } %25, 0
  store ptr %26, ptr %5, align 8
  %27 = extractvalue { ptr, i32 } %25, 1
  store i32 %27, ptr %6, align 4
  %28 = icmp eq ptr %14, %17
  br i1 %28, label %33, label %29

29:                                               ; preds = %29, %24
  %30 = phi ptr [ %17, %24 ], [ %31, %29 ]
  %31 = getelementptr inbounds %"struct.Simd::Base::JpegImgComp", ptr %30, i64 -1
  call void @_ZN4Simd4Base11JpegImgCompD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %31) #4
  %32 = icmp eq ptr %31, %14
  br i1 %32, label %33, label %29

33:                                               ; preds = %29, %24
  br label %45

34:                                               ; preds = %21
  %35 = landingpad { ptr, i32 }
          cleanup
  %36 = extractvalue { ptr, i32 } %35, 0
  store ptr %36, ptr %5, align 8
  %37 = extractvalue { ptr, i32 } %35, 1
  store i32 %37, ptr %6, align 4
  %38 = getelementptr inbounds [4 x %"struct.Simd::Base::JpegImgComp"], ptr %13, i32 0, i32 0
  %39 = getelementptr inbounds %"struct.Simd::Base::JpegImgComp", ptr %38, i64 4
  br label %40

40:                                               ; preds = %40, %34
  %41 = phi ptr [ %39, %34 ], [ %42, %40 ]
  %42 = getelementptr inbounds %"struct.Simd::Base::JpegImgComp", ptr %41, i64 -1
  call void @_ZN4Simd4Base11JpegImgCompD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %42) #4
  %43 = icmp eq ptr %42, %38
  br i1 %43, label %44, label %40

44:                                               ; preds = %40
  br label %45

45:                                               ; preds = %44, %33
  %46 = load ptr, ptr %5, align 8
  %47 = load i32, ptr %6, align 4
  %48 = insertvalue { ptr, i32 } poison, ptr %46, 0
  %49 = insertvalue { ptr, i32 } %48, i32 %47, 1
  resume { ptr, i32 } %49
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4Simd4Base11JpegImgCompC2Ev(ptr noundef nonnull align 8 dereferenceable(120)) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd5ArrayIhEC2Embm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i1 noundef zeroext, i64 noundef) 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 = { inlinehint 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 = { 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 = { 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 = { 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, !6, i64 0}
!10 = !{!"_ZTSN4Simd4Base11JpegContextE", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !7, i64 24, !7, i64 10840, !7, i64 21656, !11, i64 22168, !11, i64 22172, !11, i64 22176, !11, i64 22180, !11, i64 22184, !11, i64 22188, !7, i64 22192, !11, i64 22672, !11, i64 22676, !7, i64 22680, !11, i64 22684, !11, i64 22688, !11, i64 22692, !11, i64 22696, !11, i64 22700, !11, i64 22704, !11, i64 22708, !11, i64 22712, !11, i64 22716, !11, i64 22720, !11, i64 22724, !7, i64 22728, !11, i64 22744, !11, i64 22748, !12, i64 22752, !6, i64 22768, !6, i64 22776, !6, i64 22784, !6, i64 22792, !6, i64 22800, !6, i64 22808, !6, i64 22816, !6, i64 22824}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSN4Simd5ArrayIhEE", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !11, 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 @_ZN4Simd4Base11JpegContextC2EPNS_17InputMemoryStreamE(ptr noundef nonnull align 8 dereferenceable(22832) %0, ptr noundef %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  store ptr %1, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 0, ptr %3, align 8, !tbaa !13
  %.ptr.ptr = getelementptr inbounds i8, ptr %0, i64 22192
  tail call void @_ZN4Simd4Base11JpegImgCompC2Ev(ptr noundef nonnull align 8 dereferenceable(120) %.ptr.ptr)
  %.ptr.ptr.1 = getelementptr inbounds i8, ptr %0, i64 22312
  invoke void @_ZN4Simd4Base11JpegImgCompC2Ev(ptr noundef nonnull align 8 dereferenceable(120) %.ptr.ptr.1)
          to label %4 unwind label %.preheader.preheader

4:                                                ; preds = %2
  %.ptr.ptr.2 = getelementptr inbounds i8, ptr %0, i64 22432
  invoke void @_ZN4Simd4Base11JpegImgCompC2Ev(ptr noundef nonnull align 8 dereferenceable(120) %.ptr.ptr.2)
          to label %5 unwind label %.preheader.preheader

5:                                                ; preds = %4
  %.ptr.ptr.3 = getelementptr inbounds i8, ptr %0, i64 22552
  invoke void @_ZN4Simd4Base11JpegImgCompC2Ev(ptr noundef nonnull align 8 dereferenceable(120) %.ptr.ptr.3)
          to label %6 unwind label %.preheader.preheader

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 22752
  invoke void @_ZN4Simd5ArrayIhEC2Embm(ptr noundef nonnull align 8 dereferenceable(16) %7, i64 noundef 0, i1 noundef zeroext false, i64 noundef 8)
          to label %8 unwind label %.loopexit.loopexit

8:                                                ; preds = %6
  ret void

.preheader.preheader:                             ; preds = %2, %4, %5
  %.idx.lcssa.ph = phi i64 [ 22552, %5 ], [ 22432, %4 ], [ 22312, %2 ]
  %lpad.thr_comm = landingpad { ptr, i32 }
          cleanup
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.idx9 = phi i64 [ %.add10, %.preheader ], [ %.idx.lcssa.ph, %.preheader.preheader ]
  %.add10 = add nsw i64 %.idx9, -120
  %.ptr12 = getelementptr inbounds i8, ptr %0, i64 %.add10
  tail call void @_ZN4Simd4Base11JpegImgCompD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %.ptr12) #4
  %9 = icmp eq i64 %.add10, 22192
  br i1 %9, label %.loopexit, label %.preheader

.loopexit.loopexit:                               ; preds = %6
  %10 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN4Simd4Base11JpegImgCompD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %.ptr.ptr.3) #4
  tail call void @_ZN4Simd4Base11JpegImgCompD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %.ptr.ptr.2) #4
  tail call void @_ZN4Simd4Base11JpegImgCompD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %.ptr.ptr.1) #4
  tail call void @_ZN4Simd4Base11JpegImgCompD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %.ptr.ptr) #4
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.loopexit.loopexit
  %.pn = phi { ptr, i32 } [ %10, %.loopexit.loopexit ], [ %lpad.thr_comm, %.preheader ]
  resume { ptr, i32 } %.pn
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4Simd4Base11JpegImgCompC2Ev(ptr noundef nonnull align 8 dereferenceable(120)) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN4Simd5ArrayIhEC2Embm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i1 noundef zeroext, i64 noundef) 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 = { inlinehint 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 = { 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 = { 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN4Simd4Base11JpegContextE", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !8, i64 24, !8, i64 10840, !8, i64 21656, !10, i64 22168, !10, i64 22172, !10, i64 22176, !10, i64 22180, !10, i64 22184, !10, i64 22188, !8, i64 22192, !10, i64 22672, !10, i64 22676, !8, i64 22680, !10, i64 22684, !10, i64 22688, !10, i64 22692, !10, i64 22696, !10, i64 22700, !10, i64 22704, !10, i64 22708, !10, i64 22712, !10, i64 22716, !10, i64 22720, !10, i64 22724, !8, i64 22728, !10, i64 22744, !10, i64 22748, !11, i64 22752, !7, i64 22768, !7, i64 22776, !7, i64 22784, !7, i64 22792, !7, i64 22800, !7, i64 22808, !7, i64 22816, !7, i64 22824}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSN4Simd5ArrayIhEE", !7, i64 0, !12, i64 8}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass