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

; 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) #1

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

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

22:                                               ; preds = %89, %6
  %23 = load i64, ptr %14, align 8, !tbaa !9
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 2, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %94

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 0, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %85, %27
  %29 = load i64, ptr %17, align 8, !tbaa !9
  %30 = load i64, ptr %14, align 8, !tbaa !9
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 5, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %88

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

51:                                               ; preds = %77, %33
  %52 = load i64, ptr %19, align 8, !tbaa !9
  %53 = load i64, ptr %16, align 8, !tbaa !9
  %54 = load i64, ptr %13, align 8, !tbaa !9
  %55 = add i64 %53, %54
  %56 = icmp ult i64 %52, %55
  br i1 %56, label %58, label %57

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

58:                                               ; preds = %51
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i64, ptr %19, align 8, !tbaa !9
  %61 = getelementptr inbounds i64, ptr %59, i64 %60
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load i64, ptr %19, align 8, !tbaa !9
  %64 = load i64, ptr %13, align 8, !tbaa !9
  %65 = add i64 %63, %64
  %66 = getelementptr inbounds i64, ptr %62, i64 %65
  %67 = load i64, ptr %10, align 8, !tbaa !9
  call void @harvey_fwd_butterfly(ptr noundef %61, ptr noundef %66, ptr noundef byval(%struct.mul_op_s) align 16 %18, i64 noundef %67)
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load i64, ptr %19, align 8, !tbaa !9
  %70 = getelementptr inbounds i64, ptr %68, i64 %69
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load i64, ptr %19, align 8, !tbaa !9
  %73 = load i64, ptr %13, align 8, !tbaa !9
  %74 = add i64 %72, %73
  %75 = getelementptr inbounds i64, ptr %71, i64 %74
  %76 = load i64, ptr %10, align 8, !tbaa !9
  call void @harvey_fwd_butterfly(ptr noundef %70, ptr noundef %75, ptr noundef byval(%struct.mul_op_s) align 16 %18, i64 noundef %76)
  br label %77

77:                                               ; preds = %58
  %78 = load i64, ptr %19, align 8, !tbaa !9
  %79 = add i64 %78, 1
  store i64 %79, ptr %19, align 8, !tbaa !9
  br label %51, !llvm.loop !15

80:                                               ; preds = %57
  %81 = load i64, ptr %16, align 8, !tbaa !9
  %82 = load i64, ptr %13, align 8, !tbaa !9
  %83 = mul i64 2, %82
  %84 = add i64 %81, %83
  store i64 %84, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 32, ptr %18) #3
  br label %85

85:                                               ; preds = %80
  %86 = load i64, ptr %17, align 8, !tbaa !9
  %87 = add i64 %86, 1
  store i64 %87, ptr %17, align 8, !tbaa !9
  br label %28, !llvm.loop !17

88:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %89

89:                                               ; preds = %88
  %90 = load i64, ptr %14, align 8, !tbaa !9
  %91 = shl i64 %90, 1
  store i64 %91, ptr %14, align 8, !tbaa !9
  %92 = load i64, ptr %13, align 8, !tbaa !9
  %93 = lshr i64 %92, 1
  store i64 %93, ptr %13, align 8, !tbaa !9
  br label %22, !llvm.loop !18

94:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; 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 #1

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

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

.preheader.lr.ph:                                 ; preds = %6
  %9 = getelementptr inbounds i8, ptr %7, i64 16
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge40
  %.03443 = phi i64 [ 1, %.preheader.lr.ph ], [ %11, %._crit_edge40 ]
  %.035.in42 = phi i64 [ %2, %.preheader.lr.ph ], [ %.03544, %._crit_edge40 ]
  %.03544 = lshr i64 %.035.in42, 1
  %.not = icmp eq i64 %.03443, 0
  br i1 %.not, label %._crit_edge40, label %.lr.ph39

.lr.ph39:                                         ; preds = %.preheader
  %10 = and i64 %.035.in42, -2
  br label %13

._crit_edge45:                                    ; preds = %._crit_edge40, %6
  ret void

._crit_edge40:                                    ; preds = %._crit_edge, %.preheader
  %11 = shl i64 %.03443, 1
  %12 = icmp ult i64 %11, %2
  br i1 %12, label %.preheader, label %._crit_edge45, !llvm.loop !5

13:                                               ; preds = %.lr.ph39, %._crit_edge
  %indvars.iv = phi i64 [ %.03544, %.lr.ph39 ], [ %indvars.iv.next, %._crit_edge ]
  %.03238 = phi i64 [ 0, %.lr.ph39 ], [ %24, %._crit_edge ]
  %.03337 = phi i64 [ 0, %.lr.ph39 ], [ %23, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #3
  %14 = add i64 %.03238, %.03443
  %15 = getelementptr inbounds i64, ptr %4, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !7
  %17 = zext i64 %16 to i128
  store i128 %17, ptr %7, align 16, !tbaa !11
  %18 = getelementptr inbounds i64, ptr %5, i64 %14
  %19 = load i64, ptr %18, align 8, !tbaa !7
  %20 = zext i64 %19 to i128
  store i128 %20, ptr %9, align 16, !tbaa !14
  %21 = add i64 %.03337, %.03544
  %22 = icmp ult i64 %.03337, %21
  br i1 %22, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %13
  %23 = add i64 %.03337, %10
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #3
  %24 = add nuw i64 %.03238, 1
  %indvars.iv.next = add i64 %indvars.iv, %10
  %exitcond46.not = icmp eq i64 %24, %.03443
  br i1 %exitcond46.not, label %._crit_edge40, label %13, !llvm.loop !15

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.036 = phi i64 [ %30, %.lr.ph ], [ %.03337, %13 ]
  %25 = getelementptr inbounds i64, ptr %0, i64 %.036
  %26 = add i64 %.036, %.03544
  %27 = getelementptr inbounds i64, ptr %0, i64 %26
  tail call void @harvey_fwd_butterfly(ptr noundef %25, ptr noundef %27, ptr noundef nonnull byval(%struct.mul_op_s) align 16 %7, i64 noundef %3)
  %28 = getelementptr inbounds i64, ptr %1, i64 %.036
  %29 = getelementptr inbounds i64, ptr %1, i64 %26
  tail call void @harvey_fwd_butterfly(ptr noundef %28, ptr noundef %29, ptr noundef nonnull byval(%struct.mul_op_s) align 16 %7, i64 noundef %3)
  %30 = add i64 %.036, 1
  %exitcond.not = icmp eq i64 %30, %indvars.iv
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !6}
!16 = distinct !{!16, !6}


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