; 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

; Function Attrs: nounwind uwtable
declare dso_local void @sm2_z256_set_zero(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @sm2_z256_point_is_at_infinity(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @sm2_z256_point_get_xy(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [4 x i64], align 16
  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
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = call i32 @sm2_z256_point_is_at_infinity(ptr noundef %9)
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %19

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  call void @sm2_z256_set_zero(ptr noundef %13)
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  call void @sm2_z256_set_zero(ptr noundef %17)
  br label %18

18:                                               ; preds = %16, %12
  store i32 0, ptr %4, align 4
  br label %72

19:                                               ; preds = %3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %20, i32 0, i32 2
  %22 = getelementptr inbounds [4 x i64], ptr %21, i64 0, i64 0
  %23 = load ptr, ptr @SM2_Z256_MODP_MONT_ONE, align 8, !tbaa !5
  %24 = call i32 @sm2_z256_cmp(ptr noundef %22, ptr noundef %23)
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %39

26:                                               ; preds = %19
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds [4 x i64], ptr %29, i64 0, i64 0
  call void @sm2_z256_modp_from_mont(ptr noundef %27, ptr noundef %30)
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %38

33:                                               ; preds = %26
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %35, i32 0, i32 1
  %37 = getelementptr inbounds [4 x i64], ptr %36, i64 0, i64 0
  call void @sm2_z256_modp_from_mont(ptr noundef %34, ptr noundef %37)
  br label %38

38:                                               ; preds = %33, %26
  br label %71

39:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #2
  %40 = getelementptr inbounds [4 x i64], ptr %8, i64 0, i64 0
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %41, i32 0, i32 2
  %43 = getelementptr inbounds [4 x i64], ptr %42, i64 0, i64 0
  call void @sm2_z256_modp_mont_inv(ptr noundef %40, ptr noundef %43)
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %52

46:                                               ; preds = %39
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.SM2_Z256_POINT, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds [4 x i64], ptr %49, i64 0, i64 0
  %51 = getelementptr inbounds [4 x i64], ptr %8, i64 0, i64 0
  call void @sm2_z256_modp_mont_mul(ptr noundef %47, ptr noundef %50, ptr noundef %51)
  br label %52

52:                                               ; preds = %46, %39
  %53 = getelementptr inbounds [4 x i64], ptr %8, i64 0, i64 0
  %54 = getelementptr inbounds [4 x i64], ptr %8, i64 0, i64 0
  call void @sm2_z256_modp_mont_sqr(ptr noundef %53, ptr noundef %54)
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %5, 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
  %59 = getelementptr inbounds [4 x i64], ptr %8, i64 0, i64 0
  call void @sm2_z256_modp_mont_mul(ptr noundef %55, ptr noundef %58, ptr noundef %59)
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  call void @sm2_z256_modp_from_mont(ptr noundef %60, ptr noundef %61)
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %70

64:                                               ; preds = %52
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds [4 x i64], ptr %8, i64 0, i64 0
  call void @sm2_z256_modp_mont_mul(ptr noundef %65, ptr noundef %66, ptr noundef %67)
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  call void @sm2_z256_modp_from_mont(ptr noundef %68, ptr noundef %69)
  br label %70

70:                                               ; preds = %64, %52
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #2
  br label %71

71:                                               ; preds = %70, %38
  store i32 1, ptr %4, align 4
  br label %72

72:                                               ; preds = %71, %18
  %73 = load i32, ptr %4, align 4
  ret i32 %73
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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

; Function Attrs: nounwind uwtable
declare dso_local void @sm2_z256_set_zero(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @sm2_z256_point_get_xy(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [4 x i64], align 16
  %5 = tail call i32 @sm2_z256_point_is_at_infinity(ptr noundef %0)
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  tail call void @sm2_z256_set_zero(ptr noundef %1)
  %.not25 = icmp eq ptr %2, null
  br i1 %.not25, label %21, label %8

8:                                                ; preds = %7
  tail call void @sm2_z256_set_zero(ptr noundef nonnull %2)
  br label %21

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 64
  %11 = load ptr, ptr @SM2_Z256_MODP_MONT_ONE, align 8, !tbaa !5
  %12 = tail call i32 @sm2_z256_cmp(ptr noundef nonnull %10, ptr noundef %11)
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %9
  tail call void @sm2_z256_modp_from_mont(ptr noundef %1, ptr noundef %0)
  %.not24 = icmp eq ptr %2, null
  br i1 %.not24, label %21, label %15

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @sm2_z256_modp_from_mont(ptr noundef nonnull %2, ptr noundef nonnull %16)
  br label %21

17:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #2
  call void @sm2_z256_modp_mont_inv(ptr noundef nonnull %4, ptr noundef nonnull %10)
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.critedge, label %18

18:                                               ; preds = %17
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  call void @sm2_z256_modp_mont_mul(ptr noundef nonnull %2, ptr noundef nonnull %19, ptr noundef nonnull %4)
  call void @sm2_z256_modp_mont_sqr(ptr noundef nonnull %4, ptr noundef nonnull %4)
  call void @sm2_z256_modp_mont_mul(ptr noundef %1, ptr noundef %0, ptr noundef nonnull %4)
  call void @sm2_z256_modp_from_mont(ptr noundef %1, ptr noundef %1)
  call void @sm2_z256_modp_mont_mul(ptr noundef nonnull %2, ptr noundef nonnull %2, ptr noundef nonnull %4)
  call void @sm2_z256_modp_from_mont(ptr noundef nonnull %2, ptr noundef nonnull %2)
  br label %20

.critedge:                                        ; preds = %17
  call void @sm2_z256_modp_mont_sqr(ptr noundef nonnull %4, ptr noundef nonnull %4)
  call void @sm2_z256_modp_mont_mul(ptr noundef %1, ptr noundef %0, ptr noundef nonnull %4)
  call void @sm2_z256_modp_from_mont(ptr noundef %1, ptr noundef %1)
  br label %20

20:                                               ; preds = %.critedge, %18
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #2
  br label %21

21:                                               ; preds = %20, %15, %14, %7, %8
  %.0 = phi i32 [ 0, %8 ], [ 0, %7 ], [ 1, %14 ], [ 1, %15 ], [ 1, %20 ]
  ret i32 %.0
}

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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