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

; 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: 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: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base11JpegContext5ResetEv(ptr noundef nonnull align 8 dereferenceable(22832) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %4, i32 0, i32 16
  store i32 0, ptr %5, align 4, !tbaa !9
  %6 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %4, i32 0, i32 15
  store i32 0, ptr %6, align 8, !tbaa !14
  %7 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %4, i32 0, i32 18
  store i32 0, ptr %7, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !16
  br label %8

8:                                                ; preds = %18, %1
  %9 = load i32, ptr %3, align 4, !tbaa !16
  %10 = icmp slt i32 %9, 4
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %21

12:                                               ; preds = %8
  %13 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %4, i32 0, i32 14
  %14 = load i32, ptr %3, align 4, !tbaa !16
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [4 x %"struct.Simd::Base::JpegImgComp"], ptr %13, i64 0, i64 %15
  %17 = getelementptr inbounds %"struct.Simd::Base::JpegImgComp", ptr %16, i32 0, i32 6
  store i32 0, ptr %17, align 8, !tbaa !17
  br label %18

18:                                               ; preds = %12
  %19 = load i32, ptr %3, align 4, !tbaa !16
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %3, align 4, !tbaa !16
  br label %8, !llvm.loop !20

21:                                               ; preds = %11
  %22 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %4, i32 0, i32 17
  store i8 -1, ptr %22, align 8, !tbaa !22
  %23 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %4, i32 0, i32 30
  %24 = load i32, ptr %23, align 8, !tbaa !23
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %21
  %27 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %4, i32 0, i32 30
  %28 = load i32, ptr %27, align 8, !tbaa !23
  br label %30

29:                                               ; preds = %21
  br label %30

30:                                               ; preds = %29, %26
  %31 = phi i32 [ %28, %26 ], [ 2147483647, %29 ]
  %32 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %4, i32 0, i32 31
  store i32 %31, ptr %32, align 4, !tbaa !24
  %33 = getelementptr inbounds %"struct.Simd::Base::JpegContext", ptr %4, i32 0, i32 24
  store i32 0, ptr %33, align 4, !tbaa !25
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !11, i64 22676}
!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 22672}
!15 = !{!10, !11, i64 22684}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !11, i64 24}
!18 = !{!"_ZTSN4Simd4Base11JpegImgCompE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !12, i64 48, !12, i64 64, !6, i64 80, !19, i64 88, !6, i64 104, !11, i64 112, !11, i64 116}
!19 = !{!"_ZTSN4Simd5ArrayIsEE", !6, i64 0, !13, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !7, i64 22680}
!23 = !{!10, !11, i64 22744}
!24 = !{!10, !11, i64 22748}
!25 = !{!10, !11, i64 22708}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN4Simd4Base11JpegContext5ResetEv(ptr nocapture noundef nonnull align 8 dereferenceable(22832) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 22676
  store i32 0, ptr %2, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 22672
  store i32 0, ptr %3, align 8, !tbaa !13
  %4 = getelementptr inbounds i8, ptr %0, i64 22684
  store i32 0, ptr %4, align 4, !tbaa !14
  %5 = getelementptr inbounds i8, ptr %0, i64 22216
  store i32 0, ptr %5, align 8, !tbaa !15
  %6 = getelementptr inbounds i8, ptr %0, i64 22336
  store i32 0, ptr %6, align 8, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %0, i64 22456
  store i32 0, ptr %7, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 22576
  store i32 0, ptr %8, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %0, i64 22680
  store i8 -1, ptr %9, align 8, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %0, i64 22744
  %11 = load i32, ptr %10, align 8, !tbaa !19
  %.not = icmp eq i32 %11, 0
  %spec.select = select i1 %.not, i32 2147483647, i32 %11
  %12 = getelementptr inbounds i8, ptr %0, i64 22748
  store i32 %spec.select, ptr %12, align 4, !tbaa !20
  %13 = getelementptr inbounds i8, ptr %0, i64 22708
  store i32 0, ptr %13, align 4, !tbaa !21
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !10, i64 22676}
!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 22672}
!14 = !{!6, !10, i64 22684}
!15 = !{!16, !10, i64 24}
!16 = !{!"_ZTSN4Simd4Base11JpegImgCompE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !11, i64 48, !11, i64 64, !7, i64 80, !17, i64 88, !7, i64 104, !10, i64 112, !10, i64 116}
!17 = !{!"_ZTSN4Simd5ArrayIsEE", !7, i64 0, !12, i64 8}
!18 = !{!6, !8, i64 22680}
!19 = !{!6, !10, i64 22744}
!20 = !{!6, !10, i64 22748}
!21 = !{!6, !10, i64 22708}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass