; 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 @uECC_vli_isZero(ptr noundef, i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @uECC_vli_cmp(ptr noundef, ptr noundef, i8 noundef signext) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @uECC_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 [16 x i32], align 16
  %10 = 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 64, ptr %9) #2
  %11 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 0
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.uECC_Curve_t, ptr %13, i32 0, i32 2
  %15 = load i16, ptr %14, align 2, !tbaa !9
  %16 = sext i16 %15 to i32
  %17 = add nsw i32 %16, 7
  %18 = sdiv i32 %17, 8
  call void @uECC_vli_bytesToNative(ptr noundef %11, ptr noundef %12, i32 noundef %18)
  %19 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 0
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.uECC_Curve_t, ptr %20, i32 0, i32 2
  %22 = load i16, ptr %21, align 2, !tbaa !9
  %23 = sext i16 %22 to i32
  %24 = add nsw i32 %23, 31
  %25 = sdiv i32 %24, 32
  %26 = trunc i32 %25 to i8
  %27 = call i32 @uECC_vli_isZero(ptr noundef %19, i8 noundef signext %26)
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %30

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

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

45:                                               ; preds = %30
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %78

46:                                               ; preds = %30
  %47 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  %48 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 0
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = call i32 @EccPoint_compute_public_key(ptr noundef %47, ptr noundef %48, ptr noundef %49)
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %53, label %52

52:                                               ; preds = %46
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %78

53:                                               ; preds = %46
  %54 = load ptr, ptr %6, 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 !12
  %58 = sext i8 %57 to i32
  %59 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  call void @uECC_vli_nativeToBytes(ptr noundef %54, i32 noundef %58, ptr noundef %59)
  %60 = load ptr, ptr %6, 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 !12
  %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 !12
  %70 = sext i8 %69 to i32
  %71 = getelementptr inbounds [16 x i32], ptr %9, 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 !13
  %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)
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %78

78:                                               ; preds = %53, %52, %45, %29
  call void @llvm.lifetime.end.p0(i64 64, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #2
  %79 = load i32, ptr %4, align 4
  ret i32 %79
}

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, !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}
!12 = !{!10, !7, i64 1}
!13 = !{!10, !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 @uECC_vli_isZero(ptr noundef, i8 noundef signext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @uECC_vli_cmp(ptr noundef, ptr noundef, i8 noundef signext) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @uECC_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 [16 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #2
  %6 = getelementptr inbounds i8, ptr %2, i64 2
  %7 = load i16, ptr %6, align 2, !tbaa !5
  %8 = sext i16 %7 to i32
  %9 = add nsw i32 %8, 7
  %10 = sdiv i32 %9, 8
  call void @uECC_vli_bytesToNative(ptr noundef nonnull %4, ptr noundef %0, i32 noundef %10)
  %11 = load i16, ptr %6, align 2, !tbaa !5
  %12 = sext i16 %11 to i32
  %13 = add nsw i32 %12, 31
  %14 = sdiv i32 %13, 32
  %15 = trunc i32 %14 to i8
  %16 = call i32 @uECC_vli_isZero(ptr noundef nonnull %4, i8 noundef signext %15)
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %17, label %38

17:                                               ; preds = %3
  %18 = getelementptr inbounds i8, ptr %2, i64 36
  %19 = load i16, ptr %6, align 2, !tbaa !5
  %20 = sext i16 %19 to i32
  %21 = add nsw i32 %20, 31
  %22 = sdiv i32 %21, 32
  %23 = trunc i32 %22 to i8
  %24 = call signext i8 @uECC_vli_cmp(ptr noundef nonnull %18, ptr noundef nonnull %4, i8 noundef signext %23)
  %.not12 = icmp eq i8 %24, 1
  br i1 %.not12, label %25, label %38

25:                                               ; preds = %17
  %26 = call i32 @EccPoint_compute_public_key(ptr noundef nonnull %5, ptr noundef nonnull %4, ptr noundef nonnull %2)
  %.not13 = icmp eq i32 %26, 0
  br i1 %.not13, label %38, label %27

27:                                               ; preds = %25
  %28 = getelementptr inbounds i8, ptr %2, i64 1
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = sext i8 %29 to i32
  call void @uECC_vli_nativeToBytes(ptr noundef %1, i32 noundef %30, ptr noundef nonnull %5)
  %31 = load i8, ptr %28, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = sext i8 %31 to i64
  %34 = getelementptr inbounds i8, ptr %1, i64 %33
  %35 = load i8, ptr %2, align 8, !tbaa !12
  %36 = sext i8 %35 to i64
  %37 = getelementptr inbounds i32, ptr %5, i64 %36
  call void @uECC_vli_nativeToBytes(ptr noundef %34, i32 noundef %32, ptr noundef nonnull %37)
  br label %38

38:                                               ; preds = %25, %17, %3, %27
  %.0 = phi i32 [ 1, %27 ], [ 0, %3 ], [ 0, %17 ], [ 0, %25 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #2
  ret i32 %.0
}

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, !9, i64 2}
!6 = !{!"uECC_Curve_t", !7, i64 0, !7, i64 1, !9, i64 2, !7, i64 4, !7, i64 36, !7, i64 68, !7, i64 132, !10, i64 168, !10, i64 176, !10, i64 184}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !7, i64 1}
!12 = !{!6, !7, i64 0}


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