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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@SM2_Z256_MODP_MONT_ONE = external dso_local global ptr, align 8
@__FUNCTION__.sm2_z256_point_set_xy = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @sm2_z256_prime() #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sm2_z256_point_set_xy(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = call ptr @sm2_z256_prime()
  %10 = call i32 @sm2_z256_cmp(ptr noundef %8, ptr noundef %9)
  %11 = icmp sge i32 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %3
  br label %13

13:                                               ; preds = %12
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1662, ptr noundef @__FUNCTION__.sm2_z256_point_set_xy) #2
  br label %16

16:                                               ; preds = %13
  store i32 -1, ptr %4, align 4
  br label %49

17:                                               ; preds = %3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = call ptr @sm2_z256_prime()
  %20 = call i32 @sm2_z256_cmp(ptr noundef %18, ptr noundef %19)
  %21 = icmp sge i32 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %17
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr @stderr, align 8, !tbaa !5
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1666, ptr noundef @__FUNCTION__.sm2_z256_point_set_xy) #2
  br label %26

26:                                               ; preds = %23
  store i32 -1, ptr %4, align 4
  br label %49

27:                                               ; preds = %17
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds [4 x i64], ptr %30, i64 0, i64 0
  call void @sm2_z256_modp_to_mont(ptr noundef %28, ptr noundef %31)
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds [4 x i64], ptr %34, i64 0, i64 0
  call void @sm2_z256_modp_to_mont(ptr noundef %32, ptr noundef %35)
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %36, i32 0, i32 2
  %38 = getelementptr inbounds [4 x i64], ptr %37, i64 0, i64 0
  %39 = load ptr, ptr @SM2_Z256_MODP_MONT_ONE, align 8, !tbaa !5
  call void @sm2_z256_copy(ptr noundef %38, ptr noundef %39)
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call i32 @sm2_z256_point_is_on_curve(ptr noundef %40)
  %42 = icmp ne i32 %41, 1
  br i1 %42, label %43, label %48

43:                                               ; preds = %27
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1675, ptr noundef @__FUNCTION__.sm2_z256_point_set_xy) #2
  br label %47

47:                                               ; preds = %44
  store i32 -1, ptr %4, align 4
  br label %49

48:                                               ; preds = %27
  store i32 1, ptr %4, align 4
  br label %49

49:                                               ; preds = %48, %47, %26, %16
  %50 = load i32, ptr %4, align 4
  ret i32 %50
}

attributes #0 = { nounwind "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, !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@SM2_Z256_MODP_MONT_ONE = external dso_local local_unnamed_addr global ptr, align 8
@__FUNCTION__.sm2_z256_point_set_xy = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @sm2_z256_prime() local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sm2_z256_point_set_xy(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call ptr @sm2_z256_prime()
  %5 = tail call i32 @sm2_z256_cmp(ptr noundef %1, ptr noundef %4)
  %6 = icmp sgt i32 %5, -1
  br i1 %6, label %.sink.split, label %7

7:                                                ; preds = %3
  %8 = tail call ptr @sm2_z256_prime()
  %9 = tail call i32 @sm2_z256_cmp(ptr noundef %2, ptr noundef %8)
  %10 = icmp sgt i32 %9, -1
  br i1 %10, label %.sink.split, label %11

11:                                               ; preds = %7
  tail call void @sm2_z256_modp_to_mont(ptr noundef %1, ptr noundef %0)
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @sm2_z256_modp_to_mont(ptr noundef %2, ptr noundef nonnull %12)
  %13 = getelementptr inbounds i8, ptr %0, i64 64
  %14 = load ptr, ptr @SM2_Z256_MODP_MONT_ONE, align 8, !tbaa !5
  tail call void @sm2_z256_copy(ptr noundef nonnull %13, ptr noundef %14)
  %15 = tail call i32 @sm2_z256_point_is_on_curve(ptr noundef %0)
  %.not = icmp eq i32 %15, 1
  br i1 %.not, label %18, label %.sink.split

.sink.split:                                      ; preds = %11, %7, %3
  %.sink8 = phi i32 [ 1662, %3 ], [ 1666, %7 ], [ 1675, %11 ]
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink8, ptr noundef nonnull @__FUNCTION__.sm2_z256_point_set_xy) #2
  br label %18

18:                                               ; preds = %.sink.split, %11
  %.0 = phi i32 [ 1, %11 ], [ -1, %.sink.split ]
  ret i32 %.0
}

attributes #0 = { nofree nounwind "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 = { cold 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