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

; 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_adjustCParams_internal(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4 %0, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8 %1, i64 noundef %2, i64 noundef %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i64 %2, ptr %5, align 8, !tbaa !5
  store i64 %3, ptr %6, align 8, !tbaa !9
  %10 = load i64, ptr %6, align 8, !tbaa !9
  %11 = icmp ne i64 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %4
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = add i64 %13, 1
  %15 = icmp ult i64 %14, 2
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  store i64 513, ptr %5, align 8, !tbaa !5
  br label %22

17:                                               ; preds = %12, %4
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i64 -1, ptr %5, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %20, %17
  br label %22

22:                                               ; preds = %21, %16
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = icmp ult i64 %23, 1073741824
  br i1 %24, label %25, label %51

25:                                               ; preds = %22
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = icmp ult i64 %26, 1073741824
  br i1 %27, label %28, label %51

28:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = add i64 %29, %30
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %33 = load i32, ptr %7, align 4, !tbaa !11
  %34 = icmp ult i32 %33, 64
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  br label %41

36:                                               ; preds = %28
  %37 = load i32, ptr %7, align 4, !tbaa !11
  %38 = sub i32 %37, 1
  %39 = call i32 @ZSTD_highbit32(i32 noundef %38)
  %40 = add i32 %39, 1
  br label %41

41:                                               ; preds = %36, %35
  %42 = phi i32 [ 6, %35 ], [ %40, %36 ]
  store i32 %42, ptr %8, align 4, !tbaa !11
  %43 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !13
  %45 = load i32, ptr %8, align 4, !tbaa !11
  %46 = icmp ugt i32 %44, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %41
  %48 = load i32, ptr %8, align 4, !tbaa !11
  %49 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 0
  store i32 %48, ptr %49, align 8, !tbaa !13
  br label %50

50:                                               ; preds = %47, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %51

51:                                               ; preds = %50, %25, %22
  %52 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !15
  %54 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !13
  %56 = icmp ugt i32 %53, %55
  br i1 %56, label %57, label %61

57:                                               ; preds = %51
  %58 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !13
  %60 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 2
  store i32 %59, ptr %60, align 8, !tbaa !15
  br label %61

61:                                               ; preds = %57, %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %62 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !16
  %64 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 6
  %65 = load i32, ptr %64, align 8, !tbaa !17
  %66 = call i32 @ZSTD_cycleLog(i32 noundef %63, i32 noundef %65)
  store i32 %66, ptr %9, align 4, !tbaa !11
  %67 = load i32, ptr %9, align 4, !tbaa !11
  %68 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 0
  %69 = load i32, ptr %68, align 8, !tbaa !13
  %70 = icmp ugt i32 %67, %69
  br i1 %70, label %71, label %79

71:                                               ; preds = %61
  %72 = load i32, ptr %9, align 4, !tbaa !11
  %73 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 0
  %74 = load i32, ptr %73, align 8, !tbaa !13
  %75 = sub i32 %72, %74
  %76 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 1
  %77 = load i32, ptr %76, align 4, !tbaa !16
  %78 = sub i32 %77, %75
  store i32 %78, ptr %76, align 4, !tbaa !16
  br label %79

79:                                               ; preds = %71, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %80 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 0
  %81 = load i32, ptr %80, align 8, !tbaa !13
  %82 = icmp ult i32 %81, 10
  br i1 %82, label %83, label %85

83:                                               ; preds = %79
  %84 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %1, i32 0, i32 0
  store i32 10, ptr %84, align 8, !tbaa !13
  br label %85

85:                                               ; preds = %83, %79
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 8 %1, i64 28, i1 false), !tbaa.struct !18
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ZSTD_highbit32(i32 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @ZSTD_cycleLog(i32 noundef, i32 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 = { inlinehint 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 #4 = { 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 = !{!"long long", !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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24}
!15 = !{!14, !12, i64 8}
!16 = !{!14, !12, i64 4}
!17 = !{!14, !12, i64 24}
!18 = !{i64 0, i64 4, !11, i64 4, i64 4, !11, i64 8, i64 4, !11, i64 12, i64 4, !11, i64 16, i64 4, !11, i64 20, i64 4, !11, i64 24, i64 4, !11}


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

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

; Function Attrs: nounwind uwtable
define dso_local void @ZSTD_adjustCParams_internal(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.ZSTD_compressionParameters) align 4 %0, ptr nocapture noundef byval(%struct.ZSTD_compressionParameters) align 8 %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  %.not = icmp ne i64 %3, 0
  %5 = add i64 %2, 1
  %6 = icmp ult i64 %5, 2
  %or.cond21 = and i1 %.not, %6
  %7 = icmp eq i64 %2, 0
  %spec.store.select = select i1 %7, i64 -1, i64 %2
  %.0 = select i1 %or.cond21, i64 513, i64 %spec.store.select
  %8 = or i64 %.0, %3
  %or.cond = icmp ult i64 %8, 1073741824
  br i1 %or.cond, label %9, label %thread-pre-split

9:                                                ; preds = %4
  %10 = add nuw nsw i64 %.0, %3
  %11 = icmp ult i64 %10, 64
  br i1 %11, label %17, label %12

12:                                               ; preds = %9
  %13 = trunc nuw nsw i64 %10 to i32
  %14 = add nsw i32 %13, -1
  %15 = tail call i32 @ZSTD_highbit32(i32 noundef %14)
  %16 = add i32 %15, 1
  br label %17

17:                                               ; preds = %9, %12
  %18 = phi i32 [ %16, %12 ], [ 6, %9 ]
  %19 = load i32, ptr %1, align 8, !tbaa !5
  %20 = icmp ugt i32 %19, %18
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  store i32 %18, ptr %1, align 8, !tbaa !5
  br label %22

thread-pre-split:                                 ; preds = %4
  %.pr = load i32, ptr %1, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %thread-pre-split, %17, %21
  %23 = phi i32 [ %.pr, %thread-pre-split ], [ %19, %17 ], [ %18, %21 ]
  %24 = getelementptr inbounds i8, ptr %1, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !10
  %26 = icmp ugt i32 %25, %23
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  store i32 %23, ptr %24, align 8, !tbaa !10
  br label %28

28:                                               ; preds = %27, %22
  %29 = getelementptr inbounds i8, ptr %1, i64 4
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = getelementptr inbounds i8, ptr %1, i64 24
  %32 = load i32, ptr %31, align 8, !tbaa !12
  %33 = tail call i32 @ZSTD_cycleLog(i32 noundef %30, i32 noundef %32)
  %34 = icmp ugt i32 %33, %23
  br i1 %34, label %35, label %37

35:                                               ; preds = %28
  %.neg = add i32 %30, %23
  %36 = sub i32 %.neg, %33
  store i32 %36, ptr %29, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %35, %28
  %38 = icmp ult i32 %23, 10
  br i1 %38, label %39, label %40

39:                                               ; preds = %37
  store i32 10, ptr %1, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %39, %37
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(28) %0, ptr noundef nonnull align 8 dereferenceable(28) %1, i64 28, i1 false), !tbaa.struct !13
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ZSTD_highbit32(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @ZSTD_cycleLog(i32 noundef, i32 noundef) local_unnamed_addr #1

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


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