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

; 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._cpRijndael128 = type { i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, [124 x i32] }

@rij128nKeys = external hidden global [3 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsAESUnpack(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %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
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr null, %12
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp eq ptr null, %16
  br i1 %17, label %18, label %19

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

19:                                               ; preds = %15
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = call i32 @cpSizeofCtx_AES()
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %24

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

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %25, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._cpRijndael128, ptr %26, i32 0, i32 12
  %28 = getelementptr inbounds [124 x i32], ptr %27, i64 0, i64 0
  %29 = call i64 @IPP_INT_PTR(ptr noundef %28)
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i64 @IPP_INT_PTR(ptr noundef %30)
  %32 = sub nsw i64 %29, %31
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 496, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._cpRijndael128, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = call i32 @rij_index(i32 noundef %36)
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [3 x i32], ptr @rij128nKeys, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  store i32 %40, ptr %11, align 4, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !9
  call void @CopyBlock(ptr noundef %41, ptr noundef %42, i32 noundef %43)
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._cpRijndael128, ptr %44, i32 0, i32 12
  %46 = getelementptr inbounds [124 x i32], ptr %45, i64 0, i64 0
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._cpRijndael128, ptr %47, i32 0, i32 12
  %49 = getelementptr inbounds [124 x i32], ptr %48, i64 0, i64 0
  %50 = call i64 @IPP_INT_PTR(ptr noundef %49)
  %51 = and i64 %50, 15
  %52 = xor i64 %51, -1
  %53 = add nsw i64 %52, 1
  %54 = and i64 %53, 15
  %55 = getelementptr inbounds i8, ptr %46, i64 %54
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._cpRijndael128, ptr %56, i32 0, i32 8
  store ptr %55, ptr %57, align 8, !tbaa !13
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._cpRijndael128, ptr %58, i32 0, i32 8
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i32, ptr %60, i64 %62
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._cpRijndael128, ptr %64, i32 0, i32 9
  store ptr %63, ptr %65, align 8, !tbaa !14
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i8, ptr %66, i64 %68
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._cpRijndael128, ptr %70, i32 0, i32 8
  %72 = load ptr, ptr %71, align 8, !tbaa !13
  %73 = load i32, ptr %10, align 4, !tbaa !9
  %74 = sub nsw i32 %73, 16
  call void @CopyBlock(ptr noundef %69, ptr noundef %72, i32 noundef %74)
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = call i64 @IPP_UINT_PTR(ptr noundef %75)
  %77 = trunc i64 %76 to i32
  %78 = xor i32 542263626, %77
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._cpRijndael128, ptr %79, i32 0, i32 0
  store i32 %78, ptr %80, align 8, !tbaa !15
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._cpRijndael128, ptr %81, i32 0, i32 6
  store ptr null, ptr %82, align 8, !tbaa !16
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._cpRijndael128, ptr %83, i32 0, i32 7
  store ptr null, ptr %84, align 8, !tbaa !17
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %85

85:                                               ; preds = %24, %23, %18, %14
  %86 = load i32, ptr %4, align 4
  ret i32 %86
}

; 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.start.p0(i64 immarg, ptr nocapture) #2

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

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

; 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 4}
!12 = !{!"_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}
!13 = !{!12, !6, i64 48}
!14 = !{!12, !6, i64 56}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !6, i64 40}


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

@rij128nKeys = external hidden local_unnamed_addr global [3 x i32], align 4

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

6:                                                ; preds = %3
  %7 = tail call i32 @cpSizeofCtx_AES()
  %8 = icmp sgt i32 %7, %2
  br i1 %8, label %35, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %1, i64 72
  %11 = tail call i64 @IPP_INT_PTR(ptr noundef nonnull %10)
  %12 = tail call i64 @IPP_INT_PTR(ptr noundef nonnull %1)
  %13 = sub nsw i64 %11, %12
  %14 = trunc i64 %13 to i32
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = tail call i32 @rij_index(i32 noundef %16)
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [3 x i32], ptr @rij128nKeys, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !11
  tail call void @CopyBlock(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %14)
  %21 = tail call i64 @IPP_INT_PTR(ptr noundef nonnull %10)
  %22 = sub i64 0, %21
  %23 = and i64 %22, 15
  %24 = getelementptr inbounds i8, ptr %10, i64 %23
  %25 = getelementptr inbounds i8, ptr %1, i64 48
  store ptr %24, ptr %25, align 8, !tbaa !12
  %26 = sext i32 %20 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  %28 = getelementptr inbounds i8, ptr %1, i64 56
  store ptr %27, ptr %28, align 8, !tbaa !13
  %sext = shl i64 %13, 32
  %29 = ashr exact i64 %sext, 32
  %30 = getelementptr inbounds i8, ptr %0, i64 %29
  tail call void @CopyBlock(ptr noundef nonnull %30, ptr noundef nonnull %24, i32 noundef 480)
  %31 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %1)
  %32 = trunc i64 %31 to i32
  %33 = xor i32 %32, 542263626
  store i32 %33, ptr %1, align 8, !tbaa !14
  %34 = getelementptr inbounds i8, ptr %1, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %34, i8 0, i64 16, i1 false)
  br label %35

35:                                               ; preds = %6, %3, %9
  %.0 = phi i32 [ 0, %9 ], [ -8, %3 ], [ -15, %6 ]
  ret i32 %.0
}

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @rij_index(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 i64 @IPP_UINT_PTR(ptr 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 4}
!6 = !{!"_cpRijndael128", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !7, i64 68, !8, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !10, i64 48}
!13 = !{!6, !10, i64 56}
!14 = !{!6, !7, i64 0}


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