; LLVM IR from tleonhardt/practical_cryptography_engineering :: mbedtls (ssl_cache)

; 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_ssl_cache_context = type { ptr, i32, i32 }
%struct.mbedtls_ssl_cache_entry = type { i64, %struct.mbedtls_ssl_session, %struct.mbedtls_asn1_buf, ptr }
%struct.mbedtls_ssl_session = type { i64, i32, i32, i64, [32 x i8], [48 x i8], ptr, i32, ptr, i64, i32, i8, i32, i32 }
%struct.mbedtls_asn1_buf = type { i32, i64, ptr }
%struct.mbedtls_x509_crt = type { %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, i32, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_named_data, %struct.mbedtls_asn1_named_data, %struct.mbedtls_x509_time, %struct.mbedtls_x509_time, %struct.mbedtls_pk_context, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_sequence, i32, i32, i32, i32, %struct.mbedtls_asn1_sequence, i8, %struct.mbedtls_asn1_buf, i32, i32, ptr, ptr }
%struct.mbedtls_asn1_named_data = type { %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, ptr, i8 }
%struct.mbedtls_x509_time = type { i32, i32, i32, i32, i32, i32 }
%struct.mbedtls_pk_context = type { ptr, ptr }
%struct.mbedtls_asn1_sequence = type { %struct.mbedtls_asn1_buf, 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

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

; 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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #5

; Function Attrs: nounwind
declare void @free(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
define dso_local i32 @mbedtls_ssl_cache_set(ptr noundef %0, ptr noundef %1) #6 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  store i32 1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %13 = call i64 @time(ptr noundef null) #7
  store i64 %13, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  store i64 0, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %14, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  store i32 0, ptr %12, align 4, !tbaa !9
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.mbedtls_ssl_cache_context, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  store ptr %17, ptr %10, align 8, !tbaa !5
  store ptr null, ptr %11, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %72, %2
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %77

21:                                               ; preds = %18
  %22 = load i32, ptr %12, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %12, align 4, !tbaa !9
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mbedtls_ssl_cache_context, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !15
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %43

28:                                               ; preds = %21
  %29 = load i64, ptr %6, align 8, !tbaa !11
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %30, i32 0, i32 0
  %32 = load i64, ptr %31, align 8, !tbaa !16
  %33 = sub nsw i64 %29, %32
  %34 = trunc i64 %33 to i32
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mbedtls_ssl_cache_context, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !15
  %38 = icmp sgt i32 %34, %37
  br i1 %38, label %39, label %43

39:                                               ; preds = %28
  %40 = load i64, ptr %6, align 8, !tbaa !11
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %41, i32 0, i32 0
  store i64 %40, ptr %42, align 8, !tbaa !16
  br label %77

43:                                               ; preds = %28, %21
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mbedtls_ssl_session, ptr %44, i32 0, i32 4
  %46 = getelementptr inbounds [32 x i8], ptr %45, i64 0, i64 0
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds %struct.mbedtls_ssl_session, ptr %48, i32 0, i32 4
  %50 = getelementptr inbounds [32 x i8], ptr %49, i64 0, i64 0
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds %struct.mbedtls_ssl_session, ptr %52, i32 0, i32 3
  %54 = load i64, ptr %53, align 8, !tbaa !20
  %55 = call i32 @memcmp(ptr noundef %46, ptr noundef %50, i64 noundef %54) #8
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %43
  br label %77

58:                                               ; preds = %43
  %59 = load i64, ptr %7, align 8, !tbaa !11
  %60 = icmp eq i64 %59, 0
  br i1 %60, label %67, label %61

61:                                               ; preds = %58
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %62, i32 0, i32 0
  %64 = load i64, ptr %63, align 8, !tbaa !16
  %65 = load i64, ptr %7, align 8, !tbaa !11
  %66 = icmp slt i64 %64, %65
  br i1 %66, label %67, label %72

67:                                               ; preds = %61, %58
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %68, i32 0, i32 0
  %70 = load i64, ptr %69, align 8, !tbaa !16
  store i64 %70, ptr %7, align 8, !tbaa !11
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %71, ptr %8, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %67, %61
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %73, ptr %11, align 8, !tbaa !5
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %74, i32 0, i32 3
  %76 = load ptr, ptr %75, align 8, !tbaa !21
  store ptr %76, ptr %10, align 8, !tbaa !5
  br label %18, !llvm.loop !22

77:                                               ; preds = %57, %39, %18
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = icmp eq ptr %78, null
  br i1 %79, label %80, label %113

80:                                               ; preds = %77
  %81 = load i32, ptr %12, align 4, !tbaa !9
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.mbedtls_ssl_cache_context, ptr %82, i32 0, i32 2
  %84 = load i32, ptr %83, align 4, !tbaa !24
  %85 = icmp sge i32 %81, %84
  br i1 %85, label %86, label %92

86:                                               ; preds = %80
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = icmp eq ptr %87, null
  br i1 %88, label %89, label %90

89:                                               ; preds = %86
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %181

90:                                               ; preds = %86
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %91, ptr %10, align 8, !tbaa !5
  br label %109

92:                                               ; preds = %80
  %93 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 192) #9
  store ptr %93, ptr %10, align 8, !tbaa !5
  %94 = load ptr, ptr %10, align 8, !tbaa !5
  %95 = icmp eq ptr %94, null
  br i1 %95, label %96, label %97

96:                                               ; preds = %92
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %181

97:                                               ; preds = %92
  %98 = load ptr, ptr %11, align 8, !tbaa !5
  %99 = icmp eq ptr %98, null
  br i1 %99, label %100, label %104

100:                                              ; preds = %97
  %101 = load ptr, ptr %10, align 8, !tbaa !5
  %102 = load ptr, ptr %9, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.mbedtls_ssl_cache_context, ptr %102, i32 0, i32 0
  store ptr %101, ptr %103, align 8, !tbaa !13
  br label %108

104:                                              ; preds = %97
  %105 = load ptr, ptr %10, align 8, !tbaa !5
  %106 = load ptr, ptr %11, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %106, i32 0, i32 3
  store ptr %105, ptr %107, align 8, !tbaa !21
  br label %108

108:                                              ; preds = %104, %100
  br label %109

109:                                              ; preds = %108, %90
  %110 = load i64, ptr %6, align 8, !tbaa !11
  %111 = load ptr, ptr %10, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %111, i32 0, i32 0
  store i64 %110, ptr %112, align 8, !tbaa !16
  br label %113

113:                                              ; preds = %109, %77
  %114 = load ptr, ptr %10, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %114, i32 0, i32 1
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %115, ptr align 8 %116, i64 152, i1 false)
  %117 = load ptr, ptr %10, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %117, i32 0, i32 2
  %119 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %118, i32 0, i32 2
  %120 = load ptr, ptr %119, align 8, !tbaa !25
  %121 = icmp ne ptr %120, null
  br i1 %121, label %122, label %129

122:                                              ; preds = %113
  %123 = load ptr, ptr %10, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %123, i32 0, i32 2
  %125 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %124, i32 0, i32 2
  %126 = load ptr, ptr %125, align 8, !tbaa !25
  call void @free(ptr noundef %126) #7
  %127 = load ptr, ptr %10, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %127, i32 0, i32 2
  call void @llvm.memset.p0.i64(ptr align 8 %128, i8 0, i64 24, i1 false)
  br label %129

129:                                              ; preds = %122, %113
  %130 = load ptr, ptr %4, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.mbedtls_ssl_session, ptr %130, i32 0, i32 6
  %132 = load ptr, ptr %131, align 8, !tbaa !26
  %133 = icmp ne ptr %132, null
  br i1 %133, label %134, label %180

134:                                              ; preds = %129
  %135 = load ptr, ptr %4, align 8, !tbaa !5
  %136 = getelementptr inbounds %struct.mbedtls_ssl_session, ptr %135, i32 0, i32 6
  %137 = load ptr, ptr %136, align 8, !tbaa !26
  %138 = getelementptr inbounds %struct.mbedtls_x509_crt, ptr %137, i32 0, i32 0
  %139 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %138, i32 0, i32 1
  %140 = load i64, ptr %139, align 8, !tbaa !27
  %141 = call noalias ptr @calloc(i64 noundef 1, i64 noundef %140) #9
  %142 = load ptr, ptr %10, align 8, !tbaa !5
  %143 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %142, i32 0, i32 2
  %144 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %143, i32 0, i32 2
  store ptr %141, ptr %144, align 8, !tbaa !25
  %145 = load ptr, ptr %10, align 8, !tbaa !5
  %146 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %145, i32 0, i32 2
  %147 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %146, i32 0, i32 2
  %148 = load ptr, ptr %147, align 8, !tbaa !25
  %149 = icmp eq ptr %148, null
  br i1 %149, label %150, label %151

150:                                              ; preds = %134
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %181

151:                                              ; preds = %134
  %152 = load ptr, ptr %10, align 8, !tbaa !5
  %153 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %152, i32 0, i32 2
  %154 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %153, i32 0, i32 2
  %155 = load ptr, ptr %154, align 8, !tbaa !25
  %156 = load ptr, ptr %4, align 8, !tbaa !5
  %157 = getelementptr inbounds %struct.mbedtls_ssl_session, ptr %156, i32 0, i32 6
  %158 = load ptr, ptr %157, align 8, !tbaa !26
  %159 = getelementptr inbounds %struct.mbedtls_x509_crt, ptr %158, i32 0, i32 0
  %160 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %159, i32 0, i32 2
  %161 = load ptr, ptr %160, align 8, !tbaa !33
  %162 = load ptr, ptr %4, align 8, !tbaa !5
  %163 = getelementptr inbounds %struct.mbedtls_ssl_session, ptr %162, i32 0, i32 6
  %164 = load ptr, ptr %163, align 8, !tbaa !26
  %165 = getelementptr inbounds %struct.mbedtls_x509_crt, ptr %164, i32 0, i32 0
  %166 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %165, i32 0, i32 1
  %167 = load i64, ptr %166, align 8, !tbaa !27
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %155, ptr align 1 %161, i64 %167, i1 false)
  %168 = load ptr, ptr %4, align 8, !tbaa !5
  %169 = getelementptr inbounds %struct.mbedtls_ssl_session, ptr %168, i32 0, i32 6
  %170 = load ptr, ptr %169, align 8, !tbaa !26
  %171 = getelementptr inbounds %struct.mbedtls_x509_crt, ptr %170, i32 0, i32 0
  %172 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %171, i32 0, i32 1
  %173 = load i64, ptr %172, align 8, !tbaa !27
  %174 = load ptr, ptr %10, align 8, !tbaa !5
  %175 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %174, i32 0, i32 2
  %176 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %175, i32 0, i32 1
  store i64 %173, ptr %176, align 8, !tbaa !34
  %177 = load ptr, ptr %10, align 8, !tbaa !5
  %178 = getelementptr inbounds %struct.mbedtls_ssl_cache_entry, ptr %177, i32 0, i32 1
  %179 = getelementptr inbounds %struct.mbedtls_ssl_session, ptr %178, i32 0, i32 6
  store ptr null, ptr %179, align 8, !tbaa !35
  br label %180

180:                                              ; preds = %151, %129
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %181

181:                                              ; preds = %180, %150, %96, %89
  %182 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  ret i32 %182
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 willreturn memory(read) "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 allocsize(0,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 #6 = { 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind allocsize(0,1) }

!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, !6, i64 0}
!14 = !{!"mbedtls_ssl_cache_context", !6, i64 0, !10, i64 8, !10, i64 12}
!15 = !{!14, !10, i64 8}
!16 = !{!17, !12, i64 0}
!17 = !{!"mbedtls_ssl_cache_entry", !12, i64 0, !18, i64 8, !19, i64 160, !6, i64 184}
!18 = !{!"mbedtls_ssl_session", !12, i64 0, !10, i64 8, !10, i64 12, !12, i64 16, !7, i64 24, !7, i64 56, !6, i64 104, !10, i64 112, !6, i64 120, !12, i64 128, !10, i64 136, !7, i64 140, !10, i64 144, !10, i64 148}
!19 = !{!"mbedtls_asn1_buf", !10, i64 0, !12, i64 8, !6, i64 16}
!20 = !{!17, !12, i64 24}
!21 = !{!17, !6, i64 184}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!14, !10, i64 12}
!25 = !{!17, !6, i64 176}
!26 = !{!18, !6, i64 104}
!27 = !{!28, !12, i64 8}
!28 = !{!"mbedtls_x509_crt", !19, i64 0, !19, i64 24, !10, i64 48, !19, i64 56, !19, i64 80, !19, i64 104, !19, i64 128, !29, i64 152, !29, i64 216, !30, i64 280, !30, i64 304, !31, i64 328, !19, i64 344, !19, i64 368, !19, i64 392, !32, i64 416, !10, i64 448, !10, i64 452, !10, i64 456, !10, i64 460, !32, i64 464, !7, i64 496, !19, i64 504, !10, i64 528, !10, i64 532, !6, i64 536, !6, i64 544}
!29 = !{!"mbedtls_asn1_named_data", !19, i64 0, !19, i64 24, !6, i64 48, !7, i64 56}
!30 = !{!"mbedtls_x509_time", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!31 = !{!"", !6, i64 0, !6, i64 8}
!32 = !{!"mbedtls_asn1_sequence", !19, i64 0, !6, i64 24}
!33 = !{!28, !6, i64 16}
!34 = !{!17, !12, i64 168}
!35 = !{!17, !6, i64 112}


; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #1

; 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) #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @mbedtls_ssl_cache_set(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #5 {
  %3 = tail call i64 @time(ptr noundef null) #7
  %.04974 = load ptr, ptr %0, align 8, !tbaa !5
  %.not75 = icmp eq ptr %.04974, null
  br i1 %.not75, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !9
  %.not61 = icmp eq i32 %5, 0
  %6 = getelementptr inbounds i8, ptr %1, i64 24
  br i1 %.not61, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %11
  %.04979.us = phi ptr [ %.049.us, %11 ], [ %.04974, %.lr.ph ]
  %.078.us = phi i32 [ %12, %11 ], [ 0, %.lr.ph ]
  %.05277.us = phi ptr [ %.153.us, %11 ], [ null, %.lr.ph ]
  %.05476.us = phi i64 [ %.155.us, %11 ], [ 0, %.lr.ph ]
  %7 = getelementptr inbounds i8, ptr %.04979.us, i64 32
  %8 = getelementptr inbounds i8, ptr %.04979.us, i64 24
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %bcmp.us = tail call i32 @bcmp(ptr nonnull %6, ptr nonnull %7, i64 %9)
  %10 = icmp eq i32 %bcmp.us, 0
  br i1 %10, label %.thread, label %11

11:                                               ; preds = %.lr.ph.split.us
  %12 = add nuw nsw i32 %.078.us, 1
  %13 = icmp eq i64 %.05476.us, 0
  %.pre = load i64, ptr %.04979.us, align 8, !tbaa !17
  %14 = icmp slt i64 %.pre, %.05476.us
  %or.cond = select i1 %13, i1 true, i1 %14
  %.155.us = select i1 %or.cond, i64 %.pre, i64 %.05476.us
  %.153.us = select i1 %or.cond, ptr %.04979.us, ptr %.05277.us
  %15 = getelementptr inbounds i8, ptr %.04979.us, i64 184
  %.049.us = load ptr, ptr %15, align 8, !tbaa !5
  %.not.us = icmp eq ptr %.049.us, null
  br i1 %.not.us, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !18

.lr.ph.split:                                     ; preds = %.lr.ph, %26
  %.04979 = phi ptr [ %.049, %26 ], [ %.04974, %.lr.ph ]
  %.078 = phi i32 [ %16, %26 ], [ 0, %.lr.ph ]
  %.05277 = phi ptr [ %.153, %26 ], [ null, %.lr.ph ]
  %.05476 = phi i64 [ %.155, %26 ], [ 0, %.lr.ph ]
  %16 = add nuw nsw i32 %.078, 1
  %17 = load i64, ptr %.04979, align 8, !tbaa !17
  %18 = sub nsw i64 %3, %17
  %19 = trunc i64 %18 to i32
  %20 = icmp slt i32 %5, %19
  br i1 %20, label %.thread.sink.split, label %21

21:                                               ; preds = %.lr.ph.split
  %22 = getelementptr inbounds i8, ptr %.04979, i64 32
  %23 = getelementptr inbounds i8, ptr %.04979, i64 24
  %24 = load i64, ptr %23, align 8, !tbaa !12
  %bcmp = tail call i32 @bcmp(ptr nonnull %6, ptr nonnull %22, i64 %24)
  %25 = icmp eq i32 %bcmp, 0
  br i1 %25, label %.thread, label %26

26:                                               ; preds = %21
  %27 = icmp eq i64 %.05476, 0
  %28 = icmp slt i64 %17, %.05476
  %or.cond114 = or i1 %27, %28
  %.155 = select i1 %or.cond114, i64 %17, i64 %.05476
  %.153 = select i1 %or.cond114, ptr %.04979, ptr %.05277
  %29 = getelementptr inbounds i8, ptr %.04979, i64 184
  %.049 = load ptr, ptr %29, align 8, !tbaa !5
  %.not = icmp eq ptr %.049, null
  br i1 %.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !18

._crit_edge:                                      ; preds = %26, %11
  %.052.lcssa = phi ptr [ %.153.us, %11 ], [ %.153, %26 ]
  %.048.lcssa = phi ptr [ %.04979.us, %11 ], [ %.04979, %26 ]
  %.0.lcssa = phi i32 [ %12, %11 ], [ %16, %26 ]
  %30 = getelementptr inbounds i8, ptr %0, i64 12
  %31 = load i32, ptr %30, align 4, !tbaa !20
  %.not62 = icmp slt i32 %.0.lcssa, %31
  br i1 %.not62, label %36, label %34

._crit_edge.thread:                               ; preds = %2
  %32 = getelementptr inbounds i8, ptr %0, i64 12
  %33 = load i32, ptr %32, align 4, !tbaa !20
  %.not6296 = icmp sgt i32 %33, 0
  br i1 %.not6296, label %.thread101, label %.thread99

34:                                               ; preds = %._crit_edge
  %35 = icmp eq ptr %.052.lcssa, null
  br i1 %35, label %.thread99, label %.thread.sink.split

36:                                               ; preds = %._crit_edge
  %37 = tail call noalias dereferenceable_or_null(192) ptr @calloc(i64 noundef 1, i64 noundef 192) #8
  %38 = icmp eq ptr %37, null
  br i1 %38, label %.thread99, label %42

.thread101:                                       ; preds = %._crit_edge.thread
  %39 = tail call noalias dereferenceable_or_null(192) ptr @calloc(i64 noundef 1, i64 noundef 192) #8
  %40 = icmp eq ptr %39, null
  br i1 %40, label %.thread99, label %41

41:                                               ; preds = %.thread101
  store ptr %39, ptr %0, align 8, !tbaa !21
  br label %.thread.sink.split

42:                                               ; preds = %36
  %43 = getelementptr inbounds i8, ptr %.048.lcssa, i64 184
  store ptr %37, ptr %43, align 8, !tbaa !22
  br label %.thread.sink.split

.thread.sink.split:                               ; preds = %.lr.ph.split, %42, %41, %34
  %.04979.lcssa.sink = phi ptr [ %39, %41 ], [ %37, %42 ], [ %.052.lcssa, %34 ], [ %.04979, %.lr.ph.split ]
  store i64 %3, ptr %.04979.lcssa.sink, align 8, !tbaa !17
  br label %.thread

.thread:                                          ; preds = %21, %.lr.ph.split.us, %.thread.sink.split
  %.2 = phi ptr [ %.04979.lcssa.sink, %.thread.sink.split ], [ %.04979.us, %.lr.ph.split.us ], [ %.04979, %21 ]
  %44 = getelementptr inbounds i8, ptr %.2, i64 8
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(152) %44, ptr noundef nonnull align 8 dereferenceable(152) %1, i64 152, i1 false)
  %45 = getelementptr inbounds i8, ptr %.2, i64 176
  %46 = load ptr, ptr %45, align 8, !tbaa !23
  %.not63 = icmp eq ptr %46, null
  br i1 %.not63, label %49, label %47

47:                                               ; preds = %.thread
  %48 = getelementptr inbounds i8, ptr %.2, i64 160
  tail call void @free(ptr noundef nonnull %46) #7
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %48, i8 0, i64 24, i1 false)
  br label %49

49:                                               ; preds = %47, %.thread
  %50 = getelementptr inbounds i8, ptr %1, i64 104
  %51 = load ptr, ptr %50, align 8, !tbaa !24
  %.not64 = icmp eq ptr %51, null
  br i1 %.not64, label %.thread99, label %52

52:                                               ; preds = %49
  %53 = getelementptr inbounds i8, ptr %51, i64 8
  %54 = load i64, ptr %53, align 8, !tbaa !25
  %55 = tail call noalias ptr @calloc(i64 noundef 1, i64 noundef %54) #8
  store ptr %55, ptr %45, align 8, !tbaa !23
  %56 = icmp eq ptr %55, null
  br i1 %56, label %.thread99, label %57

57:                                               ; preds = %52
  %58 = getelementptr inbounds i8, ptr %51, i64 16
  %59 = load ptr, ptr %58, align 8, !tbaa !31
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %55, ptr align 1 %59, i64 %54, i1 false)
  %60 = getelementptr inbounds i8, ptr %.2, i64 168
  store i64 %54, ptr %60, align 8, !tbaa !32
  %61 = getelementptr inbounds i8, ptr %.2, i64 112
  store ptr null, ptr %61, align 8, !tbaa !33
  br label %.thread99

.thread99:                                        ; preds = %._crit_edge.thread, %.thread101, %49, %57, %52, %36, %34
  %.051 = phi i32 [ 1, %34 ], [ 1, %36 ], [ 1, %52 ], [ 0, %57 ], [ 0, %49 ], [ 1, %.thread101 ], [ 1, %._crit_edge.thread ]
  ret i32 %.051
}

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #6

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nounwind "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { 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 #6 = { nofree nounwind willreturn memory(argmem: read) }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0,1) }

!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, !11, i64 8}
!10 = !{!"mbedtls_ssl_cache_context", !6, i64 0, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 24}
!13 = !{!"mbedtls_ssl_cache_entry", !14, i64 0, !15, i64 8, !16, i64 160, !6, i64 184}
!14 = !{!"long", !7, i64 0}
!15 = !{!"mbedtls_ssl_session", !14, i64 0, !11, i64 8, !11, i64 12, !14, i64 16, !7, i64 24, !7, i64 56, !6, i64 104, !11, i64 112, !6, i64 120, !14, i64 128, !11, i64 136, !7, i64 140, !11, i64 144, !11, i64 148}
!16 = !{!"mbedtls_asn1_buf", !11, i64 0, !14, i64 8, !6, i64 16}
!17 = !{!13, !14, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !11, i64 12}
!21 = !{!10, !6, i64 0}
!22 = !{!13, !6, i64 184}
!23 = !{!13, !6, i64 176}
!24 = !{!15, !6, i64 104}
!25 = !{!26, !14, i64 8}
!26 = !{!"mbedtls_x509_crt", !16, i64 0, !16, i64 24, !11, i64 48, !16, i64 56, !16, i64 80, !16, i64 104, !16, i64 128, !27, i64 152, !27, i64 216, !28, i64 280, !28, i64 304, !29, i64 328, !16, i64 344, !16, i64 368, !16, i64 392, !30, i64 416, !11, i64 448, !11, i64 452, !11, i64 456, !11, i64 460, !30, i64 464, !7, i64 496, !16, i64 504, !11, i64 528, !11, i64 532, !6, i64 536, !6, i64 544}
!27 = !{!"mbedtls_asn1_named_data", !16, i64 0, !16, i64 24, !6, i64 48, !7, i64 56}
!28 = !{!"mbedtls_x509_time", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!29 = !{!"", !6, i64 0, !6, i64 8}
!30 = !{!"mbedtls_asn1_sequence", !16, i64 0, !6, i64 24}
!31 = !{!26, !6, i64 16}
!32 = !{!13, !14, i64 168}
!33 = !{!13, !6, i64 112}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass