; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i64 @mbedtls_mpi_size(ptr 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: nounwind uwtable
define dso_local i32 @mbedtls_rsa_import_raw(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9, i64 noundef %10) #2 {
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i64, align 8
  %22 = alloca ptr, align 8
  %23 = alloca i64, align 8
  %24 = alloca i32, align 4
  %25 = alloca i32, align 4
  store ptr %0, ptr %13, align 8, !tbaa !5
  store ptr %1, ptr %14, align 8, !tbaa !5
  store i64 %2, ptr %15, align 8, !tbaa !9
  store ptr %3, ptr %16, align 8, !tbaa !5
  store i64 %4, ptr %17, align 8, !tbaa !9
  store ptr %5, ptr %18, align 8, !tbaa !5
  store i64 %6, ptr %19, align 8, !tbaa !9
  store ptr %7, ptr %20, align 8, !tbaa !5
  store i64 %8, ptr %21, align 8, !tbaa !9
  store ptr %9, ptr %22, align 8, !tbaa !5
  store i64 %10, ptr %23, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #3
  store i32 0, ptr %24, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %11
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %14, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %48

31:                                               ; preds = %28
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %13, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %14, align 8, !tbaa !5
  %36 = load i64, ptr %15, align 8, !tbaa !9
  %37 = call i32 @mbedtls_mpi_read_binary(ptr noundef %34, ptr noundef %35, i64 noundef %36)
  store i32 %37, ptr %24, align 4, !tbaa !11
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %32
  br label %109

40:                                               ; preds = %32
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %43, i32 0, i32 2
  %45 = call i64 @mbedtls_mpi_size(ptr noundef %44)
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %46, i32 0, i32 1
  store i64 %45, ptr %47, align 8, !tbaa !13
  br label %48

48:                                               ; preds = %42, %28
  %49 = load ptr, ptr %16, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %63

51:                                               ; preds = %48
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %13, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %53, i32 0, i32 5
  %55 = load ptr, ptr %16, align 8, !tbaa !5
  %56 = load i64, ptr %17, align 8, !tbaa !9
  %57 = call i32 @mbedtls_mpi_read_binary(ptr noundef %54, ptr noundef %55, i64 noundef %56)
  store i32 %57, ptr %24, align 4, !tbaa !11
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %52
  br label %109

60:                                               ; preds = %52
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62, %48
  %64 = load ptr, ptr %18, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %78

66:                                               ; preds = %63
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %68, i32 0, i32 6
  %70 = load ptr, ptr %18, align 8, !tbaa !5
  %71 = load i64, ptr %19, align 8, !tbaa !9
  %72 = call i32 @mbedtls_mpi_read_binary(ptr noundef %69, ptr noundef %70, i64 noundef %71)
  store i32 %72, ptr %24, align 4, !tbaa !11
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %67
  br label %109

75:                                               ; preds = %67
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77, %63
  %79 = load ptr, ptr %20, align 8, !tbaa !5
  %80 = icmp ne ptr %79, null
  br i1 %80, label %81, label %93

81:                                               ; preds = %78
  br label %82

82:                                               ; preds = %81
  %83 = load ptr, ptr %13, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %83, i32 0, i32 4
  %85 = load ptr, ptr %20, align 8, !tbaa !5
  %86 = load i64, ptr %21, align 8, !tbaa !9
  %87 = call i32 @mbedtls_mpi_read_binary(ptr noundef %84, ptr noundef %85, i64 noundef %86)
  store i32 %87, ptr %24, align 4, !tbaa !11
  %88 = icmp ne i32 %87, 0
  br i1 %88, label %89, label %90

89:                                               ; preds = %82
  br label %109

90:                                               ; preds = %82
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92, %78
  %94 = load ptr, ptr %22, align 8, !tbaa !5
  %95 = icmp ne ptr %94, null
  br i1 %95, label %96, label %108

96:                                               ; preds = %93
  br label %97

97:                                               ; preds = %96
  %98 = load ptr, ptr %13, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %98, i32 0, i32 3
  %100 = load ptr, ptr %22, align 8, !tbaa !5
  %101 = load i64, ptr %23, align 8, !tbaa !9
  %102 = call i32 @mbedtls_mpi_read_binary(ptr noundef %99, ptr noundef %100, i64 noundef %101)
  store i32 %102, ptr %24, align 4, !tbaa !11
  %103 = icmp ne i32 %102, 0
  br i1 %103, label %104, label %105

104:                                              ; preds = %97
  br label %109

105:                                              ; preds = %97
  br label %106

106:                                              ; preds = %105
  br label %107

107:                                              ; preds = %106
  br label %108

108:                                              ; preds = %107, %93
  br label %109

109:                                              ; preds = %108, %104, %89, %74, %59, %39
  %110 = load i32, ptr %24, align 4, !tbaa !11
  %111 = icmp ne i32 %110, 0
  br i1 %111, label %112, label %115

112:                                              ; preds = %109
  %113 = load i32, ptr %24, align 4, !tbaa !11
  %114 = add nsw i32 -16512, %113
  store i32 %114, ptr %12, align 4
  store i32 1, ptr %25, align 4
  br label %116

115:                                              ; preds = %109
  store i32 0, ptr %12, align 4
  store i32 1, ptr %25, align 4
  br label %116

116:                                              ; preds = %115, %112
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #3
  %117 = load i32, ptr %12, align 4
  ret i32 %117
}

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

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 = { 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 #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, !10, i64 8}
!14 = !{!"mbedtls_rsa_context", !12, i64 0, !10, 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, !12, i64 328, !12, i64 332}
!15 = !{!"mbedtls_mpi", !12, i64 0, !10, 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"

declare i64 @mbedtls_mpi_size(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2147483648, 2147467136) i32 @mbedtls_rsa_import_raw(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9, i64 noundef %10) local_unnamed_addr #1 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %18, label %12

12:                                               ; preds = %11
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = tail call i32 @mbedtls_mpi_read_binary(ptr noundef nonnull %13, ptr noundef nonnull %1, i64 noundef %2) #2
  %.not36 = icmp eq i32 %14, 0
  br i1 %.not36, label %15, label %.thread

15:                                               ; preds = %12
  %16 = tail call i64 @mbedtls_mpi_size(ptr noundef nonnull %13) #2
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %16, ptr %17, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %15, %11
  %.not37 = icmp eq ptr %3, null
  br i1 %.not37, label %22, label %19

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %0, i64 88
  %21 = tail call i32 @mbedtls_mpi_read_binary(ptr noundef nonnull %20, ptr noundef nonnull %3, i64 noundef %4) #2
  %.not38 = icmp eq i32 %21, 0
  br i1 %.not38, label %22, label %.thread

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

23:                                               ; preds = %22
  %24 = getelementptr inbounds i8, ptr %0, i64 112
  %25 = tail call i32 @mbedtls_mpi_read_binary(ptr noundef nonnull %24, ptr noundef nonnull %5, i64 noundef %6) #2
  %.not40 = icmp eq i32 %25, 0
  br i1 %.not40, label %26, label %.thread

26:                                               ; preds = %23, %22
  %.not41 = icmp eq ptr %7, null
  br i1 %.not41, label %32, label %27

27:                                               ; preds = %26
  %28 = getelementptr inbounds i8, ptr %0, i64 64
  %29 = tail call i32 @mbedtls_mpi_read_binary(ptr noundef nonnull %28, ptr noundef nonnull %7, i64 noundef %8) #2
  %30 = icmp eq i32 %29, 0
  %31 = icmp ne ptr %9, null
  %or.cond = and i1 %31, %30
  br i1 %or.cond, label %33, label %37

32:                                               ; preds = %26
  %.old1.not = icmp eq ptr %9, null
  br i1 %.old1.not, label %.thread46, label %33

33:                                               ; preds = %27, %32
  %34 = getelementptr inbounds i8, ptr %0, i64 40
  %35 = tail call i32 @mbedtls_mpi_read_binary(ptr noundef nonnull %34, ptr noundef nonnull %9, i64 noundef %10) #2
  br label %37

.thread:                                          ; preds = %12, %19, %23
  %.3.ph = phi i32 [ %25, %23 ], [ %21, %19 ], [ %14, %12 ]
  %36 = add nsw i32 %.3.ph, -16512
  br label %39

37:                                               ; preds = %33, %27
  %.3 = phi i32 [ %35, %33 ], [ %29, %27 ]
  %.3.fr = freeze i32 %.3
  %.not42 = icmp eq i32 %.3.fr, 0
  %38 = add nsw i32 %.3.fr, -16512
  br i1 %.not42, label %.thread46, label %39

.thread46:                                        ; preds = %32, %37
  br label %39

39:                                               ; preds = %.thread, %37, %.thread46
  %40 = phi i32 [ 0, %.thread46 ], [ %38, %37 ], [ %36, %.thread ]
  ret i32 %40
}

declare i32 @mbedtls_mpi_read_binary(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass