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

; 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_rsa_context = type { i32, i64, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, i32, i32 }
%struct.mbedtls_mpi = type { i32, i64, ptr }

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_rsa_pkcs1_encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !9
  store i64 %4, ptr %13, align 8, !tbaa !11
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %7
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %24, i32 0, i32 15
  %26 = load i32, ptr %25, align 8, !tbaa !13
  switch i32 %26, label %45 [
    i32 0, label %27
    i32 1, label %36
  ]

27:                                               ; preds = %23
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = load i64, ptr %13, align 8, !tbaa !11
  %33 = load ptr, ptr %14, align 8, !tbaa !5
  %34 = load ptr, ptr %15, align 8, !tbaa !5
  %35 = call i32 @mbedtls_rsa_rsaes_pkcs1_v15_encrypt(ptr noundef %28, ptr noundef %29, ptr noundef %30, i32 noundef %31, i64 noundef %32, ptr noundef %33, ptr noundef %34)
  store i32 %35, ptr %8, align 4
  br label %46

36:                                               ; preds = %23
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = load i64, ptr %13, align 8, !tbaa !11
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  %43 = load ptr, ptr %15, align 8, !tbaa !5
  %44 = call i32 @mbedtls_rsa_rsaes_oaep_encrypt(ptr noundef %37, ptr noundef %38, ptr noundef %39, i32 noundef %40, ptr noundef null, i64 noundef 0, i64 noundef %41, ptr noundef %42, ptr noundef %43)
  store i32 %44, ptr %8, align 4
  br label %46

45:                                               ; preds = %23
  store i32 -16640, ptr %8, align 4
  br label %46

46:                                               ; preds = %45, %36, %27
  %47 = load i32, ptr %8, align 4
  ret i32 %47
}

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

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 328}
!14 = !{!"mbedtls_rsa_context", !10, i64 0, !12, i64 8, !15, i64 16, !15, i64 40, !15, i64 64, !15, i64 88, !15, i64 112, !15, i64 136, !15, i64 160, !15, i64 184, !15, i64 208, !15, i64 232, !15, i64 256, !15, i64 280, !15, i64 304, !10, i64 328, !10, i64 332}
!15 = !{!"mbedtls_mpi", !10, i64 0, !12, i64 8, !6, i64 16}


; 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 i32 @mbedtls_rsa_rsaes_oaep_encrypt(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_rsa_pkcs1_encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #0 {
  %8 = getelementptr inbounds i8, ptr %0, i64 328
  %9 = load i32, ptr %8, align 8, !tbaa !5
  switch i32 %9, label %14 [
    i32 0, label %10
    i32 1, label %12
  ]

10:                                               ; preds = %7
  %11 = tail call i32 @mbedtls_rsa_rsaes_pkcs1_v15_encrypt(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6)
  br label %14

12:                                               ; preds = %7
  %13 = tail call i32 @mbedtls_rsa_rsaes_oaep_encrypt(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef null, i64 noundef 0, i64 noundef %4, ptr noundef %5, ptr noundef %6)
  br label %14

14:                                               ; preds = %7, %12, %10
  %.0 = phi i32 [ %13, %12 ], [ %11, %10 ], [ -16640, %7 ]
  ret i32 %.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" }

!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 328}
!6 = !{!"mbedtls_rsa_context", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 40, !11, i64 64, !11, i64 88, !11, i64 112, !11, i64 136, !11, i64 160, !11, i64 184, !11, i64 208, !11, i64 232, !11, i64 256, !11, i64 280, !11, i64 304, !7, i64 328, !7, i64 332}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"mbedtls_mpi", !7, i64 0, !10, i64 8, !12, i64 16}
!12 = !{!"any pointer", !8, i64 0}


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