; LLVM IR from IBM/optimized-number-theoretic-transform-implementations :: src (ntt_reference)

; 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.mul_op_s = type { i128, i128 }

; Function Attrs: nounwind uwtable
define dso_local void @fwd_ntt_ref_harvey_lazy(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca %struct.mul_op_s, align 16
  %17 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = lshr i64 %18, 1
  store i64 %19, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store i64 1, ptr %12, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %78, %5
  %21 = load i64, ptr %12, align 8, !tbaa !9
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %83

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store i64 0, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %74, %25
  %27 = load i64, ptr %15, align 8, !tbaa !9
  %28 = load i64, ptr %12, align 8, !tbaa !9
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 5, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %77

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 32, ptr %16) #3
  %32 = getelementptr inbounds %struct.mul_op_s, ptr %16, i32 0, i32 0
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load i64, ptr %12, align 8, !tbaa !9
  %35 = load i64, ptr %15, align 8, !tbaa !9
  %36 = add i64 %34, %35
  %37 = getelementptr inbounds i64, ptr %33, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = zext i64 %38 to i128
  store i128 %39, ptr %32, align 16, !tbaa !11
  %40 = getelementptr inbounds %struct.mul_op_s, ptr %16, i32 0, i32 1
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = load i64, ptr %12, align 8, !tbaa !9
  %43 = load i64, ptr %15, align 8, !tbaa !9
  %44 = add i64 %42, %43
  %45 = getelementptr inbounds i64, ptr %41, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !9
  %47 = zext i64 %46 to i128
  store i128 %47, ptr %40, align 16, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %48 = load i64, ptr %14, align 8, !tbaa !9
  store i64 %48, ptr %17, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %66, %31
  %50 = load i64, ptr %17, align 8, !tbaa !9
  %51 = load i64, ptr %14, align 8, !tbaa !9
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = add i64 %51, %52
  %54 = icmp ult i64 %50, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %49
  store i32 8, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %69

56:                                               ; preds = %49
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load i64, ptr %17, align 8, !tbaa !9
  %59 = getelementptr inbounds i64, ptr %57, i64 %58
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load i64, ptr %17, align 8, !tbaa !9
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = add i64 %61, %62
  %64 = getelementptr inbounds i64, ptr %60, i64 %63
  %65 = load i64, ptr %8, align 8, !tbaa !9
  call void @harvey_fwd_butterfly(ptr noundef %59, ptr noundef %64, ptr noundef byval(%struct.mul_op_s) align 16 %16, i64 noundef %65)
  br label %66

66:                                               ; preds = %56
  %67 = load i64, ptr %17, align 8, !tbaa !9
  %68 = add i64 %67, 1
  store i64 %68, ptr %17, align 8, !tbaa !9
  br label %49, !llvm.loop !15

69:                                               ; preds = %55
  %70 = load i64, ptr %14, align 8, !tbaa !9
  %71 = load i64, ptr %11, align 8, !tbaa !9
  %72 = mul i64 2, %71
  %73 = add i64 %70, %72
  store i64 %73, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 32, ptr %16) #3
  br label %74

74:                                               ; preds = %69
  %75 = load i64, ptr %15, align 8, !tbaa !9
  %76 = add i64 %75, 1
  store i64 %76, ptr %15, align 8, !tbaa !9
  br label %26, !llvm.loop !18

77:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %78

78:                                               ; preds = %77
  %79 = load i64, ptr %12, align 8, !tbaa !9
  %80 = shl i64 %79, 1
  store i64 %80, ptr %12, align 8, !tbaa !9
  %81 = load i64, ptr %11, align 8, !tbaa !9
  %82 = lshr i64 %81, 1
  store i64 %82, ptr %11, align 8, !tbaa !9
  br label %20, !llvm.loop !19

83:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  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 nounwind uwtable
declare hidden void @harvey_fwd_butterfly(ptr noundef, ptr noundef, ptr noundef byval(%struct.mul_op_s) align 16, i64 noundef) #2

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"mul_op_s", !13, i64 0, !13, i64 16}
!13 = !{!"__int128", !7, i64 0}
!14 = !{!12, !13, i64 16}
!15 = distinct !{!15, !16, !17}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.unroll.count", i32 4}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !16}


; 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.mul_op_s = type { i128, i128 }

; Function Attrs: nounwind uwtable
define dso_local void @fwd_ntt_ref_harvey_lazy(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %6 = alloca %struct.mul_op_s, align 16
  %7 = icmp ugt i64 %1, 1
  br i1 %7, label %.preheader.lr.ph, label %._crit_edge39

.preheader.lr.ph:                                 ; preds = %5
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  %invariant.gep = getelementptr i8, ptr %0, i64 8
  %invariant.gep40 = getelementptr i8, ptr %0, i64 16
  %invariant.gep42 = getelementptr i8, ptr %0, i64 24
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge34
  %.02837 = phi i64 [ 1, %.preheader.lr.ph ], [ %12, %._crit_edge34 ]
  %.029.in36 = phi i64 [ %1, %.preheader.lr.ph ], [ %.02938, %._crit_edge34 ]
  %.02938 = lshr i64 %.029.in36, 1
  %.not = icmp eq i64 %.02837, 0
  br i1 %.not, label %._crit_edge34, label %.lr.ph33

.lr.ph33:                                         ; preds = %.preheader
  %9 = and i64 %.029.in36, -2
  %10 = add nsw i64 %.02938, -1
  %xtraiter = and i64 %.02938, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %11 = icmp ult i64 %10, 3
  br label %14

._crit_edge39:                                    ; preds = %._crit_edge34, %5
  ret void

._crit_edge34:                                    ; preds = %._crit_edge, %.preheader
  %12 = shl i64 %.02837, 1
  %13 = icmp ult i64 %12, %1
  br i1 %13, label %.preheader, label %._crit_edge39, !llvm.loop !5

14:                                               ; preds = %.lr.ph33, %._crit_edge
  %indvars.iv = phi i64 [ %.02938, %.lr.ph33 ], [ %indvars.iv.next, %._crit_edge ]
  %.02632 = phi i64 [ 0, %.lr.ph33 ], [ %28, %._crit_edge ]
  %.02731 = phi i64 [ 0, %.lr.ph33 ], [ %27, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #3
  %15 = add i64 %.02632, %.02837
  %16 = getelementptr inbounds i64, ptr %3, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !7
  %18 = zext i64 %17 to i128
  store i128 %18, ptr %6, align 16, !tbaa !11
  %19 = getelementptr inbounds i64, ptr %4, i64 %15
  %20 = load i64, ptr %19, align 8, !tbaa !7
  %21 = zext i64 %20 to i128
  store i128 %21, ptr %8, align 16, !tbaa !14
  %22 = add i64 %.02731, %.02938
  %23 = icmp ult i64 %.02731, %22
  br i1 %23, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %14
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.030.prol = phi i64 [ %26, %.lr.ph.prol ], [ %.02731, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %24 = getelementptr inbounds i64, ptr %0, i64 %.030.prol
  %25 = getelementptr i64, ptr %24, i64 %.02938
  tail call void @harvey_fwd_butterfly(ptr noundef %24, ptr noundef %25, ptr noundef nonnull byval(%struct.mul_op_s) align 16 %6, i64 noundef %2)
  %26 = add i64 %.030.prol, 1
  %prol.iter.next = add nuw nsw i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !15

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.030.unr = phi i64 [ %.02731, %.lr.ph.preheader ], [ %26, %.lr.ph.prol ]
  br i1 %11, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph.prol.loopexit, %14
  %27 = add i64 %.02731, %9
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #3
  %28 = add nuw i64 %.02632, 1
  %indvars.iv.next = add i64 %indvars.iv, %9
  %exitcond.not = icmp eq i64 %28, %.02837
  br i1 %exitcond.not, label %._crit_edge34, label %14, !llvm.loop !17

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.030 = phi i64 [ %34, %.lr.ph ], [ %.030.unr, %.lr.ph.prol.loopexit ]
  %29 = getelementptr inbounds i64, ptr %0, i64 %.030
  %30 = getelementptr i64, ptr %29, i64 %.02938
  tail call void @harvey_fwd_butterfly(ptr noundef %29, ptr noundef %30, ptr noundef nonnull byval(%struct.mul_op_s) align 16 %6, i64 noundef %2)
  %gep = getelementptr i64, ptr %invariant.gep, i64 %.030
  %31 = getelementptr i64, ptr %gep, i64 %.02938
  tail call void @harvey_fwd_butterfly(ptr noundef %gep, ptr noundef %31, ptr noundef nonnull byval(%struct.mul_op_s) align 16 %6, i64 noundef %2)
  %gep41 = getelementptr i64, ptr %invariant.gep40, i64 %.030
  %32 = getelementptr i64, ptr %gep41, i64 %.02938
  tail call void @harvey_fwd_butterfly(ptr noundef %gep41, ptr noundef %32, ptr noundef nonnull byval(%struct.mul_op_s) align 16 %6, i64 noundef %2)
  %gep43 = getelementptr i64, ptr %invariant.gep42, i64 %.030
  %33 = getelementptr i64, ptr %gep43, i64 %.02938
  tail call void @harvey_fwd_butterfly(ptr noundef %gep43, ptr noundef %33, ptr noundef nonnull byval(%struct.mul_op_s) align 16 %6, i64 noundef %2)
  %34 = add i64 %.030, 4
  %exitcond.3.not = icmp eq i64 %34, %indvars.iv
  br i1 %exitcond.3.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18
}

; 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 nounwind uwtable
declare hidden void @harvey_fwd_butterfly(ptr noundef, ptr noundef, ptr noundef byval(%struct.mul_op_s) align 16, i64 noundef) 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 = { 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 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 = { 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", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !13, i64 0}
!12 = !{!"mul_op_s", !13, i64 0, !13, i64 16}
!13 = !{!"__int128", !9, i64 0}
!14 = !{!12, !13, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !6}
!18 = distinct !{!18, !6, !16}


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