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

; 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_hmac_drbg_context = type { %struct.mbedtls_md_context_t, [64 x i8], i32, i64, i32, i32, ptr, ptr }
%struct.mbedtls_md_context_t = type { ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_hmac_drbg_update_ret(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  %9 = alloca [1 x i8], align 1
  %10 = alloca [64 x i8], align 16
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds %struct.mbedtls_md_context_t, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = call zeroext i8 @mbedtls_md_get_size(ptr noundef %15)
  %17 = zext i8 %16 to i64
  store i64 %17, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %23

20:                                               ; preds = %3
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = icmp ne i64 %21, 0
  br label %23

23:                                               ; preds = %20, %3
  %24 = phi i1 [ false, %3 ], [ %22, %20 ]
  %25 = zext i1 %24 to i64
  %26 = select i1 %24, i32 2, i32 1
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %8, align 1, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 64, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 -20736, ptr %11, align 4, !tbaa !16
  %28 = getelementptr inbounds [1 x i8], ptr %9, i64 0, i64 0
  store i8 0, ptr %28, align 1, !tbaa !15
  br label %29

29:                                               ; preds = %107, %23
  %30 = getelementptr inbounds [1 x i8], ptr %9, i64 0, i64 0
  %31 = load i8, ptr %30, align 1, !tbaa !15
  %32 = zext i8 %31 to i32
  %33 = load i8, ptr %8, align 1, !tbaa !15
  %34 = zext i8 %33 to i32
  %35 = icmp slt i32 %32, %34
  br i1 %35, label %36, label %111

36:                                               ; preds = %29
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %37, i32 0, i32 0
  %39 = call i32 @mbedtls_md_hmac_reset(ptr noundef %38)
  store i32 %39, ptr %11, align 4, !tbaa !16
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  br label %112

42:                                               ; preds = %36
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds [64 x i8], ptr %46, i64 0, i64 0
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = call i32 @mbedtls_md_hmac_update(ptr noundef %44, ptr noundef %47, i64 noundef %48)
  store i32 %49, ptr %11, align 4, !tbaa !16
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %42
  br label %112

52:                                               ; preds = %42
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds [1 x i8], ptr %9, i64 0, i64 0
  %56 = call i32 @mbedtls_md_hmac_update(ptr noundef %54, ptr noundef %55, i64 noundef 1)
  store i32 %56, ptr %11, align 4, !tbaa !16
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %52
  br label %112

59:                                               ; preds = %52
  %60 = load i8, ptr %8, align 1, !tbaa !15
  %61 = zext i8 %60 to i32
  %62 = icmp eq i32 %61, 2
  br i1 %62, label %63, label %72

63:                                               ; preds = %59
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load i64, ptr %6, align 8, !tbaa !9
  %68 = call i32 @mbedtls_md_hmac_update(ptr noundef %65, ptr noundef %66, i64 noundef %67)
  store i32 %68, ptr %11, align 4, !tbaa !16
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %71

70:                                               ; preds = %63
  br label %112

71:                                               ; preds = %63
  br label %72

72:                                               ; preds = %71, %59
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %73, i32 0, i32 0
  %75 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  %76 = call i32 @mbedtls_md_hmac_finish(ptr noundef %74, ptr noundef %75)
  store i32 %76, ptr %11, align 4, !tbaa !16
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %79

78:                                               ; preds = %72
  br label %112

79:                                               ; preds = %72
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %80, i32 0, i32 0
  %82 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  %83 = load i64, ptr %7, align 8, !tbaa !9
  %84 = call i32 @mbedtls_md_hmac_starts(ptr noundef %81, ptr noundef %82, i64 noundef %83)
  store i32 %84, ptr %11, align 4, !tbaa !16
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %79
  br label %112

87:                                               ; preds = %79
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %90, i32 0, i32 1
  %92 = getelementptr inbounds [64 x i8], ptr %91, i64 0, i64 0
  %93 = load i64, ptr %7, align 8, !tbaa !9
  %94 = call i32 @mbedtls_md_hmac_update(ptr noundef %89, ptr noundef %92, i64 noundef %93)
  store i32 %94, ptr %11, align 4, !tbaa !16
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %96, label %97

96:                                               ; preds = %87
  br label %112

97:                                               ; preds = %87
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.mbedtls_hmac_drbg_context, ptr %100, i32 0, i32 1
  %102 = getelementptr inbounds [64 x i8], ptr %101, i64 0, i64 0
  %103 = call i32 @mbedtls_md_hmac_finish(ptr noundef %99, ptr noundef %102)
  store i32 %103, ptr %11, align 4, !tbaa !16
  %104 = icmp ne i32 %103, 0
  br i1 %104, label %105, label %106

105:                                              ; preds = %97
  br label %112

106:                                              ; preds = %97
  br label %107

107:                                              ; preds = %106
  %108 = getelementptr inbounds [1 x i8], ptr %9, i64 0, i64 0
  %109 = load i8, ptr %108, align 1, !tbaa !15
  %110 = add i8 %109, 1
  store i8 %110, ptr %108, align 1, !tbaa !15
  br label %29, !llvm.loop !17

111:                                              ; preds = %29
  br label %112

112:                                              ; preds = %111, %105, %96, %86, %78, %70, %58, %51, %41
  %113 = getelementptr inbounds [64 x i8], ptr %10, i64 0, i64 0
  call void @mbedtls_platform_zeroize(ptr noundef %113, i64 noundef 64)
  %114 = load i32, ptr %11, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i32 %114
}

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

declare zeroext i8 @mbedtls_md_get_size(ptr noundef) #2

declare i32 @mbedtls_md_hmac_reset(ptr noundef) #2

declare i32 @mbedtls_md_hmac_update(ptr noundef, ptr noundef, i64 noundef) #2

declare i32 @mbedtls_md_hmac_finish(ptr noundef, ptr noundef) #2

declare i32 @mbedtls_md_hmac_starts(ptr noundef, ptr noundef, i64 noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"mbedtls_hmac_drbg_context", !13, i64 0, !7, i64 24, !14, i64 88, !10, i64 96, !14, i64 104, !14, i64 108, !6, i64 112, !6, i64 120}
!13 = !{!"mbedtls_md_context_t", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!14, !14, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_hmac_drbg_update_ret(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [1 x i8], align 1
  %5 = alloca [64 x i8], align 16
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = tail call zeroext i8 @mbedtls_md_get_size(ptr noundef %6) #3
  %8 = zext i8 %7 to i64
  %9 = icmp ne ptr %1, null
  %10 = icmp ne i64 %2, 0
  %11 = and i1 %9, %10
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #3
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 0, ptr %4, align 1, !tbaa !13
  br i1 %11, label %.split.us, label %.split

.split.us:                                        ; preds = %3, %28
  %13 = call i32 @mbedtls_md_hmac_reset(ptr noundef nonnull %0) #3
  %.not.us = icmp eq i32 %13, 0
  br i1 %.not.us, label %14, label %.split39.us

14:                                               ; preds = %.split.us
  %15 = call i32 @mbedtls_md_hmac_update(ptr noundef nonnull %0, ptr noundef nonnull %12, i64 noundef %8) #3
  %.not31.us = icmp eq i32 %15, 0
  br i1 %.not31.us, label %16, label %.split39.us

16:                                               ; preds = %14
  %17 = call i32 @mbedtls_md_hmac_update(ptr noundef nonnull %0, ptr noundef nonnull %4, i64 noundef 1) #3
  %.not32.us = icmp eq i32 %17, 0
  br i1 %.not32.us, label %18, label %.split39.us

18:                                               ; preds = %16
  %19 = call i32 @mbedtls_md_hmac_update(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2) #3
  %.not33.us = icmp eq i32 %19, 0
  br i1 %.not33.us, label %20, label %.split39.us

20:                                               ; preds = %18
  %21 = call i32 @mbedtls_md_hmac_finish(ptr noundef nonnull %0, ptr noundef nonnull %5) #3
  %.not34.us = icmp eq i32 %21, 0
  br i1 %.not34.us, label %22, label %.split39.us

22:                                               ; preds = %20
  %23 = call i32 @mbedtls_md_hmac_starts(ptr noundef nonnull %0, ptr noundef nonnull %5, i64 noundef %8) #3
  %.not35.us = icmp eq i32 %23, 0
  br i1 %.not35.us, label %24, label %.split39.us

24:                                               ; preds = %22
  %25 = call i32 @mbedtls_md_hmac_update(ptr noundef nonnull %0, ptr noundef nonnull %12, i64 noundef %8) #3
  %.not36.us = icmp eq i32 %25, 0
  br i1 %.not36.us, label %26, label %.split39.us

26:                                               ; preds = %24
  %27 = call i32 @mbedtls_md_hmac_finish(ptr noundef nonnull %0, ptr noundef nonnull %12) #3
  %.not37.us = icmp eq i32 %27, 0
  br i1 %.not37.us, label %28, label %.split39.us

28:                                               ; preds = %26
  %29 = load i8, ptr %4, align 1, !tbaa !13
  %30 = add i8 %29, 1
  store i8 %30, ptr %4, align 1, !tbaa !13
  %31 = icmp ult i8 %30, 2
  br i1 %31, label %.split.us, label %.split39.us, !llvm.loop !14

.split:                                           ; preds = %3, %45
  %32 = call i32 @mbedtls_md_hmac_reset(ptr noundef nonnull %0) #3
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %33, label %.split39.us

33:                                               ; preds = %.split
  %34 = call i32 @mbedtls_md_hmac_update(ptr noundef nonnull %0, ptr noundef nonnull %12, i64 noundef %8) #3
  %.not31 = icmp eq i32 %34, 0
  br i1 %.not31, label %35, label %.split39.us

35:                                               ; preds = %33
  %36 = call i32 @mbedtls_md_hmac_update(ptr noundef nonnull %0, ptr noundef nonnull %4, i64 noundef 1) #3
  %.not32 = icmp eq i32 %36, 0
  br i1 %.not32, label %37, label %.split39.us

37:                                               ; preds = %35
  %38 = call i32 @mbedtls_md_hmac_finish(ptr noundef nonnull %0, ptr noundef nonnull %5) #3
  %.not34 = icmp eq i32 %38, 0
  br i1 %.not34, label %39, label %.split39.us

39:                                               ; preds = %37
  %40 = call i32 @mbedtls_md_hmac_starts(ptr noundef nonnull %0, ptr noundef nonnull %5, i64 noundef %8) #3
  %.not35 = icmp eq i32 %40, 0
  br i1 %.not35, label %41, label %.split39.us

41:                                               ; preds = %39
  %42 = call i32 @mbedtls_md_hmac_update(ptr noundef nonnull %0, ptr noundef nonnull %12, i64 noundef %8) #3
  %.not36 = icmp eq i32 %42, 0
  br i1 %.not36, label %43, label %.split39.us

43:                                               ; preds = %41
  %44 = call i32 @mbedtls_md_hmac_finish(ptr noundef nonnull %0, ptr noundef nonnull %12) #3
  %.not37 = icmp eq i32 %44, 0
  br i1 %.not37, label %45, label %.split39.us

45:                                               ; preds = %43
  %46 = load i8, ptr %4, align 1, !tbaa !13
  %47 = add i8 %46, 1
  store i8 %47, ptr %4, align 1, !tbaa !13
  %48 = icmp eq i8 %47, 0
  br i1 %48, label %.split, label %.split39.us, !llvm.loop !14

.split39.us:                                      ; preds = %.split, %33, %35, %37, %39, %41, %43, %45, %.split.us, %14, %16, %18, %20, %22, %24, %26, %28
  %.us-phi = phi i32 [ %13, %.split.us ], [ %15, %14 ], [ %17, %16 ], [ %19, %18 ], [ %21, %20 ], [ %23, %22 ], [ %25, %24 ], [ %27, %26 ], [ 0, %28 ], [ %32, %.split ], [ %34, %33 ], [ %36, %35 ], [ %38, %37 ], [ %40, %39 ], [ %42, %41 ], [ %44, %43 ], [ 0, %45 ]
  call void @mbedtls_platform_zeroize(ptr noundef nonnull %5, i64 noundef 64) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  ret i32 %.us-phi
}

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

declare zeroext i8 @mbedtls_md_get_size(ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_md_hmac_reset(ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_md_hmac_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @mbedtls_md_hmac_finish(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_md_hmac_starts(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !8, i64 0}
!6 = !{!"mbedtls_hmac_drbg_context", !7, i64 0, !9, i64 24, !11, i64 88, !12, i64 96, !11, i64 104, !11, i64 108, !8, i64 112, !8, i64 120}
!7 = !{!"mbedtls_md_context_t", !8, i64 0, !8, i64 8, !8, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!9, !9, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass