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

@.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
define dso_local zeroext i1 @ec2m_is_on_curve(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  store i8 0, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.EC2m_st, ptr %12, i32 0, i32 3
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = call ptr @wa_alloc(i64 noundef %14)
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %19

17:                                               ; preds = %11
  store i32 2, ptr %10, align 4, !tbaa !11
  %18 = load i32, ptr %10, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 130, i32 noundef %18)
  br label %75

19:                                               ; preds = %11
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.EC2m_st, ptr %23, i32 0, i32 3
  %25 = load i64, ptr %24, align 8, !tbaa !13
  %26 = call ptr @wa_alloc(i64 noundef %25)
  store ptr %26, ptr %8, align 8, !tbaa !5
  %27 = icmp eq ptr null, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %22
  store i32 2, ptr %10, align 4, !tbaa !11
  %29 = load i32, ptr %10, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 131, i32 noundef %29)
  br label %75

30:                                               ; preds = %22
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  call void @gf2m_mod_add(ptr noundef %33, ptr noundef %34, ptr noundef %35)
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.EC2m_st, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  call void @gf2m_mod_mul(ptr noundef %38, ptr noundef %39, ptr noundef %40, ptr noundef %41)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.EC2m_st, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  call void @gf2m_mod_sqr(ptr noundef %44, ptr noundef %45, ptr noundef %46)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.EC2m_st, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !17
  %50 = icmp eq i64 %49, 1
  br i1 %50, label %51, label %55

51:                                               ; preds = %32
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  call void @gf2m_mod_add(ptr noundef %52, ptr noundef %53, ptr noundef %54)
  br label %55

55:                                               ; preds = %51, %32
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.EC2m_st, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  call void @gf2m_mod_mul(ptr noundef %58, ptr noundef %59, ptr noundef %60, ptr noundef %61)
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  call void @gf2m_mod_add(ptr noundef %62, ptr noundef %63, ptr noundef %64)
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.EC2m_st, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !18
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  call void @gf2m_mod_add(ptr noundef %65, ptr noundef %68, ptr noundef %69)
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = call zeroext i1 @int_is_zero(ptr noundef %70)
  %72 = zext i1 %71 to i8
  store i8 %72, ptr %9, align 1, !tbaa !9
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  call void @wa_free(ptr noundef %73)
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  call void @wa_free(ptr noundef %74)
  br label %75

75:                                               ; preds = %55, %28, %17
  %76 = load i8, ptr %9, align 1, !tbaa !9, !range !19, !noundef !20
  %77 = trunc i8 %76 to i1
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i1 %77
}

declare ptr @wa_alloc(i64 noundef) #1

declare void @gf2m_mod_add(ptr noundef, ptr noundef, ptr noundef) #1

declare void @gf2m_mod_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare void @gf2m_mod_sqr(ptr noundef, ptr noundef, ptr noundef) #1

declare zeroext i1 @int_is_zero(ptr noundef) #1

declare void @wa_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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 24}
!14 = !{!"EC2m_st", !6, i64 0, !15, i64 8, !6, i64 16, !15, i64 24}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !6, i64 0}
!17 = !{!14, !15, i64 8}
!18 = !{!14, !6, i64 16}
!19 = !{i8 0, i8 2}
!20 = !{}


; 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
define dso_local zeroext i1 @ec2m_is_on_curve(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = tail call ptr @wa_alloc(i64 noundef %5) #2
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %3
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 130, i32 noundef 2) #2
  br label %26

9:                                                ; preds = %3
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = tail call ptr @wa_alloc(i64 noundef %10) #2
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %9
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 131, i32 noundef 2) #2
  br label %26

14:                                               ; preds = %9
  tail call void @gf2m_mod_add(ptr noundef %1, ptr noundef %2, ptr noundef nonnull %6) #2
  %15 = load ptr, ptr %0, align 8, !tbaa !11
  tail call void @gf2m_mod_mul(ptr noundef %15, ptr noundef nonnull %6, ptr noundef %2, ptr noundef nonnull %6) #2
  %16 = load ptr, ptr %0, align 8, !tbaa !11
  tail call void @gf2m_mod_sqr(ptr noundef %16, ptr noundef %1, ptr noundef nonnull %11) #2
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !12
  %19 = icmp eq i64 %18, 1
  br i1 %19, label %20, label %21

20:                                               ; preds = %14
  tail call void @gf2m_mod_add(ptr noundef nonnull %6, ptr noundef nonnull %11, ptr noundef nonnull %6) #2
  br label %21

21:                                               ; preds = %20, %14
  %22 = load ptr, ptr %0, align 8, !tbaa !11
  tail call void @gf2m_mod_mul(ptr noundef %22, ptr noundef %1, ptr noundef nonnull %11, ptr noundef nonnull %11) #2
  tail call void @gf2m_mod_add(ptr noundef nonnull %6, ptr noundef nonnull %11, ptr noundef nonnull %6) #2
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  tail call void @gf2m_mod_add(ptr noundef nonnull %6, ptr noundef %24, ptr noundef nonnull %6) #2
  %25 = tail call zeroext i1 @int_is_zero(ptr noundef nonnull %6) #2
  tail call void @wa_free(ptr noundef nonnull %6) #2
  tail call void @wa_free(ptr noundef nonnull %11) #2
  br label %26

26:                                               ; preds = %21, %13, %8
  %.0 = phi i1 [ false, %8 ], [ false, %13 ], [ %25, %21 ]
  ret i1 %.0
}

declare ptr @wa_alloc(i64 noundef) local_unnamed_addr #0

declare void @gf2m_mod_add(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @gf2m_mod_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @gf2m_mod_sqr(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare zeroext i1 @int_is_zero(ptr noundef) local_unnamed_addr #0

declare void @wa_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, !10, i64 24}
!6 = !{!"EC2m_st", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 16}


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