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

; 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.mbedtls_cipher_context_t = type { ptr, i32, i32, ptr, ptr, [16 x i8], i64, [16 x i8], i64, ptr, ptr }
%struct.mbedtls_cipher_info_t = type { i32, i32, i32, ptr, i32, i32, i32, ptr }
%struct.mbedtls_cmac_context_t = type { [16 x i8], [16 x i8], i64 }

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden void @cmac_xor_block(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #3

declare i32 @mbedtls_cipher_update(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_cipher_cmac_finish(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca [16 x i8], align 16
  %10 = alloca [16 x i8], align 16
  %11 = alloca [16 x i8], align 16
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 -110, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %31, label %18

18:                                               ; preds = %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = icmp eq ptr %21, null
  br i1 %22, label %31, label %23

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %24, i32 0, i32 10
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp eq ptr %26, null
  br i1 %27, label %31, label %28

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %28, %23, %18, %2
  store i32 -24832, ptr %3, align 4
  store i32 1, ptr %15, align 4
  br label %101

32:                                               ; preds = %28
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %33, i32 0, i32 10
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  store ptr %35, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mbedtls_cipher_context_t, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %struct.mbedtls_cipher_info_t, ptr %38, i32 0, i32 6
  %40 = load i32, ptr %39, align 8, !tbaa !15
  %41 = zext i32 %40 to i64
  store i64 %41, ptr %14, align 8, !tbaa !17
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.mbedtls_cmac_context_t, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds [16 x i8], ptr %43, i64 0, i64 0
  store ptr %44, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds [16 x i8], ptr %9, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %45, i64 noundef 16)
  %46 = getelementptr inbounds [16 x i8], ptr %10, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %46, i64 noundef 16)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds [16 x i8], ptr %9, i64 0, i64 0
  %49 = getelementptr inbounds [16 x i8], ptr %10, i64 0, i64 0
  %50 = call i32 @cmac_generate_subkeys(ptr noundef %47, ptr noundef %48, ptr noundef %49)
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mbedtls_cmac_context_t, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds [16 x i8], ptr %52, i64 0, i64 0
  store ptr %53, ptr %8, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.mbedtls_cmac_context_t, ptr %54, i32 0, i32 2
  %56 = load i64, ptr %55, align 8, !tbaa !18
  %57 = load i64, ptr %14, align 8, !tbaa !17
  %58 = icmp ult i64 %56, %57
  br i1 %58, label %59, label %70

59:                                               ; preds = %32
  %60 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 0
  %61 = load i64, ptr %14, align 8, !tbaa !17
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.mbedtls_cmac_context_t, ptr %63, i32 0, i32 2
  %65 = load i64, ptr %64, align 8, !tbaa !18
  call void @cmac_pad(ptr noundef %60, i64 noundef %61, ptr noundef %62, i64 noundef %65)
  %66 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 0
  %67 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 0
  %68 = getelementptr inbounds [16 x i8], ptr %10, i64 0, i64 0
  %69 = load i64, ptr %14, align 8, !tbaa !17
  call void @cmac_xor_block(ptr noundef %66, ptr noundef %67, ptr noundef %68, i64 noundef %69)
  br label %75

70:                                               ; preds = %32
  %71 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 0
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds [16 x i8], ptr %9, i64 0, i64 0
  %74 = load i64, ptr %14, align 8, !tbaa !17
  call void @cmac_xor_block(ptr noundef %71, ptr noundef %72, ptr noundef %73, i64 noundef %74)
  br label %75

75:                                               ; preds = %70, %59
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 0
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = load i64, ptr %14, align 8, !tbaa !17
  call void @cmac_xor_block(ptr noundef %76, ptr noundef %77, ptr noundef %78, i64 noundef %79)
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = load i64, ptr %14, align 8, !tbaa !17
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = call i32 @mbedtls_cipher_update(ptr noundef %80, ptr noundef %81, i64 noundef %82, ptr noundef %83, ptr noundef %13)
  store i32 %84, ptr %12, align 4, !tbaa !9
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %75
  br label %91

87:                                               ; preds = %75
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = load i64, ptr %14, align 8, !tbaa !17
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %88, ptr align 1 %89, i64 %90, i1 false)
  br label %91

91:                                               ; preds = %87, %86
  %92 = getelementptr inbounds [16 x i8], ptr %9, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %92, i64 noundef 16)
  %93 = getelementptr inbounds [16 x i8], ptr %10, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %93, i64 noundef 16)
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.mbedtls_cmac_context_t, ptr %94, i32 0, i32 2
  store i64 0, ptr %95, align 8, !tbaa !18
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.mbedtls_cmac_context_t, ptr %96, i32 0, i32 1
  %98 = getelementptr inbounds [16 x i8], ptr %97, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %98, i64 noundef 16)
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mbedtls_platform_zeroize(ptr noundef %99, i64 noundef 16)
  %100 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %100, ptr %3, align 4
  store i32 1, ptr %15, align 4
  br label %101

101:                                              ; preds = %91, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %102 = load i32, ptr %3, align 4
  ret i32 %102
}

; Function Attrs: nounwind uwtable
declare hidden i32 @cmac_generate_subkeys(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @cmac_pad(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"mbedtls_cipher_context_t", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !7, i64 32, !13, i64 48, !7, i64 56, !13, i64 72, !6, i64 80, !6, i64 88}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 88}
!15 = !{!16, !10, i64 32}
!16 = !{!"mbedtls_cipher_info_t", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40}
!17 = !{!13, !13, i64 0}
!18 = !{!19, !13, i64 32}
!19 = !{!"mbedtls_cmac_context_t", !7, i64 0, !7, i64 16, !13, i64 32}


; 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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden void @cmac_xor_block(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

declare i32 @mbedtls_cipher_update(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_cipher_cmac_finish(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #3 {
  %3 = alloca [16 x i8], align 16
  %4 = alloca [16 x i8], align 16
  %5 = alloca [16 x i8], align 16
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %7 = icmp eq ptr %0, null
  br i1 %7, label %31, label %8

8:                                                ; preds = %2
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %31, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 88
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = icmp eq ptr %13, null
  %15 = icmp eq ptr %1, null
  %or.cond = or i1 %15, %14
  br i1 %or.cond, label %31, label %16

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %9, i64 32
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = zext i32 %18 to i64
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %3, i64 noundef 16) #4
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %4, i64 noundef 16) #4
  %20 = call i32 @cmac_generate_subkeys(ptr noundef nonnull %0, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %21 = getelementptr inbounds i8, ptr %13, i64 16
  %22 = getelementptr inbounds i8, ptr %13, i64 32
  %23 = load i64, ptr %22, align 8, !tbaa !15
  %24 = icmp ult i64 %23, %19
  br i1 %24, label %25, label %26

25:                                               ; preds = %16
  call void @cmac_pad(ptr noundef nonnull %5, i64 noundef %19, ptr noundef nonnull %21, i64 noundef %23)
  call void @cmac_xor_block(ptr noundef nonnull %5, ptr noundef nonnull %5, ptr noundef nonnull %4, i64 noundef %19)
  br label %27

26:                                               ; preds = %16
  call void @cmac_xor_block(ptr noundef nonnull %5, ptr noundef nonnull %21, ptr noundef nonnull %3, i64 noundef %19)
  br label %27

27:                                               ; preds = %26, %25
  call void @cmac_xor_block(ptr noundef nonnull %13, ptr noundef nonnull %5, ptr noundef nonnull %13, i64 noundef %19)
  %28 = call i32 @mbedtls_cipher_update(ptr noundef nonnull %0, ptr noundef nonnull %13, i64 noundef %19, ptr noundef nonnull %13, ptr noundef nonnull %6) #4
  %.not = icmp eq i32 %28, 0
  br i1 %.not, label %29, label %30

29:                                               ; preds = %27
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %1, ptr nonnull align 1 %13, i64 %19, i1 false)
  br label %30

30:                                               ; preds = %27, %29
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %3, i64 noundef 16) #4
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %4, i64 noundef 16) #4
  store i64 0, ptr %22, align 8, !tbaa !15
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %21, i64 noundef 16) #4
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %13, i64 noundef 16) #4
  br label %31

31:                                               ; preds = %2, %8, %11, %30
  %.0 = phi i32 [ %28, %30 ], [ -24832, %11 ], [ -24832, %8 ], [ -24832, %2 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @cmac_generate_subkeys(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @cmac_pad(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !7, i64 0}
!6 = !{!"mbedtls_cipher_context_t", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !8, i64 32, !11, i64 48, !8, i64 56, !11, i64 72, !7, i64 80, !7, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 88}
!13 = !{!14, !10, i64 32}
!14 = !{!"mbedtls_cipher_info_t", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 40}
!15 = !{!16, !11, i64 32}
!16 = !{!"mbedtls_cmac_context_t", !8, i64 0, !8, i64 16, !11, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass