; 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: 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 @inv_ntt_ref_harvey(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef byval(%struct.mul_op_s) align 16 %3, i64 noundef %4, ptr noundef %5, ptr noundef %6) #1 {
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca %struct.mul_op_s, align 16
  %20 = alloca i64, align 8
  %21 = alloca i128, align 16
  %22 = alloca %struct.mul_op_s, align 16
  %23 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store i64 %2, ptr %10, align 8, !tbaa !9
  store i64 %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !5
  store ptr %6, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store i64 1, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = lshr i64 %24, 1
  store i64 %25, ptr %15, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %83, %7
  %27 = load i64, ptr %15, align 8, !tbaa !9
  %28 = icmp ugt i64 %27, 1
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store i64 0, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %79, %30
  %32 = load i64, ptr %18, align 8, !tbaa !9
  %33 = load i64, ptr %15, align 8, !tbaa !9
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 5, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %82

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

54:                                               ; preds = %71, %36
  %55 = load i64, ptr %20, align 8, !tbaa !9
  %56 = load i64, ptr %17, align 8, !tbaa !9
  %57 = load i64, ptr %14, align 8, !tbaa !9
  %58 = add i64 %56, %57
  %59 = icmp ult i64 %55, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %54
  store i32 8, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  br label %74

61:                                               ; preds = %54
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load i64, ptr %20, align 8, !tbaa !9
  %64 = getelementptr inbounds i64, ptr %62, i64 %63
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load i64, ptr %20, align 8, !tbaa !9
  %67 = load i64, ptr %14, align 8, !tbaa !9
  %68 = add i64 %66, %67
  %69 = getelementptr inbounds i64, ptr %65, i64 %68
  %70 = load i64, ptr %10, align 8, !tbaa !9
  call void @harvey_bkw_butterfly(ptr noundef %64, ptr noundef %69, ptr noundef byval(%struct.mul_op_s) align 16 %19, i64 noundef %70)
  br label %71

71:                                               ; preds = %61
  %72 = load i64, ptr %20, align 8, !tbaa !9
  %73 = add i64 %72, 1
  store i64 %73, ptr %20, align 8, !tbaa !9
  br label %54, !llvm.loop !15

74:                                               ; preds = %60
  %75 = load i64, ptr %17, align 8, !tbaa !9
  %76 = load i64, ptr %14, align 8, !tbaa !9
  %77 = mul i64 2, %76
  %78 = add i64 %75, %77
  store i64 %78, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 32, ptr %19) #3
  br label %79

79:                                               ; preds = %74
  %80 = load i64, ptr %18, align 8, !tbaa !9
  %81 = add i64 %80, 1
  store i64 %81, ptr %18, align 8, !tbaa !9
  br label %31, !llvm.loop !17

82:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %83

83:                                               ; preds = %82
  %84 = load i64, ptr %15, align 8, !tbaa !9
  %85 = lshr i64 %84, 1
  store i64 %85, ptr %15, align 8, !tbaa !9
  %86 = load i64, ptr %14, align 8, !tbaa !9
  %87 = shl i64 %86, 1
  store i64 %87, ptr %14, align 8, !tbaa !9
  br label %26, !llvm.loop !18

88:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 16, ptr %21) #3
  %89 = load ptr, ptr %12, align 8, !tbaa !5
  %90 = getelementptr inbounds i64, ptr %89, i64 1
  %91 = load i64, ptr %90, align 8, !tbaa !9
  %92 = load i64, ptr %10, align 8, !tbaa !9
  %93 = call i64 @fast_mul_mod_q2(ptr noundef byval(%struct.mul_op_s) align 16 %3, i64 noundef %91, i64 noundef %92)
  %94 = zext i64 %93 to i128
  store i128 %94, ptr %21, align 16, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 32, ptr %22) #3
  %95 = getelementptr inbounds %struct.mul_op_s, ptr %22, i32 0, i32 0
  %96 = load i128, ptr %21, align 16, !tbaa !19
  store i128 %96, ptr %95, align 16, !tbaa !11
  %97 = getelementptr inbounds %struct.mul_op_s, ptr %22, i32 0, i32 1
  %98 = load i128, ptr %21, align 16, !tbaa !19
  %99 = load i64, ptr %11, align 8, !tbaa !9
  %100 = zext i64 %99 to i128
  %101 = shl i128 %98, %100
  %102 = load i64, ptr %10, align 8, !tbaa !9
  %103 = zext i64 %102 to i128
  %104 = udiv i128 %101, %103
  store i128 %104, ptr %97, align 16, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  store i64 0, ptr %23, align 8, !tbaa !9
  br label %105

105:                                              ; preds = %120, %88
  %106 = load i64, ptr %23, align 8, !tbaa !9
  %107 = load i64, ptr %14, align 8, !tbaa !9
  %108 = icmp ult i64 %106, %107
  br i1 %108, label %110, label %109

109:                                              ; preds = %105
  store i32 11, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  br label %123

110:                                              ; preds = %105
  %111 = load ptr, ptr %8, align 8, !tbaa !5
  %112 = load i64, ptr %23, align 8, !tbaa !9
  %113 = getelementptr inbounds i64, ptr %111, i64 %112
  %114 = load ptr, ptr %8, align 8, !tbaa !5
  %115 = load i64, ptr %23, align 8, !tbaa !9
  %116 = load i64, ptr %14, align 8, !tbaa !9
  %117 = add i64 %115, %116
  %118 = getelementptr inbounds i64, ptr %114, i64 %117
  %119 = load i64, ptr %10, align 8, !tbaa !9
  call void @harvey_bkw_butterfly_final(ptr noundef %113, ptr noundef %118, ptr noundef byval(%struct.mul_op_s) align 16 %22, ptr noundef byval(%struct.mul_op_s) align 16 %3, i64 noundef %119)
  br label %120

120:                                              ; preds = %110
  %121 = load i64, ptr %23, align 8, !tbaa !9
  %122 = add i64 %121, 1
  store i64 %122, ptr %23, align 8, !tbaa !9
  br label %105, !llvm.loop !20

123:                                              ; preds = %109
  call void @llvm.lifetime.end.p0(i64 32, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @harvey_bkw_butterfly(ptr noundef, ptr noundef, ptr noundef byval(%struct.mul_op_s) align 16, i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @fast_mul_mod_q2(ptr noundef byval(%struct.mul_op_s) align 16, i64 noundef, i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @harvey_bkw_butterfly_final(ptr noundef, ptr noundef, ptr noundef byval(%struct.mul_op_s) align 16, ptr noundef byval(%struct.mul_op_s) align 16, i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}
!19 = !{!13, !13, i64 0}
!20 = distinct !{!20, !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: 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 @inv_ntt_ref_harvey(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef byval(%struct.mul_op_s) align 16 %3, i64 noundef %4, ptr nocapture noundef readonly %5, ptr nocapture noundef readonly %6) local_unnamed_addr #1 {
  %8 = alloca %struct.mul_op_s, align 16
  %9 = alloca %struct.mul_op_s, align 16
  %10 = icmp ugt i64 %1, 3
  br i1 %10, label %.preheader.lr.ph, label %._crit_edge53

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

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge49
  %.04452.in = phi i64 [ %1, %.preheader.lr.ph ], [ %.04452, %._crit_edge49 ]
  %.04051 = phi i64 [ 1, %.preheader.lr.ph ], [ %.pre, %._crit_edge49 ]
  %.04452 = lshr i64 %.04452.in, 1
  %.not = icmp ult i64 %.04452.in, 2
  %.pre = shl i64 %.04051, 1
  br i1 %.not, label %._crit_edge53, label %.lr.ph48

._crit_edge53:                                    ; preds = %._crit_edge49, %.preheader, %7
  %.040.lcssa = phi i64 [ 1, %7 ], [ %.pre, %.preheader ], [ %.pre, %._crit_edge49 ]
  %12 = getelementptr inbounds i8, ptr %5, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = tail call i64 @fast_mul_mod_q2(ptr noundef nonnull byval(%struct.mul_op_s) align 16 %3, i64 noundef %13, i64 noundef %2)
  %15 = zext i64 %14 to i128
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %9) #3
  store i128 %15, ptr %9, align 16, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %9, i64 16
  %17 = zext nneg i64 %4 to i128
  %18 = shl i128 %15, %17
  %19 = zext i64 %2 to i128
  %20 = udiv i128 %18, %19
  store i128 %20, ptr %16, align 16, !tbaa !12
  %.not58 = icmp eq i64 %.040.lcssa, 0
  br i1 %.not58, label %._crit_edge57, label %.lr.ph56

._crit_edge49:                                    ; preds = %._crit_edge
  %21 = icmp ugt i64 %.04452.in, 7
  br i1 %21, label %.preheader, label %._crit_edge53, !llvm.loop !13

.lr.ph48:                                         ; preds = %.preheader, %._crit_edge
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ %.04051, %.preheader ]
  %.04247 = phi i64 [ %32, %._crit_edge ], [ 0, %.preheader ]
  %.04346 = phi i64 [ %31, %._crit_edge ], [ 0, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %8) #3
  %22 = add nuw i64 %.04247, %.04452
  %23 = getelementptr inbounds i64, ptr %5, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = zext i64 %24 to i128
  store i128 %25, ptr %8, align 16, !tbaa !9
  %26 = getelementptr inbounds i64, ptr %6, i64 %22
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = zext i64 %27 to i128
  store i128 %28, ptr %11, align 16, !tbaa !12
  %29 = add i64 %.04346, %.04051
  %30 = icmp ult i64 %.04346, %29
  br i1 %30, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph48
  %31 = add i64 %.04346, %.pre
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #3
  %32 = add nuw nsw i64 %.04247, 1
  %indvars.iv.next = add i64 %indvars.iv, %.pre
  %exitcond59.not = icmp eq i64 %32, %.04452
  br i1 %exitcond59.not, label %._crit_edge49, label %.lr.ph48, !llvm.loop !15

.lr.ph:                                           ; preds = %.lr.ph48, %.lr.ph
  %.04145 = phi i64 [ %35, %.lr.ph ], [ %.04346, %.lr.ph48 ]
  %33 = getelementptr inbounds i64, ptr %0, i64 %.04145
  %34 = getelementptr i64, ptr %33, i64 %.04051
  tail call void @harvey_bkw_butterfly(ptr noundef %33, ptr noundef %34, ptr noundef nonnull byval(%struct.mul_op_s) align 16 %8, i64 noundef %2)
  %35 = add i64 %.04145, 1
  %exitcond.not = icmp eq i64 %35, %indvars.iv
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge57:                                    ; preds = %.lr.ph56, %._crit_edge53
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %9) #3
  ret void

.lr.ph56:                                         ; preds = %._crit_edge53, %.lr.ph56
  %.054 = phi i64 [ %38, %.lr.ph56 ], [ 0, %._crit_edge53 ]
  %36 = getelementptr inbounds i64, ptr %0, i64 %.054
  %37 = getelementptr i64, ptr %36, i64 %.040.lcssa
  tail call void @harvey_bkw_butterfly_final(ptr noundef %36, ptr noundef %37, ptr noundef nonnull byval(%struct.mul_op_s) align 16 %9, ptr noundef nonnull byval(%struct.mul_op_s) align 16 %3, i64 noundef %2)
  %38 = add nuw i64 %.054, 1
  %exitcond60.not = icmp eq i64 %38, %.040.lcssa
  br i1 %exitcond60.not, label %._crit_edge57, label %.lr.ph56, !llvm.loop !17
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @harvey_bkw_butterfly(ptr noundef, ptr noundef, ptr noundef byval(%struct.mul_op_s) align 16, i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @fast_mul_mod_q2(ptr noundef byval(%struct.mul_op_s) align 16, i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @harvey_bkw_butterfly_final(ptr noundef, ptr noundef, ptr noundef byval(%struct.mul_op_s) align 16, ptr noundef byval(%struct.mul_op_s) align 16, i64 noundef) local_unnamed_addr #2

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


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