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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTDMT_CCtxParam_setMTCtxParameter(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %8 = load i32, ptr %6, align 4, !tbaa !9
  switch i32 %8, label %41 [
    i32 0, label %9
    i32 1, label %25
  ]

9:                                                ; preds = %3
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = icmp ugt i32 %10, 0
  %12 = zext i1 %11 to i32
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp ult i32 %13, 1048576
  %15 = zext i1 %14 to i32
  %16 = and i32 %12, %15
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %9
  store i32 1048576, ptr %7, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %18, %9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %21, i32 0, i32 7
  store i32 %20, ptr %22, align 4, !tbaa !11
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  store i64 %24, ptr %4, align 8
  br label %42

25:                                               ; preds = %3
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp ugt i32 %26, 9
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  store i32 9, ptr %7, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %28, %25
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp uge i32 %30, 9
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  br label %35

33:                                               ; preds = %29
  %34 = load i32, ptr %7, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %33, %32
  %36 = phi i32 [ 9, %32 ], [ %34, %33 ]
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %37, i32 0, i32 8
  store i32 %36, ptr %38, align 8, !tbaa !17
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  store i64 %40, ptr %4, align 8
  br label %42

41:                                               ; preds = %3
  store i64 -40, ptr %4, align 8
  br label %42

42:                                               ; preds = %41, %35, %19
  %43 = load i64, ptr %4, align 8
  ret i64 %43
}

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

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 60}
!12 = !{!"ZSTD_CCtx_params_s", !10, i64 0, !13, i64 4, !14, i64 32, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !15, i64 68, !16, i64 96}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!12, !10, i64 64}


; 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: write) uwtable
define dso_local range(i64 -40, 4294967296) i64 @ZSTDMT_CCtxParam_setMTCtxParameter(ptr nocapture noundef writeonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  switch i32 %1, label %12 [
    i32 0, label %4
    i32 1, label %9
  ]

4:                                                ; preds = %3
  %5 = add i32 %2, -1
  %6 = icmp ult i32 %5, 1048575
  %spec.store.select = select i1 %6, i32 1048576, i32 %2
  %7 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %spec.store.select, ptr %7, align 4, !tbaa !5
  %8 = zext i32 %spec.store.select to i64
  br label %12

9:                                                ; preds = %3
  %spec.store.select1 = tail call i32 @llvm.umin.i32(i32 %2, i32 9)
  %10 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %spec.store.select1, ptr %10, align 8, !tbaa !15
  %11 = zext nneg i32 %spec.store.select1 to i64
  br label %12

12:                                               ; preds = %3, %9, %4
  %.0 = phi i64 [ %11, %9 ], [ %8, %4 ], [ -40, %3 ]
  ret i64 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #1

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

!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 60}
!6 = !{!"ZSTD_CCtx_params_s", !7, i64 0, !10, i64 4, !11, i64 32, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !12, i64 68, !13, i64 96}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!12 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!13 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!6, !7, i64 64}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass