; LLVM IR from intel/cryptography-primitives :: sources/ippcp/sms4 (pcpsms4_ccmgettag)

; 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._cpSMS4_CCM = type { i32, i64, i64, i32, i32, [16 x i8], [16 x i8], [16 x i8], [16 x i8], [16 x i8], [260 x i8] }
%struct._cpSMS4 = type { i32, [32 x i32], [32 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsSMS4_CCMGetTag(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 [9 x i32], align 16
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  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
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = icmp eq ptr null, %13
  br i1 %14, label %15, label %16

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

16:                                               ; preds = %3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._cpSMS4_CCM, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = load ptr, ptr %7, 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, 1129136453
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %16
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = icmp eq ptr null, %27
  br i1 %28, label %29, label %30

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

30:                                               ; preds = %26
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._cpSMS4_CCM, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 8, !tbaa !14
  %35 = icmp ugt i32 %31, %34
  br i1 %35, label %39, label %36

36:                                               ; preds = %30
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = icmp slt i32 %37, 1
  br i1 %38, label %39, label %40

39:                                               ; preds = %36, %30
  store i32 -15, ptr %4, align 4
  br label %85

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 36, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %41 = getelementptr inbounds [9 x i32], ptr %8, i64 0, i64 0
  store ptr %41, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %42 = getelementptr inbounds [9 x i32], ptr %8, i64 0, i64 0
  %43 = getelementptr inbounds i32, ptr %42, i64 4
  store ptr %43, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %44 = getelementptr inbounds [9 x i32], ptr %8, i64 0, i64 0
  %45 = getelementptr inbounds i32, ptr %44, i64 8
  store ptr %45, ptr %11, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._cpSMS4_CCM, ptr %46, i32 0, i32 2
  %48 = load i64, ptr %47, align 8, !tbaa !15
  %49 = and i64 %48, 15
  %50 = trunc i64 %49 to i32
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %50, ptr %51, align 4, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._cpSMS4_CCM, ptr %52, i32 0, i32 9
  %54 = getelementptr inbounds [16 x i8], ptr %53, i64 0, i64 0
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  call void @CopyBlock16(ptr noundef %54, ptr noundef %55)
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %77

59:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._cpSMS4_CCM, ptr %60, i32 0, i32 10
  store ptr %61, ptr %12, align 8, !tbaa !5
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  call void @FillBlock16(i8 noundef zeroext 0, ptr noundef null, ptr noundef %62, i32 noundef 0)
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._cpSMS4_CCM, ptr %63, i32 0, i32 8
  %65 = getelementptr inbounds [16 x i8], ptr %64, i64 0, i64 0
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = load i32, ptr %67, align 4, !tbaa !9
  call void @CopyBlock(ptr noundef %65, ptr noundef %66, i32 noundef %68)
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  call void @XorBlock16(ptr noundef %69, ptr noundef %70, ptr noundef %71)
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._cpSMS4, ptr %74, i32 0, i32 1
  %76 = getelementptr inbounds [32 x i32], ptr %75, i64 0, i64 0
  call void @cpSMS4_Cipher(ptr noundef %72, ptr noundef %73, ptr noundef %76)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %77

77:                                               ; preds = %59, %40
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._cpSMS4_CCM, ptr %79, i32 0, i32 6
  %81 = getelementptr inbounds [16 x i8], ptr %80, i64 0, i64 0
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = load i32, ptr %6, align 4, !tbaa !9
  call void @XorBlock(ptr noundef %78, ptr noundef %81, ptr noundef %82, i32 noundef %83)
  %84 = getelementptr inbounds [9 x i32], ptr %8, i64 0, i64 0
  call void @PurgeBlock(ptr noundef %84, i32 noundef 36)
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr %8) #4
  br label %85

85:                                               ; preds = %77, %39, %29, %25, %15
  %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: inlinehint nounwind uwtable
declare hidden void @CopyBlock16(ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @FillBlock16(i8 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CopyBlock(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @XorBlock16(ptr noundef, ptr noundef, ptr noundef) #1

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @XorBlock(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @PurgeBlock(ptr noundef, i32 noundef) #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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_cpSMS4_CCM", !10, i64 0, !13, i64 8, !13, i64 16, !10, i64 24, !10, i64 28, !7, i64 32, !7, i64 48, !7, i64 64, !7, i64 80, !7, i64 96, !7, i64 112}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !10, i64 24}
!15 = !{!12, !13, 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 -15, 1) i32 @ippsSMS4_CCMGetTag(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [9 x i32], align 16
  %5 = icmp eq ptr %2, null
  br i1 %5, label %34, label %6

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

12:                                               ; preds = %6
  %13 = icmp eq ptr %0, null
  br i1 %13, label %34, label %14

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %2, i64 24
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = icmp ult i32 %16, %1
  %18 = icmp slt i32 %1, 1
  %or.cond = or i1 %18, %17
  br i1 %or.cond, label %34, label %19

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %4) #4
  %20 = getelementptr inbounds i8, ptr %4, i64 32
  %21 = getelementptr inbounds i8, ptr %2, i64 16
  %22 = load i64, ptr %21, align 8, !tbaa !12
  %23 = trunc i64 %22 to i32
  %24 = and i32 %23, 15
  store i32 %24, ptr %20, align 16, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %2, i64 96
  call void @CopyBlock16(ptr noundef nonnull %25, ptr noundef nonnull %4)
  %26 = load i32, ptr %20, align 16, !tbaa !13
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %32, label %27

27:                                               ; preds = %19
  %28 = getelementptr inbounds i8, ptr %4, i64 16
  call void @FillBlock16(i8 noundef zeroext 0, ptr noundef null, ptr noundef nonnull %28, i32 noundef 0)
  %29 = getelementptr inbounds i8, ptr %2, i64 80
  %30 = load i32, ptr %20, align 16, !tbaa !13
  call void @CopyBlock(ptr noundef nonnull %29, ptr noundef nonnull %28, i32 noundef %30)
  call void @XorBlock16(ptr noundef nonnull %4, ptr noundef nonnull %28, ptr noundef nonnull %4)
  %31 = getelementptr inbounds i8, ptr %2, i64 116
  call void @cpSMS4_Cipher(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull %31) #4
  br label %32

32:                                               ; preds = %27, %19
  %33 = getelementptr inbounds i8, ptr %2, i64 48
  call void @XorBlock(ptr noundef nonnull %4, ptr noundef nonnull %33, ptr noundef nonnull %0, i32 noundef %1)
  call void @PurgeBlock(ptr noundef nonnull %4, i32 noundef 36)
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %4) #4
  br label %34

34:                                               ; preds = %14, %12, %6, %3, %32
  %.0 = phi i32 [ 0, %32 ], [ -8, %3 ], [ -13, %6 ], [ -8, %12 ], [ -15, %14 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr noundef) 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: inlinehint nounwind uwtable
declare hidden void @CopyBlock16(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @FillBlock16(i8 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CopyBlock(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @XorBlock16(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @XorBlock(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @PurgeBlock(ptr noundef, i32 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" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"_cpSMS4_CCM", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 28, !8, i64 32, !8, i64 48, !8, i64 64, !8, i64 80, !8, i64 96, !8, i64 112}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !7, i64 24}
!12 = !{!6, !10, i64 16}
!13 = !{!7, !7, i64 0}


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