; LLVM IR from tangjz/acm-icpc :: hdu/6159.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
@mod = external dso_local global i32, align 4
@w = external dso_local global [65537 x %struct.complex], align 16
@sp = external dso_local global i32, align 4
@msk = external dso_local global i32, align 4

; 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 65536, 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 [65537 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 = %63, %55
  %57 = load i32, ptr @sp, align 4, !tbaa !5
  %58 = shl i32 %57, 1
  %59 = shl i32 1, %58
  %60 = load i32, ptr @mod, align 4, !tbaa !5
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %62, label %66

62:                                               ; preds = %56
  br label %63

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

66:                                               ; preds = %56
  %67 = load i32, ptr @sp, align 4, !tbaa !5
  %68 = shl i32 1, %67
  %69 = sub nsw i32 %68, 1
  store i32 %69, 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
@mod = external dso_local local_unnamed_addr global i32, align 4
@w = external dso_local local_unnamed_addr global [65537 x %struct.complex], align 16
@sp = external dso_local local_unnamed_addr global i32, align 4
@msk = external dso_local local_unnamed_addr global i32, align 4

; 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

.preheader:                                       ; preds = %._crit_edge
  %4 = load i32, ptr @mod, align 4, !tbaa !5
  br label %21

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

._crit_edge:                                      ; preds = %.lr.ph, %.preheader17
  %.014.lcssa = phi i32 [ %2, %.preheader17 ], [ %5, %.lr.ph ]
  %.0.lcssa = phi i32 [ 32768, %.preheader17 ], [ %6, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #4
  %10 = load double, ptr @_ZL2pi, align 8, !tbaa !11
  %11 = uitofp nneg i32 %.0.lcssa to double
  %12 = fdiv double %10, %11
  %13 = uitofp nneg i32 %.014.lcssa to double
  %14 = fmul double %12, %13
  %15 = call double @cos(double noundef %14) #4
  %16 = load double, ptr @_ZL2pi, align 8, !tbaa !11
  %17 = fdiv double %16, %11
  %18 = fmul double %17, %13
  %19 = call double @sin(double noundef %18) #4
  call void @_ZN7complexC2Edd(ptr noundef nonnull align 8 dereferenceable(16) %1, double noundef %15, double noundef %19)
  %20 = getelementptr inbounds [65537 x %struct.complex], ptr @w, i64 0, i64 %indvars.iv
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %20, ptr noundef nonnull align 8 dereferenceable(16) %1, i64 16, i1 false), !tbaa.struct !13
  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, 65536
  br i1 %exitcond.not, label %.preheader, label %.preheader17, !llvm.loop !14

21:                                               ; preds = %21, %.preheader
  %storemerge = phi i32 [ %25, %21 ], [ 1, %.preheader ]
  %22 = shl nuw i32 %storemerge, 1
  %23 = shl nuw i32 1, %22
  %24 = icmp slt i32 %23, %4
  %25 = add nuw nsw i32 %storemerge, 1
  br i1 %24, label %21, label %26, !llvm.loop !15

26:                                               ; preds = %21
  store i32 %storemerge, ptr @sp, align 4, !tbaa !5
  %notmask = shl nsw i32 -1, %storemerge
  %27 = xor i32 %notmask, -1
  store i32 %27, ptr @msk, align 4, !tbaa !5
  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 = !{!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}


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