; 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.SM3_CTX = type { [8 x i32], i64, [64 x i8], i64 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@SM2_Z256_P = external dso_local constant [4 x i64], align 16
@__FUNCTION__.sm2_z256_point_from_hash = external hidden unnamed_addr constant [25 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

; 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_from_bytes(ptr noundef, ptr noundef) #2

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

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

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

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

16:                                               ; preds = %52, %4
  call void @llvm.lifetime.start.p0(i64 112, ptr %14) #4
  call void @sm3_init(ptr noundef %14)
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load i64, ptr %8, align 8, !tbaa !9
  call void @sm3_update(ptr noundef %14, ptr noundef %17, i64 noundef %18)
  %19 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  call void @sm3_finish(ptr noundef %14, ptr noundef %19)
  %20 = getelementptr inbounds [4 x i64], ptr %10, i64 0, i64 0
  %21 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  call void @sm2_z256_from_bytes(ptr noundef %20, ptr noundef %21)
  %22 = getelementptr inbounds [4 x i64], ptr %10, i64 0, i64 0
  %23 = call i32 @sm2_z256_cmp(ptr noundef %22, ptr noundef @SM2_Z256_P)
  %24 = icmp sge i32 %23, 0
  br i1 %24, label %25, label %29

25:                                               ; preds = %16
  %26 = getelementptr inbounds [4 x i64], ptr %10, i64 0, i64 0
  %27 = getelementptr inbounds [4 x i64], ptr %10, i64 0, i64 0
  %28 = call i64 @sm2_z256_sub(ptr noundef %26, ptr noundef %27, ptr noundef @SM2_Z256_P)
  br label %29

29:                                               ; preds = %25, %16
  %30 = getelementptr inbounds [4 x i64], ptr %10, i64 0, i64 0
  %31 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  call void @sm2_z256_to_bytes(ptr noundef %30, ptr noundef %31)
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  %34 = load i32, ptr %9, align 4, !tbaa !11
  %35 = call i32 @sm2_z256_point_from_x_bytes(ptr noundef %32, ptr noundef %33, i32 noundef %34)
  store i32 %35, ptr %13, align 4, !tbaa !11
  %36 = icmp eq i32 %35, 1
  br i1 %36, label %37, label %38

37:                                               ; preds = %29
  store i32 2, ptr %15, align 4
  br label %49

38:                                               ; preds = %29
  %39 = load i32, ptr %13, align 4, !tbaa !11
  %40 = icmp slt i32 %39, 0
  br i1 %40, label %41, label %47

41:                                               ; preds = %38
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr @stderr, align 8, !tbaa !5
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1839, ptr noundef @__FUNCTION__.sm2_z256_point_from_hash) #4
  br label %45

45:                                               ; preds = %42
  br label %46

46:                                               ; preds = %45
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %49

47:                                               ; preds = %38
  %48 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  store ptr %48, ptr %7, align 8, !tbaa !5
  store i64 32, ptr %8, align 8, !tbaa !9
  store i32 0, ptr %15, align 4
  br label %49

49:                                               ; preds = %47, %46, %37
  call void @llvm.lifetime.end.p0(i64 112, ptr %14) #4
  %50 = load i32, ptr %15, align 4
  switch i32 %50, label %54 [
    i32 0, label %51
    i32 2, label %53
  ]

51:                                               ; preds = %49
  br label %52

52:                                               ; preds = %51
  br i1 true, label %16, label %53

53:                                               ; preds = %52, %49
  store i32 1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %54

54:                                               ; preds = %53, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #4
  %55 = load i32, ptr %5, align 4
  ret i32 %55
}

declare void @sm3_init(ptr noundef) #3

declare void @sm3_update(ptr noundef, ptr noundef, i64 noundef) #3

declare void @sm3_finish(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 #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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; 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.SM3_CTX = type { [8 x i32], i64, [64 x i8], i64 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@SM2_Z256_P = external dso_local constant [4 x i64], align 16
@__FUNCTION__.sm2_z256_point_from_hash = external hidden unnamed_addr constant [25 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: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; 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_from_bytes(ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @sm2_z256_point_from_hash(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #2 {
.peel.begin:
  %4 = alloca [4 x i64], align 16
  %5 = alloca [32 x i8], align 16
  %6 = alloca [32 x i8], align 16
  %7 = alloca %struct.SM3_CTX, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %7) #4
  call void @sm3_init(ptr noundef nonnull %7) #4
  call void @sm3_update(ptr noundef nonnull %7, ptr noundef %1, i64 noundef %2) #4
  call void @sm3_finish(ptr noundef nonnull %7, ptr noundef nonnull %6) #4
  call void @sm2_z256_from_bytes(ptr noundef nonnull %4, ptr noundef nonnull %6)
  %8 = call i32 @sm2_z256_cmp(ptr noundef nonnull %4, ptr noundef nonnull @SM2_Z256_P)
  %9 = icmp sgt i32 %8, -1
  br i1 %9, label %10, label %12

10:                                               ; preds = %.peel.begin
  %11 = call i64 @sm2_z256_sub(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull @SM2_Z256_P)
  br label %12

12:                                               ; preds = %10, %.peel.begin
  call void @sm2_z256_to_bytes(ptr noundef nonnull %4, ptr noundef nonnull %5)
  %13 = call i32 @sm2_z256_point_from_x_bytes(ptr noundef %0, ptr noundef nonnull %5, i32 noundef %3)
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %.loopexit, label %15

15:                                               ; preds = %12
  %16 = icmp slt i32 %13, 0
  br i1 %16, label %.thread, label %.peel.next

.peel.next:                                       ; preds = %15
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %7) #4
  br label %17

17:                                               ; preds = %29, %.peel.next
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %7) #4
  call void @sm3_init(ptr noundef nonnull %7) #4
  call void @sm3_update(ptr noundef nonnull %7, ptr noundef nonnull %6, i64 noundef 32) #4
  call void @sm3_finish(ptr noundef nonnull %7, ptr noundef nonnull %6) #4
  call void @sm2_z256_from_bytes(ptr noundef nonnull %4, ptr noundef nonnull %6)
  %18 = call i32 @sm2_z256_cmp(ptr noundef nonnull %4, ptr noundef nonnull @SM2_Z256_P)
  %19 = icmp sgt i32 %18, -1
  br i1 %19, label %20, label %22

20:                                               ; preds = %17
  %21 = call i64 @sm2_z256_sub(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull @SM2_Z256_P)
  br label %22

22:                                               ; preds = %20, %17
  call void @sm2_z256_to_bytes(ptr noundef nonnull %4, ptr noundef nonnull %5)
  %23 = call i32 @sm2_z256_point_from_x_bytes(ptr noundef %0, ptr noundef nonnull %5, i32 noundef %3)
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %.loopexit, label %25

25:                                               ; preds = %22
  %26 = icmp slt i32 %23, 0
  br i1 %26, label %.thread, label %29

.thread:                                          ; preds = %25, %15
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1839, ptr noundef nonnull @__FUNCTION__.sm2_z256_point_from_hash) #5
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %7) #4
  br label %30

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %7) #4
  br label %17, !llvm.loop !9

.loopexit:                                        ; preds = %22, %12
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %7) #4
  br label %30

30:                                               ; preds = %.thread, %.loopexit
  %.2 = phi i32 [ 1, %.loopexit ], [ -1, %.thread ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  ret i32 %.2
}

declare void @sm3_init(ptr noundef) local_unnamed_addr #3

declare void @sm3_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

declare void @sm3_finish(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 #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 = { "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 #4 = { nounwind }
attributes #5 = { cold 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopFullUnrollPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass