; 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
define dso_local i32 @tc_hmac_prng_init(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 %5, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %16, label %10

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

13:                                               ; preds = %10
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp ugt i32 %14, -1
  br i1 %15, label %16, label %17

16:                                               ; preds = %13, %10, %3
  store i32 0, ptr %4, align 4
  br label %29

17:                                               ; preds = %13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.tc_hmac_prng_struct, ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  call void @_set(ptr noundef %20, i8 noundef zeroext 0, i32 noundef 32)
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.tc_hmac_prng_struct, ptr %21, i32 0, i32 2
  %23 = getelementptr inbounds [32 x i8], ptr %22, i64 0, i64 0
  call void @_set(ptr noundef %23, i8 noundef zeroext 1, i32 noundef 32)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  call void @update(ptr noundef %24, ptr noundef %25, i32 noundef %26, ptr noundef null, i32 noundef 0)
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tc_hmac_prng_struct, ptr %27, i32 0, i32 3
  store i32 0, ptr %28, align 8, !tbaa !11
  store i32 1, ptr %4, align 4
  br label %29

29:                                               ; preds = %17, %16
  %30 = load i32, ptr %4, align 4
  ret i32 %30
}

declare void @_set(ptr noundef, i8 noundef zeroext, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @update(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) #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" }
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" }

!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
define dso_local range(i32 0, 2) i32 @tc_hmac_prng_init(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %1, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %10, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 240
  tail call void @_set(ptr noundef nonnull %7, i8 noundef zeroext 0, i32 noundef 32) #2
  %8 = getelementptr inbounds i8, ptr %0, i64 272
  tail call void @_set(ptr noundef nonnull %8, i8 noundef zeroext 1, i32 noundef 32) #2
  tail call void @update(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %2, ptr noundef null, i32 noundef 0)
  %9 = getelementptr inbounds i8, ptr %0, i64 304
  store i32 0, ptr %9, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %3, %6
  %.0 = phi i32 [ 1, %6 ], [ 0, %3 ]
  ret i32 %.0
}

declare void @_set(ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @update(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #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" }
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 }

!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