; LLVM IR from intel/cryptography-primitives :: sources/ippcp/gfpec/sm2 (sm2_key_exchange_get_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 @ippsGFpECKeyExchangeSM2_GetSize(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr null, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 -8, ptr %3, align 4
  br label %67

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr null, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  store i32 -8, ptr %3, align 4
  br label %67

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._cpGFpEC, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call i64 @IPP_UINT_PTR(ptr noundef %20)
  %22 = trunc i64 %21 to i32
  %23 = xor i32 %19, %22
  %24 = icmp eq i32 %23, 1129136461
  br i1 %24, label %26, label %25

25:                                               ; preds = %16
  store i32 -13, ptr %3, align 4
  br label %67

26:                                               ; preds = %16
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._cpGFpEC, ptr %27, i32 0, i32 3
  %29 = load i32, ptr %28, align 8, !tbaa !12
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %26
  store i32 -13, ptr %3, align 4
  br label %67

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._cpGFpEC, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = getelementptr inbounds %struct._cpGFp, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  store ptr %37, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._gsModEngine, ptr %38, i32 0, i32 3
  %40 = load i32, ptr %39, align 8, !tbaa !16
  store i32 %40, ptr %7, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %41 = load i32, ptr %7, align 4, !tbaa !19
  %42 = mul nsw i32 24, %41
  %43 = add nsw i32 104, %42
  %44 = add nsw i32 %43, 24
  %45 = load i32, ptr %7, align 4, !tbaa !19
  %46 = mul nsw i32 24, %45
  %47 = add nsw i32 %44, %46
  %48 = add nsw i32 %47, 24
  %49 = load i32, ptr %7, align 4, !tbaa !19
  %50 = mul nsw i32 24, %49
  %51 = add nsw i32 %48, %50
  %52 = add nsw i32 %51, 24
  %53 = load i32, ptr %7, align 4, !tbaa !19
  %54 = mul nsw i32 24, %53
  %55 = add nsw i32 %52, %54
  %56 = add nsw i32 %55, 32
  %57 = add nsw i32 %56, 32
  %58 = add nsw i32 %57, 32
  %59 = load i32, ptr %7, align 4, !tbaa !19
  %60 = mul nsw i32 8, %59
  %61 = add nsw i32 %58, %60
  %62 = load i32, ptr %7, align 4, !tbaa !19
  %63 = mul nsw i32 8, %62
  %64 = add nsw i32 %61, %63
  store i32 %64, ptr %8, align 4, !tbaa !19
  %65 = load i32, ptr %8, align 4, !tbaa !19
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %65, ptr %66, align 4, !tbaa !19
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %67

67:                                               ; preds = %32, %31, %25, %15, %11
  %68 = load i32, ptr %3, align 4
  ret i32 %68
}

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

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

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

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

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %reass.mul19 = mul i32 %20, 112
  %21 = add i32 %reass.mul19, 272
  store i32 %21, ptr %1, align 4, !tbaa !18
  br label %22

22:                                               ; preds = %11, %5, %2, %14
  %.0 = phi i32 [ 0, %14 ], [ -8, %2 ], [ -13, %5 ], [ -13, %11 ]
  ret i32 %.0
}

; 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 16}
!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 = !{!7, !7, i64 0}


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