; 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
define dso_local i32 @mbedtls_rsa_import(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 -110, ptr %14, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %6
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %27

21:                                               ; preds = %18
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = call i32 @mbedtls_mpi_copy(ptr noundef %23, ptr noundef %24)
  store i32 %25, ptr %14, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %63, label %27

27:                                               ; preds = %21, %18
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %36

30:                                               ; preds = %27
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %31, i32 0, i32 5
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = call i32 @mbedtls_mpi_copy(ptr noundef %32, ptr noundef %33)
  store i32 %34, ptr %14, align 4, !tbaa !9
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %63, label %36

36:                                               ; preds = %30, %27
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %45

39:                                               ; preds = %36
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %40, i32 0, i32 6
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = call i32 @mbedtls_mpi_copy(ptr noundef %41, ptr noundef %42)
  store i32 %43, ptr %14, align 4, !tbaa !9
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %63, label %45

45:                                               ; preds = %39, %36
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %54

48:                                               ; preds = %45
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %49, i32 0, i32 4
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = call i32 @mbedtls_mpi_copy(ptr noundef %50, ptr noundef %51)
  store i32 %52, ptr %14, align 4, !tbaa !9
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %63, label %54

54:                                               ; preds = %48, %45
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %66

57:                                               ; preds = %54
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %58, i32 0, i32 3
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = call i32 @mbedtls_mpi_copy(ptr noundef %59, ptr noundef %60)
  store i32 %61, ptr %14, align 4, !tbaa !9
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %66

63:                                               ; preds = %57, %48, %39, %30, %21
  %64 = load i32, ptr %14, align 4, !tbaa !9
  %65 = add nsw i32 -16512, %64
  store i32 %65, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %76

66:                                               ; preds = %57, %54
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %75

69:                                               ; preds = %66
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %70, i32 0, i32 2
  %72 = call i64 @mbedtls_mpi_size(ptr noundef %71)
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %73, i32 0, i32 1
  store i64 %72, ptr %74, align 8, !tbaa !11
  br label %75

75:                                               ; preds = %69, %66
  store i32 0, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %76

76:                                               ; preds = %75, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %77 = load i32, ptr %7, align 4
  ret i32 %77
}

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

declare i32 @mbedtls_mpi_copy(ptr noundef, ptr noundef) #2

declare i64 @mbedtls_mpi_size(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"mbedtls_rsa_context", !10, i64 0, !13, i64 8, !14, i64 16, !14, i64 40, !14, i64 64, !14, i64 88, !14, i64 112, !14, i64 136, !14, i64 160, !14, i64 184, !14, i64 208, !14, i64 232, !14, i64 256, !14, i64 280, !14, i64 304, !10, i64 328, !10, i64 332}
!13 = !{!"long", !7, i64 0}
!14 = !{!"mbedtls_mpi", !10, i64 0, !13, 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
define dso_local range(i32 -2147483648, 2147467136) i32 @mbedtls_rsa_import(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %10, label %7

7:                                                ; preds = %6
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = tail call i32 @mbedtls_mpi_copy(ptr noundef nonnull %8, ptr noundef nonnull %1) #2
  %.not30 = icmp eq i32 %9, 0
  br i1 %.not30, label %10, label %26

10:                                               ; preds = %7, %6
  %.not31 = icmp eq ptr %2, null
  br i1 %.not31, label %14, label %11

11:                                               ; preds = %10
  %12 = getelementptr inbounds i8, ptr %0, i64 88
  %13 = tail call i32 @mbedtls_mpi_copy(ptr noundef nonnull %12, ptr noundef nonnull %2) #2
  %.not32 = icmp eq i32 %13, 0
  br i1 %.not32, label %14, label %26

14:                                               ; preds = %11, %10
  %.not33 = icmp eq ptr %3, null
  br i1 %.not33, label %18, label %15

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %0, i64 112
  %17 = tail call i32 @mbedtls_mpi_copy(ptr noundef nonnull %16, ptr noundef nonnull %3) #2
  %.not34 = icmp eq i32 %17, 0
  br i1 %.not34, label %18, label %26

18:                                               ; preds = %15, %14
  %.not35 = icmp eq ptr %4, null
  br i1 %.not35, label %22, label %19

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %0, i64 64
  %21 = tail call i32 @mbedtls_mpi_copy(ptr noundef nonnull %20, ptr noundef nonnull %4) #2
  %.not36 = icmp eq i32 %21, 0
  br i1 %.not36, label %22, label %26

22:                                               ; preds = %19, %18
  %.not37 = icmp eq ptr %5, null
  br i1 %.not37, label %28, label %23

23:                                               ; preds = %22
  %24 = getelementptr inbounds i8, ptr %0, i64 40
  %25 = tail call i32 @mbedtls_mpi_copy(ptr noundef nonnull %24, ptr noundef nonnull %5) #2
  %.not38 = icmp eq i32 %25, 0
  br i1 %.not38, label %28, label %26

26:                                               ; preds = %23, %19, %15, %11, %7
  %.0 = phi i32 [ %9, %7 ], [ %13, %11 ], [ %17, %15 ], [ %21, %19 ], [ %25, %23 ]
  %27 = add nsw i32 %.0, -16512
  br label %33

28:                                               ; preds = %23, %22
  br i1 %.not, label %33, label %29

29:                                               ; preds = %28
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  %31 = tail call i64 @mbedtls_mpi_size(ptr noundef nonnull %30) #2
  %32 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %31, ptr %32, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %28, %29, %26
  %.019 = phi i32 [ %27, %26 ], [ 0, %29 ], [ 0, %28 ]
  ret i32 %.019
}

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

declare i64 @mbedtls_mpi_size(ptr 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, !10, i64 8}
!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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass