; LLVM IR from IanHarvey/minicrypt :: src (aesccm_mini)

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

%struct.AESCCMMini_ctx = type { %struct.AESMini_ctx, i32, i32 }
%struct.AESMini_ctx = type { %struct.AESMini_keys, %struct.AESMini_keys }
%struct.AESMini_keys = type { i32, [60 x i32] }

; 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
declare dso_local i32 @AESCCMMini_DecryptLength(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @AESCCM_common(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @AESCCMMini_Decrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i8, align 1
  %14 = alloca [16 x i8], align 16
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = call i32 @AESCCMMini_DecryptLength(ptr noundef %18, i64 noundef %19, ptr noundef %12)
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %26, label %22

22:                                               ; preds = %5
  %23 = load i64, ptr %12, align 8, !tbaa !9
  %24 = load i64, ptr %11, align 8, !tbaa !9
  %25 = icmp ne i64 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %22, %5
  store i32 2, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %87

27:                                               ; preds = %22
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.AESCCMMini_ctx, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = sub i32 15, %33
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %30, i64 %35
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load i64, ptr %11, align 8, !tbaa !9
  %39 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %40 = call i32 @AESCCM_common(ptr noundef %28, ptr noundef %29, ptr noundef %36, ptr noundef %37, i64 noundef %38, ptr noundef %39, i32 noundef 1)
  store i32 %40, ptr %15, align 4, !tbaa !16
  %41 = load i32, ptr %15, align 4, !tbaa !16
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %27
  %44 = load i32, ptr %15, align 4, !tbaa !16
  store i32 %44, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %87

45:                                               ; preds = %27
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.AESCCMMini_ctx, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !11
  %50 = sub i32 15, %49
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %46, i64 %51
  %53 = load i64, ptr %11, align 8, !tbaa !9
  %54 = getelementptr inbounds i8, ptr %52, i64 %53
  store ptr %54, ptr %8, align 8, !tbaa !5
  store i8 0, ptr %13, align 1, !tbaa !17
  store i32 0, ptr %16, align 4, !tbaa !16
  br label %55

55:                                               ; preds = %78, %45
  %56 = load i32, ptr %16, align 4, !tbaa !16
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.AESCCMMini_ctx, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !18
  %60 = icmp ult i32 %56, %59
  br i1 %60, label %61, label %81

61:                                               ; preds = %55
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load i32, ptr %16, align 4, !tbaa !16
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !17
  %67 = zext i8 %66 to i32
  %68 = load i32, ptr %16, align 4, !tbaa !16
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !17
  %72 = zext i8 %71 to i32
  %73 = xor i32 %67, %72
  %74 = load i8, ptr %13, align 1, !tbaa !17
  %75 = zext i8 %74 to i32
  %76 = or i32 %75, %73
  %77 = trunc i32 %76 to i8
  store i8 %77, ptr %13, align 1, !tbaa !17
  br label %78

78:                                               ; preds = %61
  %79 = load i32, ptr %16, align 4, !tbaa !16
  %80 = add i32 %79, 1
  store i32 %80, ptr %16, align 4, !tbaa !16
  br label %55, !llvm.loop !19

81:                                               ; preds = %55
  %82 = load i8, ptr %13, align 1, !tbaa !17
  %83 = zext i8 %82 to i32
  %84 = icmp eq i32 %83, 0
  %85 = zext i1 %84 to i64
  %86 = select i1 %84, i32 0, i32 1
  store i32 %86, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %87

87:                                               ; preds = %81, %43, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %88 = load i32, ptr %6, align 4
  ret i32 %88
}

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", !7, i64 0}
!11 = !{!12, !15, i64 488}
!12 = !{!"", !13, i64 0, !15, i64 488, !15, i64 492}
!13 = !{!"", !14, i64 0, !14, i64 244}
!14 = !{!"", !15, i64 0, !7, i64 4}
!15 = !{!"int", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!12, !15, i64 492}
!19 = distinct !{!19, !20}
!20 = !{!"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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @AESCCMMini_DecryptLength(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @AESCCM_common(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @AESCCMMini_Decrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #1 {
  %6 = alloca i64, align 8
  %7 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #3
  %8 = call i32 @AESCCMMini_DecryptLength(ptr noundef %0, i64 noundef %2, ptr noundef nonnull %6)
  %.not = icmp eq i32 %8, 0
  %9 = load i64, ptr %6, align 8
  %.not26 = icmp eq i64 %9, %4
  %or.cond = select i1 %.not, i1 %.not26, i1 false
  br i1 %or.cond, label %10, label %._crit_edge

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %0, i64 488
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sub i32 15, %12
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %1, i64 %14
  %16 = call i32 @AESCCM_common(ptr noundef %0, ptr noundef %1, ptr noundef %15, ptr noundef %3, i64 noundef %4, ptr noundef nonnull %7, i32 noundef 1)
  %.not27 = icmp eq i32 %16, 0
  br i1 %.not27, label %17, label %._crit_edge

17:                                               ; preds = %10
  %18 = load i32, ptr %11, align 4, !tbaa !5
  %19 = sub i32 15, %18
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %1, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 %4
  %23 = getelementptr inbounds i8, ptr %0, i64 492
  %24 = load i32, ptr %23, align 4, !tbaa !12
  %.not30 = icmp eq i32 %24, 0
  br i1 %.not30, label %._crit_edge, label %iter.check

iter.check:                                       ; preds = %17
  %wide.trip.count = zext i32 %24 to i64
  %min.iters.check = icmp ult i32 %24, 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.check31 = icmp ult i32 %24, 32
  br i1 %min.iters.check31, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %wide.trip.count, 4294967264
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <16 x i8> [ zeroinitializer, %vector.ph ], [ %31, %vector.body ]
  %vec.phi32 = phi <16 x i8> [ zeroinitializer, %vector.ph ], [ %32, %vector.body ]
  %25 = getelementptr inbounds i8, ptr %22, i64 %index
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %wide.load = load <16 x i8>, ptr %25, align 1, !tbaa !13
  %wide.load33 = load <16 x i8>, ptr %26, align 1, !tbaa !13
  %27 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 %index
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %wide.load34 = load <16 x i8>, ptr %27, align 16, !tbaa !13
  %wide.load35 = load <16 x i8>, ptr %28, align 16, !tbaa !13
  %29 = xor <16 x i8> %wide.load34, %wide.load
  %30 = xor <16 x i8> %wide.load35, %wide.load33
  %31 = or <16 x i8> %29, %vec.phi
  %32 = or <16 x i8> %30, %vec.phi32
  %index.next = add nuw i64 %index, 32
  %33 = icmp eq i64 %index.next, %n.vec
  br i1 %33, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %bin.rdx = or <16 x i8> %32, %31
  %34 = call i8 @llvm.vector.reduce.or.v16i8(<16 x i8> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge.loopexit, 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

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.vec37 = and i64 %wide.trip.count, 4294967288
  %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
  %index38 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next42, %vec.epilog.vector.body ]
  %vec.phi39 = phi <8 x i8> [ %35, %vec.epilog.ph ], [ %39, %vec.epilog.vector.body ]
  %36 = getelementptr inbounds i8, ptr %22, i64 %index38
  %wide.load40 = load <8 x i8>, ptr %36, align 1, !tbaa !13
  %37 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 %index38
  %wide.load41 = load <8 x i8>, ptr %37, align 8, !tbaa !13
  %38 = xor <8 x i8> %wide.load41, %wide.load40
  %39 = or <8 x i8> %38, %vec.phi39
  %index.next42 = add nuw i64 %index38, 8
  %40 = icmp eq i64 %index.next42, %n.vec37
  br i1 %40, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !18

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

.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.vec37, %vec.epilog.middle.block ]
  %.02328.ph = phi i8 [ 0, %iter.check ], [ %34, %vec.epilog.iter.check ], [ %41, %vec.epilog.middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader ]
  %.02328 = phi i8 [ %47, %.lr.ph ], [ %.02328.ph, %.lr.ph.preheader ]
  %42 = getelementptr inbounds i8, ptr %22, i64 %indvars.iv
  %43 = load i8, ptr %42, align 1, !tbaa !13
  %44 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 %indvars.iv
  %45 = load i8, ptr %44, align 1, !tbaa !13
  %46 = xor i8 %45, %43
  %47 = or i8 %46, %.02328
  %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.loopexit, label %.lr.ph, !llvm.loop !19

._crit_edge.loopexit:                             ; preds = %.lr.ph, %vec.epilog.middle.block, %middle.block
  %.lcssa = phi i8 [ %34, %middle.block ], [ %41, %vec.epilog.middle.block ], [ %47, %.lr.ph ]
  %48 = icmp ne i8 %.lcssa, 0
  %49 = zext i1 %48 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %17, %._crit_edge.loopexit, %10, %5
  %.022 = phi i32 [ 2, %5 ], [ %16, %10 ], [ 0, %17 ], [ %49, %._crit_edge.loopexit ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i32 %.022
}

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

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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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, !9, i64 488}
!6 = !{!"", !7, i64 0, !9, i64 488, !9, i64 492}
!7 = !{!"", !8, i64 0, !8, i64 244}
!8 = !{!"", !9, i64 0, !10, i64 4}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!6, !9, i64 492}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16, !17}
!19 = distinct !{!19, !15, !17, !16}


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