; LLVM IR from jgaeddert/liquid-dsp :: src/fft/src (spgramcf)

; 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.asgramcf_s = type { i32, i32, i32, ptr, ptr, ptr, [10 x float], [10 x i8], i32, float, float }

@.str = external hidden unnamed_addr constant [81 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [52 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @asgramcf_set_scale(ptr noundef %0, float noundef %1, float noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  %9 = load float, ptr %7, align 4, !tbaa !9
  %10 = fcmp ole float %9, 0.000000e+00
  br i1 %10, label %11, label %13

11:                                               ; preds = %3
  %12 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str, i32 noundef 137, ptr noundef @.str.5, ptr noundef @.str.2)
  store i32 %12, ptr %4, align 4
  br label %45

13:                                               ; preds = %3
  %14 = load float, ptr %6, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.asgramcf_s, ptr %15, i32 0, i32 10
  store float %14, ptr %16, align 4, !tbaa !11
  %17 = load float, ptr %7, align 4, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.asgramcf_s, ptr %18, i32 0, i32 9
  store float %17, ptr %19, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %20

20:                                               ; preds = %41, %13
  %21 = load i32, ptr %8, align 4, !tbaa !15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.asgramcf_s, ptr %22, i32 0, i32 8
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = icmp ult i32 %21, %24
  br i1 %25, label %26, label %44

26:                                               ; preds = %20
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.asgramcf_s, ptr %27, i32 0, i32 10
  %29 = load float, ptr %28, align 4, !tbaa !11
  %30 = load i32, ptr %8, align 4, !tbaa !15
  %31 = uitofp i32 %30 to float
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.asgramcf_s, ptr %32, i32 0, i32 9
  %34 = load float, ptr %33, align 8, !tbaa !14
  %35 = call float @llvm.fmuladd.f32(float %31, float %34, float %29)
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.asgramcf_s, ptr %36, i32 0, i32 6
  %38 = load i32, ptr %8, align 4, !tbaa !15
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds [10 x float], ptr %37, i64 0, i64 %39
  store float %35, ptr %40, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %26
  %42 = load i32, ptr %8, align 4, !tbaa !15
  %43 = add i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !15
  br label %20, !llvm.loop !17

44:                                               ; preds = %20
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %45

45:                                               ; preds = %44, %11
  %46 = load i32, ptr %4, align 4
  ret i32 %46
}

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

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !10, i64 100}
!12 = !{!"asgramcf_s", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !7, i64 80, !13, i64 92, !10, i64 96, !10, i64 100}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 96}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !13, i64 92}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@.str = external hidden unnamed_addr constant [81 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @asgramcf_set_scale(ptr nocapture noundef %0, float noundef %1, float noundef %2) local_unnamed_addr #0 {
  %4 = fcmp ugt float %2, 0.000000e+00
  br i1 %4, label %7, label %5

5:                                                ; preds = %3
  %6 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str, i32 noundef 137, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.2) #3
  br label %.loopexit

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 100
  store float %1, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 96
  store float %2, ptr %9, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %0, i64 92
  %11 = load i32, ptr %10, align 4, !tbaa !13
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %wide.trip.count = zext i32 %11 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %13 = icmp eq i32 %11, 1
  br i1 %13, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %14

14:                                               ; preds = %14, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %14 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %14 ]
  %15 = load float, ptr %8, align 4, !tbaa !5
  %16 = trunc nuw i64 %indvars.iv to i32
  %17 = uitofp i32 %16 to float
  %18 = load float, ptr %9, align 8, !tbaa !12
  %19 = tail call float @llvm.fmuladd.f32(float %17, float %18, float %15)
  %20 = getelementptr inbounds [10 x float], ptr %12, i64 0, i64 %indvars.iv
  store float %19, ptr %20, align 4, !tbaa !14
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %21 = load float, ptr %8, align 4, !tbaa !5
  %22 = trunc nuw i64 %indvars.iv.next to i32
  %23 = uitofp i32 %22 to float
  %24 = load float, ptr %9, align 8, !tbaa !12
  %25 = tail call float @llvm.fmuladd.f32(float %23, float %24, float %21)
  %26 = getelementptr inbounds [10 x float], ptr %12, i64 0, i64 %indvars.iv.next
  store float %25, ptr %26, align 4, !tbaa !14
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %14, !llvm.loop !15

.loopexit.loopexit.unr-lcssa:                     ; preds = %14, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %14 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %27 = load float, ptr %8, align 4, !tbaa !5
  %28 = trunc nuw i64 %indvars.iv.unr to i32
  %29 = uitofp i32 %28 to float
  %30 = load float, ptr %9, align 8, !tbaa !12
  %31 = tail call float @llvm.fmuladd.f32(float %29, float %30, float %27)
  %32 = getelementptr inbounds [10 x float], ptr %12, i64 0, i64 %indvars.iv.unr
  store float %31, ptr %32, align 4, !tbaa !14
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %7, %5
  %.013 = phi i32 [ %6, %5 ], [ 0, %7 ], [ 0, %.loopexit.loopexit.unr-lcssa ], [ 0, %.loopexit.loopexit.epilog-lcssa ]
  ret i32 %.013
}

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

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 = { "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 100}
!6 = !{!"asgramcf_s", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !8, i64 40, !8, i64 80, !7, i64 92, !11, i64 96, !11, i64 100}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !11, i64 96}
!13 = !{!6, !7, i64 92}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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