; LLVM IR from ARMmbed/mbed-crypto :: library (md)

; 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_md_info_t = type { ptr, i32, i8, i8 }

; Function Attrs: nounwind uwtable
define dso_local void @mbedtls_md_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 = icmp eq ptr %3, null
  br i1 %4, label %10, label %5

5:                                                ; preds = %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %5, %1
  br label %69

11:                                               ; preds = %5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %47

16:                                               ; preds = %11
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.mbedtls_md_info_t, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !12
  switch i32 %21, label %42 [
    i32 3, label %22
    i32 9, label %26
    i32 4, label %30
    i32 5, label %34
    i32 6, label %34
    i32 7, label %38
    i32 8, label %38
  ]

22:                                               ; preds = %16
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  call void @mbedtls_md5_free(ptr noundef %25)
  br label %43

26:                                               ; preds = %16
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  call void @mbedtls_ripemd160_free(ptr noundef %29)
  br label %43

30:                                               ; preds = %16
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  call void @mbedtls_sha1_free(ptr noundef %33)
  br label %43

34:                                               ; preds = %16, %16
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  call void @mbedtls_sha256_free(ptr noundef %37)
  br label %43

38:                                               ; preds = %16, %16
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  call void @mbedtls_sha512_free(ptr noundef %41)
  br label %43

42:                                               ; preds = %16
  br label %43

43:                                               ; preds = %42, %38, %34, %30, %26, %22
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  call void @free(ptr noundef %46) #3
  br label %47

47:                                               ; preds = %43, %11
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %67

52:                                               ; preds = %47
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.mbedtls_md_info_t, ptr %58, i32 0, i32 3
  %60 = load i8, ptr %59, align 1, !tbaa !16
  %61 = zext i8 %60 to i32
  %62 = mul nsw i32 2, %61
  %63 = sext i32 %62 to i64
  call void @mbedtls_platform_zeroize(ptr noundef %55, i64 noundef %63)
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  call void @free(ptr noundef %66) #3
  br label %67

67:                                               ; preds = %52, %47
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  call void @mbedtls_platform_zeroize(ptr noundef %68, i64 noundef 24)
  br label %69

69:                                               ; preds = %67, %10
  ret void
}

declare void @mbedtls_md5_free(ptr noundef) #1

declare void @mbedtls_ripemd160_free(ptr noundef) #1

declare void @mbedtls_sha1_free(ptr noundef) #1

declare void @mbedtls_sha256_free(ptr noundef) #1

declare void @mbedtls_sha512_free(ptr noundef) #1

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

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) #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 "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 0}
!10 = !{!"mbedtls_md_context_t", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !14, i64 8}
!13 = !{!"mbedtls_md_info_t", !6, i64 0, !14, i64 8, !7, i64 12, !7, i64 13}
!14 = !{!"int", !7, i64 0}
!15 = !{!10, !6, i64 16}
!16 = !{!13, !7, i64 13}


; 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 void @mbedtls_md_free(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %30, label %3

3:                                                ; preds = %1
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %30, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !10
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %19, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !11
  switch i32 %11, label %17 [
    i32 3, label %12
    i32 9, label %13
    i32 4, label %14
    i32 5, label %15
    i32 6, label %15
    i32 7, label %16
    i32 8, label %16
  ]

12:                                               ; preds = %9
  tail call void @mbedtls_md5_free(ptr noundef nonnull %8) #3
  br label %17

13:                                               ; preds = %9
  tail call void @mbedtls_ripemd160_free(ptr noundef nonnull %8) #3
  br label %17

14:                                               ; preds = %9
  tail call void @mbedtls_sha1_free(ptr noundef nonnull %8) #3
  br label %17

15:                                               ; preds = %9, %9
  tail call void @mbedtls_sha256_free(ptr noundef nonnull %8) #3
  br label %17

16:                                               ; preds = %9, %9
  tail call void @mbedtls_sha512_free(ptr noundef nonnull %8) #3
  br label %17

17:                                               ; preds = %9, %16, %15, %14, %13, %12
  %18 = load ptr, ptr %7, align 8, !tbaa !10
  tail call void @free(ptr noundef %18) #3
  br label %19

19:                                               ; preds = %17, %6
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %.not18 = icmp eq ptr %21, null
  br i1 %.not18, label %29, label %22

22:                                               ; preds = %19
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 13
  %25 = load i8, ptr %24, align 1, !tbaa !15
  %26 = zext i8 %25 to i64
  %27 = shl nuw nsw i64 %26, 1
  tail call void @mbedtls_platform_zeroize(ptr noundef nonnull %21, i64 noundef %27) #3
  %28 = load ptr, ptr %20, align 8, !tbaa !14
  tail call void @free(ptr noundef %28) #3
  br label %29

29:                                               ; preds = %22, %19
  tail call void @mbedtls_platform_zeroize(ptr noundef nonnull %0, i64 noundef 24) #3
  br label %30

30:                                               ; preds = %1, %3, %29
  ret void
}

declare void @mbedtls_md5_free(ptr noundef) local_unnamed_addr #1

declare void @mbedtls_ripemd160_free(ptr noundef) local_unnamed_addr #1

declare void @mbedtls_sha1_free(ptr noundef) local_unnamed_addr #1

declare void @mbedtls_sha256_free(ptr noundef) local_unnamed_addr #1

declare void @mbedtls_sha512_free(ptr noundef) local_unnamed_addr #1

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

declare void @mbedtls_platform_zeroize(ptr noundef, i64 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 = { 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 #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, !7, i64 0}
!6 = !{!"mbedtls_md_context_t", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !13, i64 8}
!12 = !{!"mbedtls_md_info_t", !7, i64 0, !13, i64 8, !8, i64 12, !8, i64 13}
!13 = !{!"int", !8, i64 0}
!14 = !{!6, !7, i64 16}
!15 = !{!12, !8, i64 13}


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