; 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] }

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local void @sm2_z256_point_mul(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca [16 x %struct.SM2_Z256_POINT], align 16
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = 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 4, ptr %7) #4
  store i32 5, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1536, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = add nsw i32 256, %13
  %15 = sub nsw i32 %14, 1
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = sdiv i32 %15, %16
  store i32 %17, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds [16 x %struct.SM2_Z256_POINT], ptr %8, i64 0, i64 0
  call void @sm2_z256_point_mul_pre_compute(ptr noundef %18, ptr noundef %19)
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 1
  store i32 %21, ptr %11, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %76, %3
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = icmp sge i32 %23, 0
  br i1 %24, label %25, label %79

25:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = call i32 @sm2_z256_get_booth(ptr noundef %26, i32 noundef %27, i32 noundef %28)
  store i32 %29, ptr %12, align 4, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %42

32:                                               ; preds = %25
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %41

35:                                               ; preds = %32
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %12, align 4, !tbaa !9
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [16 x %struct.SM2_Z256_POINT], ptr %8, i64 0, i64 %39
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %36, ptr align 16 %40, i64 96, i1 false), !tbaa.struct !11
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %35, %32
  br label %75

42:                                               ; preds = %25
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sm2_z256_point_dbl(ptr noundef %43, ptr noundef %44)
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sm2_z256_point_dbl(ptr noundef %45, ptr noundef %46)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sm2_z256_point_dbl(ptr noundef %47, ptr noundef %48)
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sm2_z256_point_dbl(ptr noundef %49, ptr noundef %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sm2_z256_point_dbl(ptr noundef %51, ptr noundef %52)
  %53 = load i32, ptr %12, align 4, !tbaa !9
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %55, label %62

55:                                               ; preds = %42
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = sub nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [16 x %struct.SM2_Z256_POINT], ptr %8, i64 0, i64 %60
  call void @sm2_z256_point_add(ptr noundef %56, ptr noundef %57, ptr noundef %61)
  br label %74

62:                                               ; preds = %42
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = icmp slt i32 %63, 0
  br i1 %64, label %65, label %73

65:                                               ; preds = %62
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = sub nsw i32 0, %68
  %70 = sub nsw i32 %69, 1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [16 x %struct.SM2_Z256_POINT], ptr %8, i64 0, i64 %71
  call void @sm2_z256_point_sub(ptr noundef %66, ptr noundef %67, ptr noundef %72)
  br label %73

73:                                               ; preds = %65, %62
  br label %74

74:                                               ; preds = %73, %55
  br label %75

75:                                               ; preds = %74, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = add nsw i32 %77, -1
  store i32 %78, ptr %11, align 4, !tbaa !9
  br label %22, !llvm.loop !13

79:                                               ; preds = %22
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %84

82:                                               ; preds = %79
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %83, i8 0, i64 96, i1 false)
  br label %84

84:                                               ; preds = %82, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1536, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{i64 0, i64 32, !12, i64 32, i64 32, !12, i64 64, i64 32, !12}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

%struct.SM2_Z256_POINT = type { [4 x i64], [4 x i64], [4 x i64] }

; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local void @sm2_z256_point_mul(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca [16 x %struct.SM2_Z256_POINT], align 16
  call void @llvm.lifetime.start.p0(i64 1536, ptr nonnull %4) #4
  call void @sm2_z256_point_mul_pre_compute(ptr noundef %2, ptr noundef nonnull %4)
  br label %5

5:                                                ; preds = %.backedge, %3
  %.038 = phi i32 [ 1, %3 ], [ %.038.be, %.backedge ]
  %.03237 = phi i32 [ 51, %3 ], [ %.03237.be, %.backedge ]
  %6 = call i32 @sm2_z256_get_booth(ptr noundef %1, i32 noundef 5, i32 noundef %.03237)
  %.not35 = icmp eq i32 %.038, 0
  br i1 %.not35, label %12, label %7

7:                                                ; preds = %5
  %.not36 = icmp eq i32 %6, 0
  br i1 %.not36, label %.thread, label %8

8:                                                ; preds = %7
  %9 = add nsw i32 %6, -1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [16 x %struct.SM2_Z256_POINT], ptr %4, i64 0, i64 %10
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(96) %0, ptr noundef nonnull align 16 dereferenceable(96) %11, i64 96, i1 false), !tbaa.struct !5
  br label %24

12:                                               ; preds = %5
  call void @sm2_z256_point_dbl(ptr noundef %0, ptr noundef %0)
  call void @sm2_z256_point_dbl(ptr noundef %0, ptr noundef %0)
  call void @sm2_z256_point_dbl(ptr noundef %0, ptr noundef %0)
  call void @sm2_z256_point_dbl(ptr noundef %0, ptr noundef %0)
  call void @sm2_z256_point_dbl(ptr noundef %0, ptr noundef %0)
  %13 = icmp sgt i32 %6, 0
  br i1 %13, label %14, label %18

14:                                               ; preds = %12
  %15 = add nsw i32 %6, -1
  %16 = zext nneg i32 %15 to i64
  %17 = getelementptr inbounds [16 x %struct.SM2_Z256_POINT], ptr %4, i64 0, i64 %16
  call void @sm2_z256_point_add(ptr noundef %0, ptr noundef %0, ptr noundef nonnull %17)
  br label %24

18:                                               ; preds = %12
  %19 = icmp slt i32 %6, 0
  br i1 %19, label %20, label %24

20:                                               ; preds = %18
  %21 = xor i32 %6, -1
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds [16 x %struct.SM2_Z256_POINT], ptr %4, i64 0, i64 %22
  call void @sm2_z256_point_sub(ptr noundef %0, ptr noundef %0, ptr noundef nonnull %23)
  br label %24

24:                                               ; preds = %14, %20, %18, %8
  %.not39 = icmp eq i32 %.03237, 0
  br i1 %.not39, label %.loopexit, label %.backedge

.backedge:                                        ; preds = %24, %.thread
  %.038.be = phi i32 [ 0, %24 ], [ 1, %.thread ]
  %.03237.be = add nsw i32 %.03237, -1
  br label %5, !llvm.loop !9

.thread:                                          ; preds = %7
  %.not3942 = icmp eq i32 %.03237, 0
  br i1 %.not3942, label %25, label %.backedge

25:                                               ; preds = %.thread
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(96) %0, i8 0, i64 96, i1 false)
  br label %.loopexit

.loopexit:                                        ; preds = %24, %25
  call void @llvm.lifetime.end.p0(i64 1536, ptr nonnull %4) #4
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{i64 0, i64 32, !6, i64 32, i64 32, !6, i64 64, i64 32, !6}
!6 = !{!7, !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,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass