; 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_info_t = type { ptr, i32, i8, i8 }
%struct.mbedtls_md_context_t = type { ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_md_free(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_md_setup(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %13, label %10

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %10, %3
  store i32 -20736, ptr %4, align 4
  br label %116

14:                                               ; preds = %10
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.mbedtls_md_info_t, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !11
  switch i32 %17, label %93 [
    i32 3, label %18
    i32 9, label %33
    i32 4, label %48
    i32 5, label %63
    i32 6, label %63
    i32 7, label %78
    i32 8, label %78
  ]

18:                                               ; preds = %14
  br label %19

19:                                               ; preds = %18
  %20 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 88) #3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %21, i32 0, i32 1
  store ptr %20, ptr %22, align 8, !tbaa !13
  %23 = load ptr, ptr %5, 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 !13
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %19
  store i32 -20864, ptr %4, align 4
  br label %116

28:                                               ; preds = %19
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  call void @mbedtls_md5_init(ptr noundef %31)
  br label %32

32:                                               ; preds = %28
  br label %94

33:                                               ; preds = %14
  br label %34

34:                                               ; preds = %33
  %35 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 92) #3
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %36, i32 0, i32 1
  store ptr %35, ptr %37, align 8, !tbaa !13
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %34
  store i32 -20864, ptr %4, align 4
  br label %116

43:                                               ; preds = %34
  %44 = load ptr, ptr %5, 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 !13
  call void @mbedtls_ripemd160_init(ptr noundef %46)
  br label %47

47:                                               ; preds = %43
  br label %94

48:                                               ; preds = %14
  br label %49

49:                                               ; preds = %48
  %50 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 92) #3
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %51, i32 0, i32 1
  store ptr %50, ptr %52, align 8, !tbaa !13
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %58

57:                                               ; preds = %49
  store i32 -20864, ptr %4, align 4
  br label %116

58:                                               ; preds = %49
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  call void @mbedtls_sha1_init(ptr noundef %61)
  br label %62

62:                                               ; preds = %58
  br label %94

63:                                               ; preds = %14, %14
  br label %64

64:                                               ; preds = %63
  %65 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 108) #3
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %66, i32 0, i32 1
  store ptr %65, ptr %67, align 8, !tbaa !13
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !13
  %71 = icmp eq ptr %70, null
  br i1 %71, label %72, label %73

72:                                               ; preds = %64
  store i32 -20864, ptr %4, align 4
  br label %116

73:                                               ; preds = %64
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !13
  call void @mbedtls_sha256_init(ptr noundef %76)
  br label %77

77:                                               ; preds = %73
  br label %94

78:                                               ; preds = %14, %14
  br label %79

79:                                               ; preds = %78
  %80 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 216) #3
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %81, i32 0, i32 1
  store ptr %80, ptr %82, align 8, !tbaa !13
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %83, i32 0, i32 1
  %85 = load ptr, ptr %84, align 8, !tbaa !13
  %86 = icmp eq ptr %85, null
  br i1 %86, label %87, label %88

87:                                               ; preds = %79
  store i32 -20864, ptr %4, align 4
  br label %116

88:                                               ; preds = %79
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %89, i32 0, i32 1
  %91 = load ptr, ptr %90, align 8, !tbaa !13
  call void @mbedtls_sha512_init(ptr noundef %91)
  br label %92

92:                                               ; preds = %88
  br label %94

93:                                               ; preds = %14
  store i32 -20736, ptr %4, align 4
  br label %116

94:                                               ; preds = %92, %77, %62, %47, %32
  %95 = load i32, ptr %7, align 4, !tbaa !9
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %112

97:                                               ; preds = %94
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.mbedtls_md_info_t, ptr %98, i32 0, i32 3
  %100 = load i8, ptr %99, align 1, !tbaa !15
  %101 = zext i8 %100 to i64
  %102 = call noalias ptr @calloc(i64 noundef 2, i64 noundef %101) #3
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %103, i32 0, i32 2
  store ptr %102, ptr %104, align 8, !tbaa !16
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %105, i32 0, i32 2
  %107 = load ptr, ptr %106, align 8, !tbaa !16
  %108 = icmp eq ptr %107, null
  br i1 %108, label %109, label %111

109:                                              ; preds = %97
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mbedtls_md_free(ptr noundef %110)
  store i32 -20864, ptr %4, align 4
  br label %116

111:                                              ; preds = %97
  br label %112

112:                                              ; preds = %111, %94
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %114, i32 0, i32 0
  store ptr %113, ptr %115, align 8, !tbaa !17
  store i32 0, ptr %4, align 4
  br label %116

116:                                              ; preds = %112, %109, %93, %87, %72, %57, %42, %27, %13
  %117 = load i32, ptr %4, align 4
  ret i32 %117
}

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

declare void @mbedtls_md5_init(ptr noundef) #2

declare void @mbedtls_ripemd160_init(ptr noundef) #2

declare void @mbedtls_sha1_init(ptr noundef) #2

declare void @mbedtls_sha256_init(ptr noundef) #2

declare void @mbedtls_sha512_init(ptr noundef) #2

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 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 #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 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, !10, i64 8}
!12 = !{!"mbedtls_md_info_t", !6, i64 0, !10, i64 8, !7, i64 12, !7, i64 13}
!13 = !{!14, !6, i64 8}
!14 = !{!"mbedtls_md_context_t", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!12, !7, i64 13}
!16 = !{!14, !6, i64 16}
!17 = !{!14, !6, 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"

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_md_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -20864, 1) i32 @mbedtls_md_setup(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %1, null
  %5 = icmp eq ptr %0, null
  %or.cond = or i1 %5, %4
  br i1 %or.cond, label %44, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !5
  switch i32 %8, label %44 [
    i32 3, label %9
    i32 9, label %14
    i32 4, label %19
    i32 5, label %24
    i32 6, label %24
    i32 7, label %29
    i32 8, label %29
  ]

9:                                                ; preds = %6
  %10 = tail call noalias dereferenceable_or_null(88) ptr @calloc(i64 noundef 1, i64 noundef 88) #3
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %10, ptr %11, align 8, !tbaa !11
  %12 = icmp eq ptr %10, null
  br i1 %12, label %44, label %13

13:                                               ; preds = %9
  tail call void @mbedtls_md5_init(ptr noundef nonnull %10) #4
  br label %34

14:                                               ; preds = %6
  %15 = tail call noalias dereferenceable_or_null(92) ptr @calloc(i64 noundef 1, i64 noundef 92) #3
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %15, ptr %16, align 8, !tbaa !11
  %17 = icmp eq ptr %15, null
  br i1 %17, label %44, label %18

18:                                               ; preds = %14
  tail call void @mbedtls_ripemd160_init(ptr noundef nonnull %15) #4
  br label %34

19:                                               ; preds = %6
  %20 = tail call noalias dereferenceable_or_null(92) ptr @calloc(i64 noundef 1, i64 noundef 92) #3
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %20, ptr %21, align 8, !tbaa !11
  %22 = icmp eq ptr %20, null
  br i1 %22, label %44, label %23

23:                                               ; preds = %19
  tail call void @mbedtls_sha1_init(ptr noundef nonnull %20) #4
  br label %34

24:                                               ; preds = %6, %6
  %25 = tail call noalias dereferenceable_or_null(108) ptr @calloc(i64 noundef 1, i64 noundef 108) #3
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %25, ptr %26, align 8, !tbaa !11
  %27 = icmp eq ptr %25, null
  br i1 %27, label %44, label %28

28:                                               ; preds = %24
  tail call void @mbedtls_sha256_init(ptr noundef nonnull %25) #4
  br label %34

29:                                               ; preds = %6, %6
  %30 = tail call noalias dereferenceable_or_null(216) ptr @calloc(i64 noundef 1, i64 noundef 216) #3
  %31 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %30, ptr %31, align 8, !tbaa !11
  %32 = icmp eq ptr %30, null
  br i1 %32, label %44, label %33

33:                                               ; preds = %29
  tail call void @mbedtls_sha512_init(ptr noundef nonnull %30) #4
  br label %34

34:                                               ; preds = %33, %28, %23, %18, %13
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %43, label %35

35:                                               ; preds = %34
  %36 = getelementptr inbounds i8, ptr %1, i64 13
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = zext i8 %37 to i64
  %39 = tail call noalias ptr @calloc(i64 noundef 2, i64 noundef %38) #3
  %40 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %39, ptr %40, align 8, !tbaa !14
  %41 = icmp eq ptr %39, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %35
  tail call void @mbedtls_md_free(ptr noundef nonnull %0)
  br label %44

43:                                               ; preds = %35, %34
  store ptr %1, ptr %0, align 8, !tbaa !15
  br label %44

44:                                               ; preds = %6, %29, %24, %19, %14, %9, %3, %43, %42
  %.0 = phi i32 [ -20864, %42 ], [ 0, %43 ], [ -20736, %3 ], [ -20864, %9 ], [ -20864, %14 ], [ -20864, %19 ], [ -20864, %24 ], [ -20864, %29 ], [ -20736, %6 ]
  ret i32 %.0
}

; 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 #1

declare void @mbedtls_md5_init(ptr noundef) local_unnamed_addr #2

declare void @mbedtls_ripemd160_init(ptr noundef) local_unnamed_addr #2

declare void @mbedtls_sha1_init(ptr noundef) local_unnamed_addr #2

declare void @mbedtls_sha256_init(ptr noundef) local_unnamed_addr #2

declare void @mbedtls_sha512_init(ptr noundef) local_unnamed_addr #2

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 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 #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 allocsize(0,1) }
attributes #4 = { 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_md_info_t", !7, i64 0, !10, i64 8, !8, i64 12, !8, i64 13}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 8}
!12 = !{!"mbedtls_md_context_t", !7, i64 0, !7, i64 8, !7, i64 16}
!13 = !{!6, !8, i64 13}
!14 = !{!12, !7, i64 16}
!15 = !{!12, !7, i64 0}


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