; LLVM IR from jgaeddert/liquid-dsp :: src/audio/src (cvsd)

; 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.cvsd_s = type { i32, i8, i8, float, float, float, float, float, float, float, 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
define dso_local zeroext i8 @cvsd_encode(ptr noundef %0, float noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.cvsd_s, ptr %7, i32 0, i32 10
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = load float, ptr %4, align 4, !tbaa !9
  %11 = call i32 @iirfilt_rrrf_execute(ptr noundef %9, float noundef %10, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.cvsd_s, ptr %12, i32 0, i32 3
  %14 = load float, ptr %13, align 8, !tbaa !14
  %15 = load float, ptr %5, align 4, !tbaa !9
  %16 = fcmp ogt float %14, %15
  %17 = zext i1 %16 to i64
  %18 = select i1 %16, i32 0, i32 1
  %19 = trunc i32 %18 to i8
  store i8 %19, ptr %6, align 1, !tbaa !15
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.cvsd_s, ptr %20, i32 0, i32 1
  %22 = load i8, ptr %21, align 4, !tbaa !16
  %23 = zext i8 %22 to i32
  %24 = shl i32 %23, 1
  %25 = trunc i32 %24 to i8
  store i8 %25, ptr %21, align 4, !tbaa !16
  %26 = load i8, ptr %6, align 1, !tbaa !15
  %27 = zext i8 %26 to i32
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.cvsd_s, ptr %28, i32 0, i32 1
  %30 = load i8, ptr %29, align 4, !tbaa !16
  %31 = zext i8 %30 to i32
  %32 = or i32 %31, %27
  %33 = trunc i32 %32 to i8
  store i8 %33, ptr %29, align 4, !tbaa !16
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.cvsd_s, ptr %34, i32 0, i32 2
  %36 = load i8, ptr %35, align 1, !tbaa !17
  %37 = zext i8 %36 to i32
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.cvsd_s, ptr %38, i32 0, i32 1
  %40 = load i8, ptr %39, align 4, !tbaa !16
  %41 = zext i8 %40 to i32
  %42 = and i32 %41, %37
  %43 = trunc i32 %42 to i8
  store i8 %43, ptr %39, align 4, !tbaa !16
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.cvsd_s, ptr %44, i32 0, i32 1
  %46 = load i8, ptr %45, align 4, !tbaa !16
  %47 = zext i8 %46 to i32
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %59, label %49

49:                                               ; preds = %2
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.cvsd_s, ptr %50, i32 0, i32 1
  %52 = load i8, ptr %51, align 4, !tbaa !16
  %53 = zext i8 %52 to i32
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.cvsd_s, ptr %54, i32 0, i32 2
  %56 = load i8, ptr %55, align 1, !tbaa !17
  %57 = zext i8 %56 to i32
  %58 = icmp eq i32 %53, %57
  br i1 %58, label %59, label %67

59:                                               ; preds = %49, %2
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.cvsd_s, ptr %60, i32 0, i32 4
  %62 = load float, ptr %61, align 4, !tbaa !18
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.cvsd_s, ptr %63, i32 0, i32 5
  %65 = load float, ptr %64, align 8, !tbaa !19
  %66 = fmul float %65, %62
  store float %66, ptr %64, align 8, !tbaa !19
  br label %75

67:                                               ; preds = %49
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.cvsd_s, ptr %68, i32 0, i32 4
  %70 = load float, ptr %69, align 4, !tbaa !18
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.cvsd_s, ptr %71, i32 0, i32 5
  %73 = load float, ptr %72, align 8, !tbaa !19
  %74 = fdiv float %73, %70
  store float %74, ptr %72, align 8, !tbaa !19
  br label %75

75:                                               ; preds = %67, %59
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.cvsd_s, ptr %76, i32 0, i32 5
  %78 = load float, ptr %77, align 8, !tbaa !19
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.cvsd_s, ptr %79, i32 0, i32 7
  %81 = load float, ptr %80, align 8, !tbaa !20
  %82 = fcmp ogt float %78, %81
  br i1 %82, label %83, label %87

83:                                               ; preds = %75
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.cvsd_s, ptr %84, i32 0, i32 7
  %86 = load float, ptr %85, align 8, !tbaa !20
  br label %91

87:                                               ; preds = %75
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.cvsd_s, ptr %88, i32 0, i32 5
  %90 = load float, ptr %89, align 8, !tbaa !19
  br label %91

91:                                               ; preds = %87, %83
  %92 = phi float [ %86, %83 ], [ %90, %87 ]
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.cvsd_s, ptr %93, i32 0, i32 5
  store float %92, ptr %94, align 8, !tbaa !19
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.cvsd_s, ptr %95, i32 0, i32 5
  %97 = load float, ptr %96, align 8, !tbaa !19
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.cvsd_s, ptr %98, i32 0, i32 6
  %100 = load float, ptr %99, align 4, !tbaa !21
  %101 = fcmp olt float %97, %100
  br i1 %101, label %102, label %106

102:                                              ; preds = %91
  %103 = load ptr, ptr %3, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.cvsd_s, ptr %103, i32 0, i32 6
  %105 = load float, ptr %104, align 4, !tbaa !21
  br label %110

106:                                              ; preds = %91
  %107 = load ptr, ptr %3, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.cvsd_s, ptr %107, i32 0, i32 5
  %109 = load float, ptr %108, align 8, !tbaa !19
  br label %110

110:                                              ; preds = %106, %102
  %111 = phi float [ %105, %102 ], [ %109, %106 ]
  %112 = load ptr, ptr %3, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.cvsd_s, ptr %112, i32 0, i32 5
  store float %111, ptr %113, align 8, !tbaa !19
  %114 = load i8, ptr %6, align 1, !tbaa !15
  %115 = zext i8 %114 to i32
  %116 = icmp ne i32 %115, 0
  br i1 %116, label %117, label %121

117:                                              ; preds = %110
  %118 = load ptr, ptr %3, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.cvsd_s, ptr %118, i32 0, i32 5
  %120 = load float, ptr %119, align 8, !tbaa !19
  br label %126

121:                                              ; preds = %110
  %122 = load ptr, ptr %3, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct.cvsd_s, ptr %122, i32 0, i32 5
  %124 = load float, ptr %123, align 8, !tbaa !19
  %125 = fneg float %124
  br label %126

126:                                              ; preds = %121, %117
  %127 = phi float [ %120, %117 ], [ %125, %121 ]
  %128 = load ptr, ptr %3, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.cvsd_s, ptr %128, i32 0, i32 3
  %130 = load float, ptr %129, align 8, !tbaa !14
  %131 = fadd float %130, %127
  store float %131, ptr %129, align 8, !tbaa !14
  %132 = load ptr, ptr %3, align 8, !tbaa !5
  %133 = getelementptr inbounds %struct.cvsd_s, ptr %132, i32 0, i32 3
  %134 = load float, ptr %133, align 8, !tbaa !14
  %135 = fcmp ogt float %134, 1.000000e+00
  br i1 %135, label %136, label %137

136:                                              ; preds = %126
  br label %141

137:                                              ; preds = %126
  %138 = load ptr, ptr %3, align 8, !tbaa !5
  %139 = getelementptr inbounds %struct.cvsd_s, ptr %138, i32 0, i32 3
  %140 = load float, ptr %139, align 8, !tbaa !14
  br label %141

141:                                              ; preds = %137, %136
  %142 = phi float [ 1.000000e+00, %136 ], [ %140, %137 ]
  %143 = load ptr, ptr %3, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.cvsd_s, ptr %143, i32 0, i32 3
  store float %142, ptr %144, align 8, !tbaa !14
  %145 = load ptr, ptr %3, align 8, !tbaa !5
  %146 = getelementptr inbounds %struct.cvsd_s, ptr %145, i32 0, i32 3
  %147 = load float, ptr %146, align 8, !tbaa !14
  %148 = fcmp olt float %147, -1.000000e+00
  br i1 %148, label %149, label %150

149:                                              ; preds = %141
  br label %154

150:                                              ; preds = %141
  %151 = load ptr, ptr %3, align 8, !tbaa !5
  %152 = getelementptr inbounds %struct.cvsd_s, ptr %151, i32 0, i32 3
  %153 = load float, ptr %152, align 8, !tbaa !14
  br label %154

154:                                              ; preds = %150, %149
  %155 = phi float [ -1.000000e+00, %149 ], [ %153, %150 ]
  %156 = load ptr, ptr %3, align 8, !tbaa !5
  %157 = getelementptr inbounds %struct.cvsd_s, ptr %156, i32 0, i32 3
  store float %155, ptr %157, align 8, !tbaa !14
  %158 = load i8, ptr %6, align 1, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i8 %158
}

declare i32 @iirfilt_rrrf_execute(ptr noundef, float noundef, ptr noundef) #2

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 = { "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 = !{!"float", !7, i64 0}
!11 = !{!12, !6, i64 40}
!12 = !{!"cvsd_s", !13, i64 0, !7, i64 4, !7, i64 5, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !7, i64 4}
!17 = !{!12, !7, i64 5}
!18 = !{!12, !10, i64 12}
!19 = !{!12, !10, i64 16}
!20 = !{!12, !10, i64 24}
!21 = !{!12, !10, i64 20}


; 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: 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
define dso_local zeroext range(i8 0, 2) i8 @cvsd_encode(ptr nocapture noundef %0, float noundef %1) local_unnamed_addr #1 {
  %3 = alloca float, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = call i32 @iirfilt_rrrf_execute(ptr noundef %5, float noundef %1, ptr noundef nonnull %3) #3
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load float, ptr %7, align 8, !tbaa !12
  %9 = load float, ptr %3, align 4, !tbaa !13
  %10 = fcmp ule float %8, %9
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = load i8, ptr %11, align 4, !tbaa !14
  %13 = shl i8 %12, 1
  %14 = zext i1 %10 to i8
  %15 = or disjoint i8 %13, %14
  %16 = getelementptr inbounds i8, ptr %0, i64 5
  %17 = load i8, ptr %16, align 1, !tbaa !15
  %18 = and i8 %15, %17
  store i8 %18, ptr %11, align 4, !tbaa !14
  %19 = icmp eq i8 %18, 0
  %20 = icmp eq i8 %18, %17
  %or.cond = or i1 %19, %20
  %21 = getelementptr inbounds i8, ptr %0, i64 12
  %22 = load float, ptr %21, align 4, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load float, ptr %23, align 8, !tbaa !17
  %25 = fdiv float %24, %22
  %26 = fmul float %22, %24
  %27 = select i1 %or.cond, float %26, float %25
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  %29 = getelementptr inbounds i8, ptr %0, i64 24
  %30 = load float, ptr %29, align 8, !tbaa !18
  %31 = fcmp ogt float %27, %30
  %. = select i1 %31, float %30, float %27
  %32 = getelementptr inbounds i8, ptr %0, i64 20
  %33 = load float, ptr %32, align 4, !tbaa !19
  %34 = fcmp olt float %., %33
  %35 = select i1 %34, float %33, float %.
  store float %35, ptr %28, align 8, !tbaa !17
  %36 = fneg float %35
  %37 = select i1 %10, float %35, float %36
  %38 = fadd float %8, %37
  %39 = fcmp ogt float %38, 1.000000e+00
  %40 = select i1 %39, float 1.000000e+00, float %38
  %41 = fcmp olt float %40, -1.000000e+00
  %42 = select i1 %41, float -1.000000e+00, float %40
  store float %42, ptr %7, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i8 %14
}

declare i32 @iirfilt_rrrf_execute(ptr noundef, float noundef, ptr noundef) local_unnamed_addr #2

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 = { "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, !11, i64 40}
!6 = !{!"cvsd_s", !7, i64 0, !8, i64 4, !8, i64 5, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !11, i64 40, !11, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !8, i64 4}
!15 = !{!6, !8, i64 5}
!16 = !{!6, !10, i64 12}
!17 = !{!6, !10, i64 16}
!18 = !{!6, !10, i64 24}
!19 = !{!6, !10, i64 20}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass