; LLVM IR from tangjz/acm-icpc :: codeforces/gym/101234D.ll (Z7initFFTi)

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

%struct.Complex = type { x86_fp80, x86_fp80 }

@_ZL2pi = external hidden global x86_fp80, align 16
@w = external dso_local global [524291 x %struct.Complex], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7initFFTi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Complex, align 16
  %8 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds %struct.Complex, ptr @w, i64 %10
  store ptr %11, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %59, %1
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %62

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %18, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = ashr i32 %19, 1
  store i32 %20, ptr %6, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %33, %17
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = and i32 %22, 1
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %30, label %25

25:                                               ; preds = %21
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = and i32 %26, 1
  %28 = icmp ne i32 %27, 0
  %29 = xor i1 %28, true
  br label %30

30:                                               ; preds = %25, %21
  %31 = phi i1 [ false, %21 ], [ %29, %25 ]
  br i1 %31, label %32, label %38

32:                                               ; preds = %30
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = ashr i32 %34, 1
  store i32 %35, ptr %5, align 4, !tbaa !5
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = ashr i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !5
  br label %21, !llvm.loop !11

38:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #5
  %39 = load x86_fp80, ptr @_ZL2pi, align 16, !tbaa !13
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = sitofp i32 %40 to x86_fp80
  %42 = fdiv x86_fp80 %39, %41
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sitofp i32 %43 to x86_fp80
  %45 = fmul x86_fp80 %42, %44
  %46 = call noundef x86_fp80 @_ZSt3cose(x86_fp80 noundef %45)
  %47 = load x86_fp80, ptr @_ZL2pi, align 16, !tbaa !13
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sitofp i32 %48 to x86_fp80
  %50 = fdiv x86_fp80 %47, %49
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sitofp i32 %51 to x86_fp80
  %53 = fmul x86_fp80 %50, %52
  %54 = call noundef x86_fp80 @_ZSt3sine(x86_fp80 noundef %53)
  call void @_ZN7ComplexC2Eee(ptr noundef nonnull align 16 dereferenceable(32) %7, x86_fp80 noundef %46, x86_fp80 noundef %54)
  %55 = load ptr, ptr %3, align 8, !tbaa !9
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds %struct.Complex, ptr %55, i64 %57
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %58, ptr align 16 %7, i64 32, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %59

59:                                               ; preds = %38
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %4, align 4, !tbaa !5
  br label %12, !llvm.loop !16

62:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = sub nsw i32 %63, 1
  store i32 %64, ptr %8, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %77, %62
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = icmp sgt i32 %66, 0
  br i1 %67, label %69, label %68

68:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %80

69:                                               ; preds = %65
  %70 = load i32, ptr %8, align 4, !tbaa !5
  %71 = shl i32 %70, 1
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [524291 x %struct.Complex], ptr @w, i64 0, i64 %72
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [524291 x %struct.Complex], ptr @w, i64 0, i64 %75
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %76, ptr align 16 %73, i64 32, i1 false), !tbaa.struct !15
  br label %77

77:                                               ; preds = %69
  %78 = load i32, ptr %8, align 4, !tbaa !5
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr %8, align 4, !tbaa !5
  br label %65, !llvm.loop !17

80:                                               ; preds = %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  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 nounwind uwtable
declare dso_local noundef x86_fp80 @_ZSt3cose(x86_fp80 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef x86_fp80 @_ZSt3sine(x86_fp80 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7ComplexC2Eee(ptr noundef nonnull align 16 dereferenceable(32), x86_fp80 noundef, x86_fp80 noundef) unnamed_addr #3 align 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) #4

; 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 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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"long double", !7, i64 0}
!15 = !{i64 0, i64 16, !13, i64 16, i64 16, !13}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


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

%struct.Complex = type { x86_fp80, x86_fp80 }

@_ZL2pi = external hidden local_unnamed_addr global x86_fp80, align 16
@w = external dso_local local_unnamed_addr global [524291 x %struct.Complex], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7initFFTi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.Complex, align 16
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds %struct.Complex, ptr @w, i64 %3
  %5 = icmp sgt i32 %0, 0
  br i1 %5, label %.preheader25.preheader, label %._crit_edge

.preheader25.preheader:                           ; preds = %1
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.preheader25

.preheader25:                                     ; preds = %.preheader25.preheader, %12
  %indvars.iv = phi i64 [ 0, %.preheader25.preheader ], [ %indvars.iv.next, %12 ]
  %6 = trunc nuw nsw i64 %indvars.iv to i32
  br label %7

.preheader:                                       ; preds = %12
  %.not32 = icmp eq i32 %0, 1
  br i1 %.not32, label %._crit_edge, label %.lr.ph

7:                                                ; preds = %7, %.preheader25
  %.021 = phi i32 [ %11, %7 ], [ %6, %.preheader25 ]
  %.020.in = phi i32 [ %.020, %7 ], [ %0, %.preheader25 ]
  %.020 = lshr i32 %.020.in, 1
  %8 = and i32 %.021, 1
  %.not = icmp eq i32 %8, 0
  %9 = and i32 %.020.in, 2
  %.not24 = icmp eq i32 %9, 0
  %10 = select i1 %.not, i1 %.not24, i1 false
  %11 = lshr exact i32 %.021, 1
  br i1 %10, label %7, label %12, !llvm.loop !5

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #4
  %13 = load x86_fp80, ptr @_ZL2pi, align 16, !tbaa !7
  %14 = uitofp nneg i32 %.020 to x86_fp80
  %15 = fdiv x86_fp80 %13, %14
  %16 = uitofp nneg i32 %.021 to x86_fp80
  %17 = fmul x86_fp80 %15, %16
  %18 = call noundef x86_fp80 @_ZSt3cose(x86_fp80 noundef %17)
  %19 = load x86_fp80, ptr @_ZL2pi, align 16, !tbaa !7
  %20 = fdiv x86_fp80 %19, %14
  %21 = fmul x86_fp80 %20, %16
  %22 = call noundef x86_fp80 @_ZSt3sine(x86_fp80 noundef %21)
  call void @_ZN7ComplexC2Eee(ptr noundef nonnull align 16 dereferenceable(32) %2, x86_fp80 noundef %18, x86_fp80 noundef %22)
  %23 = getelementptr inbounds %struct.Complex, ptr %4, i64 %indvars.iv
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %23, ptr noundef nonnull align 16 dereferenceable(32) %2, i64 32, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #4
  %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 %.preheader, label %.preheader25, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %1, %.preheader
  ret void

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %.lr.ph ], [ %3, %.preheader ]
  %indvars.iv.next30 = add nsw i64 %indvars.iv29, -1
  %indvars.iv.next30.tr = trunc i64 %indvars.iv.next30 to i32
  %24 = shl i32 %indvars.iv.next30.tr, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [524291 x %struct.Complex], ptr @w, i64 0, i64 %25
  %27 = getelementptr inbounds [524291 x %struct.Complex], ptr @w, i64 0, i64 %indvars.iv.next30
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %27, ptr noundef nonnull align 16 dereferenceable(32) %26, i64 32, i1 false), !tbaa.struct !11
  %28 = icmp sgt i64 %indvars.iv29, 2
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

; 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 nounwind uwtable
declare dso_local noundef x86_fp80 @_ZSt3cose(x86_fp80 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef x86_fp80 @_ZSt3sine(x86_fp80 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7ComplexC2Eee(ptr noundef nonnull align 16 dereferenceable(32), x86_fp80 noundef, x86_fp80 noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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


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