; LLVM IR from rweather/lightweight-crypto :: src/arduino/LWC_Benchmark (aead-common)

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

14:                                               ; preds = %17, %6
  %15 = load i32, ptr %11, align 4, !tbaa !11
  %16 = icmp ugt i32 %15, 0
  br i1 %16, label %17, label %31

17:                                               ; preds = %14
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i32 1
  store ptr %19, ptr %9, align 8, !tbaa !5
  %20 = load i8, ptr %18, align 1, !tbaa !13
  %21 = zext i8 %20 to i32
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i32 1
  store ptr %23, ptr %10, align 8, !tbaa !5
  %24 = load i8, ptr %22, align 1, !tbaa !13
  %25 = zext i8 %24 to i32
  %26 = xor i32 %21, %25
  %27 = load i32, ptr %13, align 4, !tbaa !11
  %28 = or i32 %27, %26
  store i32 %28, ptr %13, align 4, !tbaa !11
  %29 = load i32, ptr %11, align 4, !tbaa !11
  %30 = add i32 %29, -1
  store i32 %30, ptr %11, align 4, !tbaa !11
  br label %14, !llvm.loop !14

31:                                               ; preds = %14
  %32 = load i32, ptr %13, align 4, !tbaa !11
  %33 = sub nsw i32 %32, 1
  %34 = ashr i32 %33, 8
  %35 = load i32, ptr %12, align 4, !tbaa !11
  %36 = and i32 %34, %35
  store i32 %36, ptr %13, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %40, %31
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = icmp ugt i64 %38, 0
  br i1 %39, label %40, label %50

40:                                               ; preds = %37
  %41 = load i32, ptr %13, align 4, !tbaa !11
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = load i8, ptr %42, align 1, !tbaa !13
  %45 = zext i8 %44 to i32
  %46 = and i32 %45, %41
  %47 = trunc i32 %46 to i8
  store i8 %47, ptr %42, align 1, !tbaa !13
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = add i64 %48, -1
  store i64 %49, ptr %8, align 8, !tbaa !9
  br label %37, !llvm.loop !16

50:                                               ; preds = %37
  %51 = load i32, ptr %13, align 4, !tbaa !11
  %52 = xor i32 %51, -1
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  ret i32 %52
}

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


; 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(readwrite, inaccessiblemem: none) uwtable
define dso_local i32 @aead_check_tag_precheck(ptr nocapture noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %.not17 = icmp eq i32 %4, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %7 = zext i32 %4 to i64
  %min.iters.check = icmp ult i32 %4, 8
  br i1 %min.iters.check, label %.lr.ph.preheader70, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %7, 4294967288
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end = sub i32 %4, %.cast
  %ind.end28 = getelementptr i8, ptr %3, i64 %n.vec
  %ind.end30 = getelementptr i8, ptr %2, i64 %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %14, %vector.body ]
  %vec.phi32 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %15, %vector.body ]
  %next.gep = getelementptr i8, ptr %3, i64 %index
  %next.gep34 = getelementptr i8, ptr %2, i64 %index
  %8 = getelementptr i8, ptr %next.gep34, i64 4
  %wide.load = load <4 x i8>, ptr %next.gep34, align 1, !tbaa !5
  %wide.load36 = load <4 x i8>, ptr %8, align 1, !tbaa !5
  %9 = getelementptr i8, ptr %next.gep, i64 4
  %wide.load37 = load <4 x i8>, ptr %next.gep, align 1, !tbaa !5
  %wide.load38 = load <4 x i8>, ptr %9, align 1, !tbaa !5
  %10 = xor <4 x i8> %wide.load37, %wide.load
  %11 = xor <4 x i8> %wide.load38, %wide.load36
  %12 = zext <4 x i8> %10 to <4 x i32>
  %13 = zext <4 x i8> %11 to <4 x i32>
  %14 = or <4 x i32> %vec.phi, %12
  %15 = or <4 x i32> %vec.phi32, %13
  %index.next = add nuw i64 %index, 8
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %bin.rdx = or <4 x i32> %15, %14
  %17 = tail call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %7
  br i1 %cmp.n, label %._crit_edge.loopexit, label %.lr.ph.preheader70

.lr.ph.preheader70:                               ; preds = %middle.block, %.lr.ph.preheader
  %.021.ph = phi i32 [ 0, %.lr.ph.preheader ], [ %17, %middle.block ]
  %.01220.ph = phi i32 [ %4, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01319.ph = phi ptr [ %3, %.lr.ph.preheader ], [ %ind.end28, %middle.block ]
  %.01418.ph = phi ptr [ %2, %.lr.ph.preheader ], [ %ind.end30, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader70, %.lr.ph
  %.021 = phi i32 [ %24, %.lr.ph ], [ %.021.ph, %.lr.ph.preheader70 ]
  %.01220 = phi i32 [ %25, %.lr.ph ], [ %.01220.ph, %.lr.ph.preheader70 ]
  %.01319 = phi ptr [ %20, %.lr.ph ], [ %.01319.ph, %.lr.ph.preheader70 ]
  %.01418 = phi ptr [ %18, %.lr.ph ], [ %.01418.ph, %.lr.ph.preheader70 ]
  %18 = getelementptr inbounds i8, ptr %.01418, i64 1
  %19 = load i8, ptr %.01418, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.01319, i64 1
  %21 = load i8, ptr %.01319, align 1, !tbaa !5
  %22 = xor i8 %21, %19
  %23 = zext i8 %22 to i32
  %24 = or i32 %.021, %23
  %25 = add i32 %.01220, -1
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !12

._crit_edge.loopexit:                             ; preds = %.lr.ph, %middle.block
  %.lcssa = phi i32 [ %17, %middle.block ], [ %24, %.lr.ph ]
  %26 = add nsw i32 %.lcssa, -1
  %27 = ashr i32 %26, 8
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %6
  %.0.lcssa = phi i32 [ -1, %6 ], [ %27, %._crit_edge.loopexit ]
  %28 = and i32 %.0.lcssa, %5
  %.not1622 = icmp eq i64 %1, 0
  br i1 %.not1622, label %._crit_edge27, label %iter.check

iter.check:                                       ; preds = %._crit_edge
  %29 = trunc i32 %28 to i8
  %min.iters.check41 = icmp ult i64 %1, 8
  br i1 %min.iters.check41, label %vec.epilog.scalar.ph.preheader, label %vector.main.loop.iter.check

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

vector.ph44:                                      ; preds = %vector.main.loop.iter.check
  %n.vec46 = and i64 %1, -32
  %broadcast.splatinsert = insertelement <16 x i8> poison, i8 %29, i64 0
  %broadcast.splat = shufflevector <16 x i8> %broadcast.splatinsert, <16 x i8> poison, <16 x i32> zeroinitializer
  br label %vector.body47

vector.body47:                                    ; preds = %vector.body47, %vector.ph44
  %index48 = phi i64 [ 0, %vector.ph44 ], [ %index.next53, %vector.body47 ]
  %next.gep49 = getelementptr i8, ptr %0, i64 %index48
  %30 = getelementptr i8, ptr %next.gep49, i64 16
  %wide.load51 = load <16 x i8>, ptr %next.gep49, align 1, !tbaa !5
  %wide.load52 = load <16 x i8>, ptr %30, align 1, !tbaa !5
  %31 = and <16 x i8> %wide.load51, %broadcast.splat
  %32 = and <16 x i8> %wide.load52, %broadcast.splat
  store <16 x i8> %31, ptr %next.gep49, align 1, !tbaa !5
  store <16 x i8> %32, ptr %30, align 1, !tbaa !5
  %index.next53 = add nuw i64 %index48, 32
  %33 = icmp eq i64 %index.next53, %n.vec46
  br i1 %33, label %middle.block39, label %vector.body47, !llvm.loop !13

middle.block39:                                   ; preds = %vector.body47
  %cmp.n54 = icmp eq i64 %n.vec46, %1
  br i1 %cmp.n54, label %._crit_edge27, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block39
  %ind.end61 = and i64 %1, 31
  %ind.end58 = getelementptr i8, ptr %0, i64 %n.vec46
  %n.vec.remaining = and i64 %1, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %vec.epilog.scalar.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec46, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec56 = and i64 %1, -8
  %ind.end57 = getelementptr i8, ptr %0, i64 %n.vec56
  %ind.end60 = and i64 %1, 7
  %broadcast.splatinsert66 = insertelement <8 x i8> poison, i8 %29, i64 0
  %broadcast.splat67 = shufflevector <8 x i8> %broadcast.splatinsert66, <8 x i8> poison, <8 x i32> zeroinitializer
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index63 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next68, %vec.epilog.vector.body ]
  %next.gep64 = getelementptr i8, ptr %0, i64 %index63
  %wide.load65 = load <8 x i8>, ptr %next.gep64, align 1, !tbaa !5
  %34 = and <8 x i8> %wide.load65, %broadcast.splat67
  store <8 x i8> %34, ptr %next.gep64, align 1, !tbaa !5
  %index.next68 = add nuw i64 %index63, 8
  %35 = icmp eq i64 %index.next68, %n.vec56
  br i1 %35, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !14

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n69 = icmp eq i64 %n.vec56, %1
  br i1 %cmp.n69, label %._crit_edge27, label %vec.epilog.scalar.ph.preheader

vec.epilog.scalar.ph.preheader:                   ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.01124.ph = phi ptr [ %0, %iter.check ], [ %ind.end58, %vec.epilog.iter.check ], [ %ind.end57, %vec.epilog.middle.block ]
  %.01523.ph = phi i64 [ %1, %iter.check ], [ %ind.end61, %vec.epilog.iter.check ], [ %ind.end60, %vec.epilog.middle.block ]
  br label %vec.epilog.scalar.ph

vec.epilog.scalar.ph:                             ; preds = %vec.epilog.scalar.ph.preheader, %vec.epilog.scalar.ph
  %.01124 = phi ptr [ %36, %vec.epilog.scalar.ph ], [ %.01124.ph, %vec.epilog.scalar.ph.preheader ]
  %.01523 = phi i64 [ %39, %vec.epilog.scalar.ph ], [ %.01523.ph, %vec.epilog.scalar.ph.preheader ]
  %36 = getelementptr inbounds i8, ptr %.01124, i64 1
  %37 = load i8, ptr %.01124, align 1, !tbaa !5
  %38 = and i8 %37, %29
  store i8 %38, ptr %.01124, align 1, !tbaa !5
  %39 = add i64 %.01523, -1
  %.not16 = icmp eq i64 %39, 0
  br i1 %.not16, label %._crit_edge27, label %vec.epilog.scalar.ph, !llvm.loop !15

._crit_edge27:                                    ; preds = %vec.epilog.scalar.ph, %middle.block39, %vec.epilog.middle.block, %._crit_edge
  %40 = xor i32 %28, -1
  ret i32 %40
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32>) #1

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !11, !10}
!13 = distinct !{!13, !9, !10, !11}
!14 = distinct !{!14, !9, !10, !11}
!15 = distinct !{!15, !9, !11, !10}


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