; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (math-ecp-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 }
%struct.EcGfpCtx_st = type { ptr, ptr, ptr, i8, i64 }
%struct.GfpCtx_st = type { ptr, 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

declare i64 @int_bit_len(ptr noundef) #1

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

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

declare void @wa_zero(ptr noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ecp_dual_mul(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %17 = load ptr, ptr %12, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ECPoint_st, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  call void @wa_zero(ptr noundef %19)
  %20 = load ptr, ptr %12, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ECPoint_st, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  call void @wa_zero(ptr noundef %22)
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.EcGfpCtx_st, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = getelementptr inbounds %struct.GfpCtx_st, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ECPoint_st, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = call i32 @wa_copy(ptr noundef %27, ptr noundef %30)
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = call i64 @int_bit_len(ptr noundef %32)
  %34 = trunc i64 %33 to i32
  store i32 %34, ptr %14, align 4, !tbaa !19
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = call i64 @int_bit_len(ptr noundef %35)
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %15, align 4, !tbaa !19
  %38 = load i32, ptr %14, align 4, !tbaa !19
  %39 = load i32, ptr %15, align 4, !tbaa !19
  %40 = icmp sgt i32 %38, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %6
  %42 = load i32, ptr %14, align 4, !tbaa !19
  br label %45

43:                                               ; preds = %6
  %44 = load i32, ptr %15, align 4, !tbaa !19
  br label %45

45:                                               ; preds = %43, %41
  %46 = phi i32 [ %42, %41 ], [ %44, %43 ]
  store i32 %46, ptr %13, align 4, !tbaa !19
  %47 = load i32, ptr %13, align 4, !tbaa !19
  %48 = sub nsw i32 %47, 1
  store i32 %48, ptr %16, align 4, !tbaa !19
  br label %49

49:                                               ; preds = %90, %45
  %50 = load i32, ptr %16, align 4, !tbaa !19
  %51 = icmp sge i32 %50, 0
  br i1 %51, label %52, label %93

52:                                               ; preds = %49
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  call void @ecp_double_point(ptr noundef %53, ptr noundef %54, ptr noundef %55)
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  call void @ecp_point_to_affine(ptr noundef %56, ptr noundef %57)
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load i32, ptr %16, align 4, !tbaa !19
  %60 = sext i32 %59 to i64
  %61 = call i32 @int_get_bit(ptr noundef %58, i64 noundef %60)
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %73

63:                                               ; preds = %52
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ECPoint_st, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !9
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ECPoint_st, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !11
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  call void @ecp_add_point(ptr noundef %64, ptr noundef %65, ptr noundef %68, ptr noundef %71, i32 noundef 1, ptr noundef %72)
  br label %73

73:                                               ; preds = %63, %52
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = load i32, ptr %16, align 4, !tbaa !19
  %76 = sext i32 %75 to i64
  %77 = call i32 @int_get_bit(ptr noundef %74, i64 noundef %76)
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %89

79:                                               ; preds = %73
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ECPoint_st, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !9
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.ECPoint_st, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !11
  %88 = load ptr, ptr %12, align 8, !tbaa !5
  call void @ecp_add_point(ptr noundef %80, ptr noundef %81, ptr noundef %84, ptr noundef %87, i32 noundef 1, ptr noundef %88)
  br label %89

89:                                               ; preds = %79, %73
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %16, align 4, !tbaa !19
  %92 = add nsw i32 %91, -1
  store i32 %92, ptr %16, align 4, !tbaa !19
  br label %49, !llvm.loop !21

93:                                               ; preds = %49
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load ptr, ptr %12, align 8, !tbaa !5
  call void @ecp_point_to_affine(ptr noundef %94, ptr noundef %95)
  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 = { "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, !6, i64 0}
!10 = !{!"ECPoint_st", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !6, i64 0}
!13 = !{!"EcGfpCtx_st", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !15, i64 32}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !6, i64 8}
!17 = !{!"GfpCtx_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!18 = !{!10, !6, i64 16}
!19 = !{!20, !20, i64 0}
!20 = !{!"int", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

declare i64 @int_bit_len(ptr noundef) local_unnamed_addr #0

declare i32 @wa_copy(ptr noundef, ptr noundef) local_unnamed_addr #0

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

declare void @wa_zero(ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ecp_dual_mul(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr nocapture noundef readonly %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #1 {
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  tail call void @wa_zero(ptr noundef %7) #3
  %8 = getelementptr inbounds i8, ptr %5, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !10
  tail call void @wa_zero(ptr noundef %9) #3
  %10 = load ptr, ptr %0, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %5, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = tail call i32 @wa_copy(ptr noundef %12, ptr noundef %14) #3
  %16 = tail call i64 @int_bit_len(ptr noundef %2) #3
  %17 = trunc i64 %16 to i32
  %18 = tail call i64 @int_bit_len(ptr noundef %4) #3
  %19 = trunc i64 %18 to i32
  %20 = tail call i32 @llvm.smax.i32(i32 %17, i32 %19)
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %22 = getelementptr inbounds i8, ptr %1, i64 8
  %23 = getelementptr inbounds i8, ptr %3, i64 8
  %24 = zext nneg i32 %20 to i64
  br label %25

25:                                               ; preds = %.lr.ph, %35
  %indvars.iv = phi i64 [ %24, %.lr.ph ], [ %indvars.iv.next, %35 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  tail call void @ecp_double_point(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef nonnull %5)
  tail call void @ecp_point_to_affine(ptr noundef nonnull %0, ptr noundef nonnull %5)
  %26 = tail call i32 @int_get_bit(ptr noundef %2, i64 noundef %indvars.iv.next) #3
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %30, label %27

27:                                               ; preds = %25
  %28 = load ptr, ptr %1, align 8, !tbaa !5
  %29 = load ptr, ptr %22, align 8, !tbaa !10
  tail call void @ecp_add_point(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef %28, ptr noundef %29, i32 noundef 1, ptr noundef nonnull %5)
  br label %30

30:                                               ; preds = %27, %25
  %31 = tail call i32 @int_get_bit(ptr noundef %4, i64 noundef %indvars.iv.next) #3
  %.not33 = icmp eq i32 %31, 0
  br i1 %.not33, label %35, label %32

32:                                               ; preds = %30
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %23, align 8, !tbaa !10
  tail call void @ecp_add_point(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef %33, ptr noundef %34, i32 noundef 1, ptr noundef nonnull %5)
  br label %35

35:                                               ; preds = %30, %32
  %36 = icmp ugt i64 %indvars.iv, 1
  br i1 %36, label %25, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %35, %6
  tail call void @ecp_point_to_affine(ptr noundef nonnull %0, ptr noundef nonnull %5)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

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 = { 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 = !{!12, !7, i64 0}
!12 = !{!"EcGfpCtx_st", !7, i64 0, !7, i64 8, !7, i64 16, !13, i64 24, !14, i64 32}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!16, !7, i64 8}
!16 = !{!"GfpCtx_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!17 = !{!6, !7, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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