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

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN4sptk5world6makectEiPiPd(i32 noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = getelementptr inbounds i32, ptr %11, i64 1
  store i32 %10, ptr %12, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 1
  br i1 %14, label %15, label %68

15:                                               ; preds = %3
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = ashr i32 %16, 1
  store i32 %17, ptr %8, align 4, !tbaa !5
  %18 = call double @atan(double noundef 1.000000e+00) #3
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = sitofp i32 %19 to double
  %21 = fdiv double %18, %20
  store double %21, ptr %9, align 8, !tbaa !11
  %22 = load double, ptr %9, align 8, !tbaa !11
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sitofp i32 %23 to double
  %25 = fmul double %22, %24
  %26 = call double @cos(double noundef %25) #3
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds double, ptr %27, i64 0
  store double %26, ptr %28, align 8, !tbaa !11
  %29 = load ptr, ptr %6, align 8, !tbaa !9
  %30 = getelementptr inbounds double, ptr %29, i64 0
  %31 = load double, ptr %30, align 8, !tbaa !11
  %32 = fmul double 5.000000e-01, %31
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %33, i64 %35
  store double %32, ptr %36, align 8, !tbaa !11
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %64, %15
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %67

41:                                               ; preds = %37
  %42 = load double, ptr %9, align 8, !tbaa !11
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sitofp i32 %43 to double
  %45 = fmul double %42, %44
  %46 = call double @cos(double noundef %45) #3
  %47 = fmul double 5.000000e-01, %46
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %48, i64 %50
  store double %47, ptr %51, align 8, !tbaa !11
  %52 = load double, ptr %9, align 8, !tbaa !11
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = sitofp i32 %53 to double
  %55 = fmul double %52, %54
  %56 = call double @sin(double noundef %55) #3
  %57 = fmul double 5.000000e-01, %56
  %58 = load ptr, ptr %6, align 8, !tbaa !9
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = sub nsw i32 %59, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %58, i64 %62
  store double %57, ptr %63, align 8, !tbaa !11
  br label %64

64:                                               ; preds = %41
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %7, align 4, !tbaa !5
  br label %37, !llvm.loop !13

67:                                               ; preds = %37
  br label %68

68:                                               ; preds = %67, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; 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: nounwind
declare double @atan(double noundef) #2

; Function Attrs: nounwind
declare double @cos(double noundef) #2

; Function Attrs: nounwind
declare double @sin(double noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 nofree nounwind memory(write) uwtable
define dso_local void @_ZN4sptk5world6makectEiPiPd(i32 noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  %5 = icmp sgt i32 %0, 1
  br i1 %5, label %6, label %.loopexit

6:                                                ; preds = %3
  %7 = lshr i32 %0, 1
  %8 = uitofp nneg i32 %7 to double
  %9 = fdiv double 0x3FE921FB54442D18, %8
  %10 = fmul double %9, %8
  %11 = tail call double @cos(double noundef %10) #2
  store double %11, ptr %2, align 8, !tbaa !9
  %12 = fmul double %11, 5.000000e-01
  %13 = zext nneg i32 %7 to i64
  %14 = getelementptr inbounds double, ptr %2, i64 %13
  store double %12, ptr %14, align 8, !tbaa !9
  %15 = icmp ugt i32 %0, 3
  br i1 %15, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %6
  %16 = zext nneg i32 %0 to i64
  %17 = add nsw i64 %13, -1
  %xtraiter = and i64 %17, 1
  %18 = icmp eq i32 %7, 2
  br i1 %18, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %17, -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  %20 = uitofp nneg i32 %19 to double
  %21 = fmul double %9, %20
  %22 = tail call double @cos(double noundef %21) #2
  %23 = fmul double %22, 5.000000e-01
  %24 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  store double %23, ptr %24, align 8, !tbaa !9
  %25 = tail call double @sin(double noundef %21) #2
  %26 = fmul double %25, 5.000000e-01
  %27 = sub nsw i64 %16, %indvars.iv
  %28 = getelementptr inbounds double, ptr %2, i64 %27
  store double %26, ptr %28, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = trunc nuw nsw i64 %indvars.iv.next to i32
  %30 = uitofp nneg i32 %29 to double
  %31 = fmul double %9, %30
  %32 = tail call double @cos(double noundef %31) #2
  %33 = fmul double %32, 5.000000e-01
  %34 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next
  store double %33, ptr %34, align 8, !tbaa !9
  %35 = tail call double @sin(double noundef %31) #2
  %36 = fmul double %35, 5.000000e-01
  %37 = sub nsw i64 %16, %indvars.iv.next
  %38 = getelementptr inbounds double, ptr %2, i64 %37
  store double %36, ptr %38, align 8, !tbaa !9
  %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 %.lr.ph, !llvm.loop !11

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

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa
  %39 = trunc nuw nsw i64 %indvars.iv.unr to i32
  %40 = uitofp nneg i32 %39 to double
  %41 = fmul double %9, %40
  %42 = tail call double @cos(double noundef %41) #2
  %43 = fmul double %42, 5.000000e-01
  %44 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.unr
  store double %43, ptr %44, align 8, !tbaa !9
  %45 = tail call double @sin(double noundef %41) #2
  %46 = fmul double %45, 5.000000e-01
  %47 = sub nsw i64 %16, %indvars.iv.unr
  %48 = getelementptr inbounds double, ptr %2, i64 %47
  store double %46, ptr %48, align 8, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.epil, %.loopexit.loopexit.unr-lcssa, %6, %3
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind memory(write) 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 = { mustprogress nofree nounwind willreturn memory(write) "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 = !{!"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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass