; LLVM IR from guanzhi/GmSSL :: src (sm2_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.SM2_Z256_POINT = type { [4 x i64], [4 x i64], [4 x i64] }

@SM2_Z256_MODP_MONT_ONE = external dso_local global ptr, align 8
@SM2_Z256_MODP_MONT_B = 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: nounwind uwtable
declare dso_local i32 @sm2_z256_cmp(ptr noundef, ptr noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sm2_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.SM2_Z256_POINT, ptr %8, i32 0, i32 2
  %10 = getelementptr inbounds [4 x i64], ptr %9, i64 0, i64 0
  %11 = load ptr, ptr @SM2_Z256_MODP_MONT_ONE, align 8, !tbaa !5
  %12 = call i32 @sm2_z256_cmp(ptr noundef %10, ptr noundef %11)
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %45

14:                                               ; preds = %1
  %15 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds [4 x i64], ptr %17, i64 0, i64 0
  call void @sm2_z256_modp_mont_sqr(ptr noundef %15, ptr noundef %18)
  %19 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %20 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds [4 x i64], ptr %22, i64 0, i64 0
  call void @sm2_z256_modp_add(ptr noundef %19, ptr noundef %20, ptr noundef %23)
  %24 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %25 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [4 x i64], ptr %27, i64 0, i64 0
  call void @sm2_z256_modp_add(ptr noundef %24, ptr noundef %25, ptr noundef %28)
  %29 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %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.SM2_Z256_POINT, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [4 x i64], ptr %32, i64 0, i64 0
  call void @sm2_z256_modp_add(ptr noundef %29, ptr noundef %30, ptr noundef %33)
  %34 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [4 x i64], ptr %36, i64 0, i64 0
  call void @sm2_z256_modp_mont_sqr(ptr noundef %34, ptr noundef %37)
  %38 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %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.SM2_Z256_POINT, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds [4 x i64], ptr %41, i64 0, i64 0
  call void @sm2_z256_modp_mont_mul(ptr noundef %38, ptr noundef %39, ptr noundef %42)
  %43 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %44 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm2_z256_modp_add(ptr noundef %43, ptr noundef %44, ptr noundef @SM2_Z256_MODP_MONT_B)
  br label %87

45:                                               ; preds = %1
  %46 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds [4 x i64], ptr %48, i64 0, i64 0
  call void @sm2_z256_modp_mont_sqr(ptr noundef %46, ptr noundef %49)
  %50 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %51, i32 0, i32 2
  %53 = getelementptr inbounds [4 x i64], ptr %52, i64 0, i64 0
  call void @sm2_z256_modp_mont_sqr(ptr noundef %50, ptr noundef %53)
  %54 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  %55 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm2_z256_modp_mont_sqr(ptr noundef %54, ptr noundef %55)
  %56 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %57 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %58 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  call void @sm2_z256_modp_mont_mul(ptr noundef %56, ptr noundef %57, ptr noundef %58)
  %59 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %60 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm2_z256_modp_mont_mul(ptr noundef %59, ptr noundef %60, ptr noundef @SM2_Z256_MODP_MONT_B)
  %61 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  %62 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds [4 x i64], ptr %64, i64 0, i64 0
  call void @sm2_z256_modp_mont_mul(ptr noundef %61, ptr noundef %62, ptr noundef %65)
  %66 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %67 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %68 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  call void @sm2_z256_modp_add(ptr noundef %66, ptr noundef %67, ptr noundef %68)
  %69 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %70 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %71 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  call void @sm2_z256_modp_add(ptr noundef %69, ptr noundef %70, ptr noundef %71)
  %72 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %73 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %74 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  call void @sm2_z256_modp_add(ptr noundef %72, ptr noundef %73, ptr noundef %74)
  %75 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %76, i32 0, i32 0
  %78 = getelementptr inbounds [4 x i64], ptr %77, i64 0, i64 0
  call void @sm2_z256_modp_mont_sqr(ptr noundef %75, ptr noundef %78)
  %79 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  %80 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %81, i32 0, i32 0
  %83 = getelementptr inbounds [4 x i64], ptr %82, i64 0, i64 0
  call void @sm2_z256_modp_mont_mul(ptr noundef %79, ptr noundef %80, ptr noundef %83)
  %84 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %85 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %86 = getelementptr inbounds [4 x i64], ptr %6, i64 0, i64 0
  call void @sm2_z256_modp_add(ptr noundef %84, ptr noundef %85, ptr noundef %86)
  br label %87

87:                                               ; preds = %45, %14
  %88 = getelementptr inbounds [4 x i64], ptr %4, i64 0, i64 0
  %89 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %90 = call i32 @sm2_z256_cmp(ptr noundef %88, ptr noundef %89)
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %92, label %93

92:                                               ; preds = %87
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %94

93:                                               ; preds = %87
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %94

94:                                               ; preds = %93, %92
  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
  %95 = load i32, ptr %2, align 4
  ret i32 %95
}

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"

@SM2_Z256_MODP_MONT_ONE = external dso_local local_unnamed_addr global ptr, align 8
@SM2_Z256_MODP_MONT_B = 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: nounwind uwtable
declare dso_local i32 @sm2_z256_cmp(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @sm2_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 = load ptr, ptr @SM2_Z256_MODP_MONT_ONE, align 8, !tbaa !5
  %7 = tail call i32 @sm2_z256_cmp(ptr noundef nonnull %5, ptr noundef %6)
  %8 = icmp eq i32 %7, 0
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  call void @sm2_z256_modp_mont_sqr(ptr noundef nonnull %2, ptr noundef nonnull %9)
  br i1 %8, label %10, label %11

10:                                               ; preds = %1
  call void @sm2_z256_modp_add(ptr noundef nonnull %2, ptr noundef nonnull %2, ptr noundef %0)
  call void @sm2_z256_modp_add(ptr noundef nonnull %2, ptr noundef nonnull %2, ptr noundef %0)
  call void @sm2_z256_modp_add(ptr noundef nonnull %2, ptr noundef nonnull %2, ptr noundef %0)
  call void @sm2_z256_modp_mont_sqr(ptr noundef nonnull %3, ptr noundef %0)
  call void @sm2_z256_modp_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %0)
  br label %12

11:                                               ; preds = %1
  call void @sm2_z256_modp_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %5)
  call void @sm2_z256_modp_mont_sqr(ptr noundef nonnull %4, ptr noundef nonnull %3)
  call void @sm2_z256_modp_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull %4)
  call void @sm2_z256_modp_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull @SM2_Z256_MODP_MONT_B)
  call void @sm2_z256_modp_mont_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %0)
  call void @sm2_z256_modp_add(ptr noundef nonnull %2, ptr noundef nonnull %2, ptr noundef nonnull %4)
  call void @sm2_z256_modp_add(ptr noundef nonnull %2, ptr noundef nonnull %2, ptr noundef nonnull %4)
  call void @sm2_z256_modp_add(ptr noundef nonnull %2, ptr noundef nonnull %2, ptr noundef nonnull %4)
  call void @sm2_z256_modp_mont_sqr(ptr noundef nonnull %4, ptr noundef %0)
  call void @sm2_z256_modp_mont_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %0)
  br label %12

12:                                               ; preds = %11, %10
  %.sink = phi ptr [ %4, %11 ], [ @SM2_Z256_MODP_MONT_B, %10 ]
  call void @sm2_z256_modp_add(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull %.sink)
  %13 = call i32 @sm2_z256_cmp(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not = icmp eq i32 %13, 0
  %. = zext i1 %.not 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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