; LLVM IR from guanzhi/GmSSL :: src (kyber)

; 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"

; 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 @kyber_poly_copy(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %19, %2
  %7 = load i32, ptr %5, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 256
  br i1 %8, label %9, label %22

9:                                                ; preds = %6
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i16, ptr %10, i64 %12
  %14 = load i16, ptr %13, align 2, !tbaa !11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i16, ptr %15, i64 %17
  store i16 %14, ptr %18, align 2, !tbaa !11
  br label %19

19:                                               ; preds = %9
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %5, align 4, !tbaa !9
  br label %6, !llvm.loop !13

22:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @kyber_poly_copy(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
vector.memcheck:
  %2 = ptrtoint ptr %0 to i64
  %3 = ptrtoint ptr %1 to i64
  %4 = sub i64 %2, %3
  %diff.check = icmp ult i64 %4, 32
  br i1 %diff.check, label %scalar.ph, label %vector.body

vector.body:                                      ; preds = %vector.memcheck
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %wide.load = load <8 x i16>, ptr %1, align 2, !tbaa !5
  %wide.load7 = load <8 x i16>, ptr %5, align 2, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  store <8 x i16> %wide.load, ptr %0, align 2, !tbaa !5
  store <8 x i16> %wide.load7, ptr %6, align 2, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 32
  %8 = getelementptr inbounds i8, ptr %1, i64 48
  %wide.load.1 = load <8 x i16>, ptr %7, align 2, !tbaa !5
  %wide.load7.1 = load <8 x i16>, ptr %8, align 2, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  store <8 x i16> %wide.load.1, ptr %9, align 2, !tbaa !5
  store <8 x i16> %wide.load7.1, ptr %10, align 2, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %1, i64 64
  %12 = getelementptr inbounds i8, ptr %1, i64 80
  %wide.load.2 = load <8 x i16>, ptr %11, align 2, !tbaa !5
  %wide.load7.2 = load <8 x i16>, ptr %12, align 2, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 64
  %14 = getelementptr inbounds i8, ptr %0, i64 80
  store <8 x i16> %wide.load.2, ptr %13, align 2, !tbaa !5
  store <8 x i16> %wide.load7.2, ptr %14, align 2, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %1, i64 96
  %16 = getelementptr inbounds i8, ptr %1, i64 112
  %wide.load.3 = load <8 x i16>, ptr %15, align 2, !tbaa !5
  %wide.load7.3 = load <8 x i16>, ptr %16, align 2, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 96
  %18 = getelementptr inbounds i8, ptr %0, i64 112
  store <8 x i16> %wide.load.3, ptr %17, align 2, !tbaa !5
  store <8 x i16> %wide.load7.3, ptr %18, align 2, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %1, i64 128
  %20 = getelementptr inbounds i8, ptr %1, i64 144
  %wide.load.4 = load <8 x i16>, ptr %19, align 2, !tbaa !5
  %wide.load7.4 = load <8 x i16>, ptr %20, align 2, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 128
  %22 = getelementptr inbounds i8, ptr %0, i64 144
  store <8 x i16> %wide.load.4, ptr %21, align 2, !tbaa !5
  store <8 x i16> %wide.load7.4, ptr %22, align 2, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %1, i64 160
  %24 = getelementptr inbounds i8, ptr %1, i64 176
  %wide.load.5 = load <8 x i16>, ptr %23, align 2, !tbaa !5
  %wide.load7.5 = load <8 x i16>, ptr %24, align 2, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 160
  %26 = getelementptr inbounds i8, ptr %0, i64 176
  store <8 x i16> %wide.load.5, ptr %25, align 2, !tbaa !5
  store <8 x i16> %wide.load7.5, ptr %26, align 2, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %1, i64 192
  %28 = getelementptr inbounds i8, ptr %1, i64 208
  %wide.load.6 = load <8 x i16>, ptr %27, align 2, !tbaa !5
  %wide.load7.6 = load <8 x i16>, ptr %28, align 2, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %0, i64 192
  %30 = getelementptr inbounds i8, ptr %0, i64 208
  store <8 x i16> %wide.load.6, ptr %29, align 2, !tbaa !5
  store <8 x i16> %wide.load7.6, ptr %30, align 2, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %1, i64 224
  %32 = getelementptr inbounds i8, ptr %1, i64 240
  %wide.load.7 = load <8 x i16>, ptr %31, align 2, !tbaa !5
  %wide.load7.7 = load <8 x i16>, ptr %32, align 2, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %0, i64 224
  %34 = getelementptr inbounds i8, ptr %0, i64 240
  store <8 x i16> %wide.load.7, ptr %33, align 2, !tbaa !5
  store <8 x i16> %wide.load7.7, ptr %34, align 2, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %1, i64 256
  %36 = getelementptr inbounds i8, ptr %1, i64 272
  %wide.load.8 = load <8 x i16>, ptr %35, align 2, !tbaa !5
  %wide.load7.8 = load <8 x i16>, ptr %36, align 2, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %0, i64 256
  %38 = getelementptr inbounds i8, ptr %0, i64 272
  store <8 x i16> %wide.load.8, ptr %37, align 2, !tbaa !5
  store <8 x i16> %wide.load7.8, ptr %38, align 2, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %1, i64 288
  %40 = getelementptr inbounds i8, ptr %1, i64 304
  %wide.load.9 = load <8 x i16>, ptr %39, align 2, !tbaa !5
  %wide.load7.9 = load <8 x i16>, ptr %40, align 2, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %0, i64 288
  %42 = getelementptr inbounds i8, ptr %0, i64 304
  store <8 x i16> %wide.load.9, ptr %41, align 2, !tbaa !5
  store <8 x i16> %wide.load7.9, ptr %42, align 2, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %1, i64 320
  %44 = getelementptr inbounds i8, ptr %1, i64 336
  %wide.load.10 = load <8 x i16>, ptr %43, align 2, !tbaa !5
  %wide.load7.10 = load <8 x i16>, ptr %44, align 2, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %0, i64 320
  %46 = getelementptr inbounds i8, ptr %0, i64 336
  store <8 x i16> %wide.load.10, ptr %45, align 2, !tbaa !5
  store <8 x i16> %wide.load7.10, ptr %46, align 2, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %1, i64 352
  %48 = getelementptr inbounds i8, ptr %1, i64 368
  %wide.load.11 = load <8 x i16>, ptr %47, align 2, !tbaa !5
  %wide.load7.11 = load <8 x i16>, ptr %48, align 2, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %0, i64 352
  %50 = getelementptr inbounds i8, ptr %0, i64 368
  store <8 x i16> %wide.load.11, ptr %49, align 2, !tbaa !5
  store <8 x i16> %wide.load7.11, ptr %50, align 2, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %1, i64 384
  %52 = getelementptr inbounds i8, ptr %1, i64 400
  %wide.load.12 = load <8 x i16>, ptr %51, align 2, !tbaa !5
  %wide.load7.12 = load <8 x i16>, ptr %52, align 2, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %0, i64 384
  %54 = getelementptr inbounds i8, ptr %0, i64 400
  store <8 x i16> %wide.load.12, ptr %53, align 2, !tbaa !5
  store <8 x i16> %wide.load7.12, ptr %54, align 2, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %1, i64 416
  %56 = getelementptr inbounds i8, ptr %1, i64 432
  %wide.load.13 = load <8 x i16>, ptr %55, align 2, !tbaa !5
  %wide.load7.13 = load <8 x i16>, ptr %56, align 2, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %0, i64 416
  %58 = getelementptr inbounds i8, ptr %0, i64 432
  store <8 x i16> %wide.load.13, ptr %57, align 2, !tbaa !5
  store <8 x i16> %wide.load7.13, ptr %58, align 2, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %1, i64 448
  %60 = getelementptr inbounds i8, ptr %1, i64 464
  %wide.load.14 = load <8 x i16>, ptr %59, align 2, !tbaa !5
  %wide.load7.14 = load <8 x i16>, ptr %60, align 2, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %0, i64 448
  %62 = getelementptr inbounds i8, ptr %0, i64 464
  store <8 x i16> %wide.load.14, ptr %61, align 2, !tbaa !5
  store <8 x i16> %wide.load7.14, ptr %62, align 2, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %1, i64 480
  %64 = getelementptr inbounds i8, ptr %1, i64 496
  %wide.load.15 = load <8 x i16>, ptr %63, align 2, !tbaa !5
  %wide.load7.15 = load <8 x i16>, ptr %64, align 2, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %0, i64 480
  %66 = getelementptr inbounds i8, ptr %0, i64 496
  store <8 x i16> %wide.load.15, ptr %65, align 2, !tbaa !5
  store <8 x i16> %wide.load7.15, ptr %66, align 2, !tbaa !5
  br label %middle.block

scalar.ph:                                        ; preds = %vector.memcheck, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ 0, %vector.memcheck ]
  %67 = getelementptr inbounds i16, ptr %1, i64 %indvars.iv
  %68 = load i16, ptr %67, align 2, !tbaa !5
  %69 = getelementptr inbounds i16, ptr %0, i64 %indvars.iv
  store i16 %68, ptr %69, align 2, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %70 = getelementptr inbounds i16, ptr %1, i64 %indvars.iv.next
  %71 = load i16, ptr %70, align 2, !tbaa !5
  %72 = getelementptr inbounds i16, ptr %0, i64 %indvars.iv.next
  store i16 %71, ptr %72, align 2, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %73 = getelementptr inbounds i16, ptr %1, i64 %indvars.iv.next.1
  %74 = load i16, ptr %73, align 2, !tbaa !5
  %75 = getelementptr inbounds i16, ptr %0, i64 %indvars.iv.next.1
  store i16 %74, ptr %75, align 2, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %76 = getelementptr inbounds i16, ptr %1, i64 %indvars.iv.next.2
  %77 = load i16, ptr %76, align 2, !tbaa !5
  %78 = getelementptr inbounds i16, ptr %0, i64 %indvars.iv.next.2
  store i16 %77, ptr %78, align 2, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 256
  br i1 %exitcond.not.3, label %middle.block, label %scalar.ph, !llvm.loop !9

middle.block:                                     ; preds = %scalar.ph, %vector.body
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass