; 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_N_MINUS_ONE = external dso_local constant [4 x i64], align 16
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [42 x i8], align 1
@__PRETTY_FUNCTION__.sm9_z256_fp12_pow = external hidden unnamed_addr constant [83 x i8], align 1

; 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 i32 @sm9_z256_cmp(ptr noundef, ptr noundef) #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @sm9_z256_fp12_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 [3 x [2 x [2 x [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 384, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = call i32 @sm9_z256_cmp(ptr noundef %11, ptr noundef @SM9_Z256_N_MINUS_ONE)
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %16

15:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 1601, ptr noundef @__PRETTY_FUNCTION__.sm9_z256_fp12_pow) #4
  unreachable

16:                                               ; preds = %14
  %17 = getelementptr inbounds [3 x [2 x [2 x [4 x i64]]]], ptr %7, i64 0, i64 0
  call void @sm9_z256_fp12_set_one(ptr noundef %17)
  store i32 3, ptr %9, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %47, %16
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = icmp sge i32 %19, 0
  br i1 %20, label %21, label %50

21:                                               ; preds = %18
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i64, ptr %22, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !11
  store i64 %26, ptr %8, align 8, !tbaa !11
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %43, %21
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = icmp slt i32 %28, 64
  br i1 %29, label %30, label %46

30:                                               ; preds = %27
  %31 = getelementptr inbounds [3 x [2 x [2 x [4 x i64]]]], ptr %7, i64 0, i64 0
  %32 = getelementptr inbounds [3 x [2 x [2 x [4 x i64]]]], ptr %7, i64 0, i64 0
  call void @sm9_z256_fp12_sqr(ptr noundef %31, ptr noundef %32)
  %33 = load i64, ptr %8, align 8, !tbaa !11
  %34 = and i64 %33, -9223372036854775808
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %40

36:                                               ; preds = %30
  %37 = getelementptr inbounds [3 x [2 x [2 x [4 x i64]]]], ptr %7, i64 0, i64 0
  %38 = getelementptr inbounds [3 x [2 x [2 x [4 x i64]]]], ptr %7, i64 0, i64 0
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  call void @sm9_z256_fp12_mul(ptr noundef %37, ptr noundef %38, ptr noundef %39)
  br label %40

40:                                               ; preds = %36, %30
  %41 = load i64, ptr %8, align 8, !tbaa !11
  %42 = shl i64 %41, 1
  store i64 %42, ptr %8, align 8, !tbaa !11
  br label %43

43:                                               ; preds = %40
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %10, align 4, !tbaa !9
  br label %27, !llvm.loop !13

46:                                               ; preds = %27
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr %9, align 4, !tbaa !9
  br label %18, !llvm.loop !15

50:                                               ; preds = %18
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds [3 x [2 x [2 x [4 x i64]]]], ptr %7, i64 0, i64 0
  call void @sm9_z256_fp12_copy(ptr noundef %51, ptr noundef %52)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 384, ptr %7) #3
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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 = { noreturn 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 #3 = { nounwind }
attributes #4 = { noreturn 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_N_MINUS_ONE = external dso_local constant [4 x i64], align 16
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [42 x i8], align 1
@__PRETTY_FUNCTION__.sm9_z256_fp12_pow = external hidden unnamed_addr constant [83 x i8], align 1

; 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 i32 @sm9_z256_cmp(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @sm9_z256_fp12_pow(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca [3 x [2 x [2 x [4 x i64]]]], align 16
  call void @llvm.lifetime.start.p0(i64 384, ptr nonnull %4) #3
  %5 = tail call i32 @sm9_z256_cmp(ptr noundef %2, ptr noundef nonnull @SM9_Z256_N_MINUS_ONE)
  %6 = icmp slt i32 %5, 0
  br i1 %6, label %8, label %7

7:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 1601, ptr noundef nonnull @__PRETTY_FUNCTION__.sm9_z256_fp12_pow) #4
  unreachable

8:                                                ; preds = %3
  call void @sm9_z256_fp12_set_one(ptr noundef nonnull %4)
  %9 = getelementptr inbounds i8, ptr %2, i64 24
  %10 = load i64, ptr %9, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %8, %13
  %.013 = phi i32 [ 0, %8 ], [ %15, %13 ]
  %.01112 = phi i64 [ %10, %8 ], [ %14, %13 ]
  call void @sm9_z256_fp12_sqr(ptr noundef nonnull %4, ptr noundef nonnull %4)
  %.not = icmp sgt i64 %.01112, -1
  br i1 %.not, label %13, label %12

12:                                               ; preds = %11
  call void @sm9_z256_fp12_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1)
  br label %13

13:                                               ; preds = %12, %11
  %14 = shl i64 %.01112, 1
  %15 = add nuw nsw i32 %.013, 1
  %exitcond.not = icmp eq i32 %15, 64
  br i1 %exitcond.not, label %16, label %11, !llvm.loop !9

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %2, i64 16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %21, %16
  %.013.1 = phi i32 [ 0, %16 ], [ %23, %21 ]
  %.01112.1 = phi i64 [ %18, %16 ], [ %22, %21 ]
  call void @sm9_z256_fp12_sqr(ptr noundef nonnull %4, ptr noundef nonnull %4)
  %.not.1 = icmp sgt i64 %.01112.1, -1
  br i1 %.not.1, label %21, label %20

20:                                               ; preds = %19
  call void @sm9_z256_fp12_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1)
  br label %21

21:                                               ; preds = %20, %19
  %22 = shl i64 %.01112.1, 1
  %23 = add nuw nsw i32 %.013.1, 1
  %exitcond.1.not = icmp eq i32 %23, 64
  br i1 %exitcond.1.not, label %24, label %19, !llvm.loop !9

24:                                               ; preds = %21
  %25 = getelementptr inbounds i8, ptr %2, i64 8
  %26 = load i64, ptr %25, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %29, %24
  %.013.2 = phi i32 [ 0, %24 ], [ %31, %29 ]
  %.01112.2 = phi i64 [ %26, %24 ], [ %30, %29 ]
  call void @sm9_z256_fp12_sqr(ptr noundef nonnull %4, ptr noundef nonnull %4)
  %.not.2 = icmp sgt i64 %.01112.2, -1
  br i1 %.not.2, label %29, label %28

28:                                               ; preds = %27
  call void @sm9_z256_fp12_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1)
  br label %29

29:                                               ; preds = %28, %27
  %30 = shl i64 %.01112.2, 1
  %31 = add nuw nsw i32 %.013.2, 1
  %exitcond.2.not = icmp eq i32 %31, 64
  br i1 %exitcond.2.not, label %32, label %27, !llvm.loop !9

32:                                               ; preds = %29
  %33 = load i64, ptr %2, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %36, %32
  %.013.3 = phi i32 [ 0, %32 ], [ %38, %36 ]
  %.01112.3 = phi i64 [ %33, %32 ], [ %37, %36 ]
  call void @sm9_z256_fp12_sqr(ptr noundef nonnull %4, ptr noundef nonnull %4)
  %.not.3 = icmp sgt i64 %.01112.3, -1
  br i1 %.not.3, label %36, label %35

35:                                               ; preds = %34
  call void @sm9_z256_fp12_mul(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1)
  br label %36

36:                                               ; preds = %35, %34
  %37 = shl i64 %.01112.3, 1
  %38 = add nuw nsw i32 %.013.3, 1
  %exitcond.3.not = icmp eq i32 %38, 64
  br i1 %exitcond.3.not, label %39, label %34, !llvm.loop !9

39:                                               ; preds = %36
  call void @sm9_z256_fp12_copy(ptr noundef %0, ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 384, ptr nonnull %4) #3
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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 = { noreturn 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 #3 = { nounwind }
attributes #4 = { noreturn 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,SROAPass,SimplifyCFGPass,TailCallElimPass