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

; 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: 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) #2

; 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_setCParams(ptr noundef, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8) #0

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

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

10:                                               ; preds = %2
  br label %11

11:                                               ; preds = %10
  br label %12

12:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %13 = getelementptr inbounds %struct.ZSTD_parameters, ptr %1, i32 0, i32 0
  %14 = call i64 @ZSTD_checkCParams(ptr noundef byval(%struct.ZSTD_compressionParameters) align 8 %13)
  store i64 %14, ptr %5, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = call i32 @ERR_isError(i64 noundef %15)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %32

18:                                               ; preds = %12
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %31, ptr %3, align 8
  store i32 1, ptr %6, align 4
  br label %33

32:                                               ; preds = %12
  store i32 0, ptr %6, align 4
  br label %33

33:                                               ; preds = %32, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %34 = load i32, ptr %6, align 4
  switch i32 %34, label %95 [
    i32 0, label %35
    i32 1, label %93
  ]

35:                                               ; preds = %33
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ZSTD_parameters, ptr %1, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %39, i64 12, i1 false)
  %40 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  %41 = load i64, ptr %40, align 4
  %42 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  %43 = load i32, ptr %42, align 4
  %44 = call i64 @ZSTD_CCtx_setFParams(ptr noundef %38, i64 %41, i32 %43)
  store i64 %44, ptr %7, align 8, !tbaa !9
  %45 = load i64, ptr %7, align 8, !tbaa !9
  %46 = call i32 @ERR_isError(i64 noundef %45)
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %62

48:                                               ; preds = %37
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  %61 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %61, ptr %3, align 8
  store i32 1, ptr %6, align 4
  br label %63

62:                                               ; preds = %37
  store i32 0, ptr %6, align 4
  br label %63

63:                                               ; preds = %62, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %64 = load i32, ptr %6, align 4
  switch i32 %64, label %95 [
    i32 0, label %65
    i32 1, label %93
  ]

65:                                               ; preds = %63
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.ZSTD_parameters, ptr %1, i32 0, i32 0
  %70 = call i64 @ZSTD_CCtx_setCParams(ptr noundef %68, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8 %69)
  store i64 %70, ptr %9, align 8, !tbaa !9
  %71 = load i64, ptr %9, align 8, !tbaa !9
  %72 = call i32 @ERR_isError(i64 noundef %71)
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %88

74:                                               ; preds = %67
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84
  br label %86

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

88:                                               ; preds = %67
  store i32 0, ptr %6, align 4
  br label %89

89:                                               ; preds = %88, %86
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %90 = load i32, ptr %6, align 4
  switch i32 %90, label %95 [
    i32 0, label %91
    i32 1, label %93
  ]

91:                                               ; preds = %89
  br label %92

92:                                               ; preds = %91
  store i64 0, ptr %3, align 8
  br label %93

93:                                               ; preds = %92, %89, %63, %33
  %94 = load i64, ptr %3, align 8
  ret i64 %94

95:                                               ; preds = %89, %63, %33
  unreachable
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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}


; 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_setCParams(ptr noundef, ptr noundef byval(%struct.ZSTD_compressionParameters) align 8) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @ZSTD_CCtx_setParams(ptr noundef %0, ptr noundef byval(%struct.ZSTD_parameters) align 8 %1) local_unnamed_addr #0 {
  %3 = tail call i64 @ZSTD_checkCParams(ptr noundef nonnull byval(%struct.ZSTD_compressionParameters) align 8 %1)
  %4 = tail call i32 @ERR_isError(i64 noundef %3)
  %.not.not = icmp eq i32 %4, 0
  br i1 %.not.not, label %5, label %12

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 28
  %.sroa.0.0.copyload = load i64, ptr %6, align 4
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 36
  %.sroa.2.0.copyload = load i32, ptr %.sroa.2.0..sroa_idx, align 4
  %7 = tail call i64 @ZSTD_CCtx_setFParams(ptr noundef %0, i64 %.sroa.0.0.copyload, i32 %.sroa.2.0.copyload)
  %8 = tail call i32 @ERR_isError(i64 noundef %7)
  %.not14.not = icmp eq i32 %8, 0
  br i1 %.not14.not, label %9, label %12

9:                                                ; preds = %5
  %10 = tail call i64 @ZSTD_CCtx_setCParams(ptr noundef %0, ptr noundef nonnull byval(%struct.ZSTD_compressionParameters) align 8 %1)
  %11 = tail call i32 @ERR_isError(i64 noundef %10)
  %.not15.not = icmp eq i32 %11, 0
  %spec.select = select i1 %.not15.not, i64 0, i64 %10
  br label %12

12:                                               ; preds = %9, %5, %2
  %.3 = phi i64 [ %3, %2 ], [ %7, %5 ], [ %spec.select, %9 ]
  ret i64 %.3
}

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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass