; LLVM IR from machinefi/psa-crypto-esp32 :: crypto (cmac_mode)

; 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.tc_cmac_struct = type { [16 x i8], [16 x i8], [16 x i8], [16 x i8], i32, i32, ptr, i64 }

; Function Attrs: nounwind uwtable
declare dso_local void @gf_double(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @tc_cmac_setup(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %13, label %10

10:                                               ; preds = %3
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %10, %3
  store i32 0, ptr %4, align 4
  br label %51

14:                                               ; preds = %10
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_set(ptr noundef %15, i8 noundef zeroext 0, i32 noundef 88)
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tc_cmac_struct, ptr %17, i32 0, i32 6
  store ptr %16, ptr %18, align 8, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.tc_cmac_struct, ptr %19, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call i32 @tc_aes128_set_encrypt_key(ptr noundef %21, ptr noundef %22)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.tc_cmac_struct, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  call void @_set(ptr noundef %26, i8 noundef zeroext 0, i32 noundef 16)
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tc_cmac_struct, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds [16 x i8], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.tc_cmac_struct, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [16 x i8], ptr %31, i64 0, i64 0
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.tc_cmac_struct, ptr %33, i32 0, i32 6
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = call i32 @tc_aes_encrypt(ptr noundef %29, ptr noundef %32, ptr noundef %35)
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.tc_cmac_struct, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds [16 x i8], ptr %38, i64 0, i64 0
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tc_cmac_struct, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds [16 x i8], ptr %41, i64 0, i64 0
  call void @gf_double(ptr noundef %39, ptr noundef %42)
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.tc_cmac_struct, ptr %43, i32 0, i32 2
  %45 = getelementptr inbounds [16 x i8], ptr %44, i64 0, i64 0
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.tc_cmac_struct, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds [16 x i8], ptr %47, i64 0, i64 0
  call void @gf_double(ptr noundef %45, ptr noundef %48)
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = call i32 @tc_cmac_init(ptr noundef %49)
  store i32 1, ptr %4, align 4
  br label %51

51:                                               ; preds = %14, %13
  %52 = load i32, ptr %4, align 4
  ret i32 %52
}

declare void @_set(ptr noundef, i8 noundef zeroext, i32 noundef) #1

declare i32 @tc_aes128_set_encrypt_key(ptr noundef, ptr noundef) #1

declare i32 @tc_aes_encrypt(ptr noundef, ptr noundef, ptr noundef) #1

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

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

!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, !6, i64 72}
!10 = !{!"tc_cmac_struct", !7, i64 0, !7, i64 16, !7, i64 32, !7, i64 48, !11, i64 64, !11, i64 68, !6, i64 72, !12, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}


; 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 dso_local void @gf_double(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @tc_cmac_setup(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %1, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %14, label %6

6:                                                ; preds = %3
  tail call void @_set(ptr noundef nonnull %0, i8 noundef zeroext 0, i32 noundef 88) #2
  %7 = getelementptr inbounds i8, ptr %0, i64 72
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = tail call i32 @tc_aes128_set_encrypt_key(ptr noundef %2, ptr noundef nonnull %1) #2
  tail call void @_set(ptr noundef nonnull %0, i8 noundef zeroext 0, i32 noundef 16) #2
  %9 = load ptr, ptr %7, align 8, !tbaa !5
  %10 = tail call i32 @tc_aes_encrypt(ptr noundef nonnull %0, ptr noundef nonnull %0, ptr noundef %9) #2
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @gf_double(ptr noundef nonnull %11, ptr noundef nonnull %0)
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @gf_double(ptr noundef nonnull %12, ptr noundef nonnull %11)
  %13 = tail call i32 @tc_cmac_init(ptr noundef nonnull %0)
  br label %14

14:                                               ; preds = %3, %6
  %.0 = phi i32 [ 1, %6 ], [ 0, %3 ]
  ret i32 %.0
}

declare void @_set(ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #1

declare i32 @tc_aes128_set_encrypt_key(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @tc_aes_encrypt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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, !10, i64 72}
!6 = !{!"tc_cmac_struct", !7, i64 0, !7, i64 16, !7, i64 32, !7, i64 48, !9, i64 64, !9, i64 68, !10, i64 72, !11, i64 80}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"long", !7, i64 0}


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