; LLVM IR from EntityFX/anybench :: src/benchmarks/generic/scimark2 (FFT)

; 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: nounwind uwtable
define dso_local void @FFT_bitreverse(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sdiv i32 %14, 2
  store i32 %15, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sub nsw i32 %16, 1
  store i32 %17, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %90, %2
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %93

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = shl i32 %23, 1
  store i32 %24, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = shl i32 %25, 1
  store i32 %26, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = ashr i32 %27, 1
  store i32 %28, ptr %11, align 4, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %75

32:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = load i32, ptr %9, 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
  store double %37, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %38 = load ptr, ptr %4, align 8, !tbaa !9
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %38, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !11
  store double %43, ptr %13, align 8, !tbaa !11
  %44 = load ptr, ptr %4, align 8, !tbaa !9
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %4, align 8, !tbaa !9
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds double, ptr %49, i64 %51
  store double %48, ptr %52, align 8, !tbaa !11
  %53 = load ptr, ptr %4, align 8, !tbaa !9
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %53, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !11
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %59, i64 %62
  store double %58, ptr %63, align 8, !tbaa !11
  %64 = load double, ptr %12, align 8, !tbaa !11
  %65 = load ptr, ptr %4, align 8, !tbaa !9
  %66 = load i32, ptr %10, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %65, i64 %67
  store double %64, ptr %68, align 8, !tbaa !11
  %69 = load double, ptr %13, align 8, !tbaa !11
  %70 = load ptr, ptr %4, align 8, !tbaa !9
  %71 = load i32, ptr %10, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds double, ptr %70, i64 %73
  store double %69, ptr %74, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %75

75:                                               ; preds = %32, %22
  br label %76

76:                                               ; preds = %80, %75
  %77 = load i32, ptr %11, align 4, !tbaa !5
  %78 = load i32, ptr %8, align 4, !tbaa !5
  %79 = icmp sle i32 %77, %78
  br i1 %79, label %80, label %86

80:                                               ; preds = %76
  %81 = load i32, ptr %11, align 4, !tbaa !5
  %82 = load i32, ptr %8, align 4, !tbaa !5
  %83 = sub nsw i32 %82, %81
  store i32 %83, ptr %8, align 4, !tbaa !5
  %84 = load i32, ptr %11, align 4, !tbaa !5
  %85 = ashr i32 %84, 1
  store i32 %85, ptr %11, align 4, !tbaa !5
  br label %76, !llvm.loop !13

86:                                               ; preds = %76
  %87 = load i32, ptr %11, align 4, !tbaa !5
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = add nsw i32 %88, %87
  store i32 %89, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %90

90:                                               ; preds = %86
  %91 = load i32, ptr %7, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %7, align 4, !tbaa !5
  br label %18, !llvm.loop !15

93:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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 = { 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/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"}
!15 = distinct !{!15, !14}


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @FFT_bitreverse(i32 noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = sdiv i32 %0, 2
  %4 = icmp sgt i32 %0, 3
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %5 = tail call i32 @llvm.smax.i32(i32 %3, i32 2)
  %smax = add nsw i32 %5, -1
  %wide.trip.count = zext nneg i32 %smax to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %24 ]
  %.03436 = phi i32 [ 0, %.lr.ph.preheader ], [ %25, %24 ]
  %6 = sext i32 %.03436 to i64
  %7 = icmp slt i64 %indvars.iv, %6
  br i1 %7, label %8, label %.preheader

8:                                                ; preds = %.lr.ph
  %9 = shl i32 %.03436, 1
  %10 = shl nuw i64 %indvars.iv, 1
  %11 = getelementptr inbounds double, ptr %1, i64 %10
  %12 = or disjoint i64 %10, 1
  %13 = getelementptr inbounds double, ptr %1, i64 %12
  %14 = sext i32 %9 to i64
  %15 = getelementptr inbounds double, ptr %1, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !5
  %17 = or disjoint i32 %9, 1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds double, ptr %1, i64 %18
  %20 = load <2 x double>, ptr %11, align 8, !tbaa !5
  store double %16, ptr %11, align 8, !tbaa !5
  %21 = load double, ptr %19, align 8, !tbaa !5
  store double %21, ptr %13, align 8, !tbaa !5
  store <2 x double> %20, ptr %15, align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %8, %.lr.ph
  br label %22

22:                                               ; preds = %.preheader, %22
  %.035.in = phi i32 [ %.035, %22 ], [ %3, %.preheader ]
  %.1 = phi i32 [ %23, %22 ], [ %.03436, %.preheader ]
  %.035 = lshr i32 %.035.in, 1
  %.not = icmp sgt i32 %.035, %.1
  %23 = sub nsw i32 %.1, %.035
  br i1 %.not, label %24, label %22, !llvm.loop !9

24:                                               ; preds = %22
  %25 = add nsw i32 %.1, %.035
  %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 !11

._crit_edge:                                      ; preds = %24, %2
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

attributes #0 = { 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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass