; LLVM IR from catid/Zpng :: zstd (zstd_compress)

; 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.ZSTD_frameProgression = type { i64, i64, i64 }
%struct.ZSTD_CCtx_s = type { i32, i32, i32, %struct.ZSTD_CCtx_params_s, %struct.ZSTD_CCtx_params_s, i32, ptr, i64, i64, i64, i64, i64, %struct.XXH64_state_s, %struct.ZSTD_customMem, i64, %struct.seqStore_t, %struct.ldmState_t, ptr, i64, %struct.rawSeqStore_t, %struct.ZSTD_blockState_t, ptr, ptr, i64, i64, i64, i64, ptr, i64, i64, i64, i32, i32, ptr, ptr, %struct.ZSTD_prefixDict_s }
%struct.ZSTD_CCtx_params_s = type { i32, %struct.ZSTD_compressionParameters, %struct.ZSTD_frameParameters, i32, i32, i32, i32, i32, i32, %struct.ldmParams_t, %struct.ZSTD_customMem }
%struct.ZSTD_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_frameParameters = type { i32, i32, i32 }
%struct.ldmParams_t = type { i32, i32, i32, i32, i32, i32 }
%struct.XXH64_state_s = type { i64, i64, i64, i64, i64, [4 x i64], i32, [2 x i32] }
%struct.ZSTD_customMem = type { ptr, ptr, ptr }
%struct.seqStore_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32 }
%struct.ldmState_t = type { %struct.ZSTD_window_t, ptr, ptr, i64 }
%struct.ZSTD_window_t = type { ptr, ptr, ptr, i32, i32 }
%struct.rawSeqStore_t = type { ptr, i64, i64, i64 }
%struct.ZSTD_blockState_t = type { ptr, ptr, %struct.ZSTD_matchState_t }
%struct.ZSTD_matchState_t = type { %struct.ZSTD_window_t, i32, i32, i32, i32, ptr, ptr, ptr, %struct.optState_t }
%struct.optState_t = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_prefixDict_s = type { ptr, i64, 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: nounwind uwtable
define dso_local void @ZSTD_getFrameProgression(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_frameProgression) align 8 %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %5, i32 0, i32 22
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  br label %18

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %11, i32 0, i32 25
  %13 = load i64, ptr %12, align 8, !tbaa !28
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %14, i32 0, i32 24
  %16 = load i64, ptr %15, align 8, !tbaa !29
  %17 = sub i64 %13, %16
  br label %18

18:                                               ; preds = %10, %9
  %19 = phi i64 [ 0, %9 ], [ %17, %10 ]
  store i64 %19, ptr %4, align 8, !tbaa !30
  %20 = load i64, ptr %4, align 8, !tbaa !30
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  br label %23

23:                                               ; preds = %22, %18
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %24, i32 0, i32 10
  %26 = load i64, ptr %25, align 8, !tbaa !31
  %27 = load i64, ptr %4, align 8, !tbaa !30
  %28 = add i64 %26, %27
  %29 = getelementptr inbounds %struct.ZSTD_frameProgression, ptr %0, i32 0, i32 0
  store i64 %28, ptr %29, align 8, !tbaa !32
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %30, i32 0, i32 10
  %32 = load i64, ptr %31, align 8, !tbaa !31
  %33 = getelementptr inbounds %struct.ZSTD_frameProgression, ptr %0, i32 0, i32 1
  store i64 %32, ptr %33, align 8, !tbaa !34
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %34, i32 0, i32 11
  %36 = load i64, ptr %35, align 8, !tbaa !35
  %37 = getelementptr inbounds %struct.ZSTD_frameProgression, ptr %0, i32 0, i32 2
  store i64 %36, ptr %37, align 8, !tbaa !36
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 784}
!10 = !{!"ZSTD_CCtx_s", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !12, i64 136, !11, i64 256, !6, i64 264, !17, i64 272, !17, i64 280, !18, i64 288, !18, i64 296, !18, i64 304, !19, i64 312, !16, i64 400, !17, i64 424, !20, i64 432, !21, i64 496, !6, i64 552, !17, i64 560, !23, i64 568, !24, i64 600, !6, i64 776, !6, i64 784, !17, i64 792, !17, i64 800, !17, i64 808, !17, i64 816, !6, i64 824, !17, i64 832, !17, i64 840, !17, i64 848, !11, i64 856, !11, i64 860, !6, i64 864, !6, i64 872, !27, i64 880}
!11 = !{!"int", !7, i64 0}
!12 = !{!"ZSTD_CCtx_params_s", !11, i64 0, !13, i64 4, !14, i64 32, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !15, i64 68, !16, i64 96}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!"long long", !7, i64 0}
!19 = !{!"XXH64_state_s", !18, i64 0, !18, i64 8, !18, i64 16, !18, i64 24, !18, i64 32, !7, i64 40, !11, i64 72, !7, i64 76}
!20 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !11, i64 60}
!21 = !{!"", !22, i64 0, !6, i64 32, !6, i64 40, !17, i64 48}
!22 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28}
!23 = !{!"", !6, i64 0, !17, i64 8, !17, i64 16, !17, i64 24}
!24 = !{!"", !6, i64 0, !6, i64 8, !25, i64 16}
!25 = !{!"", !22, i64 0, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !26, i64 72}
!26 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80}
!27 = !{!"ZSTD_prefixDict_s", !6, i64 0, !17, i64 8, !11, i64 16}
!28 = !{!10, !17, i64 808}
!29 = !{!10, !17, i64 800}
!30 = !{!17, !17, i64 0}
!31 = !{!10, !18, i64 296}
!32 = !{!33, !18, i64 0}
!33 = !{!"", !18, i64 0, !18, i64 8, !18, i64 16}
!34 = !{!33, !18, i64 8}
!35 = !{!10, !18, i64 304}
!36 = !{!33, !18, 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"

%struct.ZSTD_frameProgression = type { i64, i64, i64 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @ZSTD_getFrameProgression(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.ZSTD_frameProgression) align 8 %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 784
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %12, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 808
  %8 = load i64, ptr %7, align 8, !tbaa !27
  %9 = getelementptr inbounds i8, ptr %1, i64 800
  %10 = load i64, ptr %9, align 8, !tbaa !28
  %11 = sub i64 %8, %10
  br label %12

12:                                               ; preds = %2, %6
  %13 = phi i64 [ %11, %6 ], [ 0, %2 ]
  %14 = getelementptr inbounds i8, ptr %1, i64 296
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load <2 x i64>, ptr %14, align 8, !tbaa !29
  %17 = extractelement <2 x i64> %16, i64 0
  %18 = add i64 %17, %13
  store i64 %18, ptr %0, align 8, !tbaa !30
  store <2 x i64> %16, ptr %15, align 8, !tbaa !29
  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, !15, i64 784}
!6 = !{!"ZSTD_CCtx_s", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 136, !7, i64 256, !15, i64 264, !16, i64 272, !16, i64 280, !17, i64 288, !17, i64 296, !17, i64 304, !18, i64 312, !14, i64 400, !16, i64 424, !19, i64 432, !20, i64 496, !15, i64 552, !16, i64 560, !22, i64 568, !23, i64 600, !15, i64 776, !15, i64 784, !16, i64 792, !16, i64 800, !16, i64 808, !16, i64 816, !15, i64 824, !16, i64 832, !16, i64 840, !16, i64 848, !7, i64 856, !7, i64 860, !15, i64 864, !15, i64 872, !26, i64 880}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"ZSTD_CCtx_params_s", !7, i64 0, !11, i64 4, !12, i64 32, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !13, i64 68, !14, i64 96}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!12 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!13 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!14 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!"long long", !8, i64 0}
!18 = !{!"XXH64_state_s", !17, i64 0, !17, i64 8, !17, i64 16, !17, i64 24, !17, i64 32, !8, i64 40, !7, i64 72, !8, i64 76}
!19 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !15, i64 48, !7, i64 56, !7, i64 60}
!20 = !{!"", !21, i64 0, !15, i64 32, !15, i64 40, !16, i64 48}
!21 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !7, i64 24, !7, i64 28}
!22 = !{!"", !15, i64 0, !16, i64 8, !16, i64 16, !16, i64 24}
!23 = !{!"", !15, i64 0, !15, i64 8, !24, i64 16}
!24 = !{!"", !21, i64 0, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !15, i64 48, !15, i64 56, !15, i64 64, !25, i64 72}
!25 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !7, i64 80}
!26 = !{!"ZSTD_prefixDict_s", !15, i64 0, !16, i64 8, !7, i64 16}
!27 = !{!6, !16, i64 808}
!28 = !{!6, !16, i64 800}
!29 = !{!17, !17, i64 0}
!30 = !{!31, !17, i64 0}
!31 = !{!"", !17, i64 0, !17, i64 8, !17, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass