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

; 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.uECC_Curve_t = type { i8, i8, i16, [8 x i32], [8 x i32], [16 x i32], [8 x i32], ptr, ptr, ptr }

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

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

declare ptr @uECC_get_rng() #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @uECC_sign(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr 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 ptr, align 8
  %12 = alloca [16 x i32], align 16
  %13 = alloca [8 x i32], align 16
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = 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 ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %17

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

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %21 = call ptr @uECC_get_rng()
  store ptr %21, ptr %15, align 8, !tbaa !5
  %22 = load ptr, ptr %15, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %29

24:                                               ; preds = %20
  %25 = load ptr, ptr %15, align 8, !tbaa !5
  %26 = getelementptr inbounds [16 x i32], ptr %12, i64 0, i64 0
  %27 = call i32 %25(ptr noundef %26, i32 noundef 64)
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %24, %20
  store i32 0, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %53

30:                                               ; preds = %24
  %31 = getelementptr inbounds [8 x i32], ptr %13, i64 0, i64 0
  %32 = getelementptr inbounds [16 x i32], ptr %12, i64 0, i64 0
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.uECC_Curve_t, ptr %33, i32 0, i32 4
  %35 = getelementptr inbounds [8 x i32], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.uECC_Curve_t, ptr %36, i32 0, i32 2
  %38 = load i16, ptr %37, align 2, !tbaa !11
  %39 = sext i16 %38 to i32
  %40 = add nsw i32 %39, 31
  %41 = sdiv i32 %40, 32
  %42 = trunc i32 %41 to i8
  call void @uECC_vli_mmod(ptr noundef %31, ptr noundef %32, ptr noundef %35, i8 noundef signext %42)
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = getelementptr inbounds [8 x i32], ptr %13, i64 0, i64 0
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = call i32 @uECC_sign_with_k(ptr noundef %43, ptr noundef %44, i32 noundef %45, ptr noundef %46, ptr noundef %47, ptr noundef %48)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %30
  store i32 1, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %53

52:                                               ; preds = %30
  store i32 0, ptr %16, align 4
  br label %53

53:                                               ; preds = %52, %51, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  %54 = load i32, ptr %16, align 4
  switch i32 %54, label %60 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %14, align 4, !tbaa !9
  %58 = add i32 %57, 1
  store i32 %58, ptr %14, align 4, !tbaa !9
  br label %17, !llvm.loop !14

59:                                               ; preds = %17
  store i32 0, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %60

60:                                               ; preds = %59, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %12) #3
  %61 = load i32, ptr %6, align 4
  ret i32 %61
}

declare void @uECC_vli_mmod(ptr noundef, ptr noundef, ptr noundef, i8 noundef signext) #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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 2}
!12 = !{!"uECC_Curve_t", !7, i64 0, !7, i64 1, !13, i64 2, !7, i64 4, !7, i64 36, !7, i64 68, !7, i64 132, !6, i64 168, !6, i64 176, !6, i64 184}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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
declare dso_local i32 @uECC_sign_with_k(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

declare ptr @uECC_get_rng() 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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @uECC_sign(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca [16 x i32], align 16
  %7 = alloca [8 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #3
  %8 = getelementptr inbounds i8, ptr %4, i64 36
  %9 = getelementptr inbounds i8, ptr %4, i64 2
  br label %12

10:                                               ; preds = %16
  %11 = add nuw nsw i32 %.01319, 1
  %exitcond.not = icmp eq i32 %11, 64
  br i1 %exitcond.not, label %.thread, label %12, !llvm.loop !5

12:                                               ; preds = %5, %10
  %.01319 = phi i32 [ 0, %5 ], [ %11, %10 ]
  %13 = call ptr @uECC_get_rng() #3
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %.thread, label %14

14:                                               ; preds = %12
  %15 = call i32 %13(ptr noundef nonnull %6, i32 noundef 64) #3
  %.not15 = icmp eq i32 %15, 0
  br i1 %.not15, label %.thread, label %16

16:                                               ; preds = %14
  %17 = load i16, ptr %9, align 2, !tbaa !7
  %18 = sext i16 %17 to i32
  %19 = add nsw i32 %18, 31
  %20 = sdiv i32 %19, 32
  %21 = trunc i32 %20 to i8
  call void @uECC_vli_mmod(ptr noundef nonnull %7, ptr noundef nonnull %6, ptr noundef nonnull %8, i8 noundef signext %21) #3
  %22 = call i32 @uECC_sign_with_k(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef nonnull %7, ptr noundef %3, ptr noundef %4)
  %.not16 = icmp eq i32 %22, 0
  br i1 %.not16, label %10, label %.thread

.thread:                                          ; preds = %12, %14, %10, %16
  %.2 = phi i32 [ 1, %16 ], [ 0, %10 ], [ 0, %14 ], [ 0, %12 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %6) #3
  ret i32 %.2
}

declare void @uECC_vli_mmod(ptr noundef, ptr noundef, ptr noundef, i8 noundef signext) local_unnamed_addr #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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !11, i64 2}
!8 = !{!"uECC_Curve_t", !9, i64 0, !9, i64 1, !11, i64 2, !9, i64 4, !9, i64 36, !9, i64 68, !9, i64 132, !12, i64 168, !12, i64 176, !12, i64 184}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"short", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass