; 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.ZSTD_compressionParameters = type { i32, i32, i32, i32, i32, i32, i32 }
%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_frameParameters = type { i32, i32, i32 }
%struct.ldmParams_t = type { i32, i32, i32, i32, i32, i32 }
%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
declare dso_local i64 @ZSTD_compressBound(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @ZSTD_getCParamsFromCCtxParams(ptr dead_on_unwind noalias writable sret(%struct.ZSTD_compressionParameters) align 4, ptr noundef, i64 noundef, i64 noundef, i32 noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_estimateCStreamSize_usingCCtxParams(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %struct.ZSTD_compressionParameters, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %10, i32 0, i32 9
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %23

14:                                               ; preds = %9
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  store i64 -1, ptr %2, align 8
  br label %89

23:                                               ; preds = %9
  br label %24

24:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 28, ptr %4) #3
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ZSTD_getCParamsFromCCtxParams(ptr dead_on_unwind writable sret(%struct.ZSTD_compressionParameters) align 4 %4, ptr noundef %25, i64 noundef -1, i64 noundef 0, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %26, i32 0, i32 27
  %28 = load i64, ptr %27, align 8, !tbaa !17
  %29 = call i64 @ZSTD_resolveMaxBlockSize(i64 noundef %28)
  %30 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %4, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !18
  %32 = zext i32 %31 to i64
  %33 = shl i64 1, %32
  %34 = icmp ult i64 %29, %33
  br i1 %34, label %35, label %40

35:                                               ; preds = %24
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %36, i32 0, i32 27
  %38 = load i64, ptr %37, align 8, !tbaa !17
  %39 = call i64 @ZSTD_resolveMaxBlockSize(i64 noundef %38)
  br label %45

40:                                               ; preds = %24
  %41 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %4, i32 0, i32 0
  %42 = load i32, ptr %41, align 4, !tbaa !18
  %43 = zext i32 %42 to i64
  %44 = shl i64 1, %43
  br label %45

45:                                               ; preds = %40, %35
  %46 = phi i64 [ %39, %35 ], [ %44, %40 ]
  store i64 %46, ptr %5, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %47, i32 0, i32 15
  %49 = load i32, ptr %48, align 4, !tbaa !20
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %58

51:                                               ; preds = %45
  %52 = getelementptr inbounds %struct.ZSTD_compressionParameters, ptr %4, i32 0, i32 0
  %53 = load i32, ptr %52, align 4, !tbaa !18
  %54 = zext i32 %53 to i64
  %55 = shl i64 1, %54
  %56 = load i64, ptr %5, align 8, !tbaa !19
  %57 = add i64 %55, %56
  br label %59

58:                                               ; preds = %45
  br label %59

59:                                               ; preds = %58, %51
  %60 = phi i64 [ %57, %51 ], [ 0, %58 ]
  store i64 %60, ptr %6, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %61, i32 0, i32 16
  %63 = load i32, ptr %62, align 8, !tbaa !21
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %65, label %69

65:                                               ; preds = %59
  %66 = load i64, ptr %5, align 8, !tbaa !19
  %67 = call i64 @ZSTD_compressBound(i64 noundef %66)
  %68 = add i64 %67, 1
  br label %70

69:                                               ; preds = %59
  br label %70

70:                                               ; preds = %69, %65
  %71 = phi i64 [ %68, %65 ], [ 0, %69 ]
  store i64 %71, ptr %7, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %72, i32 0, i32 20
  %74 = load i32, ptr %73, align 8, !tbaa !22
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %75, i32 0, i32 1
  %77 = call i32 @ZSTD_resolveRowMatchFinderMode(i32 noundef %74, ptr noundef %76)
  store i32 %77, ptr %8, align 4, !tbaa !23
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %78, i32 0, i32 13
  %80 = load i32, ptr %8, align 4, !tbaa !23
  %81 = load i64, ptr %6, align 8, !tbaa !19
  %82 = load i64, ptr %7, align 8, !tbaa !19
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = call i32 @ZSTD_hasExtSeqProd(ptr noundef %83)
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.ZSTD_CCtx_params_s, ptr %85, i32 0, i32 27
  %87 = load i64, ptr %86, align 8, !tbaa !17
  %88 = call i64 @ZSTD_estimateCCtxSize_usingCCtxParams_internal(ptr noundef %4, ptr noundef %79, i32 noundef 1, i32 noundef %80, i64 noundef %81, i64 noundef %82, i64 noundef -1, i32 noundef %84, i64 noundef %87)
  store i64 %88, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 28, ptr %4) #3
  br label %89

89:                                               ; preds = %70, %22
  %90 = load i64, ptr %2, align 8
  ret i64 %90
}

; Function Attrs: nounwind uwtable
declare hidden i64 @ZSTD_resolveMaxBlockSize(i64 noundef) #1

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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 76}
!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, !6, i64 184, !6, i64 192, !14, i64 200, !11, i64 208}
!11 = !{!"int", !7, 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", !7, i64 0}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!10, !14, i64 200}
!18 = !{!12, !11, i64 0}
!19 = !{!14, !14, i64 0}
!20 = !{!10, !11, i64 124}
!21 = !{!10, !11, i64 128}
!22 = !{!10, !11, i64 144}
!23 = !{!11, !11, 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"

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @ZSTD_compressBound(i64 noundef) local_unnamed_addr #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_estimateCStreamSize_usingCCtxParams(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.ZSTD_compressionParameters, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 76
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %40, label %6

6:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %2) #3
  call void @ZSTD_getCParamsFromCCtxParams(ptr dead_on_unwind nonnull writable sret(%struct.ZSTD_compressionParameters) align 4 %2, ptr noundef nonnull %0, i64 noundef -1, i64 noundef 0, i32 noundef 0)
  %7 = getelementptr inbounds i8, ptr %0, i64 200
  %8 = load i64, ptr %7, align 8, !tbaa !16
  %9 = call i64 @ZSTD_resolveMaxBlockSize(i64 noundef %8)
  %10 = load i32, ptr %2, align 4
  %11 = zext nneg i32 %10 to i64
  %12 = shl nuw i64 1, %11
  %13 = icmp ult i64 %9, %12
  br i1 %13, label %14, label %17

14:                                               ; preds = %6
  %15 = load i64, ptr %7, align 8, !tbaa !16
  %16 = call i64 @ZSTD_resolveMaxBlockSize(i64 noundef %15)
  %.pre = load i32, ptr %2, align 4
  %.pre17 = zext nneg i32 %.pre to i64
  %.pre18 = shl nuw i64 1, %.pre17
  br label %17

17:                                               ; preds = %6, %14
  %.pre-phi19 = phi i64 [ %12, %6 ], [ %.pre18, %14 ]
  %18 = phi i64 [ %12, %6 ], [ %16, %14 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 124
  %20 = load i32, ptr %19, align 4, !tbaa !17
  %21 = icmp eq i32 %20, 0
  %22 = add i64 %.pre-phi19, %18
  %23 = select i1 %21, i64 %22, i64 0
  %24 = getelementptr inbounds i8, ptr %0, i64 128
  %25 = load i32, ptr %24, align 8, !tbaa !18
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %17
  %28 = call i64 @ZSTD_compressBound(i64 noundef %18)
  %29 = add i64 %28, 1
  br label %30

30:                                               ; preds = %17, %27
  %31 = phi i64 [ %29, %27 ], [ 0, %17 ]
  %32 = getelementptr inbounds i8, ptr %0, i64 144
  %33 = load i32, ptr %32, align 8, !tbaa !19
  %34 = getelementptr inbounds i8, ptr %0, i64 4
  %35 = call i32 @ZSTD_resolveRowMatchFinderMode(i32 noundef %33, ptr noundef nonnull %34)
  %36 = getelementptr inbounds i8, ptr %0, i64 96
  %37 = call i32 @ZSTD_hasExtSeqProd(ptr noundef nonnull %0)
  %38 = load i64, ptr %7, align 8, !tbaa !16
  %39 = call i64 @ZSTD_estimateCCtxSize_usingCCtxParams_internal(ptr noundef nonnull %2, ptr noundef nonnull %36, i32 noundef 1, i32 noundef %35, i64 noundef %23, i64 noundef %31, i64 noundef -1, i32 noundef %37, i64 noundef %38)
  call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %2) #3
  br label %40

40:                                               ; preds = %1, %30
  %.0 = phi i64 [ %39, %30 ], [ -1, %1 ]
  ret i64 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @ZSTD_resolveMaxBlockSize(i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { 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 #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, !7, i64 76}
!6 = !{!"ZSTD_CCtx_params_s", !7, i64 0, !10, i64 4, !11, i64 32, !7, i64 44, !7, i64 48, !12, i64 56, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !12, i64 80, !7, i64 88, !7, i64 92, !13, i64 96, !7, i64 120, !7, i64 124, !7, i64 128, !7, i64 132, !7, i64 136, !7, i64 140, !7, i64 144, !7, i64 148, !14, i64 152, !7, i64 176, !7, i64 180, !15, i64 184, !15, i64 192, !12, i64 200, !7, i64 208}
!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 = !{!"long", !8, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!14 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!6, !12, i64 200}
!17 = !{!6, !7, i64 124}
!18 = !{!6, !7, i64 128}
!19 = !{!6, !7, i64 144}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass