; LLVM IR from ARMmbed/mbed-crypto :: library (ccm)

; 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

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) #1

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

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

27:                                               ; preds = %10
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load i64, ptr %13, align 8, !tbaa !9
  %47 = load ptr, ptr %14, align 8, !tbaa !5
  %48 = load i64, ptr %15, align 8, !tbaa !9
  %49 = load ptr, ptr %16, align 8, !tbaa !5
  %50 = load i64, ptr %17, align 8, !tbaa !9
  %51 = load ptr, ptr %18, align 8, !tbaa !5
  %52 = load ptr, ptr %19, align 8, !tbaa !5
  %53 = getelementptr inbounds [16 x i8], ptr %23, i64 0, i64 0
  %54 = load i64, ptr %21, align 8, !tbaa !9
  %55 = call i32 @ccm_auth_crypt(ptr noundef %45, i32 noundef 1, i64 noundef %46, ptr noundef %47, i64 noundef %48, ptr noundef %49, i64 noundef %50, ptr noundef %51, ptr noundef %52, ptr noundef %53, i64 noundef %54)
  store i32 %55, ptr %22, align 4, !tbaa !11
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %44
  %58 = load i32, ptr %22, align 4, !tbaa !11
  store i32 %58, ptr %11, align 4
  store i32 1, ptr %26, align 4
  br label %90

59:                                               ; preds = %44
  store i32 0, ptr %25, align 4, !tbaa !11
  store i8 0, ptr %24, align 1, !tbaa !13
  br label %60

60:                                               ; preds = %80, %59
  %61 = load i8, ptr %24, align 1, !tbaa !13
  %62 = zext i8 %61 to i64
  %63 = load i64, ptr %21, align 8, !tbaa !9
  %64 = icmp ult i64 %62, %63
  br i1 %64, label %65, label %83

65:                                               ; preds = %60
  %66 = load ptr, ptr %20, align 8, !tbaa !5
  %67 = load i8, ptr %24, align 1, !tbaa !13
  %68 = zext i8 %67 to i64
  %69 = getelementptr inbounds i8, ptr %66, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !13
  %71 = zext i8 %70 to i32
  %72 = load i8, ptr %24, align 1, !tbaa !13
  %73 = zext i8 %72 to i64
  %74 = getelementptr inbounds [16 x i8], ptr %23, i64 0, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !13
  %76 = zext i8 %75 to i32
  %77 = xor i32 %71, %76
  %78 = load i32, ptr %25, align 4, !tbaa !11
  %79 = or i32 %78, %77
  store i32 %79, ptr %25, align 4, !tbaa !11
  br label %80

80:                                               ; preds = %65
  %81 = load i8, ptr %24, align 1, !tbaa !13
  %82 = add i8 %81, 1
  store i8 %82, ptr %24, align 1, !tbaa !13
  br label %60, !llvm.loop !14

83:                                               ; preds = %60
  %84 = load i32, ptr %25, align 4, !tbaa !11
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %89

86:                                               ; preds = %83
  %87 = load ptr, ptr %19, align 8, !tbaa !5
  %88 = load i64, ptr %13, align 8, !tbaa !9
  call void @mbedtls_platform_zeroize(ptr noundef %87, i64 noundef %88)
  store i32 -15, ptr %11, align 4
  store i32 1, ptr %26, align 4
  br label %90

89:                                               ; preds = %83
  store i32 0, ptr %11, align 4
  store i32 1, ptr %26, align 4
  br label %90

90:                                               ; preds = %89, %86, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  %91 = load i32, ptr %11, align 4
  ret i32 %91
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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, !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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_ccm_star_auth_decrypt(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, ptr noundef %7, ptr nocapture noundef readonly %8, i64 noundef %9) local_unnamed_addr #2 {
  %11 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %11) #4
  %12 = call i32 @ccm_auth_crypt(ptr noundef %0, i32 noundef 1, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef nonnull %11, i64 noundef %9)
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %.preheader, label %._crit_edge.thread

.preheader:                                       ; preds = %10
  %.not27 = icmp eq i64 %9, 0
  br i1 %.not27, label %._crit_edge.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %min.iters.check = icmp ult i64 %9, 8
  br i1 %min.iters.check, label %.lr.ph.preheader34, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph.preheader
  %13 = add i64 %9, -1
  %14 = and i64 %13, 255
  %15 = icmp eq i64 %14, 255
  %16 = icmp ugt i64 %13, 255
  %17 = or i1 %15, %16
  br i1 %17, label %.lr.ph.preheader34, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %9, 504
  %ind.end = trunc i64 %n.vec to i8
  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 ], [ %26, %vector.body ]
  %vec.phi30 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %27, %vector.body ]
  %18 = getelementptr inbounds i8, ptr %8, i64 %index
  %19 = getelementptr inbounds i8, ptr %18, i64 4
  %wide.load = load <4 x i8>, ptr %18, align 1, !tbaa !5
  %wide.load31 = load <4 x i8>, ptr %19, align 1, !tbaa !5
  %20 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %index
  %21 = getelementptr inbounds i8, ptr %20, i64 4
  %wide.load32 = load <4 x i8>, ptr %20, align 8, !tbaa !5
  %wide.load33 = load <4 x i8>, ptr %21, align 4, !tbaa !5
  %22 = xor <4 x i8> %wide.load32, %wide.load
  %23 = xor <4 x i8> %wide.load33, %wide.load31
  %24 = zext <4 x i8> %22 to <4 x i32>
  %25 = zext <4 x i8> %23 to <4 x i32>
  %26 = or <4 x i32> %vec.phi, %24
  %27 = or <4 x i32> %vec.phi30, %25
  %index.next = add nuw i64 %index, 8
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %bin.rdx = or <4 x i32> %27, %26
  %29 = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %9
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader34

.lr.ph.preheader34:                               ; preds = %middle.block, %vector.scevcheck, %.lr.ph.preheader
  %.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %.026.ph = phi i32 [ 0, %vector.scevcheck ], [ 0, %.lr.ph.preheader ], [ %29, %middle.block ]
  %.02025.ph = phi i8 [ 0, %vector.scevcheck ], [ 0, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader34, %.lr.ph
  %30 = phi i64 [ %39, %.lr.ph ], [ %.ph, %.lr.ph.preheader34 ]
  %.026 = phi i32 [ %37, %.lr.ph ], [ %.026.ph, %.lr.ph.preheader34 ]
  %.02025 = phi i8 [ %38, %.lr.ph ], [ %.02025.ph, %.lr.ph.preheader34 ]
  %31 = getelementptr inbounds i8, ptr %8, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %30
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %35 = xor i8 %34, %32
  %36 = zext i8 %35 to i32
  %37 = or i32 %.026, %36
  %38 = add i8 %.02025, 1
  %39 = zext i8 %38 to i64
  %40 = icmp ult i64 %39, %9
  br i1 %40, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %middle.block
  %.lcssa = phi i32 [ %29, %middle.block ], [ %37, %.lr.ph ]
  %41 = icmp eq i32 %.lcssa, 0
  br i1 %41, label %._crit_edge.thread, label %42

42:                                               ; preds = %._crit_edge
  call void @mbedtls_platform_zeroize(ptr noundef %7, i64 noundef %1) #4
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge, %10, %42
  %.021 = phi i32 [ -15, %42 ], [ %12, %10 ], [ 0, %._crit_edge ], [ 0, %.preheader ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %11) #4
  ret i32 %.021
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"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}


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