; LLVM IR from guanzhi/GmSSL :: src (sm9_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"

@SM9_Z256_ONE = 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 @sm9_z256_copy(ptr noundef, ptr noundef) #1

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

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

12:                                               ; preds = %42, %3
  %13 = load i32, ptr %9, align 4, !tbaa !9
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %15, label %45

15:                                               ; preds = %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i64, ptr %16, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !11
  store i64 %20, ptr %8, align 8, !tbaa !11
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %38, %15
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = icmp slt i32 %22, 64
  br i1 %23, label %24, label %41

24:                                               ; preds = %21
  %25 = getelementptr inbounds [4 x i64], ptr %7, i64 0, i64 0
  %26 = getelementptr inbounds [4 x i64], ptr %7, i64 0, i64 0
  %27 = getelementptr inbounds [4 x i64], ptr %7, i64 0, i64 0
  call void @sm9_z256_modn_mul(ptr noundef %25, ptr noundef %26, ptr noundef %27)
  %28 = load i64, ptr %8, align 8, !tbaa !11
  %29 = and i64 %28, -9223372036854775808
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %35

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

35:                                               ; preds = %31, %24
  %36 = load i64, ptr %8, align 8, !tbaa !11
  %37 = shl i64 %36, 1
  store i64 %37, ptr %8, align 8, !tbaa !11
  br label %38

38:                                               ; preds = %35
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %10, align 4, !tbaa !9
  br label %21, !llvm.loop !13

41:                                               ; preds = %21
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = add nsw i32 %43, -1
  store i32 %44, ptr %9, align 4, !tbaa !9
  br label %12, !llvm.loop !15

45:                                               ; preds = %12
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds [4 x i64], ptr %7, i64 0, i64 0
  call void @sm9_z256_copy(ptr noundef %46, ptr noundef %47)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@SM9_Z256_ONE = 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: 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 @sm9_z256_copy(ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @sm9_z256_modn_pow(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = alloca [4 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #2
  call void @sm9_z256_copy(ptr noundef nonnull %4, ptr noundef nonnull @SM9_Z256_ONE)
  %5 = getelementptr inbounds i8, ptr %2, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %3, %9
  %.012 = phi i32 [ 0, %3 ], [ %11, %9 ]
  %.01011 = phi i64 [ %6, %3 ], [ %10, %9 ]
  call void @sm9_z256_modn_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull %4)
  %.not = icmp sgt i64 %.01011, -1
  br i1 %.not, label %9, label %8

8:                                                ; preds = %7
  call void @sm9_z256_modn_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1)
  br label %9

9:                                                ; preds = %8, %7
  %10 = shl i64 %.01011, 1
  %11 = add nuw nsw i32 %.012, 1
  %exitcond.not = icmp eq i32 %11, 64
  br i1 %exitcond.not, label %12, label %7, !llvm.loop !9

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %2, i64 16
  %14 = load i64, ptr %13, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %17, %12
  %.012.1 = phi i32 [ 0, %12 ], [ %19, %17 ]
  %.01011.1 = phi i64 [ %14, %12 ], [ %18, %17 ]
  call void @sm9_z256_modn_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull %4)
  %.not.1 = icmp sgt i64 %.01011.1, -1
  br i1 %.not.1, label %17, label %16

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

17:                                               ; preds = %16, %15
  %18 = shl i64 %.01011.1, 1
  %19 = add nuw nsw i32 %.012.1, 1
  %exitcond.1.not = icmp eq i32 %19, 64
  br i1 %exitcond.1.not, label %20, label %15, !llvm.loop !9

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %2, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %25, %20
  %.012.2 = phi i32 [ 0, %20 ], [ %27, %25 ]
  %.01011.2 = phi i64 [ %22, %20 ], [ %26, %25 ]
  call void @sm9_z256_modn_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull %4)
  %.not.2 = icmp sgt i64 %.01011.2, -1
  br i1 %.not.2, label %25, label %24

24:                                               ; preds = %23
  call void @sm9_z256_modn_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1)
  br label %25

25:                                               ; preds = %24, %23
  %26 = shl i64 %.01011.2, 1
  %27 = add nuw nsw i32 %.012.2, 1
  %exitcond.2.not = icmp eq i32 %27, 64
  br i1 %exitcond.2.not, label %28, label %23, !llvm.loop !9

28:                                               ; preds = %25
  %29 = load i64, ptr %2, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %32, %28
  %.012.3 = phi i32 [ 0, %28 ], [ %34, %32 ]
  %.01011.3 = phi i64 [ %29, %28 ], [ %33, %32 ]
  call void @sm9_z256_modn_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull %4)
  %.not.3 = icmp sgt i64 %.01011.3, -1
  br i1 %.not.3, label %32, label %31

31:                                               ; preds = %30
  call void @sm9_z256_modn_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1)
  br label %32

32:                                               ; preds = %31, %30
  %33 = shl i64 %.01011.3, 1
  %34 = add nuw nsw i32 %.012.3, 1
  %exitcond.3.not = icmp eq i32 %34, 64
  br i1 %exitcond.3.not, label %35, label %30, !llvm.loop !9

35:                                               ; preds = %32
  call void @sm9_z256_copy(ptr noundef %0, ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #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 = !{!6, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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