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

; 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.psa_mac_operation_s = type { i32, i8, i8, %union.anon.1 }
%union.anon.1 = type { %struct.psa_hmac_internal_data }
%struct.psa_hmac_internal_data = type { %struct.psa_hash_operation_s, [128 x i8] }
%struct.psa_hash_operation_s = type { i32, %union.anon.0 }
%union.anon.0 = type { %struct.mbedtls_sha512_context }
%struct.mbedtls_sha512_context = type { [2 x i64], [8 x i64], [128 x i8], 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 hidden i32 @mbedtls_to_psa_error(i32 noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @psa_mac_abort(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_mac_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 -137, ptr %8, align 4, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.psa_mac_operation_s, ptr %11, i32 0, i32 1
  %13 = load i8, ptr %12, align 4
  %14 = and i8 %13, 1
  %15 = zext i8 %14 to i32
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %3
  store i32 -137, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %76

18:                                               ; preds = %3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.psa_mac_operation_s, ptr %19, i32 0, i32 1
  %21 = load i8, ptr %20, align 4
  %22 = lshr i8 %21, 1
  %23 = and i8 %22, 1
  %24 = zext i8 %23 to i32
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %35

26:                                               ; preds = %18
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.psa_mac_operation_s, ptr %27, i32 0, i32 1
  %29 = load i8, ptr %28, align 4
  %30 = lshr i8 %29, 2
  %31 = and i8 %30, 1
  %32 = zext i8 %31 to i32
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %35, label %34

34:                                               ; preds = %26
  store i32 -137, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %76

35:                                               ; preds = %26, %18
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.psa_mac_operation_s, ptr %36, i32 0, i32 1
  %38 = load i8, ptr %37, align 4
  %39 = and i8 %38, -9
  %40 = or i8 %39, 8
  store i8 %40, ptr %37, align 4
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.psa_mac_operation_s, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !13
  %44 = icmp eq i32 %43, 46137346
  br i1 %44, label %45, label %53

45:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.psa_mac_operation_s, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = call i32 @mbedtls_cipher_cmac_update(ptr noundef %47, ptr noundef %48, i64 noundef %49)
  store i32 %50, ptr %10, align 4, !tbaa !11
  %51 = load i32, ptr %10, align 4, !tbaa !11
  %52 = call i32 @mbedtls_to_psa_error(i32 noundef %51)
  store i32 %52, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %68

53:                                               ; preds = %35
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.psa_mac_operation_s, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !13
  %57 = and i32 %56, 2143289344
  %58 = icmp eq i32 %57, 41943040
  br i1 %58, label %59, label %66

59:                                               ; preds = %53
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.psa_mac_operation_s, ptr %60, i32 0, i32 3
  %62 = getelementptr inbounds %struct.psa_hmac_internal_data, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load i64, ptr %7, align 8, !tbaa !9
  %65 = call i32 @psa_hash_update(ptr noundef %62, ptr noundef %63, i64 noundef %64)
  store i32 %65, ptr %8, align 4, !tbaa !11
  br label %67

66:                                               ; preds = %53
  store i32 -137, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %76

67:                                               ; preds = %59
  br label %68

68:                                               ; preds = %67, %45
  %69 = load i32, ptr %8, align 4, !tbaa !11
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %74

71:                                               ; preds = %68
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = call i32 @psa_mac_abort(ptr noundef %72)
  br label %74

74:                                               ; preds = %71, %68
  %75 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %75, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %76

76:                                               ; preds = %74, %66, %34, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %77 = load i32, ptr %4, align 4
  ret i32 %77
}

declare i32 @mbedtls_cipher_cmac_update(ptr noundef, 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 = !{!14, !12, i64 0}
!14 = !{!"psa_mac_operation_s", !12, i64 0, !12, i64 4, !12, i64 4, !12, i64 4, !12, i64 4, !12, i64 4, !7, i64 5, !7, i64 8}


; 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: nounwind uwtable
declare hidden i32 @mbedtls_to_psa_error(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @psa_mac_abort(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_mac_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i8, ptr %4, align 4
  %6 = and i8 %5, 1
  %.not = icmp eq i8 %6, 0
  %7 = and i8 %5, 6
  %or.cond = icmp eq i8 %7, 2
  %or.cond21 = or i1 %.not, %or.cond
  br i1 %or.cond21, label %25, label %8

8:                                                ; preds = %3
  %9 = or i8 %5, 8
  store i8 %9, ptr %4, align 4
  %10 = load i32, ptr %0, align 8, !tbaa !5
  %11 = icmp eq i32 %10, 46137346
  br i1 %11, label %12, label %16

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = tail call i32 @mbedtls_cipher_cmac_update(ptr noundef nonnull %13, ptr noundef %1, i64 noundef %2) #2
  %15 = tail call i32 @mbedtls_to_psa_error(i32 noundef %14)
  br label %22

16:                                               ; preds = %8
  %17 = and i32 %10, 2143289344
  %18 = icmp eq i32 %17, 41943040
  br i1 %18, label %19, label %25

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = tail call i32 @psa_hash_update(ptr noundef nonnull %20, ptr noundef %1, i64 noundef %2)
  br label %22

22:                                               ; preds = %19, %12
  %.016 = phi i32 [ %15, %12 ], [ %21, %19 ]
  %.not20 = icmp eq i32 %.016, 0
  br i1 %.not20, label %25, label %23

23:                                               ; preds = %22
  %24 = tail call i32 @psa_mac_abort(ptr noundef nonnull %0)
  br label %25

25:                                               ; preds = %22, %23, %16, %3
  %.0 = phi i32 [ -137, %3 ], [ -137, %16 ], [ %.016, %23 ], [ 0, %22 ]
  ret i32 %.0
}

declare i32 @mbedtls_cipher_cmac_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #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 = { "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, !7, i64 0}
!6 = !{!"psa_mac_operation_s", !7, i64 0, !7, i64 4, !7, i64 4, !7, i64 4, !7, i64 4, !7, i64 4, !8, i64 5, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass