; LLVM IR from abeaumont/competitive-programming :: kattis/polymul2.ll (ZN7algebra3fft4initEv)

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

%"class.std::complex" = type { { double, double } }

@_ZN7algebra3fft1wE = external dso_local global [262144 x %"class.std::complex"], align 16
@_ZN7algebra3fftL2piE = external hidden global double, align 8
@_ZN7algebra3fft9initiatedE = external dso_local global i8, align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7algebra3fft4initEv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca %"class.std::complex", align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = load i8, ptr @_ZN7algebra3fft9initiatedE, align 1, !tbaa !5, !range !9, !noundef !10
  %8 = trunc i8 %7 to i1
  br i1 %8, label %47, label %9

9:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 1, ptr %1, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %43, %9
  %11 = load i32, ptr %1, align 4, !tbaa !11
  %12 = icmp slt i32 %11, 262144
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %46

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %39, %14
  %16 = load i32, ptr %3, align 4, !tbaa !11
  %17 = load i32, ptr %1, align 4, !tbaa !11
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %42

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store double 1.000000e+00, ptr %5, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %21 = load double, ptr @_ZN7algebra3fftL2piE, align 8, !tbaa !13
  %22 = load i32, ptr %3, align 4, !tbaa !11
  %23 = sitofp i32 %22 to double
  %24 = fmul double %21, %23
  %25 = load i32, ptr %1, align 4, !tbaa !11
  %26 = sitofp i32 %25 to double
  %27 = fdiv double %24, %26
  store double %27, ptr %6, align 8, !tbaa !13
  %28 = call { double, double } @_ZSt5polarIdESt7complexIT_ERKS1_S4_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %29 = getelementptr inbounds %"class.std::complex", ptr %4, i32 0, i32 0
  %30 = getelementptr inbounds { double, double }, ptr %29, i32 0, i32 0
  %31 = extractvalue { double, double } %28, 0
  store double %31, ptr %30, align 8
  %32 = getelementptr inbounds { double, double }, ptr %29, i32 0, i32 1
  %33 = extractvalue { double, double } %28, 1
  store double %33, ptr %32, align 8
  %34 = load i32, ptr %1, align 4, !tbaa !11
  %35 = load i32, ptr %3, align 4, !tbaa !11
  %36 = add nsw i32 %34, %35
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [262144 x %"class.std::complex"], ptr @_ZN7algebra3fft1wE, i64 0, i64 %37
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %38, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #4
  br label %39

39:                                               ; preds = %20
  %40 = load i32, ptr %3, align 4, !tbaa !11
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %3, align 4, !tbaa !11
  br label %15, !llvm.loop !17

42:                                               ; preds = %19
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %1, align 4, !tbaa !11
  %45 = mul nsw i32 %44, 2
  store i32 %45, ptr %1, align 4, !tbaa !11
  br label %10, !llvm.loop !19

46:                                               ; preds = %13
  store i8 1, ptr @_ZN7algebra3fft9initiatedE, align 1, !tbaa !5
  br label %47

47:                                               ; preds = %46, %0
  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: inlinehint mustprogress uwtable
declare dso_local { double, double } @_ZSt5polarIdESt7complexIT_ERKS1_S4_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{i64 0, i64 16, !16}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

%"class.std::complex" = type { { double, double } }

@_ZN7algebra3fft1wE = external dso_local local_unnamed_addr global [262144 x %"class.std::complex"], align 16
@_ZN7algebra3fftL2piE = external hidden local_unnamed_addr global double, align 8
@_ZN7algebra3fft9initiatedE = external dso_local local_unnamed_addr global i8, align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7algebra3fft4initEv() local_unnamed_addr #0 {
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = load i8, ptr @_ZN7algebra3fft9initiatedE, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %22, label %.preheader

.preheader:                                       ; preds = %0, %8
  %.012 = phi i32 [ %9, %8 ], [ 1, %0 ]
  %5 = uitofp nneg i32 %.012 to double
  %6 = zext nneg i32 %.012 to i64
  br label %11

7:                                                ; preds = %8
  store i8 1, ptr @_ZN7algebra3fft9initiatedE, align 1, !tbaa !5
  br label %22

8:                                                ; preds = %11
  %9 = shl nuw nsw i32 %.012, 1
  %10 = icmp ult i32 %.012, 131072
  br i1 %10, label %.preheader, label %7, !llvm.loop !11

11:                                               ; preds = %.preheader, %11
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %11 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  store double 1.000000e+00, ptr %1, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %12 = load double, ptr @_ZN7algebra3fftL2piE, align 8, !tbaa !13
  %13 = trunc nuw nsw i64 %indvars.iv to i32
  %14 = uitofp nneg i32 %13 to double
  %15 = fmul double %12, %14
  %16 = fdiv double %15, %5
  store double %16, ptr %2, align 8, !tbaa !13
  %17 = call { double, double } @_ZSt5polarIdESt7complexIT_ERKS1_S4_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %18 = extractvalue { double, double } %17, 0
  %19 = extractvalue { double, double } %17, 1
  %20 = add nuw nsw i64 %indvars.iv, %6
  %21 = getelementptr inbounds [262144 x %"class.std::complex"], ptr @_ZN7algebra3fft1wE, i64 0, i64 %20
  store double %18, ptr %21, align 16
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %21, i64 8
  store double %19, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %6
  br i1 %exitcond.not, label %8, label %11, !llvm.loop !16

22:                                               ; preds = %7, %0
  ret void
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { double, double } @_ZSt5polarIdESt7complexIT_ERKS1_S4_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

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

attributes #0 = { mustprogress 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !12}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass