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

; 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

; 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
declare dso_local i32 @EccPoint_isZero(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @EccPoint_mult(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i16 noundef signext, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @EccPoint_compute_public_key(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [8 x i32], align 16
  %9 = alloca [8 x i32], align 16
  %10 = alloca [2 x ptr], align 16
  %11 = alloca i32, align 4
  %12 = 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 32, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #2
  %13 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 0
  store ptr %13, ptr %10, align 8, !tbaa !5
  %14 = getelementptr inbounds ptr, ptr %10, i64 1
  %15 = getelementptr inbounds [8 x i32], ptr %9, i64 0, i64 0
  store ptr %15, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 0
  %18 = getelementptr inbounds [8 x i32], ptr %9, i64 0, i64 0
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = call i32 @regularize_k(ptr noundef %16, ptr noundef %17, ptr noundef %18, ptr noundef %19)
  store i32 %20, ptr %11, align 4, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.uECC_Curve_t, ptr %22, i32 0, i32 5
  %24 = getelementptr inbounds [16 x i32], ptr %23, i64 0, i64 0
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  %27 = xor i1 %26, true
  %28 = zext i1 %27 to i32
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2 x ptr], ptr %10, i64 0, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.uECC_Curve_t, ptr %32, i32 0, i32 2
  %34 = load i16, ptr %33, align 2, !tbaa !11
  %35 = sext i16 %34 to i32
  %36 = add nsw i32 %35, 1
  %37 = trunc i32 %36 to i16
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  call void @EccPoint_mult(ptr noundef %21, ptr noundef %24, ptr noundef %31, ptr noundef null, i16 noundef signext %37, ptr noundef %38)
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = call i32 @EccPoint_isZero(ptr noundef %39, ptr noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %45

44:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %45

45:                                               ; preds = %44, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #2
  %46 = load i32, ptr %4, align 4
  ret i32 %46
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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)"}
!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}


; 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

; 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
declare dso_local i32 @EccPoint_isZero(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @EccPoint_mult(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i16 noundef signext, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @regularize_k(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @EccPoint_compute_public_key(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca [8 x i32], align 16
  %5 = alloca [8 x i32], align 16
  %6 = alloca [2 x ptr], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #2
  store ptr %4, ptr %6, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %5, ptr %7, align 8, !tbaa !5
  %8 = call i32 @regularize_k(ptr noundef %1, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef %2)
  %9 = getelementptr inbounds i8, ptr %2, i64 68
  %.not = icmp eq i32 %8, 0
  %10 = zext i1 %.not to i64
  %11 = getelementptr inbounds [2 x ptr], ptr %6, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %2, i64 2
  %14 = load i16, ptr %13, align 2, !tbaa !9
  %15 = add i16 %14, 1
  call void @EccPoint_mult(ptr noundef %0, ptr noundef nonnull %9, ptr noundef %12, ptr noundef null, i16 noundef signext %15, ptr noundef %2)
  %16 = call i32 @EccPoint_isZero(ptr noundef %0, ptr noundef %2)
  %.not9 = icmp eq i32 %16, 0
  %. = zext i1 %.not9 to i32
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #2
  ret i32 %.
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 2}
!10 = !{!"uECC_Curve_t", !7, i64 0, !7, i64 1, !11, i64 2, !7, i64 4, !7, i64 36, !7, i64 68, !7, i64 132, !6, i64 168, !6, i64 176, !6, i64 184}
!11 = !{!"short", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass