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

12:                                               ; preds = %15, %5
  %13 = load i32, ptr %10, align 4, !tbaa !11
  %14 = icmp ugt i32 %13, 0
  br i1 %14, label %15, label %29

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

29:                                               ; preds = %12
  %30 = load i32, ptr %11, align 4, !tbaa !11
  %31 = sub nsw i32 %30, 1
  %32 = ashr i32 %31, 8
  store i32 %32, ptr %11, align 4, !tbaa !11
  br label %33

33:                                               ; preds = %36, %29
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = icmp ugt i64 %34, 0
  br i1 %35, label %36, label %46

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

46:                                               ; preds = %33
  %47 = load i32, ptr %11, align 4, !tbaa !11
  %48 = xor i32 %47, -1
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret i32 %48
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 range(i32 -1, 1) i32 @aead_check_tag(ptr nocapture noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, i32 noundef %4) local_unnamed_addr #0 {
  %.not16 = icmp eq i32 %4, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph.preheader

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

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %6, 4294967288
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end = sub i32 %4, %.cast
  %ind.end27 = getelementptr i8, ptr %3, i64 %n.vec
  %ind.end29 = 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 ], [ %13, %vector.body ]
  %vec.phi31 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %14, %vector.body ]
  %next.gep = getelementptr i8, ptr %3, i64 %index
  %next.gep33 = getelementptr i8, ptr %2, i64 %index
  %7 = getelementptr i8, ptr %next.gep33, i64 4
  %wide.load = load <4 x i8>, ptr %next.gep33, align 1, !tbaa !5
  %wide.load35 = load <4 x i8>, ptr %7, align 1, !tbaa !5
  %8 = getelementptr i8, ptr %next.gep, i64 4
  %wide.load36 = load <4 x i8>, ptr %next.gep, align 1, !tbaa !5
  %wide.load37 = load <4 x i8>, ptr %8, align 1, !tbaa !5
  %9 = xor <4 x i8> %wide.load36, %wide.load
  %10 = xor <4 x i8> %wide.load37, %wide.load35
  %11 = zext <4 x i8> %9 to <4 x i32>
  %12 = zext <4 x i8> %10 to <4 x i32>
  %13 = or <4 x i32> %vec.phi, %11
  %14 = or <4 x i32> %vec.phi31, %12
  %index.next = add nuw i64 %index, 8
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !8

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

.lr.ph.preheader69:                               ; preds = %middle.block, %.lr.ph.preheader
  %.020.ph = phi i32 [ 0, %.lr.ph.preheader ], [ %16, %middle.block ]
  %.01019.ph = phi i32 [ %4, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01118.ph = phi ptr [ %3, %.lr.ph.preheader ], [ %ind.end27, %middle.block ]
  %.01217.ph = phi ptr [ %2, %.lr.ph.preheader ], [ %ind.end29, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader69, %.lr.ph
  %.020 = phi i32 [ %23, %.lr.ph ], [ %.020.ph, %.lr.ph.preheader69 ]
  %.01019 = phi i32 [ %24, %.lr.ph ], [ %.01019.ph, %.lr.ph.preheader69 ]
  %.01118 = phi ptr [ %19, %.lr.ph ], [ %.01118.ph, %.lr.ph.preheader69 ]
  %.01217 = phi ptr [ %17, %.lr.ph ], [ %.01217.ph, %.lr.ph.preheader69 ]
  %17 = getelementptr inbounds i8, ptr %.01217, i64 1
  %18 = load i8, ptr %.01217, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.01118, i64 1
  %20 = load i8, ptr %.01118, align 1, !tbaa !5
  %21 = xor i8 %20, %18
  %22 = zext i8 %21 to i32
  %23 = or i32 %.020, %22
  %24 = add i32 %.01019, -1
  %.not = icmp eq i32 %24, 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 [ %16, %middle.block ], [ %23, %.lr.ph ]
  %25 = add nsw i32 %.lcssa, -1
  %26 = ashr i32 %25, 8
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %5
  %.0.lcssa = phi i32 [ -1, %5 ], [ %26, %._crit_edge.loopexit ]
  %.not1521 = icmp eq i64 %1, 0
  br i1 %.not1521, label %._crit_edge26, label %iter.check

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

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

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

vector.body46:                                    ; preds = %vector.body46, %vector.ph43
  %index47 = phi i64 [ 0, %vector.ph43 ], [ %index.next52, %vector.body46 ]
  %next.gep48 = getelementptr i8, ptr %0, i64 %index47
  %28 = getelementptr i8, ptr %next.gep48, i64 16
  %wide.load50 = load <16 x i8>, ptr %next.gep48, align 1, !tbaa !5
  %wide.load51 = load <16 x i8>, ptr %28, align 1, !tbaa !5
  %29 = and <16 x i8> %wide.load50, %broadcast.splat
  %30 = and <16 x i8> %wide.load51, %broadcast.splat
  store <16 x i8> %29, ptr %next.gep48, align 1, !tbaa !5
  store <16 x i8> %30, ptr %28, align 1, !tbaa !5
  %index.next52 = add nuw i64 %index47, 32
  %31 = icmp eq i64 %index.next52, %n.vec45
  br i1 %31, label %middle.block38, label %vector.body46, !llvm.loop !13

middle.block38:                                   ; preds = %vector.body46
  %cmp.n53 = icmp eq i64 %n.vec45, %1
  br i1 %cmp.n53, label %._crit_edge26, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block38
  %ind.end60 = getelementptr i8, ptr %0, i64 %n.vec45
  %ind.end57 = and i64 %1, 31
  %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.vec45, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec55 = and i64 %1, -8
  %ind.end56 = and i64 %1, 7
  %ind.end59 = getelementptr i8, ptr %0, i64 %n.vec55
  %broadcast.splatinsert65 = insertelement <8 x i8> poison, i8 %27, i64 0
  %broadcast.splat66 = shufflevector <8 x i8> %broadcast.splatinsert65, <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
  %index62 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next67, %vec.epilog.vector.body ]
  %next.gep63 = getelementptr i8, ptr %0, i64 %index62
  %wide.load64 = load <8 x i8>, ptr %next.gep63, align 1, !tbaa !5
  %32 = and <8 x i8> %wide.load64, %broadcast.splat66
  store <8 x i8> %32, ptr %next.gep63, align 1, !tbaa !5
  %index.next67 = add nuw i64 %index62, 8
  %33 = icmp eq i64 %index.next67, %n.vec55
  br i1 %33, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !14

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

vec.epilog.scalar.ph.preheader:                   ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.01323.ph = phi i64 [ %1, %iter.check ], [ %ind.end57, %vec.epilog.iter.check ], [ %ind.end56, %vec.epilog.middle.block ]
  %.01422.ph = phi ptr [ %0, %iter.check ], [ %ind.end60, %vec.epilog.iter.check ], [ %ind.end59, %vec.epilog.middle.block ]
  br label %vec.epilog.scalar.ph

vec.epilog.scalar.ph:                             ; preds = %vec.epilog.scalar.ph.preheader, %vec.epilog.scalar.ph
  %.01323 = phi i64 [ %37, %vec.epilog.scalar.ph ], [ %.01323.ph, %vec.epilog.scalar.ph.preheader ]
  %.01422 = phi ptr [ %34, %vec.epilog.scalar.ph ], [ %.01422.ph, %vec.epilog.scalar.ph.preheader ]
  %34 = getelementptr inbounds i8, ptr %.01422, i64 1
  %35 = load i8, ptr %.01422, align 1, !tbaa !5
  %36 = and i8 %35, %27
  store i8 %36, ptr %.01422, align 1, !tbaa !5
  %37 = add i64 %.01323, -1
  %.not15 = icmp eq i64 %37, 0
  br i1 %.not15, label %._crit_edge26, label %vec.epilog.scalar.ph, !llvm.loop !15

._crit_edge26:                                    ; preds = %vec.epilog.scalar.ph, %middle.block38, %vec.epilog.middle.block, %._crit_edge
  %38 = xor i32 %.0.lcssa, -1
  ret i32 %38
}

; 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,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass