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

; 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 i32 @ZSTD_isError(i64 noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @ZSTD_getFrameContentSize(ptr noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_findDecompressedSize(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %79, %77, %2
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = call i64 @ZSTD_startingInputLength(i32 noundef 0)
  %15 = icmp uge i64 %13, %14
  br i1 %15, label %16, label %80

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i32 @MEM_readLE32(ptr noundef %17)
  store i32 %18, ptr %7, align 4, !tbaa !13
  %19 = load i32, ptr %7, align 4, !tbaa !13
  %20 = and i32 %19, -16
  %21 = icmp eq i32 %20, 407710288
  br i1 %21, label %22, label %38

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i64, ptr %5, align 8, !tbaa !9
  %25 = call i64 @readSkippableFrameSize(ptr noundef %23, i64 noundef %24)
  store i64 %25, ptr %8, align 8, !tbaa !9
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = call i32 @ZSTD_isError(i64 noundef %26)
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %22
  store i64 -2, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %37

30:                                               ; preds = %22
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %31, i64 %32
  store ptr %33, ptr %4, align 8, !tbaa !5
  %34 = load i64, ptr %8, align 8, !tbaa !9
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = sub i64 %35, %34
  store i64 %36, ptr %5, align 8, !tbaa !9
  store i32 2, ptr %9, align 4
  br label %37, !llvm.loop !15

37:                                               ; preds = %30, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %77

38:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = call i64 @ZSTD_getFrameContentSize(ptr noundef %39, i64 noundef %40)
  store i64 %41, ptr %10, align 8, !tbaa !11
  %42 = load i64, ptr %10, align 8, !tbaa !11
  %43 = icmp uge i64 %42, -2
  br i1 %43, label %44, label %46

44:                                               ; preds = %38
  %45 = load i64, ptr %10, align 8, !tbaa !11
  store i64 %45, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %57

46:                                               ; preds = %38
  %47 = load i64, ptr %6, align 8, !tbaa !11
  %48 = load i64, ptr %10, align 8, !tbaa !11
  %49 = add i64 %47, %48
  %50 = load i64, ptr %6, align 8, !tbaa !11
  %51 = icmp ult i64 %49, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %46
  store i64 -2, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %57

53:                                               ; preds = %46
  %54 = load i64, ptr %10, align 8, !tbaa !11
  %55 = load i64, ptr %6, align 8, !tbaa !11
  %56 = add i64 %55, %54
  store i64 %56, ptr %6, align 8, !tbaa !11
  store i32 0, ptr %9, align 4
  br label %57

57:                                               ; preds = %53, %52, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %58 = load i32, ptr %9, align 4
  switch i32 %58, label %77 [
    i32 0, label %59
  ]

59:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = call i64 @ZSTD_findFrameCompressedSize(ptr noundef %60, i64 noundef %61)
  store i64 %62, ptr %11, align 8, !tbaa !9
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = call i32 @ZSTD_isError(i64 noundef %63)
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %59
  store i64 -2, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %74

67:                                               ; preds = %59
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = load i64, ptr %11, align 8, !tbaa !9
  %70 = getelementptr inbounds i8, ptr %68, i64 %69
  store ptr %70, ptr %4, align 8, !tbaa !5
  %71 = load i64, ptr %11, align 8, !tbaa !9
  %72 = load i64, ptr %5, align 8, !tbaa !9
  %73 = sub i64 %72, %71
  store i64 %73, ptr %5, align 8, !tbaa !9
  store i32 0, ptr %9, align 4
  br label %74

74:                                               ; preds = %67, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %75 = load i32, ptr %9, align 4
  switch i32 %75, label %77 [
    i32 0, label %76
  ]

76:                                               ; preds = %74
  store i32 0, ptr %9, align 4
  br label %77

77:                                               ; preds = %76, %74, %57, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %78 = load i32, ptr %9, align 4
  switch i32 %78, label %86 [
    i32 0, label %79
    i32 2, label %12
  ]

79:                                               ; preds = %77
  br label %12, !llvm.loop !15

80:                                               ; preds = %12
  %81 = load i64, ptr %5, align 8, !tbaa !9
  %82 = icmp ne i64 %81, 0
  br i1 %82, label %83, label %84

83:                                               ; preds = %80
  store i64 -2, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %86

84:                                               ; preds = %80
  %85 = load i64, ptr %6, align 8, !tbaa !11
  store i64 %85, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %86

86:                                               ; preds = %84, %83, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %87 = load i64, ptr %3, align 8
  ret i64 %87
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @ZSTD_findFrameCompressedSize(ptr noundef, 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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: nounwind uwtable
declare dso_local i32 @ZSTD_isError(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden i64 @ZSTD_startingInputLength(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @ZSTD_getFrameContentSize(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @readSkippableFrameSize(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_findDecompressedSize(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @ZSTD_startingInputLength(i32 noundef 0)
  %.not67 = icmp ugt i64 %3, %1
  br i1 %.not67, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %18
  %.03270 = phi ptr [ %.335, %18 ], [ %0, %2 ]
  %.04069 = phi i64 [ %.343, %18 ], [ %1, %2 ]
  %.04468 = phi i64 [ %.246, %18 ], [ 0, %2 ]
  %4 = tail call i32 @MEM_readLE32(ptr noundef %.03270)
  %5 = and i32 %4, -16
  %6 = icmp eq i32 %5, 407710288
  br i1 %6, label %7, label %10

7:                                                ; preds = %.lr.ph
  %8 = tail call i64 @readSkippableFrameSize(ptr noundef %.03270, i64 noundef %.04069)
  %9 = tail call i32 @ZSTD_isError(i64 noundef %8)
  %.not52 = icmp eq i32 %9, 0
  br i1 %.not52, label %18, label %.thread57, !llvm.loop !5

10:                                               ; preds = %.lr.ph
  %11 = tail call i64 @ZSTD_getFrameContentSize(ptr noundef %.03270, i64 noundef %.04069)
  %12 = icmp ugt i64 %11, -3
  br i1 %12, label %.thread57, label %13

13:                                               ; preds = %10
  %14 = add i64 %11, %.04468
  %.not63 = icmp ult i64 %14, %.04468
  br i1 %.not63, label %.thread57, label %15

15:                                               ; preds = %13
  %16 = tail call i64 @ZSTD_findFrameCompressedSize(ptr noundef %.03270, i64 noundef %.04069)
  %17 = tail call i32 @ZSTD_isError(i64 noundef %16)
  %.not51 = icmp eq i32 %17, 0
  br i1 %.not51, label %18, label %.thread57

18:                                               ; preds = %15, %7
  %.246 = phi i64 [ %.04468, %7 ], [ %14, %15 ]
  %.pn = phi i64 [ %8, %7 ], [ %16, %15 ]
  %.335 = getelementptr inbounds i8, ptr %.03270, i64 %.pn
  %.343 = sub i64 %.04069, %.pn
  %19 = tail call i64 @ZSTD_startingInputLength(i32 noundef 0)
  %.not = icmp ult i64 %.343, %19
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %18, %2
  %.044.lcssa = phi i64 [ 0, %2 ], [ %.246, %18 ]
  %.040.lcssa = phi i64 [ %1, %2 ], [ %.343, %18 ]
  %.not50 = icmp eq i64 %.040.lcssa, 0
  %.044.53 = select i1 %.not50, i64 %.044.lcssa, i64 -2
  br label %.thread57

.thread57:                                        ; preds = %10, %15, %7, %13, %._crit_edge
  %.5 = phi i64 [ %.044.53, %._crit_edge ], [ %11, %10 ], [ -2, %13 ], [ -2, %7 ], [ -2, %15 ]
  ret i64 %.5
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @ZSTD_findFrameCompressedSize(ptr noundef, i64 noundef) local_unnamed_addr #0

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" }
attributes #1 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass