; 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_inBuffer_s = type { ptr, i64, i64 }
%struct.ZSTD_outBuffer_s = type { ptr, 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @ERR_isError(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @ZSTD_compressStream_generic(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_flushStream(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.ZSTD_inBuffer_s, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #3
  call void @llvm.memset.p0.i64(ptr align 8 %6, i8 0, i64 24, i1 false)
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ZSTD_outBuffer_s, ptr %9, i32 0, i32 2
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ZSTD_outBuffer_s, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %15 = icmp ugt i64 %11, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i64 -1, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %37

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i64 @ZSTD_compressStream_generic(ptr noundef %18, ptr noundef %19, ptr noundef %6, i32 noundef 1)
  store i64 %20, ptr %8, align 8, !tbaa !13
  %21 = load i64, ptr %8, align 8, !tbaa !13
  %22 = call i32 @ERR_isError(i64 noundef %21)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %17
  %25 = load i64, ptr %8, align 8, !tbaa !13
  store i64 %25, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %27

26:                                               ; preds = %17
  store i32 0, ptr %7, align 4
  br label %27

27:                                               ; preds = %26, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %28 = load i32, ptr %7, align 4
  switch i32 %28, label %37 [
    i32 0, label %29
  ]

29:                                               ; preds = %27
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %30, i32 0, i32 29
  %32 = load i64, ptr %31, align 8, !tbaa !14
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %33, i32 0, i32 30
  %35 = load i64, ptr %34, align 8, !tbaa !32
  %36 = sub i64 %32, %35
  store i64 %36, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %37

37:                                               ; preds = %29, %27, %16
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #3
  %38 = load i64, ptr %3, align 8
  ret i64 %38
}

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


; 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_inBuffer_s = type { ptr, i64, i64 }

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @ERR_isError(i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @ZSTD_compressStream_generic(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_flushStream(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.ZSTD_inBuffer_s, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, i8 0, i64 24, i1 false)
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = icmp ugt i64 %5, %7
  br i1 %8, label %18, label %9

9:                                                ; preds = %2
  %10 = call i64 @ZSTD_compressStream_generic(ptr noundef %0, ptr noundef nonnull %1, ptr noundef nonnull %3, i32 noundef 1)
  %11 = call i32 @ERR_isError(i64 noundef %10)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %18

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 840
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %0, i64 848
  %16 = load i64, ptr %15, align 8, !tbaa !30
  %17 = sub i64 %14, %16
  br label %18

18:                                               ; preds = %2, %9, %12
  %.1 = phi i64 [ %17, %12 ], [ %10, %9 ], [ -1, %2 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  ret i64 %.1
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass