; LLVM IR from guanzhi/GmSSL :: src (sm9_z256)

; 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.SM9_Z256_POINT = type { [4 x i64], [4 x i64], [4 x i64] }

@SM9_Z256_MODP_MONT_ONE = external dso_local constant [4 x i64], align 16
@SM9_Z256_MODP_MONT_FIVE = external dso_local constant [4 x i64], align 16

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sm9_z256_point_is_on_curve(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca [4 x i64], align 16
  %5 = alloca [4 x i64], align 16
  %6 = alloca [4 x i64], align 16
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.SM9_Z256_POINT, ptr %8, i32 0, i32 2
  %10 = getelementptr inbounds [4 x i64], ptr %9, i64 0, i64 0
  %11 = call i64 @sm9_z256_equ(ptr noundef %10, ptr noundef @SM9_Z256_MODP_MONT_ONE)
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %29

13:                                               ; preds = %1
  %14 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.SM9_Z256_POINT, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds [4 x i64], ptr %16, i64 0, i64 0
  call void @sm9_z256_modp_mont_sqr(ptr noundef %14, ptr noundef %17)
  %18 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.SM9_Z256_POINT, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds [4 x i64], ptr %20, i64 0, i64 0
  call void @sm9_z256_modp_mont_sqr(ptr noundef %18, ptr noundef %21)
  %22 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %23 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SM9_Z256_POINT, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [4 x i64], ptr %25, i64 0, i64 0
  call void @sm9_z256_modp_mont_mul(ptr noundef %22, ptr noundef %23, ptr noundef %26)
  %27 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %28 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm9_z256_modp_add(ptr noundef %27, ptr noundef %28, ptr noundef @SM9_Z256_MODP_MONT_FIVE)
  br label %57

29:                                               ; preds = %1
  %30 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SM9_Z256_POINT, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [4 x i64], ptr %32, i64 0, i64 0
  call void @sm9_z256_modp_mont_sqr(ptr noundef %30, ptr noundef %33)
  %34 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %35 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SM9_Z256_POINT, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds [4 x i64], ptr %37, i64 0, i64 0
  call void @sm9_z256_modp_mont_mul(ptr noundef %34, ptr noundef %35, ptr noundef %38)
  %39 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.SM9_Z256_POINT, ptr %40, i32 0, i32 2
  %42 = getelementptr inbounds [4 x i64], ptr %41, i64 0, i64 0
  call void @sm9_z256_modp_mont_sqr(ptr noundef %39, ptr noundef %42)
  %43 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  %44 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm9_z256_modp_mont_sqr(ptr noundef %43, ptr noundef %44)
  %45 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %46 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %47 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  call void @sm9_z256_modp_mont_mul(ptr noundef %45, ptr noundef %46, ptr noundef %47)
  %48 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %49 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm9_z256_modp_mont_mul(ptr noundef %48, ptr noundef %49, ptr noundef @SM9_Z256_MODP_MONT_FIVE)
  %50 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %51 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %52 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm9_z256_modp_add(ptr noundef %50, ptr noundef %51, ptr noundef %52)
  %53 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.SM9_Z256_POINT, ptr %54, i32 0, i32 1
  %56 = getelementptr inbounds [4 x i64], ptr %55, i64 0, i64 0
  call void @sm9_z256_modp_mont_sqr(ptr noundef %53, ptr noundef %56)
  br label %57

57:                                               ; preds = %29, %13
  %58 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %59 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %60 = call i64 @sm9_z256_equ(ptr noundef %58, ptr noundef %59)
  %61 = icmp ne i64 %60, 1
  br i1 %61, label %62, label %63

62:                                               ; preds = %57
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %64

63:                                               ; preds = %57
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %64

64:                                               ; preds = %63, %62
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #2
  %65 = load i32, ptr %2, align 4
  ret i32 %65
}

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


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

@SM9_Z256_MODP_MONT_ONE = external dso_local constant [4 x i64], align 16
@SM9_Z256_MODP_MONT_FIVE = external dso_local constant [4 x i64], align 16

; 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 i64 @sm9_z256_equ(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @sm9_z256_point_is_on_curve(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [4 x i64], align 16
  %3 = alloca [4 x i64], align 16
  %4 = alloca [4 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #2
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #2
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #2
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = tail call i64 @sm9_z256_equ(ptr noundef nonnull %5, ptr noundef nonnull @SM9_Z256_MODP_MONT_ONE)
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %9, label %7

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  call void @sm9_z256_modp_mont_sqr(ptr noundef nonnull %2, ptr noundef nonnull %8)
  call void @sm9_z256_modp_mont_sqr(ptr noundef nonnull %3, ptr noundef %0)
  call void @sm9_z256_modp_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %0)
  call void @sm9_z256_modp_add(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull @SM9_Z256_MODP_MONT_FIVE)
  br label %11

9:                                                ; preds = %1
  call void @sm9_z256_modp_mont_sqr(ptr noundef nonnull %2, ptr noundef %0)
  call void @sm9_z256_modp_mont_mul(ptr noundef nonnull %2, ptr noundef nonnull %2, ptr noundef %0)
  call void @sm9_z256_modp_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %5)
  call void @sm9_z256_modp_mont_sqr(ptr noundef nonnull %4, ptr noundef nonnull %3)
  call void @sm9_z256_modp_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull %4)
  call void @sm9_z256_modp_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull @SM9_Z256_MODP_MONT_FIVE)
  call void @sm9_z256_modp_add(ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  call void @sm9_z256_modp_mont_sqr(ptr noundef nonnull %2, ptr noundef nonnull %10)
  br label %11

11:                                               ; preds = %9, %7
  %12 = call i64 @sm9_z256_equ(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not8 = icmp eq i64 %12, 1
  %. = zext i1 %.not8 to i32
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #2
  ret i32 %.
}

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)"}


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