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

; 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_config = type { [4 x ptr], ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.mbedtls_mpi, %struct.mbedtls_mpi, ptr, i64, ptr, i64, ptr, i32, i32, i32, i32, [8 x i8], i32, i32, i8, i8, i8, i8, i32 }
%struct.mbedtls_mpi = type { i32, i64, ptr }

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

declare void @mbedtls_mpi_free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @mbedtls_ssl_config_free(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %3, i32 0, i32 28
  call void @mbedtls_mpi_free(ptr noundef %4)
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %5, i32 0, i32 29
  call void @mbedtls_mpi_free(ptr noundef %6)
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %7, i32 0, i32 30
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %34

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %12, i32 0, i32 30
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %15, i32 0, i32 31
  %17 = load i64, ptr %16, align 8, !tbaa !14
  call void @mbedtls_zeroize(ptr noundef %14, i64 noundef %17)
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %18, i32 0, i32 32
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %21, i32 0, i32 33
  %23 = load i64, ptr %22, align 8, !tbaa !16
  call void @mbedtls_zeroize(ptr noundef %20, i64 noundef %23)
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %24, i32 0, i32 30
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  call void @free(ptr noundef %26) #3
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %27, i32 0, i32 32
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  call void @free(ptr noundef %29) #3
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %30, i32 0, i32 31
  store i64 0, ptr %31, align 8, !tbaa !14
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %32, i32 0, i32 33
  store i64 0, ptr %33, align 8, !tbaa !16
  br label %34

34:                                               ; preds = %11, %1
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mbedtls_ssl_config, ptr %35, i32 0, i32 23
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  call void @ssl_key_cert_free(ptr noundef %37)
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  call void @mbedtls_zeroize(ptr noundef %38, i64 noundef 376)
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @ssl_key_cert_free(ptr noundef) #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" }
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 = { "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, !6, i64 296}
!10 = !{!"mbedtls_ssl_config", !7, i64 0, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !11, i64 248, !11, i64 272, !6, i64 296, !13, i64 304, !6, i64 312, !13, i64 320, !6, i64 328, !12, i64 336, !12, i64 340, !12, i64 344, !12, i64 348, !7, i64 352, !12, i64 360, !12, i64 364, !7, i64 368, !7, i64 369, !7, i64 370, !7, i64 371, !12, i64 372, !12, i64 372, !12, i64 372, !12, i64 372, !12, i64 372, !12, i64 372, !12, i64 373, !12, i64 373, !12, i64 373, !12, i64 373, !12, i64 373, !12, i64 373, !12, i64 374, !12, i64 374, !12, i64 374}
!11 = !{!"", !12, i64 0, !13, i64 8, !6, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !13, i64 304}
!15 = !{!10, !6, i64 312}
!16 = !{!10, !13, i64 320}
!17 = !{!10, !6, i64 208}


; 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 hidden void @mbedtls_zeroize(ptr noundef, i64 noundef) local_unnamed_addr #0

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

declare void @mbedtls_mpi_free(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @mbedtls_ssl_config_free(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 248
  tail call void @mbedtls_mpi_free(ptr noundef nonnull %2) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 272
  tail call void @mbedtls_mpi_free(ptr noundef nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 296
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %15, label %6

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 304
  %8 = load i64, ptr %7, align 8, !tbaa !13
  tail call void @mbedtls_zeroize(ptr noundef nonnull %5, i64 noundef %8)
  %9 = getelementptr inbounds i8, ptr %0, i64 312
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %0, i64 320
  %12 = load i64, ptr %11, align 8, !tbaa !15
  tail call void @mbedtls_zeroize(ptr noundef %10, i64 noundef %12)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  tail call void @free(ptr noundef %13) #3
  %14 = load ptr, ptr %9, align 8, !tbaa !14
  tail call void @free(ptr noundef %14) #3
  store i64 0, ptr %7, align 8, !tbaa !13
  store i64 0, ptr %11, align 8, !tbaa !15
  br label %15

15:                                               ; preds = %6, %1
  %16 = getelementptr inbounds i8, ptr %0, i64 208
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  tail call void @ssl_key_cert_free(ptr noundef %17)
  tail call void @mbedtls_zeroize(ptr noundef nonnull %0, i64 noundef 376)
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @ssl_key_cert_free(ptr noundef) local_unnamed_addr #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" }
attributes #1 = { 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 #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, !9, i64 296}
!6 = !{!"mbedtls_ssl_config", !7, i64 0, !9, i64 32, !9, i64 40, !9, i64 48, !9, i64 56, !9, i64 64, !9, i64 72, !9, i64 80, !9, i64 88, !9, i64 96, !9, i64 104, !9, i64 112, !9, i64 120, !9, i64 128, !9, i64 136, !9, i64 144, !9, i64 152, !9, i64 160, !9, i64 168, !9, i64 176, !9, i64 184, !9, i64 192, !9, i64 200, !9, i64 208, !9, i64 216, !9, i64 224, !9, i64 232, !9, i64 240, !10, i64 248, !10, i64 272, !9, i64 296, !12, i64 304, !9, i64 312, !12, i64 320, !9, i64 328, !11, i64 336, !11, i64 340, !11, i64 344, !11, i64 348, !7, i64 352, !11, i64 360, !11, i64 364, !7, i64 368, !7, i64 369, !7, i64 370, !7, i64 371, !11, i64 372, !11, i64 372, !11, i64 372, !11, i64 372, !11, i64 372, !11, i64 372, !11, i64 373, !11, i64 373, !11, i64 373, !11, i64 373, !11, i64 373, !11, i64 373, !11, i64 374, !11, i64 374, !11, i64 374}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !9, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!6, !12, i64 304}
!14 = !{!6, !9, i64 312}
!15 = !{!6, !12, i64 320}
!16 = !{!6, !9, i64 208}


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