; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/ay/sndrender.ll (Z9init_diffv)

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

@_ZL11filter_diff = external hidden global [128 x i32], align 16
@_ZL12filter_coeff = external hidden constant [128 x double], align 16

; 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: mustprogress nounwind uwtable
define dso_local void @_Z9init_diffv() #1 {
  %1 = alloca double, align 8
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  store double 0.000000e+00, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %3

3:                                                ; preds = %20, %0
  %4 = load i32, ptr %2, align 4, !tbaa !9
  %5 = icmp ult i32 %4, 128
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %23

7:                                                ; preds = %3
  %8 = load double, ptr %1, align 8, !tbaa !5
  %9 = fmul double %8, 6.553600e+04
  %10 = fptosi double %9 to i32
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [128 x i32], ptr @_ZL11filter_diff, i64 0, i64 %12
  store i32 %10, ptr %13, align 4, !tbaa !9
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [128 x double], ptr @_ZL12filter_coeff, i64 0, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = load double, ptr %1, align 8, !tbaa !5
  %19 = fadd double %18, %17
  store double %19, ptr %1, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %7
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %2, align 4, !tbaa !9
  br label %3, !llvm.loop !11

23:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@_ZL11filter_diff = external hidden local_unnamed_addr global [128 x i32], align 16
@_ZL12filter_coeff = external hidden local_unnamed_addr constant [128 x double], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z9init_diffv() local_unnamed_addr #0 {
  br label %2

1:                                                ; preds = %2
  ret void

2:                                                ; preds = %2, %0
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next.1, %2 ]
  %.056 = phi double [ 0.000000e+00, %0 ], [ %14, %2 ]
  %3 = fmul double %.056, 6.553600e+04
  %4 = fptosi double %3 to i32
  %5 = getelementptr inbounds [128 x i32], ptr @_ZL11filter_diff, i64 0, i64 %indvars.iv
  store i32 %4, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds [128 x double], ptr @_ZL12filter_coeff, i64 0, i64 %indvars.iv
  %7 = load double, ptr %6, align 16, !tbaa !9
  %8 = fadd double %.056, %7
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %9 = fmul double %8, 6.553600e+04
  %10 = fptosi double %9 to i32
  %11 = getelementptr inbounds [128 x i32], ptr @_ZL11filter_diff, i64 0, i64 %indvars.iv.next
  store i32 %10, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds [128 x double], ptr @_ZL12filter_coeff, i64 0, i64 %indvars.iv.next
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = fadd double %8, %13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 128
  br i1 %exitcond.not.1, label %1, label %2, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass