; LLVM IR from tangjz/acm-icpc :: 51nod/1971.ll (Z8FFT_initv)

; 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 { double, double }

@_ZL2pi = external hidden global double, align 8
@sp = external dso_local global i32, align 4
@msk = external dso_local global i32, align 4
@w = external dso_local global [524289 x %struct.complex], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8FFT_initv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.complex, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 524288, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %52, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  br label %55

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %12 = load i32, ptr %1, align 4, !tbaa !5
  store i32 %12, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = ashr i32 %13, 1
  store i32 %14, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %27, %11
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = and i32 %16, 1
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %24, label %19

19:                                               ; preds = %15
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = and i32 %20, 1
  %22 = icmp ne i32 %21, 0
  %23 = xor i1 %22, true
  br label %24

24:                                               ; preds = %19, %15
  %25 = phi i1 [ false, %15 ], [ %23, %19 ]
  br i1 %25, label %26, label %32

26:                                               ; preds = %24
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = ashr i32 %28, 1
  store i32 %29, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = ashr i32 %30, 1
  store i32 %31, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !9

32:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #5
  %33 = load double, ptr @_ZL2pi, align 8, !tbaa !11
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sitofp i32 %34 to double
  %36 = fdiv double %33, %35
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sitofp i32 %37 to double
  %39 = fmul double %36, %38
  %40 = call double @cos(double noundef %39) #5
  %41 = load double, ptr @_ZL2pi, align 8, !tbaa !11
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sitofp i32 %42 to double
  %44 = fdiv double %41, %43
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sitofp i32 %45 to double
  %47 = fmul double %44, %46
  %48 = call double @sin(double noundef %47) #5
  call void @_ZN7complexC2Edd(ptr noundef nonnull align 8 dereferenceable(16) %5, double noundef %40, double noundef %48)
  %49 = load i32, ptr %1, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [524289 x %struct.complex], ptr @w, i64 0, i64 %50
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %51, ptr align 8 %5, i64 16, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %52

52:                                               ; preds = %32
  %53 = load i32, ptr %1, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !14

55:                                               ; preds = %10
  store i32 1, ptr @sp, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %62, %55
  %57 = load i32, ptr @sp, align 4, !tbaa !5
  %58 = shl i32 %57, 1
  %59 = shl i32 1, %58
  %60 = icmp slt i32 %59, 1000000007
  br i1 %60, label %61, label %65

61:                                               ; preds = %56
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr @sp, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr @sp, align 4, !tbaa !5
  br label %56, !llvm.loop !15

65:                                               ; preds = %56
  %66 = load i32, ptr @sp, align 4, !tbaa !5
  %67 = shl i32 1, %66
  %68 = sub nsw i32 %67, 1
  store i32 %68, ptr @msk, align 4, !tbaa !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: nounwind
declare double @cos(double noundef) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7complexC2Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double 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 = { 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{i64 0, i64 8, !11, i64 8, i64 8, !11}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


; 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 { double, double }

@_ZL2pi = external hidden local_unnamed_addr global double, align 8
@sp = external dso_local local_unnamed_addr global i32, align 4
@msk = external dso_local local_unnamed_addr global i32, align 4
@w = external dso_local local_unnamed_addr global [524289 x %struct.complex], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8FFT_initv() local_unnamed_addr #0 {
  %1 = alloca %struct.complex, align 8
  br label %.preheader17

.preheader17:                                     ; preds = %0, %._crit_edge
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %._crit_edge ]
  %2 = trunc nuw nsw i64 %indvars.iv to i32
  %3 = and i32 %2, 1
  %.not18 = icmp eq i32 %3, 0
  br i1 %.not18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader17, %.lr.ph
  %.020 = phi i32 [ %5, %.lr.ph ], [ 262144, %.preheader17 ]
  %.01419 = phi i32 [ %4, %.lr.ph ], [ %2, %.preheader17 ]
  %4 = lshr exact i32 %.01419, 1
  %5 = lshr exact i32 %.020, 1
  %6 = and i32 %.01419, 2
  %.not = icmp eq i32 %6, 0
  %7 = and i32 %.020, 2
  %.not16 = icmp eq i32 %7, 0
  %8 = select i1 %.not, i1 %.not16, i1 false
  br i1 %8, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %.preheader17
  %.014.lcssa = phi i32 [ %2, %.preheader17 ], [ %4, %.lr.ph ]
  %.0.lcssa = phi i32 [ 262144, %.preheader17 ], [ %5, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #4
  %9 = load double, ptr @_ZL2pi, align 8, !tbaa !7
  %10 = uitofp nneg i32 %.0.lcssa to double
  %11 = fdiv double %9, %10
  %12 = uitofp nneg i32 %.014.lcssa to double
  %13 = fmul double %11, %12
  %14 = call double @cos(double noundef %13) #4
  %15 = load double, ptr @_ZL2pi, align 8, !tbaa !7
  %16 = fdiv double %15, %10
  %17 = fmul double %16, %12
  %18 = call double @sin(double noundef %17) #4
  call void @_ZN7complexC2Edd(ptr noundef nonnull align 8 dereferenceable(16) %1, double noundef %14, double noundef %18)
  %19 = getelementptr inbounds [524289 x %struct.complex], ptr @w, i64 0, i64 %indvars.iv
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %19, ptr noundef nonnull align 8 dereferenceable(16) %1, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 524288
  br i1 %exitcond.not, label %.preheader.preheader, label %.preheader17, !llvm.loop !12

.preheader.preheader:                             ; preds = %._crit_edge
  store i32 15, ptr @sp, align 4, !tbaa !13
  store i32 32767, ptr @msk, align 4, !tbaa !13
  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: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7complexC2Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double 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 = { 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 #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 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{i64 0, i64 8, !7, i64 8, i64 8, !7}
!12 = distinct !{!12, !6}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !9, i64 0}


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