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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @EccPoint_compute_public_key(ptr noundef, ptr noundef, ptr noundef) #1

declare void @uECC_vli_nativeToBytes(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @_set_secure(ptr noundef, i8 noundef zeroext, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @uECC_make_key(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [16 x i32], align 16
  %9 = alloca [8 x i32], align 16
  %10 = alloca [16 x i32], align 16
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %83, %3
  %15 = load i32, ptr %11, align 4, !tbaa !9
  %16 = icmp ult i32 %15, 64
  br i1 %16, label %17, label %86

17:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %18 = call ptr @uECC_get_rng()
  store ptr %18, ptr %12, align 8, !tbaa !5
  %19 = load ptr, ptr %12, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %26

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

26:                                               ; preds = %21, %17
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %80

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

45:                                               ; preds = %27
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.uECC_Curve_t, ptr %47, i32 0, i32 2
  %49 = load i16, ptr %48, align 2, !tbaa !11
  %50 = sext i16 %49 to i32
  %51 = add nsw i32 %50, 7
  %52 = sdiv i32 %51, 8
  %53 = getelementptr inbounds [8 x i32], ptr %9, i64 0, i64 0
  call void @uECC_vli_nativeToBytes(ptr noundef %46, i32 noundef %52, ptr noundef %53)
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.uECC_Curve_t, ptr %55, i32 0, i32 1
  %57 = load i8, ptr %56, align 1, !tbaa !14
  %58 = sext i8 %57 to i32
  %59 = getelementptr inbounds [16 x i32], ptr %10, i64 0, i64 0
  call void @uECC_vli_nativeToBytes(ptr noundef %54, i32 noundef %58, ptr noundef %59)
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.uECC_Curve_t, ptr %61, i32 0, i32 1
  %63 = load i8, ptr %62, align 1, !tbaa !14
  %64 = sext i8 %63 to i32
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %60, i64 %65
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.uECC_Curve_t, ptr %67, i32 0, i32 1
  %69 = load i8, ptr %68, align 1, !tbaa !14
  %70 = sext i8 %69 to i32
  %71 = getelementptr inbounds [16 x i32], ptr %10, i64 0, i64 0
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.uECC_Curve_t, ptr %72, i32 0, i32 0
  %74 = load i8, ptr %73, align 8, !tbaa !15
  %75 = sext i8 %74 to i32
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i32, ptr %71, i64 %76
  call void @uECC_vli_nativeToBytes(ptr noundef %66, i32 noundef %70, ptr noundef %77)
  %78 = getelementptr inbounds [8 x i32], ptr %9, i64 0, i64 0
  call void @_set_secure(ptr noundef %78, i8 noundef zeroext 0, i32 noundef 32)
  store i32 1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %80

79:                                               ; preds = %27
  store i32 0, ptr %13, align 4
  br label %80

80:                                               ; preds = %79, %45, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %81 = load i32, ptr %13, align 4
  switch i32 %81, label %87 [
    i32 0, label %82
  ]

82:                                               ; preds = %80
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %11, align 4, !tbaa !9
  %85 = add i32 %84, 1
  store i32 %85, ptr %11, align 4, !tbaa !9
  br label %14, !llvm.loop !16

86:                                               ; preds = %14
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %87

87:                                               ; preds = %86, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %8) #4
  %88 = load i32, ptr %4, align 4
  ret i32 %88
}

declare ptr @uECC_get_rng() #1

declare void @uECC_vli_mmod(ptr noundef, ptr noundef, ptr noundef, i8 noundef signext) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #3 = { 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 #4 = { 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 = !{!12, !7, i64 1}
!15 = !{!12, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @EccPoint_compute_public_key(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @uECC_vli_nativeToBytes(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @_set_secure(ptr noundef, i8 noundef zeroext, i32 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) #0

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

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

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

13:                                               ; preds = %11
  %14 = call i32 %12(ptr noundef nonnull %4, i32 noundef 64) #4
  %.not19 = icmp eq i32 %14, 0
  br i1 %.not19, label %.thread, label %15

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

22:                                               ; preds = %15
  %23 = load i16, ptr %8, align 2, !tbaa !7
  %24 = sext i16 %23 to i32
  %25 = add nsw i32 %24, 7
  %26 = sdiv i32 %25, 8
  call void @uECC_vli_nativeToBytes(ptr noundef %1, i32 noundef %26, ptr noundef nonnull %5) #4
  %27 = getelementptr inbounds i8, ptr %2, i64 1
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = sext i8 %28 to i32
  call void @uECC_vli_nativeToBytes(ptr noundef %0, i32 noundef %29, ptr noundef nonnull %6) #4
  %30 = load i8, ptr %27, align 1, !tbaa !13
  %31 = sext i8 %30 to i32
  %32 = sext i8 %30 to i64
  %33 = getelementptr inbounds i8, ptr %0, i64 %32
  %34 = load i8, ptr %2, align 8, !tbaa !14
  %35 = sext i8 %34 to i64
  %36 = getelementptr inbounds i32, ptr %6, i64 %35
  call void @uECC_vli_nativeToBytes(ptr noundef %33, i32 noundef %31, ptr noundef nonnull %36) #4
  call void @_set_secure(ptr noundef nonnull %5, i8 noundef zeroext 0, i32 noundef 32)
  br label %.thread

.thread:                                          ; preds = %11, %13, %9, %22
  %.2 = phi i32 [ 1, %22 ], [ 0, %9 ], [ 0, %13 ], [ 0, %11 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #4
  ret i32 %.2
}

declare ptr @uECC_get_rng() local_unnamed_addr #1

declare void @uECC_vli_mmod(ptr noundef, ptr noundef, ptr noundef, i8 noundef signext) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #3 = { 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 #4 = { 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}
!13 = !{!8, !9, i64 1}
!14 = !{!8, !9, i64 0}


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