; 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_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }
%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_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
declare dso_local i64 @ZSTD_freeCDict(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @ZSTD_getCParamsFromCCtxParams(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4, ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_CCtx_loadDictionary_advanced(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.ZSTD_compressionParameters, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !11
  store i32 %4, ptr %11, align 4, !tbaa !11
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %14, i32 0, i32 31
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %5
  store i64 -60, ptr %6, align 8
  br label %72

19:                                               ; preds = %5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %20, i32 0, i32 14
  %22 = load i64, ptr %21, align 8, !tbaa !30
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %19
  store i64 -64, ptr %6, align 8
  br label %72

25:                                               ; preds = %19
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %26, i32 0, i32 33
  %28 = load ptr, ptr %27, align 8, !tbaa !31
  %29 = call i64 @ZSTD_freeCDict(ptr noundef %28)
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %35, label %32

32:                                               ; preds = %25
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = icmp eq i64 %33, 0
  br i1 %34, label %35, label %40

35:                                               ; preds = %32, %25
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %36, i32 0, i32 33
  store ptr null, ptr %37, align 8, !tbaa !31
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %38, i32 0, i32 34
  store ptr null, ptr %39, align 8, !tbaa !32
  br label %71

40:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 28, ptr %12) #2
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %43, i32 0, i32 9
  %45 = load i64, ptr %44, align 8, !tbaa !33
  %46 = sub i64 %45, 1
  %47 = load i64, ptr %9, align 8, !tbaa !9
  call void @ZSTD_getCParamsFromCCtxParams(ptr dead_on_unwind writable sret(%struct.ZSTD_compressionParameters) align 4 %12, ptr noundef %42, i64 noundef %46, i64 noundef %47)
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !11
  %51 = load i32, ptr %11, align 4, !tbaa !11
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %52, i32 0, i32 13
  %54 = call ptr @ZSTD_createCDict_advanced(ptr noundef %48, i64 noundef %49, i32 noundef %50, i32 noundef %51, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8 %12, ptr noundef byval(%struct.ZSTD_customMem) align 8 %53)
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %55, i32 0, i32 33
  store ptr %54, ptr %56, align 8, !tbaa !31
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %57, i32 0, i32 33
  %59 = load ptr, ptr %58, align 8, !tbaa !31
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %60, i32 0, i32 34
  store ptr %59, ptr %61, align 8, !tbaa !32
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %62, i32 0, i32 33
  %64 = load ptr, ptr %63, align 8, !tbaa !31
  %65 = icmp eq ptr %64, null
  br i1 %65, label %66, label %67

66:                                               ; preds = %40
  store i64 -64, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %68

67:                                               ; preds = %40
  store i32 0, ptr %13, align 4
  br label %68

68:                                               ; preds = %67, %66
  call void @llvm.lifetime.end.p0(i64 28, ptr %12) #2
  %69 = load i32, ptr %13, align 4
  switch i32 %69, label %74 [
    i32 0, label %70
    i32 1, label %72
  ]

70:                                               ; preds = %68
  br label %71

71:                                               ; preds = %70, %35
  store i64 0, ptr %6, align 8
  br label %72

72:                                               ; preds = %71, %68, %24, %18
  %73 = load i64, ptr %6, align 8
  ret i64 %73

74:                                               ; preds = %68
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @ZSTD_createCDict_advanced(ptr noundef, i64 noundef, i32 noundef, i32 noundef, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8, ptr noundef byval(%struct.ZSTD_customMem) align 8) #1

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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 856}
!14 = !{!"ZSTD_CCtx_s", !12, i64 0, !12, i64 4, !12, i64 8, !15, i64 16, !15, i64 136, !12, i64 256, !6, 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, !6, i64 552, !10, i64 560, !25, i64 568, !26, i64 600, !6, i64 776, !6, i64 784, !10, i64 792, !10, i64 800, !10, i64 808, !10, i64 816, !6, i64 824, !10, i64 832, !10, i64 840, !10, i64 848, !12, i64 856, !12, i64 860, !6, i64 864, !6, i64 872, !29, i64 880}
!15 = !{!"ZSTD_CCtx_params_s", !12, i64 0, !16, i64 4, !17, i64 32, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !18, i64 68, !19, i64 96}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24}
!17 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!18 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!19 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!"long long", !7, i64 0}
!21 = !{!"XXH64_state_s", !20, i64 0, !20, i64 8, !20, i64 16, !20, i64 24, !20, i64 32, !7, i64 40, !12, i64 72, !7, i64 76}
!22 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !12, i64 56, !12, i64 60}
!23 = !{!"", !24, i64 0, !6, i64 32, !6, i64 40, !10, i64 48}
!24 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !12, i64 28}
!25 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!26 = !{!"", !6, i64 0, !6, i64 8, !27, i64 16}
!27 = !{!"", !24, i64 0, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !28, i64 72}
!28 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !12, i64 80}
!29 = !{!"ZSTD_prefixDict_s", !6, i64 0, !10, i64 8, !12, i64 16}
!30 = !{!14, !10, i64 424}
!31 = !{!14, !6, i64 864}
!32 = !{!14, !6, i64 872}
!33 = !{!14, !20, i64 288}


; 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_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_customMem = type { ptr, ptr, ptr }

; 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: nounwind uwtable
declare dso_local i64 @ZSTD_freeCDict(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @ZSTD_getCParamsFromCCtxParams(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -64, 1) i64 @ZSTD_CCtx_loadDictionary_advanced(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = alloca %struct.ZSTD_compressionParameters, align 8
  %7 = getelementptr inbounds i8, ptr %0, i64 856
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %28

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 424
  %11 = load i64, ptr %10, align 8, !tbaa !27
  %.not24 = icmp eq i64 %11, 0
  br i1 %.not24, label %12, label %28

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 864
  %14 = load ptr, ptr %13, align 8, !tbaa !28
  %15 = tail call i64 @ZSTD_freeCDict(ptr noundef %14)
  %16 = icmp eq ptr %1, null
  %17 = icmp eq i64 %2, 0
  %or.cond = or i1 %16, %17
  br i1 %or.cond, label %18, label %19

18:                                               ; preds = %12
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %13, i8 0, i64 16, i1 false)
  br label %27

19:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %6) #3
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = getelementptr inbounds i8, ptr %0, i64 288
  %22 = load i64, ptr %21, align 8, !tbaa !29
  %23 = add i64 %22, -1
  call void @ZSTD_getCParamsFromCCtxParams(ptr dead_on_unwind nonnull writable sret(%struct.ZSTD_compressionParameters) align 4 %6, ptr noundef nonnull %20, i64 noundef %23, i64 noundef %2)
  %24 = getelementptr inbounds i8, ptr %0, i64 400
  %25 = call ptr @ZSTD_createCDict_advanced(ptr noundef nonnull %1, i64 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef nonnull byval(%struct.ZSTD_compressionParameters) align 8 %6, ptr noundef nonnull byval(%struct.ZSTD_customMem) align 8 %24)
  store ptr %25, ptr %13, align 8, !tbaa !28
  %26 = getelementptr inbounds i8, ptr %0, i64 872
  store ptr %25, ptr %26, align 8, !tbaa !30
  %.not25 = icmp eq ptr %25, null
  call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %6) #3
  br i1 %.not25, label %28, label %27

27:                                               ; preds = %19, %18
  br label %28

28:                                               ; preds = %19, %9, %5, %27
  %.1 = phi i64 [ 0, %27 ], [ -64, %19 ], [ -60, %5 ], [ -64, %9 ]
  ret i64 %.1
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @ZSTD_createCDict_advanced(ptr noundef, i64 noundef, i32 noundef, i32 noundef, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8, ptr noundef byval(%struct.ZSTD_customMem) align 8) local_unnamed_addr #1

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

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 856}
!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 424}
!28 = !{!6, !15, i64 864}
!29 = !{!6, !17, i64 288}
!30 = !{!6, !15, i64 872}


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