; 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 }

; 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 void @ec2m_double(ptr noundef, ptr noundef, ptr noundef) #1

declare void @ec_point_zero(ptr noundef) #2

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

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

declare i64 @int_bit_len(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @ec2m_dual_mul(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %23

19:                                               ; preds = %6
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = call i64 @int_bit_len(ptr noundef %20)
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %15, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %19, %6
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  call void @ec_point_zero(ptr noundef %24)
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = call i64 @int_bit_len(ptr noundef %25)
  %27 = trunc i64 %26 to i32
  store i32 %27, ptr %14, align 4, !tbaa !9
  %28 = load i32, ptr %14, align 4, !tbaa !9
  %29 = load i32, ptr %15, align 4, !tbaa !9
  %30 = icmp sgt i32 %28, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %23
  %32 = load i32, ptr %14, align 4, !tbaa !9
  br label %35

33:                                               ; preds = %23
  %34 = load i32, ptr %15, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %33, %31
  %36 = phi i32 [ %32, %31 ], [ %34, %33 ]
  store i32 %36, ptr %13, align 4, !tbaa !9
  %37 = load i32, ptr %13, align 4, !tbaa !9
  %38 = sub nsw i32 %37, 1
  store i32 %38, ptr %16, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %84, %35
  %40 = load i32, ptr %16, align 4, !tbaa !9
  %41 = icmp sge i32 %40, 0
  br i1 %41, label %42, label %87

42:                                               ; preds = %39
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  call void @ec2m_double(ptr noundef %43, ptr noundef %44, ptr noundef %45)
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load i32, ptr %16, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = call i32 @int_get_bit(ptr noundef %46, i64 noundef %48)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %61

51:                                               ; preds = %42
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ECPoint_st, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ECPoint_st, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  call void @ec2m_add(ptr noundef %52, ptr noundef %53, ptr noundef %56, ptr noundef %59, i32 noundef 1, ptr noundef %60)
  br label %61

61:                                               ; preds = %51, %42
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %83

64:                                               ; preds = %61
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %83

67:                                               ; preds = %64
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load i32, ptr %16, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = call i32 @int_get_bit(ptr noundef %68, i64 noundef %70)
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %83

73:                                               ; preds = %67
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.ECPoint_st, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !11
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ECPoint_st, ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !13
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  call void @ec2m_add(ptr noundef %74, ptr noundef %75, ptr noundef %78, ptr noundef %81, i32 noundef 1, ptr noundef %82)
  br label %83

83:                                               ; preds = %73, %67, %64, %61
  br label %84

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

87:                                               ; preds = %39
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = load ptr, ptr %12, align 8, !tbaa !5
  call void @ec2m_point_to_affine(ptr noundef %88, ptr noundef %89)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

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 = { "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"

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

declare void @ec_point_zero(ptr noundef) local_unnamed_addr #1

; 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 #0

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

declare i64 @int_bit_len(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @ec2m_dual_mul(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef readonly %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = icmp ne ptr %3, null
  br i1 %7, label %8, label %11

8:                                                ; preds = %6
  %9 = tail call i64 @int_bit_len(ptr noundef %4) #3
  %10 = trunc i64 %9 to i32
  br label %11

11:                                               ; preds = %8, %6
  %.032 = phi i32 [ %10, %8 ], [ 0, %6 ]
  tail call void @ec_point_zero(ptr noundef %5) #3
  %12 = tail call i64 @int_bit_len(ptr noundef %2) #3
  %13 = trunc i64 %12 to i32
  %14 = tail call i32 @llvm.smax.i32(i32 %.032, i32 %13)
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %11
  %.036 = add nsw i32 %14, -1
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  %17 = icmp ne ptr %4, null
  %or.cond = and i1 %7, %17
  %18 = getelementptr inbounds i8, ptr %3, i64 8
  %19 = zext nneg i32 %.036 to i64
  br i1 %or.cond, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %29
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %29 ], [ %19, %.lr.ph ]
  tail call void @ec2m_double(ptr noundef %0, ptr noundef %5, ptr noundef %5)
  %20 = tail call i32 @int_get_bit(ptr noundef %2, i64 noundef %indvars.iv40) #3
  %.not.us = icmp eq i32 %20, 0
  br i1 %.not.us, label %24, label %21

21:                                               ; preds = %.lr.ph.split.us
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = load ptr, ptr %16, align 8, !tbaa !10
  tail call void @ec2m_add(ptr noundef %0, ptr noundef %5, ptr noundef %22, ptr noundef %23, i32 noundef 1, ptr noundef %5)
  br label %24

24:                                               ; preds = %21, %.lr.ph.split.us
  %25 = tail call i32 @int_get_bit(ptr noundef nonnull %4, i64 noundef %indvars.iv40) #3
  %.not35.us = icmp eq i32 %25, 0
  br i1 %.not35.us, label %29, label %26

26:                                               ; preds = %24
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %18, align 8, !tbaa !10
  tail call void @ec2m_add(ptr noundef %0, ptr noundef %5, ptr noundef %27, ptr noundef %28, i32 noundef 1, ptr noundef %5)
  br label %29

29:                                               ; preds = %26, %24
  %indvars.iv.next41 = add nsw i64 %indvars.iv40, -1
  %30 = icmp sgt i64 %indvars.iv40, 0
  br i1 %30, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !11

.lr.ph.split:                                     ; preds = %.lr.ph, %35
  %indvars.iv = phi i64 [ %indvars.iv.next, %35 ], [ %19, %.lr.ph ]
  tail call void @ec2m_double(ptr noundef %0, ptr noundef %5, ptr noundef %5)
  %31 = tail call i32 @int_get_bit(ptr noundef %2, i64 noundef %indvars.iv) #3
  %.not = icmp eq i32 %31, 0
  br i1 %.not, label %35, label %32

32:                                               ; preds = %.lr.ph.split
  %33 = load ptr, ptr %1, align 8, !tbaa !5
  %34 = load ptr, ptr %16, align 8, !tbaa !10
  tail call void @ec2m_add(ptr noundef %0, ptr noundef %5, ptr noundef %33, ptr noundef %34, i32 noundef 1, ptr noundef %5)
  br label %35

35:                                               ; preds = %32, %.lr.ph.split
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %36 = icmp sgt i64 %indvars.iv, 0
  br i1 %36, label %.lr.ph.split, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %35, %29, %11
  tail call void @ec2m_point_to_affine(ptr noundef %0, ptr noundef %5)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !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,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass