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

; 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._cpAES_GCM = type { i32, i32, i64, i64, i64, i32, [12 x i8], [16 x i8], [16 x i8], [16 x i8], [16 x i8], ptr, ptr, ptr, ptr, %struct._cpRijndael128, [8 x i8], [16 x i8] }
%struct._cpRijndael128 = type { i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, [124 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsAES_GCMReset(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr null, %4
  br i1 %5, label %6, label %7

6:                                                ; preds = %1
  store i32 -8, ptr %2, align 4
  br label %48

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i64 @IPP_INT_PTR(ptr noundef %9)
  %11 = and i64 %10, 15
  %12 = xor i64 %11, -1
  %13 = add nsw i64 %12, 1
  %14 = and i64 %13, 15
  %15 = getelementptr inbounds i8, ptr %8, i64 %14
  store ptr %15, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._cpAES_GCM, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 16, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = call i64 @IPP_UINT_PTR(ptr noundef %19)
  %21 = trunc i64 %20 to i32
  %22 = xor i32 %18, %21
  %23 = icmp eq i32 %22, 1129136454
  br i1 %23, label %25, label %24

24:                                               ; preds = %7
  store i32 -13, ptr %2, align 4
  br label %48

25:                                               ; preds = %7
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._cpAES_GCM, ptr %26, i32 0, i32 1
  store i32 0, ptr %27, align 4, !tbaa !14
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._cpAES_GCM, ptr %28, i32 0, i32 2
  store i64 0, ptr %29, align 8, !tbaa !15
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._cpAES_GCM, ptr %30, i32 0, i32 3
  store i64 0, ptr %31, align 16, !tbaa !16
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._cpAES_GCM, ptr %32, i32 0, i32 4
  store i64 0, ptr %33, align 8, !tbaa !17
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._cpAES_GCM, ptr %34, i32 0, i32 5
  store i32 0, ptr %35, align 16, !tbaa !18
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._cpAES_GCM, ptr %36, i32 0, i32 7
  %38 = getelementptr inbounds [16 x i8], ptr %37, i64 0, i64 0
  call void @PadBlock(i8 noundef zeroext 0, ptr noundef %38, i32 noundef 16)
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._cpAES_GCM, ptr %39, i32 0, i32 9
  %41 = getelementptr inbounds [16 x i8], ptr %40, i64 0, i64 0
  call void @PadBlock(i8 noundef zeroext 0, ptr noundef %41, i32 noundef 16)
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._cpAES_GCM, ptr %42, i32 0, i32 8
  %44 = getelementptr inbounds [16 x i8], ptr %43, i64 0, i64 0
  call void @PadBlock(i8 noundef zeroext 0, ptr noundef %44, i32 noundef 16)
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._cpAES_GCM, ptr %45, i32 0, i32 10
  %47 = getelementptr inbounds [16 x i8], ptr %46, i64 0, i64 0
  call void @PadBlock(i8 noundef zeroext 0, ptr noundef %47, i32 noundef 16)
  store i32 0, ptr %2, align 4
  br label %48

48:                                               ; preds = %25, %24, %6
  %49 = load i32, ptr %2, align 4
  ret i32 %49
}

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @PadBlock(i8 noundef zeroext, 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" }

!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 = !{!"_cpAES_GCM", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !12, i64 24, !11, i64 32, !7, i64 48, !7, i64 64, !7, i64 80, !7, i64 96, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !13, i64 144, !7, i64 720}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"_cpRijndael128", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !11, i64 64, !11, i64 68, !7, i64 72}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !12, i64 8}
!16 = !{!10, !12, i64 16}
!17 = !{!10, !12, i64 24}
!18 = !{!10, !11, i64 32}


; 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 @ippsAES_GCMReset(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %19, label %3

3:                                                ; preds = %1
  %4 = tail call i64 @IPP_INT_PTR(ptr noundef nonnull %0)
  %5 = sub i64 0, %4
  %6 = and i64 %5, 15
  %7 = getelementptr inbounds i8, ptr %0, i64 %6
  %8 = load i32, ptr %7, align 16, !tbaa !5
  %9 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %7)
  %10 = trunc i64 %9 to i32
  %11 = xor i32 %8, %10
  %12 = icmp eq i32 %11, 1129136454
  br i1 %12, label %13, label %19

13:                                               ; preds = %3
  %14 = getelementptr inbounds i8, ptr %7, i64 4
  %15 = getelementptr inbounds i8, ptr %7, i64 48
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %14, i8 0, i64 32, i1 false)
  tail call void @PadBlock(i8 noundef zeroext 0, ptr noundef nonnull %15, i32 noundef 16)
  %16 = getelementptr inbounds i8, ptr %7, i64 80
  tail call void @PadBlock(i8 noundef zeroext 0, ptr noundef nonnull %16, i32 noundef 16)
  %17 = getelementptr inbounds i8, ptr %7, i64 64
  tail call void @PadBlock(i8 noundef zeroext 0, ptr noundef nonnull %17, i32 noundef 16)
  %18 = getelementptr inbounds i8, ptr %7, i64 96
  tail call void @PadBlock(i8 noundef zeroext 0, ptr noundef nonnull %18, i32 noundef 16)
  br label %19

19:                                               ; preds = %3, %1, %13
  %.0 = phi i32 [ 0, %13 ], [ -8, %1 ], [ -13, %3 ]
  ret i32 %.0
}

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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 = !{!"_cpAES_GCM", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !8, i64 48, !8, i64 64, !8, i64 80, !8, i64 96, !11, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !12, i64 144, !8, i64 720}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"_cpRijndael128", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !7, i64 64, !7, i64 68, !8, i64 72}


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