; 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_parameters = type { %struct.ZSTD_compressionParameters, %struct.ZSTD_frameParameters }
%struct.ZSTD_frameParameters = type { i32, i32, i32 }
%struct.ZSTD_CCtx_s = type { i32, i32, i32, %struct.ZSTD_CCtx_params_s, %struct.ZSTD_CCtx_params_s, %struct.ZSTD_CCtx_params_s, i32, i64, %struct.ZSTD_cwksp, i64, i64, i64, i64, %struct.XXH_NAMESPACEXXH64_state_s, %struct.ZSTD_customMem, ptr, i64, %struct.SeqCollector, i32, i32, %struct.seqStore_t, %struct.ldmState_t, ptr, i64, %struct.rawSeqStore_t, %struct.ZSTD_blockState_t, ptr, i32, ptr, i64, i64, i64, i64, ptr, i64, i64, i64, i32, i32, %struct.ZSTD_inBuffer_s, i64, i64, %struct.ZSTD_localDict, ptr, %struct.ZSTD_prefixDict_s, ptr, %struct.ZSTD_blockSplitCtx, ptr, i64 }
%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.ldmParams_t = type { i32, i32, i32, i32, i32, i32 }
%struct.ZSTD_cwksp = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8, i32, i32, i32 }
%struct.XXH_NAMESPACEXXH64_state_s = type { i64, [4 x i64], [4 x i64], i32, i32, i64 }
%struct.ZSTD_customMem = type { ptr, ptr, ptr }
%struct.SeqCollector = type { i32, ptr, i64, i64 }
%struct.seqStore_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i32, i32 }
%struct.ldmState_t = type { %struct.ZSTD_window_t, ptr, i32, ptr, [64 x i64], [64 x %struct.ldmMatchCandidate_t] }
%struct.ZSTD_window_t = type { ptr, ptr, ptr, i32, i32, i32 }
%struct.ldmMatchCandidate_t = type { ptr, i32, i32, ptr }
%struct.rawSeqStore_t = type { ptr, i64, i64, i64, i64 }
%struct.ZSTD_blockState_t = type { ptr, ptr, %struct.ZSTD_matchState_t }
%struct.ZSTD_matchState_t = type { %struct.ZSTD_window_t, i32, i32, i32, i32, ptr, [8 x i32], i64, i32, ptr, ptr, ptr, i32, i32, %struct.optState_t, ptr, %struct.ZSTD_compressionParameters, ptr, i32, i32 }
%struct.optState_t = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i32 }
%struct.ZSTD_inBuffer_s = type { ptr, i64, i64 }
%struct.ZSTD_localDict = type { ptr, ptr, i64, i32, ptr }
%struct.ZSTD_prefixDict_s = type { ptr, i64, i32 }
%struct.ZSTD_blockSplitCtx = type { %struct.seqStore_t, %struct.seqStore_t, %struct.seqStore_t, %struct.seqStore_t, %struct.seqStore_t, [196 x i32], %struct.ZSTD_entropyCTablesMetadata_t }
%struct.ZSTD_entropyCTablesMetadata_t = type { %struct.ZSTD_hufCTablesMetadata_t, %struct.ZSTD_fseCTablesMetadata_t }
%struct.ZSTD_hufCTablesMetadata_t = type { i32, [128 x i8], i64 }
%struct.ZSTD_fseCTablesMetadata_t = type { i32, i32, i32, [133 x i8], i64, i64 }

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @ZSTD_checkCParams(ptr noundef byval(%struct.ZSTD_compressionParameters) align 8) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_initCStream_advanced(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef byval(%struct.ZSTD_parameters) align 8 %3, i64 noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %4, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %17 = load i64, ptr %10, align 8, !tbaa !11
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %25

19:                                               ; preds = %5
  %20 = getelementptr inbounds %struct.ZSTD_parameters, ptr %3, i32 0, i32 1
  %21 = getelementptr inbounds %struct.ZSTD_frameParameters, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %19
  br label %27

25:                                               ; preds = %19, %5
  %26 = load i64, ptr %10, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %25, %24
  %28 = phi i64 [ -1, %24 ], [ %26, %25 ]
  store i64 %28, ptr %11, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %27
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = call i64 @ZSTD_CCtx_reset(ptr noundef %33, i32 noundef 1)
  store i64 %34, ptr %12, align 8, !tbaa !9
  %35 = load i64, ptr %12, align 8, !tbaa !9
  %36 = call i32 @ERR_isError(i64 noundef %35)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %52

38:                                               ; preds = %32
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %51, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %53

52:                                               ; preds = %32
  store i32 0, ptr %13, align 4
  br label %53

53:                                               ; preds = %52, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %54 = load i32, ptr %13, align 4
  switch i32 %54, label %141 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i64, ptr %11, align 8, !tbaa !9
  %61 = call i64 @ZSTD_CCtx_setPledgedSrcSize(ptr noundef %59, i64 noundef %60)
  store i64 %61, ptr %14, align 8, !tbaa !9
  %62 = load i64, ptr %14, align 8, !tbaa !9
  %63 = call i32 @ERR_isError(i64 noundef %62)
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %79

65:                                               ; preds = %58
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  %78 = load i64, ptr %14, align 8, !tbaa !9
  store i64 %78, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %80

79:                                               ; preds = %58
  store i32 0, ptr %13, align 4
  br label %80

80:                                               ; preds = %79, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  %81 = load i32, ptr %13, align 4
  switch i32 %81, label %141 [
    i32 0, label %82
  ]

82:                                               ; preds = %80
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %86 = getelementptr inbounds %struct.ZSTD_parameters, ptr %3, i32 0, i32 0
  %87 = call i64 @ZSTD_checkCParams(ptr noundef byval(%struct.ZSTD_compressionParameters) align 8 %86)
  store i64 %87, ptr %15, align 8, !tbaa !9
  %88 = load i64, ptr %15, align 8, !tbaa !9
  %89 = call i32 @ERR_isError(i64 noundef %88)
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %91, label %105

91:                                               ; preds = %85
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94
  br label %96

96:                                               ; preds = %95
  br label %97

97:                                               ; preds = %96
  br label %98

98:                                               ; preds = %97
  br label %99

99:                                               ; preds = %98
  br label %100

100:                                              ; preds = %99
  br label %101

101:                                              ; preds = %100
  br label %102

102:                                              ; preds = %101
  br label %103

103:                                              ; preds = %102
  %104 = load i64, ptr %15, align 8, !tbaa !9
  store i64 %104, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %106

105:                                              ; preds = %85
  store i32 0, ptr %13, align 4
  br label %106

106:                                              ; preds = %105, %103
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  %107 = load i32, ptr %13, align 4
  switch i32 %107, label %141 [
    i32 0, label %108
  ]

108:                                              ; preds = %106
  br label %109

109:                                              ; preds = %108
  br label %110

110:                                              ; preds = %109
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.ZSTD_CCtx_s, ptr %111, i32 0, i32 3
  call void @ZSTD_CCtxParams_setZstdParams(ptr noundef %112, ptr noundef %3)
  br label %113

113:                                              ; preds = %110
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  %114 = load ptr, ptr %7, align 8, !tbaa !5
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  %116 = load i64, ptr %9, align 8, !tbaa !9
  %117 = call i64 @ZSTD_CCtx_loadDictionary(ptr noundef %114, ptr noundef %115, i64 noundef %116)
  store i64 %117, ptr %16, align 8, !tbaa !9
  %118 = load i64, ptr %16, align 8, !tbaa !9
  %119 = call i32 @ERR_isError(i64 noundef %118)
  %120 = icmp ne i32 %119, 0
  br i1 %120, label %121, label %135

121:                                              ; preds = %113
  br label %122

122:                                              ; preds = %121
  br label %123

123:                                              ; preds = %122
  br label %124

124:                                              ; preds = %123
  br label %125

125:                                              ; preds = %124
  br label %126

126:                                              ; preds = %125
  br label %127

127:                                              ; preds = %126
  br label %128

128:                                              ; preds = %127
  br label %129

129:                                              ; preds = %128
  br label %130

130:                                              ; preds = %129
  br label %131

131:                                              ; preds = %130
  br label %132

132:                                              ; preds = %131
  br label %133

133:                                              ; preds = %132
  %134 = load i64, ptr %16, align 8, !tbaa !9
  store i64 %134, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %136

135:                                              ; preds = %113
  store i32 0, ptr %13, align 4
  br label %136

136:                                              ; preds = %135, %133
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  %137 = load i32, ptr %13, align 4
  switch i32 %137, label %141 [
    i32 0, label %138
  ]

138:                                              ; preds = %136
  br label %139

139:                                              ; preds = %138
  br label %140

140:                                              ; preds = %139
  store i64 0, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %141

141:                                              ; preds = %140, %136, %106, %80, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %142 = load i64, ptr %6, align 8
  ret i64 %142
}

; Function Attrs: nounwind uwtable
declare hidden void @ZSTD_CCtxParams_setZstdParams(ptr noundef, ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !16, i64 28}
!14 = !{!"", !15, i64 0, !17, i64 28}
!15 = !{!"", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12, !16, i64 16, !16, i64 20, !16, i64 24}
!16 = !{!"int", !7, i64 0}
!17 = !{!"", !16, i64 0, !16, i64 4, !16, i64 8}


; 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 }
%struct.ZSTD_parameters = type { %struct.ZSTD_compressionParameters, %struct.ZSTD_frameParameters }
%struct.ZSTD_frameParameters = type { i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @ZSTD_checkCParams(ptr noundef byval(%struct.ZSTD_compressionParameters) align 8) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_initCStream_advanced(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef byval(%struct.ZSTD_parameters) align 8 %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %3, i64 28
  %7 = load i32, ptr %6, align 4
  %8 = tail call i64 @ZSTD_CCtx_reset(ptr noundef %0, i32 noundef 1)
  %9 = tail call i32 @ERR_isError(i64 noundef %8)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %23

10:                                               ; preds = %5
  %11 = icmp eq i64 %4, 0
  %12 = icmp eq i32 %7, 0
  %or.cond = select i1 %11, i1 %12, i1 false
  %13 = select i1 %or.cond, i64 -1, i64 %4
  %14 = tail call i64 @ZSTD_CCtx_setPledgedSrcSize(ptr noundef %0, i64 noundef %13)
  %15 = tail call i32 @ERR_isError(i64 noundef %14)
  %.not31 = icmp eq i32 %15, 0
  br i1 %.not31, label %16, label %23

16:                                               ; preds = %10
  %17 = tail call i64 @ZSTD_checkCParams(ptr noundef nonnull byval(%struct.ZSTD_compressionParameters) align 8 %3)
  %18 = tail call i32 @ERR_isError(i64 noundef %17)
  %.not32 = icmp eq i32 %18, 0
  br i1 %.not32, label %19, label %23

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  call void @ZSTD_CCtxParams_setZstdParams(ptr noundef nonnull %20, ptr noundef nonnull %3)
  %21 = call i64 @ZSTD_CCtx_loadDictionary(ptr noundef %0, ptr noundef %1, i64 noundef %2)
  %22 = call i32 @ERR_isError(i64 noundef %21)
  %.not33 = icmp eq i32 %22, 0
  %spec.select = select i1 %.not33, i64 0, i64 %21
  br label %23

23:                                               ; preds = %19, %16, %10, %5
  %.4 = phi i64 [ %17, %16 ], [ %14, %10 ], [ %8, %5 ], [ %spec.select, %19 ]
  ret i64 %.4
}

; Function Attrs: nounwind uwtable
declare hidden void @ZSTD_CCtxParams_setZstdParams(ptr noundef, ptr 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" }

!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)"}


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