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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_gcm_auth_decrypt(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8, ptr noundef %9) #1 {
  %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 i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i32, align 4
  %23 = alloca [16 x i8], align 16
  %24 = alloca i64, align 8
  %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 i64 %7, ptr %19, align 8, !tbaa !9
  store ptr %8, ptr %20, align 8, !tbaa !5
  store ptr %9, ptr %21, align 8, !tbaa !5
  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 8, 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 %20, align 8, !tbaa !5
  %52 = load ptr, ptr %21, align 8, !tbaa !5
  %53 = load i64, ptr %19, align 8, !tbaa !9
  %54 = getelementptr inbounds [16 x i8], ptr %23, i64 0, i64 0
  %55 = call i32 @mbedtls_gcm_crypt_and_tag(ptr noundef %45, i32 noundef 0, i64 noundef %46, ptr noundef %47, i64 noundef %48, ptr noundef %49, i64 noundef %50, ptr noundef %51, ptr noundef %52, i64 noundef %53, ptr 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 %87

59:                                               ; preds = %44
  store i32 0, ptr %25, align 4, !tbaa !11
  store i64 0, ptr %24, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %77, %59
  %61 = load i64, ptr %24, align 8, !tbaa !9
  %62 = load i64, ptr %19, align 8, !tbaa !9
  %63 = icmp ult i64 %61, %62
  br i1 %63, label %64, label %80

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

77:                                               ; preds = %64
  %78 = load i64, ptr %24, align 8, !tbaa !9
  %79 = add i64 %78, 1
  store i64 %79, ptr %24, align 8, !tbaa !9
  br label %60, !llvm.loop !14

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

83:                                               ; preds = %80
  %84 = load ptr, ptr %21, align 8, !tbaa !5
  %85 = load i64, ptr %13, align 8, !tbaa !9
  call void @mbedtls_platform_zeroize(ptr noundef %84, i64 noundef %85)
  store i32 -18, ptr %11, align 4
  store i32 1, ptr %26, align 4
  br label %87

86:                                               ; preds = %80
  store i32 0, ptr %11, align 4
  store i32 1, ptr %26, align 4
  br label %87

87:                                               ; preds = %86, %83, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  %88 = load i32, ptr %11, align 4
  ret i32 %88
}

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

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 = { "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

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

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

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

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

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %7, -8
  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 ], [ %21, %vector.body ]
  %vec.phi28 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %22, %vector.body ]
  %13 = getelementptr inbounds i8, ptr %6, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %wide.load = load <4 x i8>, ptr %13, align 1, !tbaa !5
  %wide.load29 = load <4 x i8>, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 4
  %wide.load30 = load <4 x i8>, ptr %15, align 8, !tbaa !5
  %wide.load31 = load <4 x i8>, ptr %16, align 4, !tbaa !5
  %17 = xor <4 x i8> %wide.load30, %wide.load
  %18 = xor <4 x i8> %wide.load31, %wide.load29
  %19 = zext <4 x i8> %17 to <4 x i32>
  %20 = zext <4 x i8> %18 to <4 x i32>
  %21 = or <4 x i32> %vec.phi, %19
  %22 = or <4 x i32> %vec.phi28, %20
  %index.next = add nuw i64 %index, 8
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %bin.rdx = or <4 x i32> %22, %21
  %24 = 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, label %.lr.ph.preheader32

.lr.ph.preheader32:                               ; preds = %middle.block, %.lr.ph.preheader
  %.025.ph = phi i32 [ 0, %.lr.ph.preheader ], [ %24, %middle.block ]
  %.02024.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader32, %.lr.ph
  %.025 = phi i32 [ %31, %.lr.ph ], [ %.025.ph, %.lr.ph.preheader32 ]
  %.02024 = phi i64 [ %32, %.lr.ph ], [ %.02024.ph, %.lr.ph.preheader32 ]
  %25 = getelementptr inbounds i8, ptr %6, i64 %.02024
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %.02024
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = xor i8 %28, %26
  %30 = zext i8 %29 to i32
  %31 = or i32 %.025, %30
  %32 = add nuw i64 %.02024, 1
  %exitcond.not = icmp eq i64 %32, %7
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %middle.block
  %.lcssa = phi i32 [ %24, %middle.block ], [ %31, %.lr.ph ]
  %33 = icmp eq i32 %.lcssa, 0
  br i1 %33, label %._crit_edge.thread, label %34

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

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

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

; 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 = { 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 = { "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, !11, !10}


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