; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (math-ec2m-internal)

; 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.ECPoint_st = type { ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [28 x i8], align 1

; 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

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @ec2m_double(ptr noundef, ptr noundef, ptr noundef) #2

declare void @ec_point_zero(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @ec2m_point_to_affine(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @ec2m_mul(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %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
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = icmp eq ptr %13, %14
  br i1 %15, label %16, label %26

16:                                               ; preds = %4
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call ptr @ec_point_copy_with_alloc(ptr noundef %18)
  store ptr %19, ptr %9, align 8, !tbaa !5
  %20 = icmp eq ptr null, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %17
  store i32 2, ptr %12, align 4, !tbaa !9
  %22 = load i32, ptr %12, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 359, i32 noundef %22)
  br label %64

23:                                               ; preds = %17
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  br label %28

26:                                               ; preds = %4
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %27, ptr %9, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %26, %25
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  call void @ec_point_zero(ptr noundef %29)
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = call i64 @int_bit_len(ptr noundef %30)
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %10, align 4, !tbaa !9
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 1
  store i32 %34, ptr %11, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %58, %28
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = icmp sge i32 %36, 0
  br i1 %37, label %38, label %61

38:                                               ; preds = %35
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  call void @ec2m_double(ptr noundef %39, ptr noundef %40, ptr noundef %41)
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = call i32 @int_get_bit(ptr noundef %42, i64 noundef %44)
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %57

47:                                               ; preds = %38
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ECPoint_st, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !11
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ECPoint_st, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  call void @ec2m_add(ptr noundef %48, ptr noundef %49, ptr noundef %52, ptr noundef %55, i32 noundef 1, ptr noundef %56)
  br label %57

57:                                               ; preds = %47, %38
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = add nsw i32 %59, -1
  store i32 %60, ptr %11, align 4, !tbaa !9
  br label %35, !llvm.loop !14

61:                                               ; preds = %35
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  call void @ec2m_point_to_affine(ptr noundef %62, ptr noundef %63)
  br label %64

64:                                               ; preds = %61, %21
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = icmp eq ptr %65, %66
  br i1 %67, label %68, label %70

68:                                               ; preds = %64
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  call void @ec_point_free(ptr noundef %69)
  br label %70

70:                                               ; preds = %68, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

declare ptr @ec_point_copy_with_alloc(ptr noundef) #1

declare i64 @int_bit_len(ptr noundef) #1

declare i32 @int_get_bit(ptr noundef, i64 noundef) #1

declare void @ec_point_free(ptr noundef) #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 = { 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 }

!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, !6, i64 0}
!12 = !{!"ECPoint_st", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!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"

@.str = external hidden unnamed_addr constant [28 x i8], align 1

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

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

declare void @ec_point_zero(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ec2m_mul(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = icmp eq ptr %1, %3
  br i1 %5, label %6, label %9

6:                                                ; preds = %4
  %7 = tail call ptr @ec_point_copy_with_alloc(ptr noundef %1) #2
  %8 = icmp eq ptr %7, null
  br i1 %8, label %.thread, label %9

.thread:                                          ; preds = %6
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 359, i32 noundef 2) #2
  br label %22

9:                                                ; preds = %4, %6
  %.024 = phi ptr [ %7, %6 ], [ %1, %4 ]
  tail call void @ec_point_zero(ptr noundef %3) #2
  %10 = tail call i64 @int_bit_len(ptr noundef %2) #2
  %11 = trunc i64 %10 to i32
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9
  %13 = getelementptr inbounds i8, ptr %.024, i64 8
  %14 = and i64 %10, 2147483647
  br label %15

15:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ %14, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  tail call void @ec2m_double(ptr noundef %0, ptr noundef %3, ptr noundef %3)
  %16 = tail call i32 @int_get_bit(ptr noundef %2, i64 noundef %indvars.iv.next) #2
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %20, label %17

17:                                               ; preds = %15
  %18 = load ptr, ptr %.024, align 8, !tbaa !5
  %19 = load ptr, ptr %13, align 8, !tbaa !10
  tail call void @ec2m_add(ptr noundef %0, ptr noundef %3, ptr noundef %18, ptr noundef %19, i32 noundef 1, ptr noundef %3)
  br label %20

20:                                               ; preds = %15, %17
  %21 = icmp ugt i64 %indvars.iv, 1
  br i1 %21, label %15, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %20, %9
  tail call void @ec2m_point_to_affine(ptr noundef %0, ptr noundef %3)
  br i1 %5, label %22, label %23

22:                                               ; preds = %.thread, %._crit_edge
  %.130 = phi ptr [ null, %.thread ], [ %.024, %._crit_edge ]
  tail call void @ec_point_free(ptr noundef %.130) #2
  br label %23

23:                                               ; preds = %22, %._crit_edge
  ret void
}

declare ptr @ec_point_copy_with_alloc(ptr noundef) local_unnamed_addr #0

declare i64 @int_bit_len(ptr noundef) local_unnamed_addr #0

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

declare void @ec_point_free(ptr 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)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"ECPoint_st", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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