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

@SM2_Z256_N_MINUS_TWO = 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 void @sm2_z256_copy(ptr noundef, ptr noundef) #1

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

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

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

11:                                               ; preds = %20, %2
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 30
  br i1 %13, label %14, label %23

14:                                               ; preds = %11
  %15 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %16 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm2_z256_modn_mont_sqr(ptr noundef %15, ptr noundef %16)
  %17 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %18 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sm2_z256_modn_mont_mul(ptr noundef %17, ptr noundef %18, ptr noundef %19)
  br label %20

20:                                               ; preds = %14
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %7, align 4, !tbaa !9
  br label %11, !llvm.loop !11

23:                                               ; preds = %11
  %24 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %25 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm2_z256_modn_mont_sqr(ptr noundef %24, ptr noundef %25)
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %35, %23
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 96
  br i1 %28, label %29, label %38

29:                                               ; preds = %26
  %30 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %31 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm2_z256_modn_mont_sqr(ptr noundef %30, ptr noundef %31)
  %32 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %33 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sm2_z256_modn_mont_mul(ptr noundef %32, ptr noundef %33, ptr noundef %34)
  br label %35

35:                                               ; preds = %29
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %7, align 4, !tbaa !9
  br label %26, !llvm.loop !13

38:                                               ; preds = %26
  %39 = load i64, ptr getelementptr inbounds ([4 x i64], ptr @SM2_Z256_N_MINUS_TWO, i64 0, i64 1), align 8, !tbaa !14
  store i64 %39, ptr %6, align 8, !tbaa !14
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %56, %38
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = icmp slt i32 %41, 64
  br i1 %42, label %43, label %59

43:                                               ; preds = %40
  %44 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %45 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm2_z256_modn_mont_sqr(ptr noundef %44, ptr noundef %45)
  %46 = load i64, ptr %6, align 8, !tbaa !14
  %47 = and i64 %46, -9223372036854775808
  %48 = icmp ne i64 %47, 0
  br i1 %48, label %49, label %53

49:                                               ; preds = %43
  %50 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %51 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sm2_z256_modn_mont_mul(ptr noundef %50, ptr noundef %51, ptr noundef %52)
  br label %53

53:                                               ; preds = %49, %43
  %54 = load i64, ptr %6, align 8, !tbaa !14
  %55 = shl i64 %54, 1
  store i64 %55, ptr %6, align 8, !tbaa !14
  br label %56

56:                                               ; preds = %53
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %7, align 4, !tbaa !9
  br label %40, !llvm.loop !16

59:                                               ; preds = %40
  %60 = load i64, ptr @SM2_Z256_N_MINUS_TWO, align 16, !tbaa !14
  store i64 %60, ptr %6, align 8, !tbaa !14
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %77, %59
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = icmp slt i32 %62, 64
  br i1 %63, label %64, label %80

64:                                               ; preds = %61
  %65 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %66 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm2_z256_modn_mont_sqr(ptr noundef %65, ptr noundef %66)
  %67 = load i64, ptr %6, align 8, !tbaa !14
  %68 = and i64 %67, -9223372036854775808
  %69 = icmp ne i64 %68, 0
  br i1 %69, label %70, label %74

70:                                               ; preds = %64
  %71 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %72 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sm2_z256_modn_mont_mul(ptr noundef %71, ptr noundef %72, ptr noundef %73)
  br label %74

74:                                               ; preds = %70, %64
  %75 = load i64, ptr %6, align 8, !tbaa !14
  %76 = shl i64 %75, 1
  store i64 %76, ptr %6, align 8, !tbaa !14
  br label %77

77:                                               ; preds = %74
  %78 = load i32, ptr %7, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %7, align 4, !tbaa !9
  br label %61, !llvm.loop !17

80:                                               ; preds = %61
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds [4 x i64], ptr %5, i64 0, i64 0
  call void @sm2_z256_copy(ptr noundef %81, ptr noundef %82)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #2
  ret void
}

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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


; 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_N_MINUS_TWO = external dso_local local_unnamed_addr 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 void @sm2_z256_copy(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @sm2_z256_modn_mont_inv(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [4 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #2
  call void @sm2_z256_copy(ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  br label %4

4:                                                ; preds = %2, %4
  %.11821 = phi i32 [ 0, %2 ], [ %5, %4 ]
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  %5 = add nuw nsw i32 %.11821, 1
  %exitcond.not = icmp eq i32 %5, 96
  br i1 %exitcond.not, label %6, label %4, !llvm.loop !5

6:                                                ; preds = %4
  %7 = load i64, ptr getelementptr inbounds (i8, ptr @SM2_Z256_N_MINUS_TWO, i64 8), align 8, !tbaa !7
  br label %8

8:                                                ; preds = %6, %10
  %.023 = phi i64 [ %7, %6 ], [ %11, %10 ]
  %.222 = phi i32 [ 0, %6 ], [ %12, %10 ]
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  %.not19 = icmp sgt i64 %.023, -1
  br i1 %.not19, label %10, label %9

9:                                                ; preds = %8
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  br label %10

10:                                               ; preds = %9, %8
  %11 = shl i64 %.023, 1
  %12 = add nuw nsw i32 %.222, 1
  %exitcond26.not = icmp eq i32 %12, 64
  br i1 %exitcond26.not, label %13, label %8, !llvm.loop !11

13:                                               ; preds = %10
  %14 = load i64, ptr @SM2_Z256_N_MINUS_TWO, align 16, !tbaa !7
  br label %15

15:                                               ; preds = %13, %17
  %.125 = phi i64 [ %14, %13 ], [ %18, %17 ]
  %.324 = phi i32 [ 0, %13 ], [ %19, %17 ]
  call void @sm2_z256_modn_mont_sqr(ptr noundef nonnull %3, ptr noundef nonnull %3)
  %.not = icmp sgt i64 %.125, -1
  br i1 %.not, label %17, label %16

16:                                               ; preds = %15
  call void @sm2_z256_modn_mont_mul(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef %1)
  br label %17

17:                                               ; preds = %16, %15
  %18 = shl i64 %.125, 1
  %19 = add nuw nsw i32 %.324, 1
  %exitcond27.not = icmp eq i32 %19, 64
  br i1 %exitcond27.not, label %20, label %15, !llvm.loop !12

20:                                               ; preds = %17
  call void @sm2_z256_copy(ptr noundef %0, ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #2
  ret void
}

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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !6}
!12 = distinct !{!12, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass