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

@ZSTD_defaultCParameters = external hidden constant [4 x [23 x %struct.ZSTD_compressionParameters]], align 16

; 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
define dso_local void @ZSTD_getCParams(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4 %0, i32 noundef %1, i64 noundef %2, i64 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.ZSTD_compressionParameters, align 8
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  store i64 %3, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp ne i64 %13, 0
  %15 = zext i1 %14 to i64
  %16 = select i1 %14, i32 0, i32 500
  %17 = sext i32 %16 to i64
  store i64 %17, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = load i64, ptr %7, align 8, !tbaa !11
  %20 = add i64 %18, %19
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %28

22:                                               ; preds = %4
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = load i64, ptr %7, align 8, !tbaa !11
  %25 = add i64 %23, %24
  %26 = load i64, ptr %8, align 8, !tbaa !11
  %27 = add i64 %25, %26
  br label %29

28:                                               ; preds = %4
  br label %29

29:                                               ; preds = %28, %22
  %30 = phi i64 [ %27, %22 ], [ -1, %28 ]
  store i64 %30, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %31 = load i64, ptr %9, align 8, !tbaa !11
  %32 = icmp ule i64 %31, 262144
  %33 = zext i1 %32 to i32
  %34 = load i64, ptr %9, align 8, !tbaa !11
  %35 = icmp ule i64 %34, 131072
  %36 = zext i1 %35 to i32
  %37 = add nsw i32 %33, %36
  %38 = load i64, ptr %9, align 8, !tbaa !11
  %39 = icmp ule i64 %38, 16384
  %40 = zext i1 %39 to i32
  %41 = add nsw i32 %37, %40
  store i32 %41, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %42 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %42, ptr %11, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %29
  store i32 3, ptr %11, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %45, %29
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = icmp slt i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %46
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %49, %46
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = icmp sgt i32 %51, 22
  br i1 %52, label %53, label %54

53:                                               ; preds = %50
  store i32 22, ptr %11, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %53, %50
  call void @llvm.lifetime.start.p0(i64 28, ptr %12) #3
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds [4 x [23 x %struct.ZSTD_compressionParameters]], ptr @ZSTD_defaultCParameters, i64 0, i64 %56
  %58 = load i32, ptr %11, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [23 x %struct.ZSTD_compressionParameters], ptr %57, i64 0, i64 %59
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %60, i64 28, i1 false), !tbaa.struct !13
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = icmp slt i32 %61, 0
  br i1 %62, label %63, label %67

63:                                               ; preds = %54
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = sub nsw i32 0, %64
  %66 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %12, i32 0, i32 5
  store i32 %65, ptr %66, align 4, !tbaa !14
  br label %67

67:                                               ; preds = %63, %54
  %68 = load i64, ptr %6, align 8, !tbaa !9
  %69 = load i64, ptr %7, align 8, !tbaa !11
  call void @ZSTD_adjustCParams_internal(ptr dead_on_unwind writable sret(%struct.ZSTD_compressionParameters) align 4 %0, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8 %12, i64 noundef %68, i64 noundef %69)
  call void @llvm.lifetime.end.p0(i64 28, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @ZSTD_adjustCParams_internal(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8, i64 noundef, i64 noundef) #2

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 4, !5, i64 20, i64 4, !5, i64 24, i64 4, !5}
!14 = !{!15, !6, i64 20}
!15 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !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"

%struct.ZSTD_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }

@ZSTD_defaultCParameters = external hidden local_unnamed_addr constant [4 x [23 x %struct.ZSTD_compressionParameters]], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; 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) #1

; Function Attrs: mustprogress 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 void @ZSTD_getCParams(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4 %0, i32 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.ZSTD_compressionParameters, align 8
  %6 = add i64 %3, %2
  %.not22 = icmp eq i64 %6, 0
  %.not = icmp eq i64 %2, 0
  %7 = select i1 %.not, i64 500, i64 0
  %8 = add i64 %6, %7
  %9 = select i1 %.not22, i64 -1, i64 %8
  %10 = icmp ult i64 %9, 262145
  %11 = zext i1 %10 to i64
  %12 = icmp ult i64 %9, 131073
  %13 = zext i1 %12 to i64
  %14 = add nuw nsw i64 %11, %13
  %15 = icmp ult i64 %9, 16385
  %16 = zext i1 %15 to i64
  %17 = add nuw nsw i64 %14, %16
  %18 = icmp eq i32 %1, 0
  %spec.store.select = select i1 %18, i32 3, i32 %1
  %19 = icmp slt i32 %1, 0
  %spec.store.select1 = select i1 %19, i32 0, i32 %spec.store.select
  %20 = icmp sgt i32 %1, 22
  %spec.store.select2 = select i1 %20, i32 22, i32 %spec.store.select1
  call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %5) #3
  %21 = sext i32 %spec.store.select2 to i64
  %22 = getelementptr inbounds [4 x [23 x %struct.ZSTD_compressionParameters]], ptr @ZSTD_defaultCParameters, i64 0, i64 %17, i64 %21
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %5, ptr noundef nonnull align 4 dereferenceable(28) %22, i64 28, i1 false), !tbaa.struct !5
  br i1 %19, label %23, label %26

23:                                               ; preds = %4
  %24 = sub nsw i32 0, %1
  %25 = getelementptr inbounds i8, ptr %5, i64 20
  store i32 %24, ptr %25, align 4, !tbaa !10
  br label %26

26:                                               ; preds = %23, %4
  tail call void @ZSTD_adjustCParams_internal(ptr dead_on_unwind writable sret(%struct.ZSTD_compressionParameters) align 4 %0, ptr noundef nonnull byval(%struct.ZSTD_compressionParameters) align 8 %5, i64 noundef %2, i64 noundef %3)
  call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %5) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @ZSTD_adjustCParams_internal(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8, i64 noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 = !{i64 0, i64 4, !6, i64 4, i64 4, !6, i64 8, i64 4, !6, i64 12, i64 4, !6, i64 16, i64 4, !6, i64 20, i64 4, !6, i64 24, i64 4, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 20}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}


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