; LLVM IR from pms67/HadesFCS :: Communication/UAVDataLink (UAVDataLink)

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

7:                                                ; preds = %25, %2
  %8 = load i8, ptr %6, align 1, !tbaa !9
  %9 = zext i8 %8 to i32
  %10 = load i8, ptr %4, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = icmp slt i32 %9, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  br label %28

14:                                               ; preds = %7
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load i8, ptr %6, align 1, !tbaa !9
  %17 = zext i8 %16 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = load i8, ptr %5, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = xor i32 %22, %20
  %24 = trunc i32 %23 to i8
  store i8 %24, ptr %5, align 1, !tbaa !9
  br label %25

25:                                               ; preds = %14
  %26 = load i8, ptr %6, align 1, !tbaa !9
  %27 = add i8 %26, 1
  store i8 %27, ptr %6, align 1, !tbaa !9
  br label %7, !llvm.loop !10

28:                                               ; preds = %13
  %29 = load i8, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  ret i8 %29
}

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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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: read) uwtable
define dso_local zeroext i8 @UAVDataLink_checksum(ptr nocapture noundef readonly %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %.not = icmp eq i8 %1, 0
  br i1 %.not, label %._crit_edge, label %iter.check

iter.check:                                       ; preds = %2
  %wide.trip.count = zext i8 %1 to i64
  %min.iters.check = icmp ult i8 %1, 8
  br i1 %min.iters.check, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check10 = icmp ult i8 %1, 32
  br i1 %min.iters.check10, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %wide.trip.count, 224
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %wide.load = load <16 x i8>, ptr %0, align 1, !tbaa !5
  %wide.load12 = load <16 x i8>, ptr %3, align 1, !tbaa !5
  %4 = icmp eq i64 %n.vec, 32
  br i1 %4, label %middle.block, label %vector.body.1, !llvm.loop !8

vector.body.1:                                    ; preds = %vector.ph
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %wide.load.1 = load <16 x i8>, ptr %5, align 1, !tbaa !5
  %wide.load12.1 = load <16 x i8>, ptr %6, align 1, !tbaa !5
  %7 = xor <16 x i8> %wide.load.1, %wide.load
  %8 = xor <16 x i8> %wide.load12.1, %wide.load12
  %9 = icmp eq i64 %n.vec, 64
  br i1 %9, label %middle.block, label %vector.body.2, !llvm.loop !8

vector.body.2:                                    ; preds = %vector.body.1
  %10 = getelementptr inbounds i8, ptr %0, i64 64
  %11 = getelementptr inbounds i8, ptr %0, i64 80
  %wide.load.2 = load <16 x i8>, ptr %10, align 1, !tbaa !5
  %wide.load12.2 = load <16 x i8>, ptr %11, align 1, !tbaa !5
  %12 = xor <16 x i8> %wide.load.2, %7
  %13 = xor <16 x i8> %wide.load12.2, %8
  %14 = icmp eq i64 %n.vec, 96
  br i1 %14, label %middle.block, label %vector.body.3, !llvm.loop !8

vector.body.3:                                    ; preds = %vector.body.2
  %15 = getelementptr inbounds i8, ptr %0, i64 96
  %16 = getelementptr inbounds i8, ptr %0, i64 112
  %wide.load.3 = load <16 x i8>, ptr %15, align 1, !tbaa !5
  %wide.load12.3 = load <16 x i8>, ptr %16, align 1, !tbaa !5
  %17 = xor <16 x i8> %wide.load.3, %12
  %18 = xor <16 x i8> %wide.load12.3, %13
  %19 = icmp eq i64 %n.vec, 128
  br i1 %19, label %middle.block, label %vector.body.4, !llvm.loop !8

vector.body.4:                                    ; preds = %vector.body.3
  %20 = getelementptr inbounds i8, ptr %0, i64 128
  %21 = getelementptr inbounds i8, ptr %0, i64 144
  %wide.load.4 = load <16 x i8>, ptr %20, align 1, !tbaa !5
  %wide.load12.4 = load <16 x i8>, ptr %21, align 1, !tbaa !5
  %22 = xor <16 x i8> %wide.load.4, %17
  %23 = xor <16 x i8> %wide.load12.4, %18
  %24 = icmp eq i64 %n.vec, 160
  br i1 %24, label %middle.block, label %vector.body.5, !llvm.loop !8

vector.body.5:                                    ; preds = %vector.body.4
  %25 = getelementptr inbounds i8, ptr %0, i64 160
  %26 = getelementptr inbounds i8, ptr %0, i64 176
  %wide.load.5 = load <16 x i8>, ptr %25, align 1, !tbaa !5
  %wide.load12.5 = load <16 x i8>, ptr %26, align 1, !tbaa !5
  %27 = xor <16 x i8> %wide.load.5, %22
  %28 = xor <16 x i8> %wide.load12.5, %23
  %29 = icmp eq i64 %n.vec, 192
  br i1 %29, label %middle.block, label %vector.body.6, !llvm.loop !8

vector.body.6:                                    ; preds = %vector.body.5
  %30 = getelementptr inbounds i8, ptr %0, i64 192
  %31 = getelementptr inbounds i8, ptr %0, i64 208
  %wide.load.6 = load <16 x i8>, ptr %30, align 1, !tbaa !5
  %wide.load12.6 = load <16 x i8>, ptr %31, align 1, !tbaa !5
  %32 = xor <16 x i8> %wide.load.6, %27
  %33 = xor <16 x i8> %wide.load12.6, %28
  br label %middle.block

middle.block:                                     ; preds = %vector.body.6, %vector.body.5, %vector.body.4, %vector.body.3, %vector.body.2, %vector.body.1, %vector.ph
  %.lcssa23 = phi <16 x i8> [ %wide.load, %vector.ph ], [ %7, %vector.body.1 ], [ %12, %vector.body.2 ], [ %17, %vector.body.3 ], [ %22, %vector.body.4 ], [ %27, %vector.body.5 ], [ %32, %vector.body.6 ]
  %.lcssa22 = phi <16 x i8> [ %wide.load12, %vector.ph ], [ %8, %vector.body.1 ], [ %13, %vector.body.2 ], [ %18, %vector.body.3 ], [ %23, %vector.body.4 ], [ %28, %vector.body.5 ], [ %33, %vector.body.6 ]
  %bin.rdx = xor <16 x i8> %.lcssa22, %.lcssa23
  %34 = tail call i8 @llvm.vector.reduce.xor.v16i8(<16 x i8> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %n.vec.remaining = and i64 %wide.trip.count, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %indvars.iv.ph = phi i64 [ 0, %iter.check ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec14, %vec.epilog.middle.block ]
  %.067.ph = phi i8 [ 0, %iter.check ], [ %34, %vec.epilog.iter.check ], [ %39, %vec.epilog.middle.block ]
  br label %.lr.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %bc.merge.rdx = phi i8 [ %34, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec14 = and i64 %wide.trip.count, 248
  %35 = insertelement <8 x i8> <i8 poison, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>, i8 %bc.merge.rdx, i64 0
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index15 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next18, %vec.epilog.vector.body ]
  %vec.phi16 = phi <8 x i8> [ %35, %vec.epilog.ph ], [ %37, %vec.epilog.vector.body ]
  %36 = getelementptr inbounds i8, ptr %0, i64 %index15
  %wide.load17 = load <8 x i8>, ptr %36, align 1, !tbaa !5
  %37 = xor <8 x i8> %wide.load17, %vec.phi16
  %index.next18 = add nuw i64 %index15, 8
  %38 = icmp eq i64 %index.next18, %n.vec14
  br i1 %38, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !12

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %39 = tail call i8 @llvm.vector.reduce.xor.v8i8(<8 x i8> %37)
  %cmp.n19 = icmp eq i64 %n.vec14, %wide.trip.count
  br i1 %cmp.n19, label %._crit_edge, label %.lr.ph.preheader

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %vec.epilog.middle.block, %2
  %.06.lcssa = phi i8 [ 0, %2 ], [ %34, %middle.block ], [ %39, %vec.epilog.middle.block ], [ %42, %.lr.ph ]
  ret i8 %.06.lcssa

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader ]
  %.067 = phi i8 [ %42, %.lr.ph ], [ %.067.ph, %.lr.ph.preheader ]
  %40 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %41 = load i8, ptr %40, align 1, !tbaa !5
  %42 = xor i8 %41, %.067
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

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

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

attributes #0 = { nofree norecurse nosync nounwind 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/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, !11}
!13 = distinct !{!13, !9, !11, !10}


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