; LLVM IR from p4lang/p4c :: lib/nethash.ll (ZN2P47NetHash5xor16EPKhm)

; 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: mustprogress nounwind uwtable
define dso_local noundef zeroext i16 @_ZN2P47NetHash5xor16EPKhm(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  store i16 255, ptr %5, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #2
  store i16 0, ptr %6, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #2
  br label %10

10:                                               ; preds = %13, %2
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = icmp uge i64 %11, 2
  br i1 %12, label %13, label %46

13:                                               ; preds = %10
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !13
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !15
  %19 = zext i8 %18 to i16
  %20 = zext i16 %19 to i32
  %21 = shl i32 %20, 8
  %22 = trunc i32 %21 to i16
  store i16 %22, ptr %8, align 2, !tbaa !11
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !13
  %25 = add i32 %24, 1
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %23, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !15
  %29 = zext i8 %28 to i16
  store i16 %29, ptr %9, align 2, !tbaa !11
  %30 = load i16, ptr %6, align 2, !tbaa !11
  %31 = zext i16 %30 to i32
  %32 = load i16, ptr %8, align 2, !tbaa !11
  %33 = zext i16 %32 to i32
  %34 = load i16, ptr %9, align 2, !tbaa !11
  %35 = zext i16 %34 to i32
  %36 = load i16, ptr %5, align 2, !tbaa !11
  %37 = zext i16 %36 to i32
  %38 = and i32 %35, %37
  %39 = add nsw i32 %33, %38
  %40 = xor i32 %31, %39
  %41 = trunc i32 %40 to i16
  store i16 %41, ptr %6, align 2, !tbaa !11
  %42 = load i32, ptr %7, align 4, !tbaa !13
  %43 = add i32 %42, 2
  store i32 %43, ptr %7, align 4, !tbaa !13
  %44 = load i64, ptr %4, align 8, !tbaa !9
  %45 = sub i64 %44, 2
  store i64 %45, ptr %4, align 8, !tbaa !9
  br label %10, !llvm.loop !16

46:                                               ; preds = %10
  %47 = load i64, ptr %4, align 8, !tbaa !9
  %48 = icmp ugt i64 %47, 0
  br i1 %48, label %49, label %65

49:                                               ; preds = %46
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !13
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !15
  %55 = zext i8 %54 to i16
  %56 = zext i16 %55 to i32
  %57 = shl i32 %56, 8
  %58 = trunc i32 %57 to i16
  store i16 %58, ptr %8, align 2, !tbaa !11
  %59 = load i16, ptr %6, align 2, !tbaa !11
  %60 = zext i16 %59 to i32
  %61 = load i16, ptr %8, align 2, !tbaa !11
  %62 = zext i16 %61 to i32
  %63 = xor i32 %60, %62
  %64 = trunc i32 %63 to i16
  store i16 %64, ptr %6, align 2, !tbaa !11
  br label %65

65:                                               ; preds = %49, %46
  %66 = load i16, ptr %6, align 2, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  ret i16 %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef zeroext i16 @_ZN2P47NetHash5xor16EPKhm(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp ugt i64 %1, 1
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %4 = and i64 %1, 4294967294
  %5 = add i64 %1, -2
  %6 = lshr i64 %5, 1
  %7 = add nuw i64 %6, 1
  %8 = add i64 %1, -8589934594
  %or.cond = icmp ult i64 %8, -8589934562
  br i1 %or.cond, label %.lr.ph.preheader37, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %7, -16
  %9 = shl i64 %n.vec, 1
  %ind.end = sub i64 %1, %9
  %.cast = trunc i64 %n.vec to i32
  %ind.end27 = shl i32 %.cast, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <8 x i16> [ zeroinitializer, %vector.ph ], [ %23, %vector.body ]
  %vec.phi29 = phi <8 x i16> [ zeroinitializer, %vector.ph ], [ %24, %vector.body ]
  %.cast30 = trunc i64 %index to i32
  %offset.idx31 = shl i32 %.cast30, 1
  %10 = or disjoint i32 %offset.idx31, 16
  %11 = zext i32 %offset.idx31 to i64
  %12 = zext i32 %10 to i64
  %13 = getelementptr inbounds i8, ptr %0, i64 %11
  %14 = getelementptr inbounds i8, ptr %0, i64 %12
  %wide.vec = load <16 x i8>, ptr %13, align 1, !tbaa !5
  %wide.vec32 = load <16 x i8>, ptr %14, align 1, !tbaa !5
  %strided.vec = shufflevector <16 x i8> %wide.vec, <16 x i8> poison, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14>
  %strided.vec33 = shufflevector <16 x i8> %wide.vec32, <16 x i8> poison, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14>
  %strided.vec34 = shufflevector <16 x i8> %wide.vec, <16 x i8> poison, <8 x i32> <i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13, i32 15>
  %strided.vec35 = shufflevector <16 x i8> %wide.vec32, <16 x i8> poison, <8 x i32> <i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13, i32 15>
  %15 = zext <8 x i8> %strided.vec to <8 x i16>
  %16 = zext <8 x i8> %strided.vec33 to <8 x i16>
  %17 = shl nuw <8 x i16> %15, <i16 8, i16 8, i16 8, i16 8, i16 8, i16 8, i16 8, i16 8>
  %18 = shl nuw <8 x i16> %16, <i16 8, i16 8, i16 8, i16 8, i16 8, i16 8, i16 8, i16 8>
  %19 = zext <8 x i8> %strided.vec34 to <8 x i16>
  %20 = zext <8 x i8> %strided.vec35 to <8 x i16>
  %21 = or disjoint <8 x i16> %17, %19
  %22 = or disjoint <8 x i16> %18, %20
  %23 = xor <8 x i16> %21, %vec.phi
  %24 = xor <8 x i16> %22, %vec.phi29
  %index.next = add nuw i64 %index, 16
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %bin.rdx = xor <8 x i16> %24, %23
  %26 = tail call i16 @llvm.vector.reduce.xor.v8i16(<8 x i16> %bin.rdx)
  %cmp.n = icmp eq i64 %7, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader37

.lr.ph.preheader37:                               ; preds = %middle.block, %.lr.ph.preheader
  %.020.ph = phi i64 [ %1, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01619.ph = phi i32 [ 0, %.lr.ph.preheader ], [ %ind.end27, %middle.block ]
  %.01718.ph = phi i16 [ 0, %.lr.ph.preheader ], [ %26, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader37, %.lr.ph
  %.020 = phi i64 [ %40, %.lr.ph ], [ %.020.ph, %.lr.ph.preheader37 ]
  %.01619 = phi i32 [ %39, %.lr.ph ], [ %.01619.ph, %.lr.ph.preheader37 ]
  %.01718 = phi i16 [ %38, %.lr.ph ], [ %.01718.ph, %.lr.ph.preheader37 ]
  %27 = zext i32 %.01619 to i64
  %28 = getelementptr inbounds i8, ptr %0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = zext i8 %29 to i16
  %31 = shl nuw i16 %30, 8
  %32 = or disjoint i32 %.01619, 1
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = zext i8 %35 to i16
  %37 = or disjoint i16 %31, %36
  %38 = xor i16 %37, %.01718
  %39 = add i32 %.01619, 2
  %40 = add i64 %.020, -2
  %41 = icmp ugt i64 %40, 1
  br i1 %41, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %2
  %.017.lcssa = phi i16 [ 0, %2 ], [ %26, %middle.block ], [ %38, %.lr.ph ]
  %.016.lcssa = phi i64 [ 0, %2 ], [ %4, %middle.block ], [ %4, %.lr.ph ]
  %.0.lcssa = phi i64 [ %1, %2 ], [ %ind.end, %middle.block ], [ %40, %.lr.ph ]
  %.not = icmp eq i64 %.0.lcssa, 0
  br i1 %.not, label %48, label %42

42:                                               ; preds = %._crit_edge
  %43 = getelementptr inbounds i8, ptr %0, i64 %.016.lcssa
  %44 = load i8, ptr %43, align 1, !tbaa !5
  %45 = zext i8 %44 to i16
  %46 = shl nuw i16 %45, 8
  %47 = xor i16 %46, %.017.lcssa
  br label %48

48:                                               ; preds = %42, %._crit_edge
  %.1 = phi i16 [ %47, %42 ], [ %.017.lcssa, %._crit_edge ]
  ret i16 %.1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.vector.reduce.xor.v8i16(<8 x i16>) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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 speculatable willreturn memory(none) }

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


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