; LLVM IR from sp-nitech/SPTK :: third_party/WORLD/fft_world.ll (ZN4sptk5world6dctsubEiPdiS1_)

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

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4sptk5world6dctsubEiPdiS1_(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = ashr i32 %17, 1
  store i32 %18, ptr %13, align 4, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sdiv i32 %19, %20
  store i32 %21, ptr %12, align 4, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !5
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %97, %4
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = load i32, ptr %13, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %26, label %100

26:                                               ; preds = %22
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = sub nsw i32 %27, %28
  store i32 %29, ptr %10, align 4, !tbaa !5
  %30 = load i32, ptr %12, align 4, !tbaa !5
  %31 = load i32, ptr %11, align 4, !tbaa !5
  %32 = add nsw i32 %31, %30
  store i32 %32, ptr %11, align 4, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %33, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = load ptr, ptr %8, align 8, !tbaa !9
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = sub nsw i32 %39, %40
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %38, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = fsub double %37, %44
  store double %45, ptr %14, align 8, !tbaa !11
  %46 = load ptr, ptr %8, align 8, !tbaa !9
  %47 = load i32, ptr %11, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %46, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = load i32, ptr %11, align 4, !tbaa !5
  %54 = sub nsw i32 %52, %53
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds double, ptr %51, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !11
  %58 = fadd double %50, %57
  store double %58, ptr %15, align 8, !tbaa !11
  %59 = load double, ptr %15, align 8, !tbaa !11
  %60 = load ptr, ptr %6, align 8, !tbaa !9
  %61 = load i32, ptr %9, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %60, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !11
  %65 = load double, ptr %14, align 8, !tbaa !11
  %66 = load ptr, ptr %6, align 8, !tbaa !9
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds double, ptr %66, i64 %68
  %70 = load double, ptr %69, align 8, !tbaa !11
  %71 = fmul double %65, %70
  %72 = fneg double %71
  %73 = call double @llvm.fmuladd.f64(double %59, double %64, double %72)
  store double %73, ptr %16, align 8, !tbaa !11
  %74 = load double, ptr %14, align 8, !tbaa !11
  %75 = load ptr, ptr %6, align 8, !tbaa !9
  %76 = load i32, ptr %9, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds double, ptr %75, i64 %77
  %79 = load double, ptr %78, align 8, !tbaa !11
  %80 = load double, ptr %15, align 8, !tbaa !11
  %81 = load ptr, ptr %6, align 8, !tbaa !9
  %82 = load i32, ptr %10, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds double, ptr %81, i64 %83
  %85 = load double, ptr %84, align 8, !tbaa !11
  %86 = fmul double %80, %85
  %87 = call double @llvm.fmuladd.f64(double %74, double %79, double %86)
  %88 = load ptr, ptr %6, align 8, !tbaa !9
  %89 = load i32, ptr %9, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds double, ptr %88, i64 %90
  store double %87, ptr %91, align 8, !tbaa !11
  %92 = load double, ptr %16, align 8, !tbaa !11
  %93 = load ptr, ptr %6, align 8, !tbaa !9
  %94 = load i32, ptr %10, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds double, ptr %93, i64 %95
  store double %92, ptr %96, align 8, !tbaa !11
  br label %97

97:                                               ; preds = %26
  %98 = load i32, ptr %9, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %9, align 4, !tbaa !5
  br label %22, !llvm.loop !13

100:                                              ; preds = %22
  %101 = load ptr, ptr %8, align 8, !tbaa !9
  %102 = getelementptr inbounds double, ptr %101, i64 0
  %103 = load double, ptr %102, align 8, !tbaa !11
  %104 = load ptr, ptr %6, align 8, !tbaa !9
  %105 = load i32, ptr %13, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds double, ptr %104, i64 %106
  %108 = load double, ptr %107, align 8, !tbaa !11
  %109 = fmul double %108, %103
  store double %109, ptr %107, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN4sptk5world6dctsubEiPdiS1_(i32 noundef %0, ptr nocapture noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #1 {
  %5 = ashr i32 %0, 1
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %7 = sdiv i32 %2, %0
  %8 = zext nneg i32 %0 to i64
  %9 = sext i32 %7 to i64
  %10 = sext i32 %2 to i64
  %wide.trip.count = zext nneg i32 %5 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv43 = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next44, %.lr.ph ]
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %11 = sub nsw i64 %8, %indvars.iv
  %indvars.iv.next44 = add nsw i64 %indvars.iv43, %9
  %12 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next44
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = sub nsw i64 %10, %indvars.iv.next44
  %15 = getelementptr inbounds double, ptr %3, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !5
  %17 = fsub double %13, %16
  %18 = fadd double %13, %16
  %19 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds double, ptr %1, i64 %11
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = fneg double %17
  %24 = fmul double %22, %23
  %25 = tail call double @llvm.fmuladd.f64(double %18, double %20, double %24)
  %26 = fmul double %18, %22
  %27 = tail call double @llvm.fmuladd.f64(double %17, double %20, double %26)
  store double %27, ptr %19, align 8, !tbaa !5
  store double %25, ptr %21, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %4
  %28 = load double, ptr %3, align 8, !tbaa !5
  %29 = sext i32 %5 to i64
  %30 = getelementptr inbounds double, ptr %1, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = fmul double %28, %31
  store double %32, ptr %30, align 8, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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