; LLVM IR from catid/Zpng :: zstd (zstdmt_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.ZSTDMT_CCtx_s = type { ptr, ptr, ptr, ptr, ptr, %struct.ZSTD_CCtx_params_s, i64, i64, %struct.roundBuff_t, %struct.inBuff_t, i32, %struct.serialState_t, i32, i32, i32, i32, i32, i32, i64, i64, i64, %struct.ZSTD_customMem, ptr, ptr }
%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.roundBuff_t = type { ptr, i64, i64 }
%struct.inBuff_t = type { %struct.range_t, %struct.buffer_s, i64 }
%struct.range_t = type { ptr, i64 }
%struct.buffer_s = type { ptr, i64 }
%struct.serialState_t = type { i32, i32, %struct.ZSTD_CCtx_params_s, %struct.ldmState_t, %struct.XXH64_state_s, i32, i32, i32, %struct.ZSTD_window_t }
%struct.ldmState_t = type { %struct.ZSTD_window_t, ptr, ptr, i64 }
%struct.XXH64_state_s = type { i64, i64, i64, i64, i64, [4 x i64], i32, [2 x i32] }
%struct.ZSTD_window_t = type { ptr, ptr, ptr, i32, i32 }
%struct.ZSTD_customMem = type { ptr, ptr, ptr }
%struct.ZSTDMT_CCtxPool = type { i32, i32, i32, %struct.ZSTD_customMem, [1 x ptr] }

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTDMT_endStream(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ZSTDMT_CCtx_s, ptr %6, i32 0, i32 12
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %19

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ZSTDMT_CCtx_s, ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !27
  %14 = getelementptr inbounds %struct.ZSTDMT_CCtxPool, ptr %13, i32 0, i32 4
  %15 = getelementptr inbounds [1 x ptr], ptr %14, i64 0, i64 0
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call i64 @ZSTD_endStream(ptr noundef %16, ptr noundef %17)
  store i64 %18, ptr %3, align 8
  br label %23

19:                                               ; preds = %2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call i64 @ZSTDMT_flushStream_internal(ptr noundef %20, ptr noundef %21, i32 noundef 2)
  store i64 %22, ptr %3, align 8
  br label %23

23:                                               ; preds = %19, %10
  %24 = load i64, ptr %3, align 8
  ret i64 %24
}

declare i64 @ZSTD_endStream(ptr noundef, ptr noundef) #1

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

!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, !12, i64 568}
!10 = !{!"ZSTDMT_CCtx_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !17, i64 160, !17, i64 168, !18, i64 176, !19, i64 200, !12, i64 240, !22, i64 248, !12, i64 568, !12, i64 572, !12, i64 576, !12, i64 580, !12, i64 584, !12, i64 588, !26, i64 592, !26, i64 600, !26, i64 608, !16, i64 616, !6, i64 640, !6, i64 648}
!11 = !{!"ZSTD_CCtx_params_s", !12, i64 0, !13, i64 4, !14, i64 32, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !15, i64 68, !16, i64 96}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24}
!14 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!15 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!"", !6, i64 0, !17, i64 8, !17, i64 16}
!19 = !{!"", !20, i64 0, !21, i64 16, !17, i64 32}
!20 = !{!"", !6, i64 0, !17, i64 8}
!21 = !{!"buffer_s", !6, i64 0, !17, i64 8}
!22 = !{!"", !12, i64 0, !12, i64 4, !11, i64 8, !23, i64 128, !25, i64 184, !12, i64 272, !12, i64 276, !12, i64 280, !24, i64 288}
!23 = !{!"", !24, i64 0, !6, i64 32, !6, i64 40, !17, i64 48}
!24 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !12, i64 28}
!25 = !{!"XXH64_state_s", !26, i64 0, !26, i64 8, !26, i64 16, !26, i64 24, !26, i64 32, !7, i64 40, !12, i64 72, !7, i64 76}
!26 = !{!"long long", !7, i64 0}
!27 = !{!10, !6, i64 24}


; 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 @ZSTDMT_flushStream_internal(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTDMT_endStream(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 568
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %11, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !26
  %8 = getelementptr inbounds i8, ptr %7, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !27
  %10 = tail call i64 @ZSTD_endStream(ptr noundef %9, ptr noundef %1) #2
  br label %13

11:                                               ; preds = %2
  %12 = tail call i64 @ZSTDMT_flushStream_internal(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 2)
  br label %13

13:                                               ; preds = %11, %5
  %.0 = phi i64 [ %10, %5 ], [ %12, %11 ]
  ret i64 %.0
}

declare i64 @ZSTD_endStream(ptr noundef, ptr noundef) local_unnamed_addr #1

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, !11, i64 568}
!6 = !{!"ZSTDMT_CCtx_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !16, i64 160, !16, i64 168, !17, i64 176, !18, i64 200, !11, i64 240, !21, i64 248, !11, i64 568, !11, i64 572, !11, i64 576, !11, i64 580, !11, i64 584, !11, i64 588, !25, i64 592, !25, i64 600, !25, i64 608, !15, i64 616, !7, i64 640, !7, i64 648}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"ZSTD_CCtx_params_s", !11, i64 0, !12, i64 4, !13, i64 32, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !14, i64 68, !15, i64 96}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!15 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!16 = !{!"long", !8, i64 0}
!17 = !{!"", !7, i64 0, !16, i64 8, !16, i64 16}
!18 = !{!"", !19, i64 0, !20, i64 16, !16, i64 32}
!19 = !{!"", !7, i64 0, !16, i64 8}
!20 = !{!"buffer_s", !7, i64 0, !16, i64 8}
!21 = !{!"", !11, i64 0, !11, i64 4, !10, i64 8, !22, i64 128, !24, i64 184, !11, i64 272, !11, i64 276, !11, i64 280, !23, i64 288}
!22 = !{!"", !23, i64 0, !7, i64 32, !7, i64 40, !16, i64 48}
!23 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !11, i64 24, !11, i64 28}
!24 = !{!"XXH64_state_s", !25, i64 0, !25, i64 8, !25, i64 16, !25, i64 24, !25, i64 32, !8, i64 40, !11, i64 72, !8, i64 76}
!25 = !{!"long long", !8, i64 0}
!26 = !{!6, !7, i64 24}
!27 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass