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

; 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] }

@RijEncSbox = external constant [256 x i8], align 64

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

16:                                               ; preds = %4
  store i32 -8, ptr %5, align 4
  br label %93

17:                                               ; preds = %4
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = call i32 @cpSizeofCtx_AESGCM()
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  store i32 -9, ptr %5, align 4
  br label %93

22:                                               ; preds = %17
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call i64 @IPP_INT_PTR(ptr noundef %24)
  %26 = and i64 %25, 15
  %27 = xor i64 %26, -1
  %28 = add nsw i64 %27, 1
  %29 = and i64 %28, 15
  %30 = getelementptr inbounds i8, ptr %23, i64 %29
  store ptr %30, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = call i64 @IPP_UINT_PTR(ptr noundef %31)
  %33 = trunc i64 %32 to i32
  %34 = xor i32 1129136454, %33
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._cpAES_GCM, ptr %35, i32 0, i32 0
  store i32 %34, ptr %36, align 16, !tbaa !11
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = call i32 @ippsAES_GCMReset(ptr noundef %37)
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 16
  br i1 %40, label %41, label %48

41:                                               ; preds = %22
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = icmp ne i32 %42, 24
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = icmp ne i32 %45, 32
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  store i32 -15, ptr %5, align 4
  br label %93

48:                                               ; preds = %44, %41, %22
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  call void @cpAesGCM_setup_ptrs_and_methods(ptr noundef %49, i64 noundef %51)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._cpAES_GCM, ptr %54, i32 0, i32 15
  %56 = call i32 @cpSizeofCtx_AES()
  %57 = call i32 @ippsAESInit(ptr noundef %52, i32 noundef %53, ptr noundef %55, i32 noundef %56)
  store i32 %57, ptr %10, align 4, !tbaa !9
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = icmp ne i32 0, %58
  br i1 %59, label %60, label %62

60:                                               ; preds = %48
  %61 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %61, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %63

62:                                               ; preds = %48
  store i32 0, ptr %11, align 4
  br label %63

63:                                               ; preds = %62, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %64 = load i32, ptr %11, align 4
  switch i32 %64, label %95 [
    i32 0, label %65
    i32 1, label %93
  ]

65:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._cpAES_GCM, ptr %66, i32 0, i32 15
  store ptr %67, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._cpRijndael128, ptr %68, i32 0, i32 4
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  store ptr %70, ptr %13, align 8, !tbaa !5
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._cpAES_GCM, ptr %71, i32 0, i32 17
  %73 = getelementptr inbounds [16 x i8], ptr %72, i64 0, i64 0
  call void @PadBlock(i8 noundef zeroext 0, ptr noundef %73, i32 noundef 16)
  %74 = load ptr, ptr %13, align 8, !tbaa !5
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._cpAES_GCM, ptr %75, i32 0, i32 17
  %77 = getelementptr inbounds [16 x i8], ptr %76, i64 0, i64 0
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct._cpAES_GCM, ptr %78, i32 0, i32 17
  %80 = getelementptr inbounds [16 x i8], ptr %79, i64 0, i64 0
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._cpRijndael128, ptr %81, i32 0, i32 3
  %83 = load i32, ptr %82, align 4, !tbaa !16
  %84 = load ptr, ptr %12, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._cpRijndael128, ptr %84, i32 0, i32 8
  %86 = load ptr, ptr %85, align 8, !tbaa !17
  call void %74(ptr noundef %77, ptr noundef %80, i32 noundef %83, ptr noundef %86, ptr noundef @RijEncSbox)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct._cpAES_GCM, ptr %87, i32 0, i32 17
  %89 = getelementptr inbounds [16 x i8], ptr %88, i64 0, i64 0
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct._cpAES_GCM, ptr %90, i32 0, i32 17
  %92 = getelementptr inbounds [16 x i8], ptr %91, i64 0, i64 0
  call void @AesGcmPrecompute_table2K(ptr noundef %89, ptr noundef %92)
  store i32 0, ptr %5, align 4
  br label %93

93:                                               ; preds = %65, %63, %47, %21, %16
  %94 = load i32, ptr %5, align 4
  ret i32 %94

95:                                               ; preds = %63
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden i32 @cpSizeofCtx_AESGCM() #0

; 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

declare i32 @ippsAES_GCMReset(ptr noundef) #2

declare void @cpAesGCM_setup_ptrs_and_methods(ptr noundef, i64 noundef) #2

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

declare i32 @ippsAESInit(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpSizeofCtx_AES() #1

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

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

declare void @AesGcmPrecompute_table2K(ptr noundef, ptr noundef) #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 = { "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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_cpAES_GCM", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 16, !13, i64 24, !10, 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, !14, i64 144, !7, i64 720}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"_cpRijndael128", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !7, i64 72}
!15 = !{!14, !6, i64 16}
!16 = !{!14, !10, i64 12}
!17 = !{!14, !6, i64 48}


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

@RijEncSbox = external constant [256 x i8], align 64

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsAES_GCMInit(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %2, null
  br i1 %5, label %31, label %6

6:                                                ; preds = %4
  %7 = tail call i32 @cpSizeofCtx_AESGCM()
  %8 = icmp sgt i32 %7, %3
  br i1 %8, label %31, label %9

9:                                                ; preds = %6
  %10 = tail call i64 @IPP_INT_PTR(ptr noundef nonnull %2)
  %11 = sub i64 0, %10
  %12 = and i64 %11, 15
  %13 = getelementptr inbounds i8, ptr %2, i64 %12
  %14 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %13)
  %15 = trunc i64 %14 to i32
  %16 = xor i32 %15, 1129136454
  store i32 %16, ptr %13, align 16, !tbaa !5
  %17 = tail call i32 @ippsAES_GCMReset(ptr noundef nonnull %13) #3
  switch i32 %1, label %31 [
    i32 32, label %18
    i32 24, label %18
    i32 16, label %18
  ]

18:                                               ; preds = %9, %9, %9
  %19 = zext nneg i32 %1 to i64
  tail call void @cpAesGCM_setup_ptrs_and_methods(ptr noundef nonnull %13, i64 noundef %19) #3
  %20 = getelementptr inbounds i8, ptr %13, i64 144
  %21 = tail call i32 @cpSizeofCtx_AES()
  %22 = tail call i32 @ippsAESInit(ptr noundef %0, i32 noundef %1, ptr noundef nonnull %20, i32 noundef %21) #3
  %.not.not = icmp eq i32 %22, 0
  br i1 %.not.not, label %23, label %31

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %13, i64 160
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %13, i64 720
  tail call void @PadBlock(i8 noundef zeroext 0, ptr noundef nonnull %26, i32 noundef 16)
  %27 = getelementptr inbounds i8, ptr %13, i64 156
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = getelementptr inbounds i8, ptr %13, i64 192
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  tail call void %25(ptr noundef nonnull %26, ptr noundef nonnull %26, i32 noundef %28, ptr noundef %30, ptr noundef nonnull @RijEncSbox) #3
  tail call void @AesGcmPrecompute_table2K(ptr noundef nonnull %26, ptr noundef nonnull %26) #3
  br label %31

31:                                               ; preds = %18, %9, %6, %4, %23
  %.1 = phi i32 [ %22, %18 ], [ 0, %23 ], [ -8, %4 ], [ -9, %6 ], [ -15, %9 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @cpSizeofCtx_AESGCM() local_unnamed_addr #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

declare i32 @ippsAES_GCMReset(ptr noundef) local_unnamed_addr #2

declare void @cpAesGCM_setup_ptrs_and_methods(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @ippsAESInit(ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cpSizeofCtx_AES() local_unnamed_addr #1

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

declare void @AesGcmPrecompute_table2K(ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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 #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, !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}
!13 = !{!12, !11, i64 16}
!14 = !{!12, !7, i64 12}
!15 = !{!12, !11, i64 48}


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