; LLVM IR from machinefi/psa-crypto-esp32 :: crypto (hmac_prng)

; 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.tc_hmac_prng_struct = type { %struct.tc_hmac_state_struct, [32 x i8], [32 x i8], i32 }
%struct.tc_hmac_state_struct = type { %struct.tc_sha256_state_struct, [128 x i8] }
%struct.tc_sha256_state_struct = type { [8 x i32], i64, [64 x i8], i64 }

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

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

14:                                               ; preds = %5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %23, label %17

17:                                               ; preds = %14
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp ult i32 %18, 32
  br i1 %19, label %23, label %20

20:                                               ; preds = %17
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp ugt i32 %21, -1
  br i1 %22, label %23, label %24

23:                                               ; preds = %20, %17, %14, %5
  store i32 0, ptr %6, align 4
  br label %48

24:                                               ; preds = %20
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %41

27:                                               ; preds = %24
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %33, label %30

30:                                               ; preds = %27
  %31 = load i32, ptr %11, align 4, !tbaa !9
  %32 = icmp ugt i32 %31, -1
  br i1 %32, label %33, label %34

33:                                               ; preds = %30, %27
  store i32 0, ptr %6, align 4
  br label %48

34:                                               ; preds = %30
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load i32, ptr %11, align 4, !tbaa !9
  call void @update(ptr noundef %35, ptr noundef %36, i32 noundef %37, ptr noundef %38, i32 noundef %39)
  br label %40

40:                                               ; preds = %34
  br label %45

41:                                               ; preds = %24
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load i32, ptr %9, align 4, !tbaa !9
  call void @update(ptr noundef %42, ptr noundef %43, i32 noundef %44, ptr noundef null, i32 noundef 0)
  br label %45

45:                                               ; preds = %41, %40
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.tc_hmac_prng_struct, ptr %46, i32 0, i32 3
  store i32 -1, ptr %47, align 8, !tbaa !11
  store i32 1, ptr %6, align 4
  br label %48

48:                                               ; preds = %45, %33, %23
  %49 = load i32, ptr %6, align 4
  ret i32 %49
}

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

!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 304}
!12 = !{!"tc_hmac_prng_struct", !13, i64 0, !7, i64 240, !7, i64 272, !10, i64 304}
!13 = !{!"tc_hmac_state_struct", !14, i64 0, !7, i64 112}
!14 = !{!"tc_sha256_state_struct", !7, i64 0, !15, i64 32, !7, i64 40, !15, i64 104}
!15 = !{!"long", !7, 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 hidden void @update(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @tc_hmac_prng_reseed(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq ptr %0, null
  %7 = icmp eq ptr %1, null
  %or.cond = or i1 %6, %7
  %8 = icmp ult i32 %2, 32
  %or.cond3 = or i1 %or.cond, %8
  br i1 %or.cond3, label %16, label %9

9:                                                ; preds = %5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %13, label %10

10:                                               ; preds = %9
  %11 = icmp eq i32 %4, 0
  br i1 %11, label %16, label %12

12:                                               ; preds = %10
  tail call void @update(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %2, ptr noundef nonnull %3, i32 noundef %4)
  br label %14

13:                                               ; preds = %9
  tail call void @update(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %2, ptr noundef null, i32 noundef 0)
  br label %14

14:                                               ; preds = %13, %12
  %15 = getelementptr inbounds i8, ptr %0, i64 304
  store i32 -1, ptr %15, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %10, %5, %14
  %.0 = phi i32 [ 1, %14 ], [ 0, %5 ], [ 0, %10 ]
  ret i32 %.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" }

!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, !12, i64 304}
!6 = !{!"tc_hmac_prng_struct", !7, i64 0, !9, i64 240, !9, i64 272, !12, i64 304}
!7 = !{!"tc_hmac_state_struct", !8, i64 0, !9, i64 112}
!8 = !{!"tc_sha256_state_struct", !9, i64 0, !11, i64 32, !9, i64 40, !11, i64 104}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"int", !9, i64 0}


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