; 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_from_bytes = external hidden unnamed_addr constant [26 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_from_bytes(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 i64 @sm2_z256_is_zero(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 void @sm2_z256_point_set_infinity(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_from_bytes(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %6, i32 0, i32 0
  %8 = getelementptr inbounds [4 x i64], ptr %7, i64 0, i64 0
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  call void @sm2_z256_from_bytes(ptr noundef %8, ptr noundef %9)
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds [4 x i64], ptr %11, i64 0, i64 0
  %13 = call ptr @sm2_z256_prime()
  %14 = call i32 @sm2_z256_cmp(ptr noundef %12, ptr noundef %13)
  %15 = icmp sge i32 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %2
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1633, ptr noundef @__FUNCTION__.sm2_z256_point_from_bytes) #2
  br label %20

20:                                               ; preds = %17
  store i32 -1, ptr %3, align 4
  br label %78

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds [4 x i64], ptr %23, i64 0, i64 0
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 32
  call void @sm2_z256_from_bytes(ptr noundef %24, ptr noundef %26)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds [4 x i64], ptr %28, i64 0, i64 0
  %30 = call ptr @sm2_z256_prime()
  %31 = call i32 @sm2_z256_cmp(ptr noundef %29, ptr noundef %30)
  %32 = icmp sge i32 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %21
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1638, ptr noundef @__FUNCTION__.sm2_z256_point_from_bytes) #2
  br label %37

37:                                               ; preds = %34
  store i32 -1, ptr %3, align 4
  br label %78

38:                                               ; preds = %21
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds [4 x i64], ptr %40, i64 0, i64 0
  %42 = call i64 @sm2_z256_is_zero(ptr noundef %41)
  %43 = icmp eq i64 %42, 1
  br i1 %43, label %44, label %52

44:                                               ; preds = %38
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds [4 x i64], ptr %46, i64 0, i64 0
  %48 = call i64 @sm2_z256_is_zero(ptr noundef %47)
  %49 = icmp eq i64 %48, 1
  br i1 %49, label %50, label %52

50:                                               ; preds = %44
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sm2_z256_point_set_infinity(ptr noundef %51)
  store i32 0, ptr %3, align 4
  br label %78

52:                                               ; preds = %44, %38
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds [4 x i64], ptr %54, i64 0, i64 0
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds [4 x i64], ptr %57, i64 0, i64 0
  call void @sm2_z256_modp_to_mont(ptr noundef %55, ptr noundef %58)
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %59, i32 0, i32 1
  %61 = getelementptr inbounds [4 x i64], ptr %60, i64 0, i64 0
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %62, i32 0, i32 1
  %64 = getelementptr inbounds [4 x i64], ptr %63, i64 0, i64 0
  call void @sm2_z256_modp_to_mont(ptr noundef %61, ptr noundef %64)
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %65, i32 0, i32 2
  %67 = getelementptr inbounds [4 x i64], ptr %66, i64 0, i64 0
  %68 = load ptr, ptr @SM2_Z256_MODP_MONT_ONE, align 8, !tbaa !5
  call void @sm2_z256_copy(ptr noundef %67, ptr noundef %68)
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = call i32 @sm2_z256_point_is_on_curve(ptr noundef %69)
  %71 = icmp ne i32 %70, 1
  br i1 %71, label %72, label %77

72:                                               ; preds = %52
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr @stderr, align 8, !tbaa !5
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1653, ptr noundef @__FUNCTION__.sm2_z256_point_from_bytes) #2
  br label %76

76:                                               ; preds = %73
  store i32 -1, ptr %3, align 4
  br label %78

77:                                               ; preds = %52
  store i32 1, ptr %3, align 4
  br label %78

78:                                               ; preds = %77, %76, %50, %37, %20
  %79 = load i32, ptr %3, align 4
  ret i32 %79
}

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_from_bytes = external hidden unnamed_addr constant [26 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_from_bytes(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 i64 @sm2_z256_is_zero(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 void @sm2_z256_point_set_infinity(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_from_bytes(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  tail call void @sm2_z256_from_bytes(ptr noundef %0, ptr noundef %1)
  %3 = tail call ptr @sm2_z256_prime()
  %4 = tail call i32 @sm2_z256_cmp(ptr noundef %0, ptr noundef %3)
  %5 = icmp sgt i32 %4, -1
  br i1 %5, label %6, label %9

6:                                                ; preds = %2
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1633, ptr noundef nonnull @__FUNCTION__.sm2_z256_point_from_bytes) #2
  br label %32

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = getelementptr inbounds i8, ptr %1, i64 32
  tail call void @sm2_z256_from_bytes(ptr noundef nonnull %10, ptr noundef nonnull %11)
  %12 = tail call ptr @sm2_z256_prime()
  %13 = tail call i32 @sm2_z256_cmp(ptr noundef nonnull %10, ptr noundef %12)
  %14 = icmp sgt i32 %13, -1
  br i1 %14, label %15, label %18

15:                                               ; preds = %9
  %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 1638, ptr noundef nonnull @__FUNCTION__.sm2_z256_point_from_bytes) #2
  br label %32

18:                                               ; preds = %9
  %19 = tail call i64 @sm2_z256_is_zero(ptr noundef %0)
  %20 = icmp eq i64 %19, 1
  br i1 %20, label %21, label %25

21:                                               ; preds = %18
  %22 = tail call i64 @sm2_z256_is_zero(ptr noundef nonnull %10)
  %23 = icmp eq i64 %22, 1
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  tail call void @sm2_z256_point_set_infinity(ptr noundef %0)
  br label %32

25:                                               ; preds = %21, %18
  tail call void @sm2_z256_modp_to_mont(ptr noundef %0, ptr noundef %0)
  tail call void @sm2_z256_modp_to_mont(ptr noundef nonnull %10, ptr noundef nonnull %10)
  %26 = getelementptr inbounds i8, ptr %0, i64 64
  %27 = load ptr, ptr @SM2_Z256_MODP_MONT_ONE, align 8, !tbaa !5
  tail call void @sm2_z256_copy(ptr noundef nonnull %26, ptr noundef %27)
  %28 = tail call i32 @sm2_z256_point_is_on_curve(ptr noundef %0)
  %.not = icmp eq i32 %28, 1
  br i1 %.not, label %32, label %29

29:                                               ; preds = %25
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1653, ptr noundef nonnull @__FUNCTION__.sm2_z256_point_from_bytes) #2
  br label %32

32:                                               ; preds = %25, %29, %24, %15, %6
  %.0 = phi i32 [ -1, %6 ], [ -1, %15 ], [ 0, %24 ], [ -1, %29 ], [ 1, %25 ]
  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