; LLVM IR from catid/Zpng :: zstd (zstd_decompress)

; 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_frameHeader = type { i64, i64, i32, i32, i32, i32, i32 }
%struct.blockProperties_t = type { 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_findFrameCompressedSize(ptr noundef %0, i64 noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.ZSTD_frameHeader, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.blockProperties_t, align 4
  %13 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = icmp uge i64 %14, 8
  br i1 %15, label %16, label %27

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i32 @MEM_readLE32(ptr noundef %17)
  %19 = and i32 %18, -16
  %20 = icmp eq i32 %19, 407710288
  br i1 %20, label %21, label %27

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 4
  %24 = call i32 @MEM_readLE32(ptr noundef %23)
  %25 = zext i32 %24 to i64
  %26 = add i64 8, %25
  store i64 %26, ptr %3, align 8
  br label %110

27:                                               ; preds = %16, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %28, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %29, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %30 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %30, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = call i64 @ZSTD_getFrameHeader(ptr noundef %9, ptr noundef %31, i64 noundef %32)
  store i64 %33, ptr %10, align 8, !tbaa !9
  %34 = load i64, ptr %10, align 8, !tbaa !9
  %35 = call i32 @ERR_isError(i64 noundef %34)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %39

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

39:                                               ; preds = %27
  %40 = load i64, ptr %10, align 8, !tbaa !9
  %41 = icmp ugt i64 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  store i64 -72, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %44

43:                                               ; preds = %39
  store i32 0, ptr %11, align 4
  br label %44

44:                                               ; preds = %43, %42, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %45 = load i32, ptr %11, align 4
  switch i32 %45, label %109 [
    i32 0, label %46
  ]

46:                                               ; preds = %44
  %47 = getelementptr inbounds %struct.ZSTD_frameHeader, ptr %9, i32 0, i32 4
  %48 = load i32, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = zext i32 %48 to i64
  %51 = getelementptr inbounds i8, ptr %49, i64 %50
  store ptr %51, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ZSTD_frameHeader, ptr %9, i32 0, i32 4
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = zext i32 %53 to i64
  %55 = load i64, ptr %8, align 8, !tbaa !9
  %56 = sub i64 %55, %54
  store i64 %56, ptr %8, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %89, %46
  br label %58

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

65:                                               ; preds = %58
  %66 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %66, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %87

67:                                               ; preds = %58
  %68 = load i64, ptr %13, align 8, !tbaa !9
  %69 = add i64 3, %68
  %70 = load i64, ptr %8, align 8, !tbaa !9
  %71 = icmp ugt i64 %69, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %67
  store i64 -72, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %87

73:                                               ; preds = %67
  %74 = load i64, ptr %13, align 8, !tbaa !9
  %75 = add i64 3, %74
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i64 %75
  store ptr %77, ptr %6, align 8, !tbaa !5
  %78 = load i64, ptr %13, align 8, !tbaa !9
  %79 = add i64 3, %78
  %80 = load i64, ptr %8, align 8, !tbaa !9
  %81 = sub i64 %80, %79
  store i64 %81, ptr %8, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.blockProperties_t, ptr %12, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !15
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %86

85:                                               ; preds = %73
  store i32 3, ptr %11, align 4
  br label %87

86:                                               ; preds = %73
  store i32 0, ptr %11, align 4
  br label %87

87:                                               ; preds = %86, %85, %72, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #3
  %88 = load i32, ptr %11, align 4
  switch i32 %88, label %109 [
    i32 0, label %89
    i32 3, label %90
  ]

89:                                               ; preds = %87
  br label %57

90:                                               ; preds = %87
  %91 = getelementptr inbounds %struct.ZSTD_frameHeader, ptr %9, i32 0, i32 6
  %92 = load i32, ptr %91, align 8, !tbaa !17
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %103

94:                                               ; preds = %90
  %95 = load i64, ptr %8, align 8, !tbaa !9
  %96 = icmp ult i64 %95, 4
  br i1 %96, label %97, label %98

97:                                               ; preds = %94
  store i64 -72, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %109

98:                                               ; preds = %94
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = getelementptr inbounds i8, ptr %99, i64 4
  store ptr %100, ptr %6, align 8, !tbaa !5
  %101 = load i64, ptr %8, align 8, !tbaa !9
  %102 = sub i64 %101, 4
  store i64 %102, ptr %8, align 8, !tbaa !9
  br label %103

103:                                              ; preds = %98, %90
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = load ptr, ptr %7, align 8, !tbaa !5
  %106 = ptrtoint ptr %104 to i64
  %107 = ptrtoint ptr %105 to i64
  %108 = sub i64 %106, %107
  store i64 %108, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %109

109:                                              ; preds = %103, %97, %87, %44
  call void @llvm.lifetime.end.p0(i64 40, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  br label %110

110:                                              ; preds = %109, %21
  %111 = load i64, ptr %3, align 8
  ret i64 %111
}

; Function Attrs: nounwind uwtable
declare hidden i32 @ERR_isError(i64 noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"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, !14, i64 24}
!12 = !{!"", !13, i64 0, !13, i64 8, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 4}
!16 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8}
!17 = !{!12, !14, i64 32}


; 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_frameHeader = type { i64, i64, i32, i32, i32, i32, i32 }
%struct.blockProperties_t = type { 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: inlinehint nounwind uwtable
declare hidden i32 @MEM_readLE32(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_findFrameCompressedSize(ptr noundef %0, i64 noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.ZSTD_frameHeader, align 8
  %4 = alloca %struct.blockProperties_t, align 4
  %5 = icmp ugt i64 %1, 7
  br i1 %5, label %6, label %15

6:                                                ; preds = %2
  %7 = tail call i32 @MEM_readLE32(ptr noundef %0)
  %8 = and i32 %7, -16
  %9 = icmp eq i32 %8, 407710288
  br i1 %9, label %10, label %15

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = tail call i32 @MEM_readLE32(ptr noundef nonnull %11)
  %13 = zext i32 %12 to i64
  %14 = add nuw nsw i64 %13, 8
  br label %50

15:                                               ; preds = %6, %2
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #3
  %16 = call i64 @ZSTD_getFrameHeader(ptr noundef nonnull %3, ptr noundef %0, i64 noundef %1)
  %17 = call i32 @ERR_isError(i64 noundef %16)
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %18, label %.thread

18:                                               ; preds = %15
  %.not38 = icmp eq i64 %16, 0
  br i1 %.not38, label %19, label %.thread

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %3, i64 24
  %21 = load i32, ptr %20, align 8, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %0, i64 %22
  %24 = sub i64 %1, %22
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #3
  %25 = call i64 @ZSTD_getcBlockSize(ptr noundef %23, i64 noundef %24, ptr noundef nonnull %4)
  %26 = call i32 @ERR_isError(i64 noundef %25)
  %.not3959 = icmp eq i32 %26, 0
  br i1 %.not3959, label %.lr.ph, label %.thread46

.lr.ph:                                           ; preds = %19
  %27 = getelementptr inbounds i8, ptr %4, i64 4
  br label %28

28:                                               ; preds = %.lr.ph, %36
  %29 = phi i64 [ %25, %.lr.ph ], [ %37, %36 ]
  %.03261 = phi ptr [ %23, %.lr.ph ], [ %33, %36 ]
  %.03560 = phi i64 [ %24, %.lr.ph ], [ %34, %36 ]
  %30 = add i64 %29, 3
  %31 = icmp ugt i64 %30, %.03560
  br i1 %31, label %.thread46, label %32

32:                                               ; preds = %28
  %33 = getelementptr inbounds i8, ptr %.03261, i64 %30
  %34 = sub i64 %.03560, %30
  %35 = load i32, ptr %27, align 4, !tbaa !11
  %.not40 = icmp eq i32 %35, 0
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #3
  br i1 %.not40, label %36, label %39

.thread46:                                        ; preds = %28, %36, %19
  %.2.ph = phi i64 [ %25, %19 ], [ %37, %36 ], [ -72, %28 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #3
  br label %.thread

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #3
  %37 = call i64 @ZSTD_getcBlockSize(ptr noundef %33, i64 noundef %34, ptr noundef nonnull %4)
  %38 = call i32 @ERR_isError(i64 noundef %37)
  %.not39 = icmp eq i32 %38, 0
  br i1 %.not39, label %28, label %.thread46

39:                                               ; preds = %32
  %40 = getelementptr inbounds i8, ptr %3, i64 32
  %41 = load i32, ptr %40, align 8, !tbaa !13
  %.not41 = icmp eq i32 %41, 0
  br i1 %.not41, label %46, label %42

42:                                               ; preds = %39
  %43 = icmp ult i64 %34, 4
  br i1 %43, label %.thread, label %44

44:                                               ; preds = %42
  %45 = getelementptr inbounds i8, ptr %33, i64 4
  br label %46

46:                                               ; preds = %44, %39
  %.234 = phi ptr [ %45, %44 ], [ %33, %39 ]
  %47 = ptrtoint ptr %.234 to i64
  %48 = ptrtoint ptr %0 to i64
  %49 = sub i64 %47, %48
  br label %.thread

.thread:                                          ; preds = %15, %.thread46, %42, %18, %46
  %.3 = phi i64 [ %49, %46 ], [ -72, %18 ], [ -72, %42 ], [ %.2.ph, %.thread46 ], [ %16, %15 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #3
  br label %50

50:                                               ; preds = %.thread, %10
  %.4 = phi i64 [ %14, %10 ], [ %.3, %.thread ]
  ret i64 %.4
}

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

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

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


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