; 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_CDict_s = type { ptr, ptr, i64, ptr, i64, %struct.ZSTD_matchState_t, %struct.ZSTD_compressedBlockState_t, %struct.ZSTD_compressionParameters, %struct.ZSTD_customMem, i32 }
%struct.ZSTD_matchState_t = type { %struct.ZSTD_window_t, i32, i32, i32, i32, ptr, ptr, ptr, %struct.optState_t }
%struct.ZSTD_window_t = type { ptr, ptr, ptr, i32, i32 }
%struct.optState_t = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_compressedBlockState_t = type { %struct.ZSTD_entropyCTables_t, [3 x i32] }
%struct.ZSTD_entropyCTables_t = type { [256 x i32], [193 x i32], [363 x i32], [329 x i32], i32, i32, i32, i32 }
%struct.ZSTD_customMem = type { ptr, ptr, ptr }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 hidden i64 @ZSTD_sizeof_matchState(ptr noundef, i32 noundef) #2

declare i32 @ZSTD_isError(i64 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i64 @ZSTD_initCDict_internal(ptr noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @ZSTD_initStaticCDict(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4, i32 noundef %5, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8 %6) #2 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !9
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i64 %3, ptr %12, align 8, !tbaa !9
  store i32 %4, ptr %13, align 4, !tbaa !11
  store i32 %5, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %20 = call i64 @ZSTD_sizeof_matchState(ptr noundef %6, i32 noundef 0)
  store i64 %20, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %21 = load i32, ptr %13, align 4, !tbaa !11
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %24

23:                                               ; preds = %7
  br label %26

24:                                               ; preds = %7
  %25 = load i64, ptr %12, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %24, %23
  %27 = phi i64 [ 0, %23 ], [ %25, %24 ]
  %28 = add i64 4856, %27
  %29 = add i64 %28, 6144
  %30 = load i64, ptr %15, align 8, !tbaa !9
  %31 = add i64 %29, %30
  store i64 %31, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %32, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = ptrtoint ptr %33 to i64
  %35 = and i64 %34, 7
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %26
  store ptr null, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %78

38:                                               ; preds = %26
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = load i64, ptr %16, align 8, !tbaa !9
  %41 = icmp ult i64 %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %38
  store ptr null, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %78

43:                                               ; preds = %38
  %44 = load i32, ptr %13, align 4, !tbaa !11
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %57

46:                                               ; preds = %43
  %47 = load ptr, ptr %17, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ZSTD_CDict_s, ptr %47, i64 1
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = load i64, ptr %12, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %48, ptr align 1 %49, i64 %50, i1 false)
  %51 = load ptr, ptr %17, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ZSTD_CDict_s, ptr %51, i64 1
  store ptr %52, ptr %11, align 8, !tbaa !5
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i64 4856
  %55 = load i64, ptr %12, align 8, !tbaa !9
  %56 = getelementptr inbounds i8, ptr %54, i64 %55
  store ptr %56, ptr %18, align 8, !tbaa !5
  br label %60

57:                                               ; preds = %43
  %58 = load ptr, ptr %17, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ZSTD_CDict_s, ptr %58, i64 1
  store ptr %59, ptr %18, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %57, %46
  %61 = load ptr, ptr %18, align 8, !tbaa !5
  %62 = load ptr, ptr %17, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ZSTD_CDict_s, ptr %62, i32 0, i32 3
  store ptr %61, ptr %63, align 8, !tbaa !13
  %64 = load i64, ptr %15, align 8, !tbaa !9
  %65 = add i64 6144, %64
  %66 = load ptr, ptr %17, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ZSTD_CDict_s, ptr %66, i32 0, i32 4
  store i64 %65, ptr %67, align 8, !tbaa !22
  %68 = load ptr, ptr %17, align 8, !tbaa !5
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = load i64, ptr %12, align 8, !tbaa !9
  %71 = load i32, ptr %14, align 4, !tbaa !11
  %72 = call i64 @ZSTD_initCDict_internal(ptr noundef %68, ptr noundef %69, i64 noundef %70, i32 noundef 1, i32 noundef %71, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8 %6)
  %73 = call i32 @ZSTD_isError(i64 noundef %72)
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %76

75:                                               ; preds = %60
  store ptr null, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %78

76:                                               ; preds = %60
  %77 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %77, ptr %8, align 8
  store i32 1, ptr %19, align 4
  br label %78

78:                                               ; preds = %76, %75, %42, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  %79 = load ptr, ptr %8, align 8
  ret ptr %79
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"ZSTD_CDict_s", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !15, i64 40, !18, i64 200, !20, i64 4792, !21, i64 4824, !12, i64 4848}
!15 = !{!"", !16, i64 0, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !17, i64 72}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !12, i64 28}
!17 = !{!"", !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}
!18 = !{!"", !19, i64 0, !7, i64 4580}
!19 = !{!"", !7, i64 0, !7, i64 1024, !7, i64 1796, !7, i64 3248, !12, i64 4564, !12, i64 4568, !12, i64 4572, !12, i64 4576}
!20 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24}
!21 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!14, !10, i64 32}


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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @ZSTD_sizeof_matchState(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @ZSTD_isError(i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @ZSTD_initStaticCDict(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4, i32 noundef %5, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8 %6) local_unnamed_addr #1 {
  %8 = call i64 @ZSTD_sizeof_matchState(ptr noundef nonnull %6, i32 noundef 0)
  %9 = ptrtoint ptr %0 to i64
  %10 = and i64 %9, 7
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %11, label %28

11:                                               ; preds = %7
  %12 = icmp eq i32 %4, 1
  %13 = add i64 %3, 11000
  %14 = select i1 %12, i64 11000, i64 %13
  %15 = add i64 %8, %14
  %16 = icmp ugt i64 %15, %1
  br i1 %16, label %28, label %17

17:                                               ; preds = %11
  %18 = icmp eq i32 %4, 0
  %19 = getelementptr inbounds i8, ptr %0, i64 4856
  br i1 %18, label %20, label %22

20:                                               ; preds = %17
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %19, ptr align 1 %2, i64 %3, i1 false)
  %21 = getelementptr inbounds i8, ptr %19, i64 %3
  br label %22

22:                                               ; preds = %17, %20
  %.025 = phi ptr [ %19, %20 ], [ %2, %17 ]
  %.0 = phi ptr [ %21, %20 ], [ %19, %17 ]
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %.0, ptr %23, align 8, !tbaa !5
  %24 = add i64 %8, 6144
  %25 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %24, ptr %25, align 8, !tbaa !19
  %26 = call i64 @ZSTD_initCDict_internal(ptr noundef %0, ptr noundef %.025, i64 noundef %3, i32 noundef 1, i32 noundef %5, ptr noundef nonnull byval(%struct.ZSTD_compressionParameters) align 8 %6)
  %27 = call i32 @ZSTD_isError(i64 noundef %26) #3
  %.not26 = icmp eq i32 %27, 0
  %. = select i1 %.not26, ptr %0, ptr null
  br label %28

28:                                               ; preds = %22, %11, %7
  %.024 = phi ptr [ null, %7 ], [ null, %11 ], [ %., %22 ]
  ret ptr %.024
}

attributes #0 = { mustprogress nocallback nofree 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 = { "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, !7, i64 24}
!6 = !{!"ZSTD_CDict_s", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !15, i64 200, !17, i64 4792, !18, i64 4824, !13, i64 4848}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"", !12, i64 0, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !7, i64 48, !7, i64 56, !7, i64 64, !14, i64 72}
!12 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !13, i64 24, !13, i64 28}
!13 = !{!"int", !8, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !13, i64 72, !13, i64 76, !13, i64 80}
!15 = !{!"", !16, i64 0, !8, i64 4580}
!16 = !{!"", !8, i64 0, !8, i64 1024, !8, i64 1796, !8, i64 3248, !13, i64 4564, !13, i64 4568, !13, i64 4572, !13, i64 4576}
!17 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24}
!18 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!19 = !{!6, !10, i64 32}


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