; LLVM IR from tleonhardt/practical_cryptography_engineering :: mbedtls (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_md_context_t = type { ptr, ptr, ptr }
%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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

declare i64 @mbedtls_mpi_bitlen(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_rsa_public(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_rsa_private(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

declare ptr @mbedtls_md_info_from_type(i32 noundef) #2

declare zeroext i8 @mbedtls_md_get_size(ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

declare void @mbedtls_md_init(ptr noundef) #2

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

declare void @mbedtls_md_free(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @mgf_mask(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @mbedtls_zeroize(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_rsa_rsassa_pss_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr noundef %6, ptr noundef %7) #3 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca [64 x i8], align 16
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  %25 = alloca i64, align 8
  %26 = alloca ptr, align 8
  %27 = alloca %struct.mbedtls_md_context_t, align 8
  %28 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store ptr %2, ptr %12, align 8, !tbaa !5
  store i32 %3, ptr %13, align 4, !tbaa !9
  store i32 %4, ptr %14, align 4, !tbaa !9
  store i32 %5, ptr %15, align 4, !tbaa !9
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %29 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %29, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %20) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #5
  store i32 0, ptr %23, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %27) #5
  %30 = load i32, ptr %13, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %38

32:                                               ; preds = %8
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %33, i32 0, i32 15
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = icmp ne i32 %35, 1
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  store i32 -16512, ptr %9, align 4
  store i32 1, ptr %28, align 4
  br label %193

38:                                               ; preds = %32, %8
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %38
  store i32 -16512, ptr %9, align 4
  store i32 1, ptr %28, align 4
  br label %193

42:                                               ; preds = %38
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !15
  store i64 %45, ptr %18, align 8, !tbaa !16
  %46 = load i32, ptr %14, align 4, !tbaa !9
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %58

48:                                               ; preds = %42
  %49 = load i32, ptr %14, align 4, !tbaa !9
  %50 = call ptr @mbedtls_md_info_from_type(i32 noundef %49)
  store ptr %50, ptr %26, align 8, !tbaa !5
  %51 = load ptr, ptr %26, align 8, !tbaa !5
  %52 = icmp eq ptr %51, null
  br i1 %52, label %53, label %54

53:                                               ; preds = %48
  store i32 -16512, ptr %9, align 4
  store i32 1, ptr %28, align 4
  br label %193

54:                                               ; preds = %48
  %55 = load ptr, ptr %26, align 8, !tbaa !5
  %56 = call zeroext i8 @mbedtls_md_get_size(ptr noundef %55)
  %57 = zext i8 %56 to i32
  store i32 %57, ptr %15, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %54, %42
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %59, i32 0, i32 16
  %61 = load i32, ptr %60, align 4, !tbaa !17
  %62 = call ptr @mbedtls_md_info_from_type(i32 noundef %61)
  store ptr %62, ptr %26, align 8, !tbaa !5
  %63 = load ptr, ptr %26, align 8, !tbaa !5
  %64 = icmp eq ptr %63, null
  br i1 %64, label %65, label %66

65:                                               ; preds = %58
  store i32 -16512, ptr %9, align 4
  store i32 1, ptr %28, align 4
  br label %193

66:                                               ; preds = %58
  %67 = load ptr, ptr %26, align 8, !tbaa !5
  %68 = call zeroext i8 @mbedtls_md_get_size(ptr noundef %67)
  %69 = zext i8 %68 to i32
  store i32 %69, ptr %22, align 4, !tbaa !9
  %70 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %70, ptr %21, align 4, !tbaa !9
  %71 = load i64, ptr %18, align 8, !tbaa !16
  %72 = load i32, ptr %22, align 4, !tbaa !9
  %73 = load i32, ptr %21, align 4, !tbaa !9
  %74 = add i32 %72, %73
  %75 = add i32 %74, 2
  %76 = zext i32 %75 to i64
  %77 = icmp ult i64 %71, %76
  br i1 %77, label %78, label %79

78:                                               ; preds = %66
  store i32 -16512, ptr %9, align 4
  store i32 1, ptr %28, align 4
  br label %193

79:                                               ; preds = %66
  %80 = load ptr, ptr %17, align 8, !tbaa !5
  %81 = load i64, ptr %18, align 8, !tbaa !16
  call void @llvm.memset.p0.i64(ptr align 1 %80, i8 0, i64 %81, i1 false)
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  %84 = getelementptr inbounds [64 x i8], ptr %20, i64 0, i64 0
  %85 = load i32, ptr %21, align 4, !tbaa !9
  %86 = zext i32 %85 to i64
  %87 = call i32 %82(ptr noundef %83, ptr noundef %84, i64 noundef %86)
  store i32 %87, ptr %24, align 4, !tbaa !9
  %88 = icmp ne i32 %87, 0
  br i1 %88, label %89, label %92

89:                                               ; preds = %79
  %90 = load i32, ptr %24, align 4, !tbaa !9
  %91 = add nsw i32 -17536, %90
  store i32 %91, ptr %9, align 4
  store i32 1, ptr %28, align 4
  br label %193

92:                                               ; preds = %79
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %93, i32 0, i32 2
  %95 = call i64 @mbedtls_mpi_bitlen(ptr noundef %94)
  %96 = sub i64 %95, 1
  store i64 %96, ptr %25, align 8, !tbaa !16
  %97 = load i64, ptr %18, align 8, !tbaa !16
  %98 = load i32, ptr %22, align 4, !tbaa !9
  %99 = mul i32 %98, 2
  %100 = zext i32 %99 to i64
  %101 = sub i64 %97, %100
  %102 = sub i64 %101, 2
  %103 = load ptr, ptr %19, align 8, !tbaa !5
  %104 = getelementptr inbounds i8, ptr %103, i64 %102
  store ptr %104, ptr %19, align 8, !tbaa !5
  %105 = load ptr, ptr %19, align 8, !tbaa !5
  %106 = getelementptr inbounds i8, ptr %105, i32 1
  store ptr %106, ptr %19, align 8, !tbaa !5
  store i8 1, ptr %105, align 1, !tbaa !18
  %107 = load ptr, ptr %19, align 8, !tbaa !5
  %108 = getelementptr inbounds [64 x i8], ptr %20, i64 0, i64 0
  %109 = load i32, ptr %21, align 4, !tbaa !9
  %110 = zext i32 %109 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %107, ptr align 16 %108, i64 %110, i1 false)
  %111 = load i32, ptr %21, align 4, !tbaa !9
  %112 = load ptr, ptr %19, align 8, !tbaa !5
  %113 = zext i32 %111 to i64
  %114 = getelementptr inbounds i8, ptr %112, i64 %113
  store ptr %114, ptr %19, align 8, !tbaa !5
  call void @mbedtls_md_init(ptr noundef %27)
  %115 = load ptr, ptr %26, align 8, !tbaa !5
  %116 = call i32 @mbedtls_md_setup(ptr noundef %27, ptr noundef %115, i32 noundef 0)
  store i32 %116, ptr %24, align 4, !tbaa !9
  %117 = icmp ne i32 %116, 0
  br i1 %117, label %118, label %120

118:                                              ; preds = %92
  call void @mbedtls_md_free(ptr noundef %27)
  %119 = load i32, ptr %24, align 4, !tbaa !9
  store i32 %119, ptr %9, align 4
  store i32 1, ptr %28, align 4
  br label %193

120:                                              ; preds = %92
  %121 = call i32 @mbedtls_md_starts(ptr noundef %27)
  %122 = load ptr, ptr %19, align 8, !tbaa !5
  %123 = call i32 @mbedtls_md_update(ptr noundef %27, ptr noundef %122, i64 noundef 8)
  %124 = load ptr, ptr %16, align 8, !tbaa !5
  %125 = load i32, ptr %15, align 4, !tbaa !9
  %126 = zext i32 %125 to i64
  %127 = call i32 @mbedtls_md_update(ptr noundef %27, ptr noundef %124, i64 noundef %126)
  %128 = getelementptr inbounds [64 x i8], ptr %20, i64 0, i64 0
  %129 = load i32, ptr %21, align 4, !tbaa !9
  %130 = zext i32 %129 to i64
  %131 = call i32 @mbedtls_md_update(ptr noundef %27, ptr noundef %128, i64 noundef %130)
  %132 = load ptr, ptr %19, align 8, !tbaa !5
  %133 = call i32 @mbedtls_md_finish(ptr noundef %27, ptr noundef %132)
  %134 = getelementptr inbounds [64 x i8], ptr %20, i64 0, i64 0
  call void @mbedtls_zeroize(ptr noundef %134, i64 noundef 64)
  %135 = load i64, ptr %25, align 8, !tbaa !16
  %136 = urem i64 %135, 8
  %137 = icmp eq i64 %136, 0
  br i1 %137, label %138, label %139

138:                                              ; preds = %120
  store i32 1, ptr %23, align 4, !tbaa !9
  br label %139

139:                                              ; preds = %138, %120
  %140 = load ptr, ptr %17, align 8, !tbaa !5
  %141 = load i32, ptr %23, align 4, !tbaa !9
  %142 = zext i32 %141 to i64
  %143 = getelementptr inbounds i8, ptr %140, i64 %142
  %144 = load i64, ptr %18, align 8, !tbaa !16
  %145 = load i32, ptr %22, align 4, !tbaa !9
  %146 = zext i32 %145 to i64
  %147 = sub i64 %144, %146
  %148 = sub i64 %147, 1
  %149 = load i32, ptr %23, align 4, !tbaa !9
  %150 = zext i32 %149 to i64
  %151 = sub i64 %148, %150
  %152 = load ptr, ptr %19, align 8, !tbaa !5
  %153 = load i32, ptr %22, align 4, !tbaa !9
  %154 = zext i32 %153 to i64
  call void @mgf_mask(ptr noundef %143, i64 noundef %151, ptr noundef %152, i64 noundef %154, ptr noundef %27)
  call void @mbedtls_md_free(ptr noundef %27)
  %155 = load ptr, ptr %10, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %155, i32 0, i32 2
  %157 = call i64 @mbedtls_mpi_bitlen(ptr noundef %156)
  %158 = sub i64 %157, 1
  store i64 %158, ptr %25, align 8, !tbaa !16
  %159 = load i64, ptr %18, align 8, !tbaa !16
  %160 = mul i64 %159, 8
  %161 = load i64, ptr %25, align 8, !tbaa !16
  %162 = sub i64 %160, %161
  %163 = trunc i64 %162 to i32
  %164 = ashr i32 255, %163
  %165 = load ptr, ptr %17, align 8, !tbaa !5
  %166 = getelementptr inbounds i8, ptr %165, i64 0
  %167 = load i8, ptr %166, align 1, !tbaa !18
  %168 = zext i8 %167 to i32
  %169 = and i32 %168, %164
  %170 = trunc i32 %169 to i8
  store i8 %170, ptr %166, align 1, !tbaa !18
  %171 = load i32, ptr %22, align 4, !tbaa !9
  %172 = load ptr, ptr %19, align 8, !tbaa !5
  %173 = zext i32 %171 to i64
  %174 = getelementptr inbounds i8, ptr %172, i64 %173
  store ptr %174, ptr %19, align 8, !tbaa !5
  %175 = load ptr, ptr %19, align 8, !tbaa !5
  %176 = getelementptr inbounds i8, ptr %175, i32 1
  store ptr %176, ptr %19, align 8, !tbaa !5
  store i8 -68, ptr %175, align 1, !tbaa !18
  %177 = load i32, ptr %13, align 4, !tbaa !9
  %178 = icmp eq i32 %177, 0
  br i1 %178, label %179, label %184

179:                                              ; preds = %139
  %180 = load ptr, ptr %10, align 8, !tbaa !5
  %181 = load ptr, ptr %17, align 8, !tbaa !5
  %182 = load ptr, ptr %17, align 8, !tbaa !5
  %183 = call i32 @mbedtls_rsa_public(ptr noundef %180, ptr noundef %181, ptr noundef %182)
  br label %191

184:                                              ; preds = %139
  %185 = load ptr, ptr %10, align 8, !tbaa !5
  %186 = load ptr, ptr %11, align 8, !tbaa !5
  %187 = load ptr, ptr %12, align 8, !tbaa !5
  %188 = load ptr, ptr %17, align 8, !tbaa !5
  %189 = load ptr, ptr %17, align 8, !tbaa !5
  %190 = call i32 @mbedtls_rsa_private(ptr noundef %185, ptr noundef %186, ptr noundef %187, ptr noundef %188, ptr noundef %189)
  br label %191

191:                                              ; preds = %184, %179
  %192 = phi i32 [ %183, %179 ], [ %190, %184 ]
  store i32 %192, ptr %9, align 4
  store i32 1, ptr %28, align 4
  br label %193

193:                                              ; preds = %191, %118, %89, %78, %65, %53, %41, %37
  call void @llvm.lifetime.end.p0(i64 24, ptr %27) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  %194 = load i32, ptr %9, align 4
  ret i32 %194
}

declare i32 @mbedtls_md_starts(ptr noundef) #2

declare i32 @mbedtls_md_update(ptr noundef, ptr noundef, i64 noundef) #2

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !10, i64 328}
!12 = !{!"", !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 = !{!"", !10, i64 0, !13, i64 8, !6, i64 16}
!15 = !{!12, !13, i64 8}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !10, i64 332}
!18 = !{!7, !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"

%struct.mbedtls_md_context_t = type { ptr, ptr, ptr }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

declare i64 @mbedtls_mpi_bitlen(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_rsa_public(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_rsa_private(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @mbedtls_md_info_from_type(i32 noundef) local_unnamed_addr #2

declare zeroext i8 @mbedtls_md_get_size(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

declare void @mbedtls_md_init(ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_md_setup(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @mbedtls_md_free(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @mgf_mask(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @mbedtls_zeroize(ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_rsa_rsassa_pss_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr noundef %6, ptr noundef %7) local_unnamed_addr #3 {
  %9 = alloca [64 x i8], align 16
  %10 = alloca %struct.mbedtls_md_context_t, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %9) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %10) #5
  %11 = icmp eq i32 %3, 1
  br i1 %11, label %12, label %16

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 328
  %14 = load i32, ptr %13, align 8, !tbaa !5
  %.not = icmp ne i32 %14, 1
  %15 = icmp eq ptr %1, null
  %or.cond = or i1 %15, %.not
  br i1 %or.cond, label %82, label %17

16:                                               ; preds = %8
  %.old = icmp eq ptr %1, null
  br i1 %.old, label %82, label %17

17:                                               ; preds = %12, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %.not71 = icmp eq i32 %4, 0
  br i1 %.not71, label %26, label %20

20:                                               ; preds = %17
  %21 = tail call ptr @mbedtls_md_info_from_type(i32 noundef %4) #5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %82, label %23

23:                                               ; preds = %20
  %24 = tail call zeroext i8 @mbedtls_md_get_size(ptr noundef nonnull %21) #5
  %25 = zext i8 %24 to i32
  br label %26

26:                                               ; preds = %23, %17
  %.063 = phi i32 [ %25, %23 ], [ %5, %17 ]
  %27 = getelementptr inbounds i8, ptr %0, i64 332
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = tail call ptr @mbedtls_md_info_from_type(i32 noundef %28) #5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %82, label %31

31:                                               ; preds = %26
  %32 = tail call zeroext i8 @mbedtls_md_get_size(ptr noundef nonnull %29) #5
  %33 = zext i8 %32 to i32
  %34 = shl nuw nsw i32 %33, 1
  %35 = add nuw nsw i32 %34, 2
  %36 = zext nneg i32 %35 to i64
  %37 = icmp ult i64 %19, %36
  br i1 %37, label %82, label %38

38:                                               ; preds = %31
  tail call void @llvm.memset.p0.i64(ptr align 1 %7, i8 0, i64 %19, i1 false)
  %39 = zext i8 %32 to i64
  %40 = call i32 %1(ptr noundef %2, ptr noundef nonnull %9, i64 noundef %39) #5
  %.not72 = icmp eq i32 %40, 0
  br i1 %.not72, label %43, label %41

41:                                               ; preds = %38
  %42 = add nsw i32 %40, -17536
  br label %82

43:                                               ; preds = %38
  %44 = getelementptr inbounds i8, ptr %0, i64 16
  %45 = call i64 @mbedtls_mpi_bitlen(ptr noundef nonnull %44) #5
  %46 = zext nneg i32 %34 to i64
  %47 = sub i64 %19, %46
  %48 = getelementptr i8, ptr %7, i64 %47
  %49 = getelementptr i8, ptr %48, i64 -2
  %50 = getelementptr i8, ptr %48, i64 -1
  store i8 1, ptr %49, align 1, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %50, ptr nonnull align 16 %9, i64 %39, i1 false)
  call void @mbedtls_md_init(ptr noundef nonnull %10) #5
  %51 = call i32 @mbedtls_md_setup(ptr noundef nonnull %10, ptr noundef nonnull %29, i32 noundef 0) #5
  %.not73 = icmp eq i32 %51, 0
  br i1 %.not73, label %53, label %52

52:                                               ; preds = %43
  call void @mbedtls_md_free(ptr noundef nonnull %10) #5
  br label %82

53:                                               ; preds = %43
  %54 = getelementptr inbounds i8, ptr %50, i64 %39
  %55 = add i64 %45, 7
  %56 = call i32 @mbedtls_md_starts(ptr noundef nonnull %10) #5
  %57 = call i32 @mbedtls_md_update(ptr noundef nonnull %10, ptr noundef %54, i64 noundef 8) #5
  %58 = zext i32 %.063 to i64
  %59 = call i32 @mbedtls_md_update(ptr noundef nonnull %10, ptr noundef %6, i64 noundef %58) #5
  %60 = call i32 @mbedtls_md_update(ptr noundef nonnull %10, ptr noundef nonnull %9, i64 noundef %39) #5
  %61 = call i32 @mbedtls_md_finish(ptr noundef nonnull %10, ptr noundef %54) #5
  call void @mbedtls_zeroize(ptr noundef nonnull %9, i64 noundef 64)
  %62 = and i64 %55, 7
  %63 = icmp eq i64 %62, 0
  %spec.select.neg75 = sext i1 %63 to i64
  %spec.select = zext i1 %63 to i64
  %64 = getelementptr inbounds i8, ptr %7, i64 %spec.select
  %65 = xor i64 %39, -1
  %66 = add i64 %19, %65
  %67 = add i64 %66, %spec.select.neg75
  call void @mgf_mask(ptr noundef %64, i64 noundef %67, ptr noundef %54, i64 noundef %39, ptr noundef nonnull %10)
  call void @mbedtls_md_free(ptr noundef nonnull %10) #5
  %68 = call i64 @mbedtls_mpi_bitlen(ptr noundef nonnull %44) #5
  %69 = shl i64 %19, 3
  %.neg74 = or disjoint i64 %69, 1
  %70 = sub i64 %.neg74, %68
  %71 = trunc i64 %70 to i32
  %72 = lshr i32 255, %71
  %73 = load i8, ptr %7, align 1, !tbaa !15
  %74 = trunc nuw i32 %72 to i8
  %75 = and i8 %73, %74
  store i8 %75, ptr %7, align 1, !tbaa !15
  %76 = getelementptr inbounds i8, ptr %54, i64 %39
  store i8 -68, ptr %76, align 1, !tbaa !15
  %77 = icmp eq i32 %3, 0
  br i1 %77, label %78, label %80

78:                                               ; preds = %53
  %79 = call i32 @mbedtls_rsa_public(ptr noundef nonnull %0, ptr noundef nonnull %7, ptr noundef nonnull %7)
  br label %82

80:                                               ; preds = %53
  %81 = call i32 @mbedtls_rsa_private(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef %2, ptr noundef nonnull %7, ptr noundef nonnull %7)
  br label %82

82:                                               ; preds = %78, %80, %31, %26, %20, %16, %12, %52, %41
  %.062 = phi i32 [ %42, %41 ], [ %51, %52 ], [ -16512, %12 ], [ -16512, %16 ], [ -16512, %20 ], [ -16512, %26 ], [ -16512, %31 ], [ %79, %78 ], [ %81, %80 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %10) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %9) #5
  ret i32 %.062
}

declare i32 @mbedtls_md_starts(ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_md_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @mbedtls_md_finish(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress 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 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 328}
!6 = !{!"", !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 = !{!"", !7, i64 0, !10, i64 8, !12, i64 16}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !7, i64 332}
!15 = !{!8, !8, i64 0}


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