; LLVM IR from indygreg/python-zstandard :: zstd (zstd)

; 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, i32, %struct.inBuff_t, %struct.roundBuff_t, %struct.serialState_t, %struct.rsyncState_t, i32, i32, i32, i32, i32, i64, i64, i64, %struct.ZSTD_customMem, ptr, ptr, i8 }
%struct.ZSTD_CCtx_params_s = type { i32, %struct.ZSTD_compressionParameters, %struct.ZSTD_frameParameters, i32, i32, i64, i32, i32, i32, i32, i64, i32, i32, %struct.ldmParams_t, i32, i32, i32, i32, i32, i32, i32, i32, %struct.ZSTD_customMem, i32, i32, ptr, ptr, i64, i32 }
%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.inBuff_t = type { %struct.range_t, %struct.buffer_s, i64 }
%struct.range_t = type { ptr, i64 }
%struct.buffer_s = type { ptr, i64 }
%struct.roundBuff_t = type { ptr, i64, i64 }
%struct.serialState_t = type { %union.pthread_mutex_t, %union.pthread_cond_t, %struct.ZSTD_CCtx_params_s, %struct.ldmState_t, %struct.XXH_NAMESPACEXXH64_state_s, i32, %union.pthread_mutex_t, %union.pthread_cond_t, %struct.ZSTD_window_t }
%struct.ldmState_t = type { %struct.ZSTD_window_t, ptr, i32, ptr, [64 x i64], [64 x %struct.ldmMatchCandidate_t] }
%struct.ldmMatchCandidate_t = type { ptr, i32, i32, ptr }
%struct.XXH_NAMESPACEXXH64_state_s = type { i64, [4 x i64], [4 x i64], i32, i32, i64 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }
%struct.ZSTD_window_t = type { ptr, ptr, ptr, i32, i32, i32 }
%struct.rsyncState_t = type { i64, i64, i64 }
%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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTDMT_nextInputSizeHint(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.ZSTDMT_CCtx_s, ptr %4, i32 0, i32 6
  %6 = load i64, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ZSTDMT_CCtx_s, ptr %7, i32 0, i32 9
  %9 = getelementptr inbounds %struct.inBuff_t, ptr %8, i32 0, i32 2
  %10 = load i64, ptr %9, align 8, !tbaa !28
  %11 = sub i64 %6, %10
  store i64 %11, ptr %3, align 8, !tbaa !29
  %12 = load i64, ptr %3, align 8, !tbaa !29
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %14, label %18

14:                                               ; preds = %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ZSTDMT_CCtx_s, ptr %15, i32 0, i32 6
  %17 = load i64, ptr %16, align 8, !tbaa !9
  store i64 %17, ptr %3, align 8, !tbaa !29
  br label %18

18:                                               ; preds = %14, %1
  %19 = load i64, ptr %3, align 8, !tbaa !29
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i64 %19
}

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, !15, i64 256}
!10 = !{!"ZSTDMT_CCtx_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !15, i64 256, !15, i64 264, !12, i64 272, !18, i64 280, !21, i64 320, !22, i64 344, !26, i64 2984, !12, i64 3008, !12, i64 3012, !12, i64 3016, !12, i64 3020, !12, i64 3024, !27, i64 3032, !27, i64 3040, !27, i64 3048, !17, i64 3056, !6, i64 3080, !6, i64 3088, !12, i64 3096}
!11 = !{!"ZSTD_CCtx_params_s", !12, i64 0, !13, i64 4, !14, i64 32, !12, i64 44, !12, i64 48, !15, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !15, i64 80, !12, i64 88, !12, i64 92, !16, i64 96, !12, i64 120, !12, i64 124, !12, i64 128, !12, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !12, i64 148, !17, i64 152, !12, i64 176, !12, i64 180, !6, i64 184, !6, i64 192, !15, i64 200, !12, i64 208}
!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 = !{!"long", !7, i64 0}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!17 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!"", !19, i64 0, !20, i64 16, !15, i64 32}
!19 = !{!"", !6, i64 0, !15, i64 8}
!20 = !{!"buffer_s", !6, i64 0, !15, i64 8}
!21 = !{!"", !6, i64 0, !15, i64 8, !15, i64 16}
!22 = !{!"", !7, i64 0, !7, i64 40, !11, i64 88, !23, i64 304, !25, i64 2416, !12, i64 2504, !7, i64 2512, !7, i64 2552, !24, i64 2600}
!23 = !{!"", !24, i64 0, !6, i64 40, !12, i64 48, !6, i64 56, !7, i64 64, !7, i64 576}
!24 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !12, i64 28, !12, i64 32}
!25 = !{!"XXH_NAMESPACEXXH64_state_s", !15, i64 0, !7, i64 8, !7, i64 40, !12, i64 72, !12, i64 76, !15, i64 80}
!26 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16}
!27 = !{!"long long", !7, i64 0}
!28 = !{!10, !15, i64 312}
!29 = !{!15, !15, i64 0}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i64 @ZSTDMT_nextInputSizeHint(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 256
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 312
  %5 = load i64, ptr %4, align 8, !tbaa !27
  %6 = icmp eq i64 %3, %5
  %7 = select i1 %6, i64 0, i64 %5
  %spec.select = sub i64 %3, %7
  ret i64 %spec.select
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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" }

!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, !14, i64 256}
!6 = !{!"ZSTDMT_CCtx_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !14, i64 256, !14, i64 264, !11, i64 272, !17, i64 280, !20, i64 320, !21, i64 344, !25, i64 2984, !11, i64 3008, !11, i64 3012, !11, i64 3016, !11, i64 3020, !11, i64 3024, !26, i64 3032, !26, i64 3040, !26, i64 3048, !16, i64 3056, !7, i64 3080, !7, i64 3088, !11, i64 3096}
!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, !14, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !14, i64 80, !11, i64 88, !11, i64 92, !15, i64 96, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !11, i64 148, !16, i64 152, !11, i64 176, !11, i64 180, !7, i64 184, !7, i64 192, !14, i64 200, !11, i64 208}
!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 = !{!"long", !8, i64 0}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!16 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!17 = !{!"", !18, i64 0, !19, i64 16, !14, i64 32}
!18 = !{!"", !7, i64 0, !14, i64 8}
!19 = !{!"buffer_s", !7, i64 0, !14, i64 8}
!20 = !{!"", !7, i64 0, !14, i64 8, !14, i64 16}
!21 = !{!"", !8, i64 0, !8, i64 40, !10, i64 88, !22, i64 304, !24, i64 2416, !11, i64 2504, !8, i64 2512, !8, i64 2552, !23, i64 2600}
!22 = !{!"", !23, i64 0, !7, i64 40, !11, i64 48, !7, i64 56, !8, i64 64, !8, i64 576}
!23 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !11, i64 24, !11, i64 28, !11, i64 32}
!24 = !{!"XXH_NAMESPACEXXH64_state_s", !14, i64 0, !8, i64 8, !8, i64 40, !11, i64 72, !11, i64 76, !14, i64 80}
!25 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16}
!26 = !{!"long long", !8, i64 0}
!27 = !{!6, !14, i64 312}


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