; 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_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
declare hidden i64 @ZSTD_compressContinue_internal(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef) #1

declare i32 @ZSTD_isError(i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_compressEnd(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 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 ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = 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 ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load i64, ptr %9, align 8, !tbaa !9
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = load i64, ptr %11, align 8, !tbaa !9
  %20 = call i64 @ZSTD_compressContinue_internal(ptr noundef %15, ptr noundef %16, i64 noundef %17, ptr noundef %18, i64 noundef %19, i32 noundef 1, i32 noundef 1)
  store i64 %20, ptr %13, align 8, !tbaa !9
  %21 = load i64, ptr %13, align 8, !tbaa !9
  %22 = call i32 @ZSTD_isError(i64 noundef %21)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %5
  %25 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %25, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %60

26:                                               ; preds = %5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load i64, ptr %13, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = load i64, ptr %13, align 8, !tbaa !9
  %33 = sub i64 %31, %32
  %34 = call i64 @ZSTD_writeEpilogue(ptr noundef %27, ptr noundef %30, i64 noundef %33)
  store i64 %34, ptr %12, align 8, !tbaa !9
  %35 = load i64, ptr %12, align 8, !tbaa !9
  %36 = call i32 @ZSTD_isError(i64 noundef %35)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %26
  %39 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %39, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %60

40:                                               ; preds = %26
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %41, i32 0, i32 9
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %56

45:                                               ; preds = %40
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %46, i32 0, i32 9
  %48 = load i64, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %49, i32 0, i32 10
  %51 = load i64, ptr %50, align 8, !tbaa !29
  %52 = add i64 %51, 1
  %53 = icmp ne i64 %48, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %45
  store i64 -72, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %60

55:                                               ; preds = %45
  br label %56

56:                                               ; preds = %55, %40
  %57 = load i64, ptr %13, align 8, !tbaa !9
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = add i64 %57, %58
  store i64 %59, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %60

60:                                               ; preds = %56, %54, %38, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %61 = load i64, ptr %6, align 8
  ret i64 %61
}

; Function Attrs: nounwind uwtable
declare hidden i64 @ZSTD_writeEpilogue(ptr noundef, ptr noundef, i64 noundef) #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 = { "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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !19, i64 288}
!12 = !{!"ZSTD_CCtx_s", !13, i64 0, !13, i64 4, !13, i64 8, !14, i64 16, !14, i64 136, !13, i64 256, !6, i64 264, !10, i64 272, !10, i64 280, !19, i64 288, !19, i64 296, !19, i64 304, !20, i64 312, !18, i64 400, !10, i64 424, !21, i64 432, !22, i64 496, !6, i64 552, !10, i64 560, !24, i64 568, !25, 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, !13, i64 856, !13, i64 860, !6, i64 864, !6, i64 872, !28, i64 880}
!13 = !{!"int", !7, i64 0}
!14 = !{!"ZSTD_CCtx_params_s", !13, i64 0, !15, i64 4, !16, i64 32, !13, i64 44, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !13, i64 64, !17, i64 68, !18, i64 96}
!15 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24}
!16 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8}
!17 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!18 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!"long long", !7, i64 0}
!20 = !{!"XXH64_state_s", !19, i64 0, !19, i64 8, !19, i64 16, !19, i64 24, !19, i64 32, !7, i64 40, !13, i64 72, !7, i64 76}
!21 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !13, i64 56, !13, i64 60}
!22 = !{!"", !23, i64 0, !6, i64 32, !6, i64 40, !10, i64 48}
!23 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 28}
!24 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!25 = !{!"", !6, i64 0, !6, i64 8, !26, i64 16}
!26 = !{!"", !23, i64 0, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !27, i64 72}
!27 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, 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}
!28 = !{!"ZSTD_prefixDict_s", !6, i64 0, !10, i64 8, !13, i64 16}
!29 = !{!12, !19, i64 296}


; 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: nounwind uwtable
declare hidden i64 @ZSTD_compressContinue_internal(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @ZSTD_isError(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @ZSTD_compressEnd(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = tail call i64 @ZSTD_compressContinue_internal(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef 1, i32 noundef 1)
  %7 = tail call i32 @ZSTD_isError(i64 noundef %6) #2
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %22

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %1, i64 %6
  %10 = sub i64 %2, %6
  %11 = tail call i64 @ZSTD_writeEpilogue(ptr noundef %0, ptr noundef %9, i64 noundef %10)
  %12 = tail call i32 @ZSTD_isError(i64 noundef %11) #2
  %.not20 = icmp eq i32 %12, 0
  br i1 %.not20, label %13, label %22

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 288
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %.not21 = icmp eq i64 %15, 0
  br i1 %.not21, label %20, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %0, i64 296
  %18 = load i64, ptr %17, align 8, !tbaa !27
  %19 = add i64 %18, 1
  %.not22 = icmp eq i64 %15, %19
  br i1 %.not22, label %20, label %22

20:                                               ; preds = %16, %13
  %21 = add i64 %11, %6
  br label %22

22:                                               ; preds = %16, %8, %5, %20
  %.0 = phi i64 [ %21, %20 ], [ %6, %5 ], [ %11, %8 ], [ -72, %16 ]
  ret i64 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @ZSTD_writeEpilogue(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

attributes #0 = { 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 #1 = { "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, !17, i64 288}
!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, !17, i64 296}


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