; 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 }

@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_md_starts(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_md_update(ptr noundef, ptr noundef, i64 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_md_file(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca %struct.mbedtls_md_context_t, align 8
  %12 = alloca [1024 x i8], align 16
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 -110, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 1024, ptr %12) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  store i32 -20736, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %58

17:                                               ; preds = %3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call noalias ptr @fopen(ptr noundef %18, ptr noundef @.str.8)
  store ptr %19, ptr %9, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  store i32 -20992, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %58

22:                                               ; preds = %17
  call void @mbedtls_md_init(ptr noundef %11)
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call i32 @mbedtls_md_setup(ptr noundef %11, ptr noundef %23, i32 noundef 0)
  store i32 %24, ptr %8, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  br label %53

27:                                               ; preds = %22
  %28 = call i32 @mbedtls_md_starts(ptr noundef %11)
  store i32 %28, ptr %8, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  br label %53

31:                                               ; preds = %27
  br label %32

32:                                               ; preds = %43, %31
  %33 = getelementptr inbounds [1024 x i8], ptr %12, i64 0, i64 0
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = call i64 @fread(ptr noundef %33, i64 noundef 1, i64 noundef 1024, ptr noundef %34)
  store i64 %35, ptr %10, align 8, !tbaa !11
  %36 = icmp ugt i64 %35, 0
  br i1 %36, label %37, label %44

37:                                               ; preds = %32
  %38 = getelementptr inbounds [1024 x i8], ptr %12, i64 0, i64 0
  %39 = load i64, ptr %10, align 8, !tbaa !11
  %40 = call i32 @mbedtls_md_update(ptr noundef %11, ptr noundef %38, i64 noundef %39)
  store i32 %40, ptr %8, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  br label %53

43:                                               ; preds = %37
  br label %32, !llvm.loop !13

44:                                               ; preds = %32
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = call i32 @ferror(ptr noundef %45) #4
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %44
  store i32 -20992, ptr %8, align 4, !tbaa !9
  br label %52

49:                                               ; preds = %44
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = call i32 @mbedtls_md_finish(ptr noundef %11, ptr noundef %50)
  store i32 %51, ptr %8, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %49, %48
  br label %53

53:                                               ; preds = %52, %42, %30, %26
  %54 = getelementptr inbounds [1024 x i8], ptr %12, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %54, i64 noundef 1024)
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = call i32 @fclose(ptr noundef %55)
  call void @mbedtls_md_free(ptr noundef %11)
  %57 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %57, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %58

58:                                               ; preds = %53, %21, %16
  call void @llvm.lifetime.end.p0(i64 1024, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %59 = load i32, ptr %4, align 4
  ret i32 %59
}

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @ferror(ptr noundef) #3

declare i32 @fclose(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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 }

@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_md_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

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

7:                                                ; preds = %3
  %8 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.8)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %22, label %10

10:                                               ; preds = %7
  call void @mbedtls_md_init(ptr noundef nonnull %4)
  %11 = call i32 @mbedtls_md_setup(ptr noundef nonnull %4, ptr noundef nonnull %0, i32 noundef 0)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %.loopexit

12:                                               ; preds = %10
  %13 = call i32 @mbedtls_md_starts(ptr noundef nonnull %4)
  %.not16 = icmp eq i32 %13, 0
  br i1 %.not16, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %12, %15
  %14 = call i64 @fread(ptr noundef nonnull %5, i64 noundef 1, i64 noundef 1024, ptr noundef nonnull %8)
  %.not17 = icmp eq i64 %14, 0
  br i1 %.not17, label %17, label %15

15:                                               ; preds = %.preheader
  %16 = call i32 @mbedtls_md_update(ptr noundef nonnull %4, ptr noundef nonnull %5, i64 noundef %14)
  %.not19 = icmp eq i32 %16, 0
  br i1 %.not19, label %.preheader, label %.loopexit, !llvm.loop !5

17:                                               ; preds = %.preheader
  %18 = call i32 @ferror(ptr noundef nonnull %8) #5
  %.not18 = icmp eq i32 %18, 0
  br i1 %.not18, label %19, label %.loopexit

19:                                               ; preds = %17
  %20 = call i32 @mbedtls_md_finish(ptr noundef nonnull %4, ptr noundef %2)
  br label %.loopexit

.loopexit:                                        ; preds = %15, %17, %19, %12, %10
  %.09 = phi i32 [ %11, %10 ], [ %13, %12 ], [ %20, %19 ], [ -20992, %17 ], [ %16, %15 ]
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %5, i64 noundef 1024) #5
  %21 = call i32 @fclose(ptr noundef nonnull %8)
  call void @mbedtls_md_free(ptr noundef nonnull %4)
  br label %22

22:                                               ; preds = %7, %3, %.loopexit
  %.0 = phi i32 [ %.09, %.loopexit ], [ -20736, %3 ], [ -20992, %7 ]
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  ret i32 %.0
}

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nofree 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 #4 = { nofree nounwind 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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