; LLVM IR from intel/cryptography-primitives :: sources/ippcp/gfpec/sm2 (sm2_decrypt_ext_dec_msg_size)

; 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._cpGFpEC = type { i32, i32, ptr, i32, i32, i32, ptr, ptr, ptr, ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._cpGFp = type { i32, i32, ptr }
%struct._gsModEngine = type { ptr, i32, i32, i32, i32, i32, ptr, ptr, ptr, i64, ptr, ptr, ptr, ptr, i32, i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsGFpECDecryptSM2_Ext_DecMsgSize(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp eq ptr null, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  store i32 -8, ptr %4, align 4
  br label %85

19:                                               ; preds = %3
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp eq ptr null, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i32 -8, ptr %4, align 4
  br label %85

23:                                               ; preds = %19
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._cpGFpEC, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = call i64 @IPP_UINT_PTR(ptr noundef %27)
  %29 = trunc i64 %28 to i32
  %30 = xor i32 %26, %29
  %31 = icmp eq i32 %30, 1129136461
  br i1 %31, label %33, label %32

32:                                               ; preds = %23
  store i32 -13, ptr %4, align 4
  br label %85

33:                                               ; preds = %23
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._cpGFpEC, ptr %34, i32 0, i32 3
  %36 = load i32, ptr %35, align 8, !tbaa !13
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %39, label %38

38:                                               ; preds = %33
  store i32 -13, ptr %4, align 4
  br label %85

39:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._cpGFpEC, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = getelementptr inbounds %struct._cpGFp, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  store ptr %44, ptr %8, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._gsModEngine, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 8, !tbaa !17
  %48 = icmp slt i32 1, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %39
  store i32 -14, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %84

50:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._cpGFpEC, ptr %51, i32 0, i32 13
  %53 = load ptr, ptr %52, align 8, !tbaa !20
  store ptr %53, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._gsModEngine, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 8, !tbaa !17
  %57 = icmp slt i32 1, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %50
  store i32 -14, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %83

59:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._gsModEngine, ptr %60, i32 0, i32 3
  %62 = load i32, ptr %61, align 8, !tbaa !21
  store i32 %62, ptr %11, align 4, !tbaa !9
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = icmp sge i32 %63, 0
  br i1 %64, label %66, label %65

65:                                               ; preds = %59
  store i32 -11, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %82

66:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 1, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = mul nsw i32 16, %67
  store i32 %68, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 32, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = load i32, ptr %13, align 4, !tbaa !9
  %71 = add nsw i32 1, %70
  %72 = add nsw i32 %71, 32
  %73 = sub nsw i32 %69, %72
  store i32 %73, ptr %15, align 4, !tbaa !9
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %74, align 4, !tbaa !9
  %75 = load i32, ptr %15, align 4, !tbaa !9
  %76 = icmp sge i32 %75, 0
  br i1 %76, label %78, label %77

77:                                               ; preds = %66
  store i32 -11, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %81

78:                                               ; preds = %66
  %79 = load i32, ptr %15, align 4, !tbaa !9
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %79, ptr %80, align 4, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %81

81:                                               ; preds = %78, %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %82

82:                                               ; preds = %81, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %83

83:                                               ; preds = %82, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %84

84:                                               ; preds = %83, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %85

85:                                               ; preds = %84, %38, %32, %22, %18
  %86 = load i32, ptr %4, align 4
  ret i32 %86
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(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

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 = { inlinehint 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_cpGFpEC", !10, i64 0, !10, i64 4, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !6, i64 8}
!16 = !{!"_cpGFp", !10, i64 0, !10, i64 4, !6, i64 8}
!17 = !{!18, !10, i64 8}
!18 = !{!"_gsModEngine", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !19, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !10, i64 100, !6, i64 104}
!19 = !{!"long long", !7, i64 0}
!20 = !{!12, !6, i64 80}
!21 = !{!18, !10, i64 16}


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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -14, 1) i32 @ippsGFpECDecryptSM2_Ext_DecMsgSize(ptr noundef %0, i32 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %2, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %37, label %6

6:                                                ; preds = %3
  %7 = load i32, ptr %0, align 8, !tbaa !5
  %8 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %0)
  %9 = trunc i64 %8 to i32
  %10 = xor i32 %7, %9
  %11 = icmp eq i32 %10, 1129136461
  br i1 %11, label %12, label %37

12:                                               ; preds = %6
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %37, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = icmp sgt i32 %21, 1
  br i1 %22, label %37, label %23

23:                                               ; preds = %15
  %24 = getelementptr inbounds i8, ptr %0, i64 80
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !15
  %28 = icmp sgt i32 %27, 1
  br i1 %28, label %37, label %29

29:                                               ; preds = %23
  %30 = icmp sgt i32 %1, -1
  br i1 %30, label %31, label %37

31:                                               ; preds = %29
  %32 = getelementptr inbounds i8, ptr %19, i64 16
  %33 = load i32, ptr %32, align 8, !tbaa !19
  %.neg22 = add nsw i32 %1, -33
  %34 = shl i32 %33, 4
  %35 = sub i32 %.neg22, %34
  %36 = icmp sgt i32 %35, -1
  %spec.store.select = select i1 %36, i32 %35, i32 0
  store i32 %spec.store.select, ptr %2, align 4
  %spec.select = select i1 %36, i32 0, i32 -11
  br label %37

37:                                               ; preds = %31, %15, %29, %23, %12, %6, %3
  %.4 = phi i32 [ -8, %3 ], [ -13, %6 ], [ -13, %12 ], [ -14, %15 ], [ -14, %23 ], [ -11, %29 ], [ %spec.select, %31 ]
  ret i32 %.4
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr noundef) local_unnamed_addr #1

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 = { inlinehint 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" }

!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, !7, i64 0}
!6 = !{!"_cpGFpEC", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !7, i64 68, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !10, i64 8}
!14 = !{!"_cpGFp", !7, i64 0, !7, i64 4, !10, i64 8}
!15 = !{!16, !7, i64 8}
!16 = !{!"_gsModEngine", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !17, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !7, i64 96, !7, i64 100, !10, i64 104}
!17 = !{!"long long", !8, i64 0}
!18 = !{!6, !10, i64 80}
!19 = !{!16, !7, i64 16}


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