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

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

declare i32 @tc_sha256_init(ptr noundef) #0

declare i32 @tc_sha256_update(ptr noundef, ptr noundef, i64 noundef) #0

declare i32 @tc_sha256_final(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @tc_hmac_final(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %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 i32, ptr %6, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 32
  br i1 %12, label %16, label %13

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

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

17:                                               ; preds = %13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.tc_hmac_state_struct, ptr %19, i32 0, i32 0
  %21 = call i32 @tc_sha256_final(ptr noundef %18, ptr noundef %20)
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.tc_hmac_state_struct, ptr %22, i32 0, i32 0
  %24 = call i32 @tc_sha256_init(ptr noundef %23)
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tc_hmac_state_struct, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tc_hmac_state_struct, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds [128 x i8], ptr %28, i64 0, i64 64
  %30 = call i32 @tc_sha256_update(ptr noundef %26, ptr noundef %29, i64 noundef 64)
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.tc_hmac_state_struct, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call i32 @tc_sha256_update(ptr noundef %32, ptr noundef %33, i64 noundef 32)
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tc_hmac_state_struct, ptr %36, i32 0, i32 0
  %38 = call i32 @tc_sha256_final(ptr noundef %35, ptr noundef %37)
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_set(ptr noundef %39, i8 noundef zeroext 0, i32 noundef 240)
  store i32 1, ptr %4, align 4
  br label %40

40:                                               ; preds = %17, %16
  %41 = load i32, ptr %4, align 4
  ret i32 %41
}

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

attributes #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 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}


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

declare i32 @tc_sha256_init(ptr noundef) local_unnamed_addr #0

declare i32 @tc_sha256_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare i32 @tc_sha256_final(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @tc_hmac_final(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %0, null
  %5 = icmp ne i32 %1, 32
  %or.cond = or i1 %4, %5
  %6 = icmp eq ptr %2, null
  %or.cond3 = or i1 %or.cond, %6
  br i1 %or.cond3, label %14, label %7

7:                                                ; preds = %3
  %8 = tail call i32 @tc_sha256_final(ptr noundef nonnull %0, ptr noundef nonnull %2) #2
  %9 = tail call i32 @tc_sha256_init(ptr noundef nonnull %2) #2
  %10 = getelementptr inbounds i8, ptr %2, i64 176
  %11 = tail call i32 @tc_sha256_update(ptr noundef nonnull %2, ptr noundef nonnull %10, i64 noundef 64) #2
  %12 = tail call i32 @tc_sha256_update(ptr noundef nonnull %2, ptr noundef nonnull %0, i64 noundef 32) #2
  %13 = tail call i32 @tc_sha256_final(ptr noundef nonnull %0, ptr noundef nonnull %2) #2
  tail call void @_set(ptr noundef nonnull %2, i8 noundef zeroext 0, i32 noundef 240) #2
  br label %14

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

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

attributes #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 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 #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)"}


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