; LLVM IR from guanzhi/GmSSL :: src (sm3_lms)

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

@stderr = external global ptr, align 8
@.str.14 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.sm3_lms_signature_from_bytes_ex = external hidden unnamed_addr constant [32 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nounwind uwtable
declare hidden i64 @sm3_lms_signature_size(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @sm3_lms_signature_from_bytes_ex(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = icmp ult i64 %14, 4
  br i1 %15, label %16, label %22

16:                                               ; preds = %4
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str.14, ptr noundef @.str.15, i32 noundef 671, ptr noundef @__FUNCTION__.sm3_lms_signature_from_bytes_ex) #3
  br label %20

20:                                               ; preds = %17
  br label %21

21:                                               ; preds = %20
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %87

22:                                               ; preds = %4
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 0
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = shl i32 %27, 24
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 1
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = shl i32 %33, 16
  %35 = or i32 %28, %34
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 2
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = zext i8 %39 to i32
  %41 = shl i32 %40, 8
  %42 = or i32 %35, %41
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 3
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = or i32 %42, %47
  store i32 %48, ptr %10, align 4, !tbaa !12
  %49 = load i32, ptr %10, align 4, !tbaa !12
  %50 = call i32 @sm3_lms_type_to_height(i32 noundef %49, ptr noundef %11)
  %51 = icmp ne i32 %50, 1
  br i1 %51, label %52, label %58

52:                                               ; preds = %22
  br label %53

53:                                               ; preds = %52
  %54 = load ptr, ptr @stderr, align 8, !tbaa !5
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %54, ptr noundef @.str.14, ptr noundef @.str.15, i32 noundef 677, ptr noundef @__FUNCTION__.sm3_lms_signature_from_bytes_ex) #3
  br label %56

56:                                               ; preds = %53
  br label %57

57:                                               ; preds = %56
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %87

58:                                               ; preds = %22
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %60, ptr %61, align 8, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !12
  %63 = call i64 @sm3_lms_signature_size(i32 noundef %62)
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %63, ptr %64, align 8, !tbaa !9
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = load i64, ptr %65, align 8, !tbaa !9
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load i64, ptr %67, align 8, !tbaa !9
  %69 = icmp ult i64 %66, %68
  br i1 %69, label %70, label %76

70:                                               ; preds = %58
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr @stderr, align 8, !tbaa !5
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef @.str.14, ptr noundef @.str.15, i32 noundef 685, ptr noundef @__FUNCTION__.sm3_lms_signature_from_bytes_ex) #3
  br label %74

74:                                               ; preds = %71
  br label %75

75:                                               ; preds = %74
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %87

76:                                               ; preds = %58
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load i64, ptr %77, align 8, !tbaa !9
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = load ptr, ptr %79, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i64 %78
  store ptr %81, ptr %79, align 8, !tbaa !5
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load i64, ptr %82, align 8, !tbaa !9
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = load i64, ptr %84, align 8, !tbaa !9
  %86 = sub i64 %85, %83
  store i64 %86, ptr %84, align 8, !tbaa !9
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %87

87:                                               ; preds = %76, %75, %57, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %88 = load i32, ptr %5, align 4
  ret i32 %88
}

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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.14 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.sm3_lms_signature_from_bytes_ex = external hidden unnamed_addr constant [32 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nounwind uwtable
declare hidden i64 @sm3_lms_signature_size(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sm3_lms_signature_from_bytes_ex(ptr nocapture noundef writeonly %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = icmp ult i64 %6, 4
  br i1 %7, label %8, label %11

8:                                                ; preds = %4
  %9 = load ptr, ptr @stderr, align 8, !tbaa !9
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str.14, ptr noundef nonnull @.str.15, i32 noundef 671, ptr noundef nonnull @__FUNCTION__.sm3_lms_signature_from_bytes_ex) #4
  br label %47

11:                                               ; preds = %4
  %12 = load ptr, ptr %2, align 8, !tbaa !9
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = zext i8 %13 to i32
  %15 = shl nuw i32 %14, 24
  %16 = getelementptr inbounds i8, ptr %12, i64 1
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = shl nuw nsw i32 %18, 16
  %20 = or disjoint i32 %19, %15
  %21 = getelementptr inbounds i8, ptr %12, i64 2
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = zext i8 %22 to i32
  %24 = shl nuw nsw i32 %23, 8
  %25 = or disjoint i32 %20, %24
  %26 = getelementptr inbounds i8, ptr %12, i64 3
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = zext i8 %27 to i32
  %29 = or disjoint i32 %25, %28
  %30 = call i32 @sm3_lms_type_to_height(i32 noundef %29, ptr noundef nonnull %5)
  %.not = icmp eq i32 %30, 1
  br i1 %.not, label %34, label %31

31:                                               ; preds = %11
  %32 = load ptr, ptr @stderr, align 8, !tbaa !9
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.14, ptr noundef nonnull @.str.15, i32 noundef 677, ptr noundef nonnull @__FUNCTION__.sm3_lms_signature_from_bytes_ex) #4
  br label %47

34:                                               ; preds = %11
  %35 = load ptr, ptr %2, align 8, !tbaa !9
  store ptr %35, ptr %0, align 8, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !12
  %37 = call i64 @sm3_lms_signature_size(i32 noundef %36)
  store i64 %37, ptr %1, align 8, !tbaa !5
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = icmp ult i64 %38, %37
  br i1 %39, label %40, label %43

40:                                               ; preds = %34
  %41 = load ptr, ptr @stderr, align 8, !tbaa !9
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str.14, ptr noundef nonnull @.str.15, i32 noundef 685, ptr noundef nonnull @__FUNCTION__.sm3_lms_signature_from_bytes_ex) #4
  br label %47

43:                                               ; preds = %34
  %44 = load ptr, ptr %2, align 8, !tbaa !9
  %45 = getelementptr inbounds i8, ptr %44, i64 %37
  store ptr %45, ptr %2, align 8, !tbaa !9
  %46 = sub i64 %38, %37
  store i64 %46, ptr %3, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %43, %40, %31, %8
  %.0 = phi i32 [ -1, %8 ], [ -1, %31 ], [ -1, %40 ], [ 1, %43 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  ret i32 %.0
}

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }
attributes #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass